@devisfuture/mega-collection 1.1.11 → 1.1.14
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 +15 -9
- package/dist/{chunk-2FHKDZDF.mjs → chunk-MQLJXCPR.mjs} +1 -1
- package/dist/chunk-OZGQBUEM.mjs +1 -0
- package/dist/index.mjs +1 -1
- package/dist/merge/index.d.mts +4 -0
- package/dist/merge/index.mjs +1 -1
- package/dist/search/index.d.mts +1 -1
- package/dist/search/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-KMSFPZKF.mjs +0 -1
package/README.md
CHANGED
|
@@ -109,6 +109,11 @@ const engine = new MergeEngines<User>({
|
|
|
109
109
|
engine.search("john");
|
|
110
110
|
engine.sort([{ field: "age", direction: "asc" }]);
|
|
111
111
|
engine.filter([{ field: "city", values: ["Miami", "New York"] }]);
|
|
112
|
+
|
|
113
|
+
// clear indexes for one module
|
|
114
|
+
engine.clearIndexes("search");
|
|
115
|
+
engine.clearIndexes("sort");
|
|
116
|
+
engine.clearIndexes("filter");
|
|
112
117
|
```
|
|
113
118
|
|
|
114
119
|
---
|
|
@@ -210,14 +215,15 @@ Unified facade that composes all three engines around a shared dataset.
|
|
|
210
215
|
|
|
211
216
|
**Methods:**
|
|
212
217
|
|
|
213
|
-
| Method | Description
|
|
214
|
-
| ----------------------------------- |
|
|
215
|
-
| `search(query)` | Search all indexed fields
|
|
216
|
-
| `search(field, query)` | Search a specific field
|
|
217
|
-
| `sort(descriptors)` | Sort using stored dataset
|
|
218
|
-
| `sort(data, descriptors, inPlace?)` | Sort with an explicit dataset
|
|
219
|
-
| `filter(criteria)` | Filter using stored dataset
|
|
220
|
-
| `filter(data, criteria)` | Filter with an explicit dataset
|
|
218
|
+
| Method | Description |
|
|
219
|
+
| ----------------------------------- | --------------------------------------------------------------- |
|
|
220
|
+
| `search(query)` | Search all indexed fields |
|
|
221
|
+
| `search(field, query)` | Search a specific field |
|
|
222
|
+
| `sort(descriptors)` | Sort using stored dataset |
|
|
223
|
+
| `sort(data, descriptors, inPlace?)` | Sort with an explicit dataset |
|
|
224
|
+
| `filter(criteria)` | Filter using stored dataset |
|
|
225
|
+
| `filter(data, criteria)` | Filter with an explicit dataset |
|
|
226
|
+
| `clearIndexes(module)` | Clear indexes for one module (`"search"`, `"sort"`, `"filter"`) |
|
|
221
227
|
|
|
222
228
|
---
|
|
223
229
|
|
|
@@ -229,7 +235,7 @@ Trigram-based text search engine.
|
|
|
229
235
|
| ---------------------- | --------------------------------------- |
|
|
230
236
|
| `search(query)` | Search all indexed fields, deduplicated |
|
|
231
237
|
| `search(field, query)` | Search a specific indexed field |
|
|
232
|
-
| `
|
|
238
|
+
| `clearIndexes()` | Free memory |
|
|
233
239
|
|
|
234
240
|
### `FilterEngine<T>` (filter module)
|
|
235
241
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=3,f=12;function x(
|
|
1
|
+
var T=3,f=12;function x(h){let t=h.toLowerCase(),n=Math.min(T,t.length),e=t.length-n+1,r=new Array(e);for(let s=0;s<e;s++)r[s]=t.substring(s,s+n);return r}function m(h){let t=x(h);if(t.length<=f)return new Set(t);let n=new Set,e=t.length-1,r=f-1;for(let s=0;s<=r;s++){let i=Math.round(s*e/r);n.add(t[i]);}return n}function L(h,t){let n=h.get(t);if(n)return n;let e=new Set;return h.set(t,e),e}var y=class{constructor(t={}){this.ngramIndexes=new Map;this.data=[];if(this.minQueryLength=t.minQueryLength??1,!!t.data&&(this.data=t.data,!!t.fields?.length))for(let n of t.fields)this.buildIndex(t.data,n);}buildIndex(t,n){let e,r;if(Array.isArray(t))e=t,r=n;else {if(!this.data.length)throw new Error("TextSearchEngine: no dataset in memory. Either pass `data` in the constructor options, or call buildIndex(data, field).");e=this.data,r=t;}this.data=e;let s=new Map;for(let i=0,l=e.length;i<l;i++){let d=e[i][r];if(typeof d!="string")continue;let o=d.toLowerCase();for(let a=0,u=o.length;a<u;a++){let g=u-a,p=Math.min(T,g);for(let c=1;c<=p;c++){let I=o.substring(a,a+c);L(s,I).add(i);}}}return this.ngramIndexes.set(r,s),this}search(t,n){return n===void 0?this.searchAllFields(t):this.searchField(t,n)}normalizeQuery(t){return t.trim().toLowerCase()}searchAllFields(t){let n=[...this.ngramIndexes.keys()],e=this.normalizeQuery(t);if(!e)return this.data;if(e.length<this.minQueryLength)return this.data;if(!n.length)return this.searchAllFieldsLinear(e);let r=m(e);if(!r.size)return [];let s=new Set,i=[];for(let l of n)for(let d of this.searchFieldWithPreparedQuery(l,e,r))s.has(d)||(s.add(d),i.push(d));return i}searchField(t,n){let e=this.normalizeQuery(n);if(!e)return this.data;if(e.length<this.minQueryLength)return this.data;if(!this.ngramIndexes.size)return this.searchFieldLinear(t,e);let r=m(e);return r.size?this.searchFieldWithPreparedQuery(t,e,r):[]}searchFieldWithPreparedQuery(t,n,e){let r=this.ngramIndexes.get(t);if(!r)return [];let s=[];for(let o of e){let a=r.get(o);if(!a)return [];s.push(a);}s.sort((o,a)=>o.size-a.size);let i=s[0],l=s.length,d=[];for(let o of i){let a=true;for(let g=1;g<l;g++)if(!s[g].has(o)){a=false;break}if(!a)continue;let u=this.data[o][t];typeof u=="string"&&u.toLowerCase().includes(n)&&d.push(this.data[o]);}return d}searchAllFieldsLinear(t){if(!this.data.length)return [];let n=[];for(let e=0;e<this.data.length;e++){let r=this.data[e],s=false;for(let i of Object.values(r))if(typeof i=="string"&&i.toLowerCase().includes(t)){s=true;break}s&&n.push(r);}return n}searchFieldLinear(t,n){if(!this.data.length)return [];let e=[];for(let r=0;r<this.data.length;r++){let s=this.data[r][t];typeof s=="string"&&s.toLowerCase().includes(n)&&e.push(this.data[r]);}return e}clearIndexes(){this.ngramIndexes.clear(),this.data=[];}};export{y as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u=class{constructor(e){let{imports:t,data:n,...s}=e,a=new Set(t),r={},o={};for(let d of a){let h=d.prototype,c=this.getMethodNames(h);if(c.length===0)continue;let p=this.getModuleInitOptions(d.name,c,s),i=new d({data:n,...p}),g=this.getModuleName(c);g&&this.hasMethod(i,"clearIndexes")&&!o[g]&&(o[g]=i.clearIndexes.bind(i));for(let l of c)r[l]||this.hasMethod(i,l)&&(r[l]=i[l].bind(i));}this.engine=Object.keys(r).length>0?r:null,this.clearIndexMethods=o;}getModuleName(e){return e.includes("search")?"search":e.includes("sort")?"sort":e.includes("filter")?"filter":null}getModuleInitOptions(e,t,n){let s={},a=n[e];this.isRecord(a)&&Object.assign(s,a);for(let r of t){let o=n[r];this.isRecord(o)&&Object.assign(s,o);}return s}getMethodNames(e){let t=e;return Object.getOwnPropertyNames(t).filter(n=>n==="constructor"?false:typeof t[n]=="function")}hasMethod(e,t){return typeof e=="object"&&e!==null&&typeof e[t]=="function"}isRecord(e){return typeof e=="object"&&e!==null}callEngineMethod(e,t){let n=this.engine?.[e];if(!n)throw new Error(`MergeEngines: Method "${e}" is not available. Add module with method "${e}" to the \`imports\` array.`);return n(...t)}search(e,t){if(!this.engine?.search)throw new Error("MergeEngines: TextSearchEngine is not available. Add TextSearchEngine to the `imports` array.");return t===void 0?this.callEngineMethod("search",[e]):this.callEngineMethod("search",[e,t])}sort(e,t,n){if(!this.engine?.sort)throw new Error("MergeEngines: SortEngine is not available. Add SortEngine to the `imports` array.");return t===void 0?this.callEngineMethod("sort",[e]):this.callEngineMethod("sort",[e,t,n])}filter(e,t){if(!this.engine?.filter)throw new Error("MergeEngines: FilterEngine is not available. Add FilterEngine to the `imports` array.");return t===void 0?this.callEngineMethod("filter",[e]):this.callEngineMethod("filter",[e,t])}clearIndexes(e){let t=this.clearIndexMethods[e];if(t){t();return}let n={search:"TextSearchEngine",sort:"SortEngine",filter:"FilterEngine"};throw new Error(`MergeEngines: ${n[e]} is not available. Add ${n[e]} to the \`imports\` array.`)}};export{u as a};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as TextSearchEngine}from'./chunk-
|
|
1
|
+
export{a as TextSearchEngine}from'./chunk-MQLJXCPR.mjs';export{a as FilterEngine}from'./chunk-XFQ56UZU.mjs';export{a as SortEngine}from'./chunk-DBAABXBP.mjs';export{a as MergeEngines}from'./chunk-OZGQBUEM.mjs';
|
package/dist/merge/index.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ export { I as IndexableKey, a as SortDirection } from '../types-D24zQWME.mjs';
|
|
|
6
6
|
* sorting, and filtering operations on collections.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
type MergeModuleName = "search" | "sort" | "filter";
|
|
9
10
|
interface EngineConstructor {
|
|
10
11
|
new (options: Record<string, unknown>): object;
|
|
11
12
|
prototype: object;
|
|
@@ -21,11 +22,13 @@ interface MergeEnginesOptions<T extends CollectionItem> {
|
|
|
21
22
|
}
|
|
22
23
|
declare class MergeEngines<T extends CollectionItem> {
|
|
23
24
|
private readonly engine;
|
|
25
|
+
private readonly clearIndexMethods;
|
|
24
26
|
/**
|
|
25
27
|
* Creates a new MergeEngines instance with the given options.
|
|
26
28
|
* Collects all modules from imports.
|
|
27
29
|
*/
|
|
28
30
|
constructor(options: MergeEnginesOptions<T>);
|
|
31
|
+
private getModuleName;
|
|
29
32
|
/**
|
|
30
33
|
* Gets the initialization options for a module.
|
|
31
34
|
*/
|
|
@@ -49,6 +52,7 @@ declare class MergeEngines<T extends CollectionItem> {
|
|
|
49
52
|
sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[];
|
|
50
53
|
filter(criteria: FilterCriterion<T>[]): T[];
|
|
51
54
|
filter(data: T[], criteria: FilterCriterion<T>[]): T[];
|
|
55
|
+
clearIndexes(module: MergeModuleName): void;
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
export { CollectionItem, type EngineApi, type EngineConstructor, FilterCriterion, MergeEngines, type MergeEnginesOptions, SortDescriptor };
|
package/dist/merge/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as MergeEngines}from'../chunk-
|
|
1
|
+
export{a as MergeEngines}from'../chunk-OZGQBUEM.mjs';
|
package/dist/search/index.d.mts
CHANGED
|
@@ -46,7 +46,7 @@ declare class TextSearchEngine<T extends CollectionItem> {
|
|
|
46
46
|
* Searches a specific field linearly without index.
|
|
47
47
|
*/
|
|
48
48
|
private searchFieldLinear;
|
|
49
|
-
|
|
49
|
+
clearIndexes(): void;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export { CollectionItem, TextSearchEngine, type TextSearchEngineOptions };
|
package/dist/search/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as TextSearchEngine}from'../chunk-
|
|
1
|
+
export{a as TextSearchEngine}from'../chunk-MQLJXCPR.mjs';
|
package/package.json
CHANGED
package/dist/chunk-KMSFPZKF.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var l=class{constructor(n){let{imports:t,data:e,...i}=n,s=new Set(t),r={};for(let o of s){let d=o.prototype,a=this.getMethodNames(d);if(a.length===0)continue;let u=this.getModuleInitOptions(o.name,a,i),g=new o({data:e,...u});for(let c of a)r[c]||this.hasMethod(g,c)&&(r[c]=g[c].bind(g));}this.engine=Object.keys(r).length>0?r:null;}getModuleInitOptions(n,t,e){let i={},s=e[n];this.isRecord(s)&&Object.assign(i,s);for(let r of t){let o=e[r];this.isRecord(o)&&Object.assign(i,o);}return i}getMethodNames(n){let t=n;return Object.getOwnPropertyNames(t).filter(e=>e==="constructor"?false:typeof t[e]=="function")}hasMethod(n,t){return typeof n=="object"&&n!==null&&typeof n[t]=="function"}isRecord(n){return typeof n=="object"&&n!==null}callEngineMethod(n,t){let e=this.engine?.[n];if(!e)throw new Error(`MergeEngines: Method "${n}" is not available. Add module with method "${n}" to the \`imports\` array.`);return e(...t)}search(n,t){if(!this.engine?.search)throw new Error("MergeEngines: TextSearchEngine is not available. Add TextSearchEngine to the `imports` array.");return t===void 0?this.callEngineMethod("search",[n]):this.callEngineMethod("search",[n,t])}sort(n,t,e){if(!this.engine?.sort)throw new Error("MergeEngines: SortEngine is not available. Add SortEngine to the `imports` array.");return t===void 0?this.callEngineMethod("sort",[n]):this.callEngineMethod("sort",[n,t,e])}filter(n,t){if(!this.engine?.filter)throw new Error("MergeEngines: FilterEngine is not available. Add FilterEngine to the `imports` array.");return t===void 0?this.callEngineMethod("filter",[n]):this.callEngineMethod("filter",[n,t])}};export{l as a};
|