querier-ts 2.4.1 → 2.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.5.0
4
+
5
+ ### Summary
6
+
7
+ - [ ] Bug fixes
8
+ - [x] Code refactoring
9
+ - [x] New features
10
+ - [x] Build and packaging updates
11
+ - [ ] Breaking changes
12
+
13
+ ### New features
14
+
15
+ - Added `distinct()` method to `Query`.
16
+
17
+ ### Code refactoring
18
+
19
+ - Improve conditions order in `column()` method.
20
+ - Added a new unit test for the `column()` method, covering no rows case.
21
+
22
+ ### Build and packaging updates
23
+
24
+ - Updated development dependencies.
25
+
3
26
  ## v2.4.1
4
27
 
5
28
  ### Summary
@@ -7,7 +30,7 @@
7
30
  - [ ] Bug fixes
8
31
  - [x] Code refactoring
9
32
  - [ ] New features
10
- - [x] Compatibility fixes
33
+ - [x] Compatibility improvements
11
34
  - [ ] Breaking changes
12
35
 
13
36
  ### Code refactoring
@@ -15,10 +38,10 @@
15
38
  - Removed redundant conditions and unecessary code.
16
39
  - Optimized array iteration performance:
17
40
  - Pre-allocate arrays to avoid dynamic resizing.
18
- - Replace Array.map() and `for...of` with indexed `for` loops.
41
+ - Replace `Array.map()` and `for...of` with indexed `for` loops.
19
42
  - Updated JSDoc for `Query`.
20
43
 
21
- ### Compatibility fixes
44
+ ### Compatibility improvements
22
45
 
23
46
  - Updated development dependencies.
24
47
 
package/README.md CHANGED
@@ -10,7 +10,7 @@ A lightweight, type-safe in-memory query engine for JavaScript and TypeScript.
10
10
 
11
11
  ## `Query`
12
12
 
13
- You can create a `Query` instance like this:
13
+ Usage:
14
14
 
15
15
  ```ts
16
16
  const usersQuery = Query.from(users);
@@ -79,6 +79,23 @@ const filteredUsers = Query.from(users)
79
79
 
80
80
  ---
81
81
 
82
+ #### `distinct(key | callback)`
83
+
84
+ Removes duplicate rows based on a key or a callback function.
85
+
86
+ - `key`: The key to be used for comparison.
87
+ - `callback`: A function that maps each row to a value.
88
+
89
+ ```ts
90
+ const uniqueCountries = Query.from(addresses)
91
+ .distinct('country')
92
+ .column('country');
93
+
94
+ const uniqueEmailProviders = Query.from(users)
95
+ .distinct((user) => user.email.split('@')[1])
96
+ .column('email');
97
+ ```
98
+
82
99
  ### Selecting data
83
100
 
84
101
  #### `select(columns)`
@@ -1 +1 @@
1
- 'use strict';var $=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var F=s=>{throw TypeError(s)};var O=(s,e,t,r)=>{for(var o=E(e,t),n=s.length-1,i;n>=0;n--)(i=s[n])&&(o=(i(e,t,o))||o);return o&&$(e,t,o),o},g=(s,e)=>(t,r)=>e(t,r,s);var N=(s,e,t)=>e.has(s)||F("Cannot "+t);var l=(s,e,t)=>(N(s,e,"read from private field"),e.get(s)),b=(s,e,t)=>e.has(s)?F("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),p=(s,e,t,r)=>(N(s,e,"write to private field"),e.set(s,t),t);var v=s=>typeof s=="number";var d=class extends Error{constructor(e){super(e),this.name="InvalidArgumentError";}};var k=new WeakMap;function V(s,e){let t=k.get(s);t||(t=new Map,k.set(s,t));let r=t.get(e);return r||(r=[],t.set(e,r)),r}function P(s){return function(e,t,r){let o=V(e,t),n=o.find(i=>i.index===r);n?n.min=s:o.push({index:r,min:s});}}function C(s,e,t){let r=V(s,e),o=r.find(n=>n.index===t);o?o.integer=true:r.push({index:t,integer:true});}function j(s,e,t){let r=t.value;t.value=function(...o){let n=k.get(s)?.get(e)??[];for(let i of n){let u=o[i.index];if(i.min!==void 0&&(!v(u)||u<i.min))throw new d(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or greater than ${i.min}.`);if(i.max!==void 0&&(!v(u)||u>i.max))throw new d(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or less than ${i.max}.`);if(i.integer&&!Number.isSafeInteger(u))throw new d(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be an integer.`)}return r.apply(this,o)};}var h=s=>typeof s=="object"&&s!==null;var R=(s,e)=>{if(s===e)return true;if(!h(s)||!h(e)||Array.isArray(s)!==Array.isArray(e))return false;let t=Object.keys(s),r=Object.keys(e);return t.length!==r.length?false:t.every(o=>Object.prototype.hasOwnProperty.call(e,o)&&R(s[o],e[o]))};var G=(s,e)=>s.length===e.length&&s.every((t,r)=>R(t,e[r]));function B(s){return Object.entries(s)}var m=s=>typeof s=="function";var x,w=class{static validate(e,t,r){for(let[o,n]of B(t))if(!this.validateColumnCondition(e,o,n,r??l(this,x)))return false;return true}static validateColumnCondition(e,t,r,o){if(o.ignoreNullValues&&r==null)return true;let n=e[t];return m(r)?r(n):Array.isArray(r)?Array.isArray(n)?G(n,r):false:h(r)?h(n)?this.validate(n,r):false:n===r}};x=new WeakMap,b(w,x,{ignoreNullValues:false});function L(s){return Object.keys(s).filter(e=>typeof s[e]!="function")}function M(s){let e=1,t=s;t.startsWith("-")&&(e=-1,t=t.slice(1));let r=t;return (o,n)=>{let i=o[r],u=n[r];return i==null&&u==null?0:i==null?1*e:u==null||i<u?-1*e:i>u?1*e:0}}function S(...s){return (e,t)=>{if(s.length===0)return 0;for(let r of s){let o=M(r)(e,t);if(o!==0)return o}return 0}}var a,f,y,c=class c{constructor(e){b(this,a,[]);b(this,f,0);b(this,y,null);p(this,a,[...e]);}static from(e){return new c(e)}select(...e){let t=l(this,a),r=t.length,o=new Array(r);for(let i=0;i<r;i++){let u={};for(let T of e)u[T]=t[i][T];o[i]=u;}let n=new c(o);return this.cloneStateInto(n),n}map(e){let t=l(this,a),r=t.length,o=new Array(r);for(let i=0;i<r;i++)o[i]=e(t[i]);let n=new c(o);return this.cloneStateInto(n),n}where(e){return this.filterRows(e),this}filterWhere(e){return this.filterRows(e,{ignoreNullValues:true}),this}orderBy(...e){return p(this,a,l(this,a).sort(S(...e))),this}skip(e){return p(this,f,e),this}limit(e){return p(this,y,e),this}all(){return this.getLimitedRows()}first(){let e=this.getLimitedRows();return e.length>0?e[0]:null}last(){let e=this.getLimitedRows();return e[e.length-1]??null}count(){return this.getLimitedRows().length}exists(){return this.count()>0}scalar(){let e=this.first(),t=this.getFirstColumn();return e&&t?e[t]:false}column(e){if(e===void 0){let n=this.getFirstColumn();if(!n)return [];e=n;}let t=this.getLimitedRows(),r=t.length;if(r===0)return [];let o=new Array(r);for(let n=0;n<r;n++)o[n]=t[n][e];return o}values(){let e=this.getLimitedRows(),t=e.length,r=new Array(t);for(let o=0;o<t;o++)r[o]=Object.values(e[o]);return r}groupBy(e,t){let r=this.getLimitedRows(),o=new Map,n=m(e);for(let i=0;i<r.length;i++){let u=r[i],T=n?e(u):u[e],K=t?t(u):u;o.has(T)?o.get(T).push(K):o.set(T,[K]);}return o}min(e){let t=this.getLimitedRows(),r=t.length;if(r===0)return null;let o=new Array(r);if(m(e))for(let n=0;n<r;n++)o[n]=e(t[n]);else for(let n=0;n<r;n++)o[n]=t[n][e];return Math.min(...o)}max(e){let t=this.getLimitedRows(),r=t.length;if(r===0)return null;let o=new Array(r);if(m(e))for(let n=0;n<r;n++)o[n]=e(t[n]);else for(let n=0;n<r;n++)o[n]=t[n][e];return Math.max(...o)}sum(e){let t=this.getLimitedRows(),r=t.length;if(r===0)return 0;let o=new Array(r);if(m(e))for(let n=0;n<r;n++)o[n]=e(t[n]);else for(let n=0;n<r;n++)o[n]=t[n][e];return o.reduce((n,i)=>n+i,0)}average(e){let t=this.count();return t===0?null:(m(e)?this.sum(e):this.sum(e))/t}filterRows(e,t){let r=l(this,a),o=[];if(m(e))for(let n=0;n<r.length;n++){let i=r[n];e(i)&&o.push(i);}else for(let n=0;n<r.length;n++){let i=r[n];w.validate(i,e,t)&&o.push(i);}p(this,a,o);}getFirstColumn(){let e=this.first();if(!e)return null;let t=L(e);return t.length>0?t[0]:null}getLimitedRows(){return l(this,a).slice(l(this,f),l(this,f)+(l(this,y)??l(this,a).length))}cloneStateInto(e){p(e,f,l(this,f)),p(e,y,l(this,y));}};a=new WeakMap,f=new WeakMap,y=new WeakMap,O([j,g(0,C),g(0,P(0))],c.prototype,"skip"),O([j,g(0,C),g(0,P(0))],c.prototype,"limit");var A=c;exports.Query=A;
1
+ 'use strict';var $=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var V=s=>{throw TypeError(s)};var O=(s,e,t,n)=>{for(var o=E(e,t),r=s.length-1,i;r>=0;r--)(i=s[r])&&(o=(i(e,t,o))||o);return o&&$(e,t,o),o},g=(s,e)=>(t,n)=>e(t,n,s);var F=(s,e,t)=>e.has(s)||V("Cannot "+t);var l=(s,e,t)=>(F(s,e,"read from private field"),e.get(s)),d=(s,e,t)=>e.has(s)?V("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),f=(s,e,t,n)=>(F(s,e,"write to private field"),e.set(s,t),t);var v=s=>typeof s=="number";var b=class extends Error{constructor(e){super(e),this.name="InvalidArgumentError";}};var k=new WeakMap;function N(s,e){let t=k.get(s);t||(t=new Map,k.set(s,t));let n=t.get(e);return n||(n=[],t.set(e,n)),n}function P(s){return function(e,t,n){let o=N(e,t),r=o.find(i=>i.index===n);r?r.min=s:o.push({index:n,min:s});}}function C(s,e,t){let n=N(s,e),o=n.find(r=>r.index===t);o?o.integer=true:n.push({index:t,integer:true});}function j(s,e,t){let n=t.value;t.value=function(...o){let r=k.get(s)?.get(e)??[];for(let i of r){let u=o[i.index];if(i.min!==void 0&&(!v(u)||u<i.min))throw new b(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or greater than ${i.min}.`);if(i.max!==void 0&&(!v(u)||u>i.max))throw new b(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or less than ${i.max}.`);if(i.integer&&!Number.isSafeInteger(u))throw new b(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be an integer.`)}return n.apply(this,o)};}var h=s=>typeof s=="object"&&s!==null;var R=(s,e)=>{if(s===e)return true;if(!h(s)||!h(e)||Array.isArray(s)!==Array.isArray(e))return false;let t=Object.keys(s),n=Object.keys(e);return t.length!==n.length?false:t.every(o=>Object.prototype.hasOwnProperty.call(e,o)&&R(s[o],e[o]))};var G=(s,e)=>s.length===e.length&&s.every((t,n)=>R(t,e[n]));function B(s){return Object.entries(s)}var m=s=>typeof s=="function";var x,w=class{static validate(e,t,n){for(let[o,r]of B(t))if(!this.validateColumnCondition(e,o,r,n??l(this,x)))return false;return true}static validateColumnCondition(e,t,n,o){if(o.ignoreNullValues&&n==null)return true;let r=e[t];return m(n)?n(r):Array.isArray(n)?Array.isArray(r)?G(r,n):false:h(n)?h(r)?this.validate(r,n):false:r===n}};x=new WeakMap,d(w,x,{ignoreNullValues:false});function S(s){return Object.keys(s).filter(e=>typeof s[e]!="function")}function L(s){let e=1,t=s;t.startsWith("-")&&(e=-1,t=t.slice(1));let n=t;return (o,r)=>{let i=o[n],u=r[n];return i==null&&u==null?0:i==null?1*e:u==null||i<u?-1*e:i>u?1*e:0}}function M(...s){return (e,t)=>{if(s.length===0)return 0;for(let n of s){let o=L(n)(e,t);if(o!==0)return o}return 0}}var a,c,y,T=class T{constructor(e){d(this,a,[]);d(this,c,0);d(this,y,null);f(this,a,[...e]);}static from(e){return new T(e)}select(...e){let t=l(this,a),n=t.length,o=new Array(n);for(let i=0;i<n;i++){let u={};for(let p of e)u[p]=t[i][p];o[i]=u;}let r=new T(o);return this.cloneStateInto(r),r}map(e){let t=l(this,a),n=t.length,o=new Array(n);for(let i=0;i<n;i++)o[i]=e(t[i]);let r=new T(o);return this.cloneStateInto(r),r}distinct(e){let t=new Set,n=[],o=l(this,a),r=m(e);for(let i=0;i<o.length;i++){let u=o[i],p=r?e(u):u[e];t.has(p)||(t.add(p),n.push(u));}return f(this,a,n),this}where(e){return this.filterRows(e),this}filterWhere(e){return this.filterRows(e,{ignoreNullValues:true}),this}orderBy(...e){return f(this,a,l(this,a).sort(M(...e))),this}skip(e){return f(this,c,e),this}limit(e){return f(this,y,e),this}all(){return this.getLimitedRows()}first(){let e=this.getLimitedRows();return e.length>0?e[0]:null}last(){let e=this.getLimitedRows();return e[e.length-1]??null}count(){return this.getLimitedRows().length}exists(){return this.count()>0}scalar(){let e=this.first(),t=this.getFirstColumn();return e&&t?e[t]:false}column(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return [];if(e===void 0){let r=this.getFirstColumn();if(!r)return [];e=r;}let o=new Array(n);for(let r=0;r<n;r++)o[r]=t[r][e];return o}values(){let e=this.getLimitedRows(),t=e.length,n=new Array(t);for(let o=0;o<t;o++)n[o]=Object.values(e[o]);return n}groupBy(e,t){let n=this.getLimitedRows(),o=new Map,r=m(e);for(let i=0;i<n.length;i++){let u=n[i],p=r?e(u):u[e],A=t?t(u):u;o.has(p)?o.get(p).push(A):o.set(p,[A]);}return o}min(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return null;let o=new Array(n);if(m(e))for(let r=0;r<n;r++)o[r]=e(t[r]);else for(let r=0;r<n;r++)o[r]=t[r][e];return Math.min(...o)}max(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return null;let o=new Array(n);if(m(e))for(let r=0;r<n;r++)o[r]=e(t[r]);else for(let r=0;r<n;r++)o[r]=t[r][e];return Math.max(...o)}sum(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return 0;let o=new Array(n);if(m(e))for(let r=0;r<n;r++)o[r]=e(t[r]);else for(let r=0;r<n;r++)o[r]=t[r][e];return o.reduce((r,i)=>r+i,0)}average(e){let t=this.count();return t===0?null:(m(e)?this.sum(e):this.sum(e))/t}filterRows(e,t){let n=l(this,a),o=[];if(m(e))for(let r=0;r<n.length;r++){let i=n[r];e(i)&&o.push(i);}else for(let r=0;r<n.length;r++){let i=n[r];w.validate(i,e,t)&&o.push(i);}f(this,a,o);}getFirstColumn(){let e=this.first();if(!e)return null;let t=S(e);return t.length>0?t[0]:null}getLimitedRows(){return l(this,a).slice(l(this,c),l(this,c)+(l(this,y)??l(this,a).length))}cloneStateInto(e){f(e,c,l(this,c)),f(e,y,l(this,y));}};a=new WeakMap,c=new WeakMap,y=new WeakMap,O([j,g(0,C),g(0,P(0))],T.prototype,"skip"),O([j,g(0,C),g(0,P(0))],T.prototype,"limit");var K=T;exports.Query=K;
@@ -111,6 +111,20 @@ declare class Query<T extends object> {
111
111
  * @returns New query with the mapped rows.
112
112
  */
113
113
  map<TReturn extends object>(callback: (obj: T) => TReturn): Query<TReturn>;
114
+ /**
115
+ * Removes duplicate rows based on a key.
116
+ *
117
+ * @param key Key to be used for comparison.
118
+ * @returns Current query.
119
+ */
120
+ distinct<K extends PropOf<T>>(key: K): this;
121
+ /**
122
+ * Removes duplicate rows based on a function.
123
+ *
124
+ * @param fn Function to be used for comparison.
125
+ * @returns Current query.
126
+ */
127
+ distinct<TValue>(fn: (row: T) => TValue): this;
114
128
  /**
115
129
  * Applies conditions to the query.
116
130
  *
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- var $=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var F=s=>{throw TypeError(s)};var O=(s,e,t,r)=>{for(var o=E(e,t),n=s.length-1,i;n>=0;n--)(i=s[n])&&(o=(i(e,t,o))||o);return o&&$(e,t,o),o},g=(s,e)=>(t,r)=>e(t,r,s);var N=(s,e,t)=>e.has(s)||F("Cannot "+t);var l=(s,e,t)=>(N(s,e,"read from private field"),e.get(s)),b=(s,e,t)=>e.has(s)?F("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),p=(s,e,t,r)=>(N(s,e,"write to private field"),e.set(s,t),t);var v=s=>typeof s=="number";var d=class extends Error{constructor(e){super(e),this.name="InvalidArgumentError";}};var k=new WeakMap;function V(s,e){let t=k.get(s);t||(t=new Map,k.set(s,t));let r=t.get(e);return r||(r=[],t.set(e,r)),r}function P(s){return function(e,t,r){let o=V(e,t),n=o.find(i=>i.index===r);n?n.min=s:o.push({index:r,min:s});}}function C(s,e,t){let r=V(s,e),o=r.find(n=>n.index===t);o?o.integer=true:r.push({index:t,integer:true});}function j(s,e,t){let r=t.value;t.value=function(...o){let n=k.get(s)?.get(e)??[];for(let i of n){let u=o[i.index];if(i.min!==void 0&&(!v(u)||u<i.min))throw new d(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or greater than ${i.min}.`);if(i.max!==void 0&&(!v(u)||u>i.max))throw new d(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or less than ${i.max}.`);if(i.integer&&!Number.isSafeInteger(u))throw new d(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be an integer.`)}return r.apply(this,o)};}var h=s=>typeof s=="object"&&s!==null;var R=(s,e)=>{if(s===e)return true;if(!h(s)||!h(e)||Array.isArray(s)!==Array.isArray(e))return false;let t=Object.keys(s),r=Object.keys(e);return t.length!==r.length?false:t.every(o=>Object.prototype.hasOwnProperty.call(e,o)&&R(s[o],e[o]))};var G=(s,e)=>s.length===e.length&&s.every((t,r)=>R(t,e[r]));function B(s){return Object.entries(s)}var m=s=>typeof s=="function";var x,w=class{static validate(e,t,r){for(let[o,n]of B(t))if(!this.validateColumnCondition(e,o,n,r??l(this,x)))return false;return true}static validateColumnCondition(e,t,r,o){if(o.ignoreNullValues&&r==null)return true;let n=e[t];return m(r)?r(n):Array.isArray(r)?Array.isArray(n)?G(n,r):false:h(r)?h(n)?this.validate(n,r):false:n===r}};x=new WeakMap,b(w,x,{ignoreNullValues:false});function L(s){return Object.keys(s).filter(e=>typeof s[e]!="function")}function M(s){let e=1,t=s;t.startsWith("-")&&(e=-1,t=t.slice(1));let r=t;return (o,n)=>{let i=o[r],u=n[r];return i==null&&u==null?0:i==null?1*e:u==null||i<u?-1*e:i>u?1*e:0}}function S(...s){return (e,t)=>{if(s.length===0)return 0;for(let r of s){let o=M(r)(e,t);if(o!==0)return o}return 0}}var a,f,y,c=class c{constructor(e){b(this,a,[]);b(this,f,0);b(this,y,null);p(this,a,[...e]);}static from(e){return new c(e)}select(...e){let t=l(this,a),r=t.length,o=new Array(r);for(let i=0;i<r;i++){let u={};for(let T of e)u[T]=t[i][T];o[i]=u;}let n=new c(o);return this.cloneStateInto(n),n}map(e){let t=l(this,a),r=t.length,o=new Array(r);for(let i=0;i<r;i++)o[i]=e(t[i]);let n=new c(o);return this.cloneStateInto(n),n}where(e){return this.filterRows(e),this}filterWhere(e){return this.filterRows(e,{ignoreNullValues:true}),this}orderBy(...e){return p(this,a,l(this,a).sort(S(...e))),this}skip(e){return p(this,f,e),this}limit(e){return p(this,y,e),this}all(){return this.getLimitedRows()}first(){let e=this.getLimitedRows();return e.length>0?e[0]:null}last(){let e=this.getLimitedRows();return e[e.length-1]??null}count(){return this.getLimitedRows().length}exists(){return this.count()>0}scalar(){let e=this.first(),t=this.getFirstColumn();return e&&t?e[t]:false}column(e){if(e===void 0){let n=this.getFirstColumn();if(!n)return [];e=n;}let t=this.getLimitedRows(),r=t.length;if(r===0)return [];let o=new Array(r);for(let n=0;n<r;n++)o[n]=t[n][e];return o}values(){let e=this.getLimitedRows(),t=e.length,r=new Array(t);for(let o=0;o<t;o++)r[o]=Object.values(e[o]);return r}groupBy(e,t){let r=this.getLimitedRows(),o=new Map,n=m(e);for(let i=0;i<r.length;i++){let u=r[i],T=n?e(u):u[e],K=t?t(u):u;o.has(T)?o.get(T).push(K):o.set(T,[K]);}return o}min(e){let t=this.getLimitedRows(),r=t.length;if(r===0)return null;let o=new Array(r);if(m(e))for(let n=0;n<r;n++)o[n]=e(t[n]);else for(let n=0;n<r;n++)o[n]=t[n][e];return Math.min(...o)}max(e){let t=this.getLimitedRows(),r=t.length;if(r===0)return null;let o=new Array(r);if(m(e))for(let n=0;n<r;n++)o[n]=e(t[n]);else for(let n=0;n<r;n++)o[n]=t[n][e];return Math.max(...o)}sum(e){let t=this.getLimitedRows(),r=t.length;if(r===0)return 0;let o=new Array(r);if(m(e))for(let n=0;n<r;n++)o[n]=e(t[n]);else for(let n=0;n<r;n++)o[n]=t[n][e];return o.reduce((n,i)=>n+i,0)}average(e){let t=this.count();return t===0?null:(m(e)?this.sum(e):this.sum(e))/t}filterRows(e,t){let r=l(this,a),o=[];if(m(e))for(let n=0;n<r.length;n++){let i=r[n];e(i)&&o.push(i);}else for(let n=0;n<r.length;n++){let i=r[n];w.validate(i,e,t)&&o.push(i);}p(this,a,o);}getFirstColumn(){let e=this.first();if(!e)return null;let t=L(e);return t.length>0?t[0]:null}getLimitedRows(){return l(this,a).slice(l(this,f),l(this,f)+(l(this,y)??l(this,a).length))}cloneStateInto(e){p(e,f,l(this,f)),p(e,y,l(this,y));}};a=new WeakMap,f=new WeakMap,y=new WeakMap,O([j,g(0,C),g(0,P(0))],c.prototype,"skip"),O([j,g(0,C),g(0,P(0))],c.prototype,"limit");var A=c;export{A as Query};
1
+ var $=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var V=s=>{throw TypeError(s)};var O=(s,e,t,n)=>{for(var o=E(e,t),r=s.length-1,i;r>=0;r--)(i=s[r])&&(o=(i(e,t,o))||o);return o&&$(e,t,o),o},g=(s,e)=>(t,n)=>e(t,n,s);var F=(s,e,t)=>e.has(s)||V("Cannot "+t);var l=(s,e,t)=>(F(s,e,"read from private field"),e.get(s)),d=(s,e,t)=>e.has(s)?V("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),f=(s,e,t,n)=>(F(s,e,"write to private field"),e.set(s,t),t);var v=s=>typeof s=="number";var b=class extends Error{constructor(e){super(e),this.name="InvalidArgumentError";}};var k=new WeakMap;function N(s,e){let t=k.get(s);t||(t=new Map,k.set(s,t));let n=t.get(e);return n||(n=[],t.set(e,n)),n}function P(s){return function(e,t,n){let o=N(e,t),r=o.find(i=>i.index===n);r?r.min=s:o.push({index:n,min:s});}}function C(s,e,t){let n=N(s,e),o=n.find(r=>r.index===t);o?o.integer=true:n.push({index:t,integer:true});}function j(s,e,t){let n=t.value;t.value=function(...o){let r=k.get(s)?.get(e)??[];for(let i of r){let u=o[i.index];if(i.min!==void 0&&(!v(u)||u<i.min))throw new b(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or greater than ${i.min}.`);if(i.max!==void 0&&(!v(u)||u>i.max))throw new b(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be equal or less than ${i.max}.`);if(i.integer&&!Number.isSafeInteger(u))throw new b(`${String(u)} is not a valid argument to param ${i.index} on ${e}(). Expected value to be an integer.`)}return n.apply(this,o)};}var h=s=>typeof s=="object"&&s!==null;var R=(s,e)=>{if(s===e)return true;if(!h(s)||!h(e)||Array.isArray(s)!==Array.isArray(e))return false;let t=Object.keys(s),n=Object.keys(e);return t.length!==n.length?false:t.every(o=>Object.prototype.hasOwnProperty.call(e,o)&&R(s[o],e[o]))};var G=(s,e)=>s.length===e.length&&s.every((t,n)=>R(t,e[n]));function B(s){return Object.entries(s)}var m=s=>typeof s=="function";var x,w=class{static validate(e,t,n){for(let[o,r]of B(t))if(!this.validateColumnCondition(e,o,r,n??l(this,x)))return false;return true}static validateColumnCondition(e,t,n,o){if(o.ignoreNullValues&&n==null)return true;let r=e[t];return m(n)?n(r):Array.isArray(n)?Array.isArray(r)?G(r,n):false:h(n)?h(r)?this.validate(r,n):false:r===n}};x=new WeakMap,d(w,x,{ignoreNullValues:false});function S(s){return Object.keys(s).filter(e=>typeof s[e]!="function")}function L(s){let e=1,t=s;t.startsWith("-")&&(e=-1,t=t.slice(1));let n=t;return (o,r)=>{let i=o[n],u=r[n];return i==null&&u==null?0:i==null?1*e:u==null||i<u?-1*e:i>u?1*e:0}}function M(...s){return (e,t)=>{if(s.length===0)return 0;for(let n of s){let o=L(n)(e,t);if(o!==0)return o}return 0}}var a,c,y,T=class T{constructor(e){d(this,a,[]);d(this,c,0);d(this,y,null);f(this,a,[...e]);}static from(e){return new T(e)}select(...e){let t=l(this,a),n=t.length,o=new Array(n);for(let i=0;i<n;i++){let u={};for(let p of e)u[p]=t[i][p];o[i]=u;}let r=new T(o);return this.cloneStateInto(r),r}map(e){let t=l(this,a),n=t.length,o=new Array(n);for(let i=0;i<n;i++)o[i]=e(t[i]);let r=new T(o);return this.cloneStateInto(r),r}distinct(e){let t=new Set,n=[],o=l(this,a),r=m(e);for(let i=0;i<o.length;i++){let u=o[i],p=r?e(u):u[e];t.has(p)||(t.add(p),n.push(u));}return f(this,a,n),this}where(e){return this.filterRows(e),this}filterWhere(e){return this.filterRows(e,{ignoreNullValues:true}),this}orderBy(...e){return f(this,a,l(this,a).sort(M(...e))),this}skip(e){return f(this,c,e),this}limit(e){return f(this,y,e),this}all(){return this.getLimitedRows()}first(){let e=this.getLimitedRows();return e.length>0?e[0]:null}last(){let e=this.getLimitedRows();return e[e.length-1]??null}count(){return this.getLimitedRows().length}exists(){return this.count()>0}scalar(){let e=this.first(),t=this.getFirstColumn();return e&&t?e[t]:false}column(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return [];if(e===void 0){let r=this.getFirstColumn();if(!r)return [];e=r;}let o=new Array(n);for(let r=0;r<n;r++)o[r]=t[r][e];return o}values(){let e=this.getLimitedRows(),t=e.length,n=new Array(t);for(let o=0;o<t;o++)n[o]=Object.values(e[o]);return n}groupBy(e,t){let n=this.getLimitedRows(),o=new Map,r=m(e);for(let i=0;i<n.length;i++){let u=n[i],p=r?e(u):u[e],A=t?t(u):u;o.has(p)?o.get(p).push(A):o.set(p,[A]);}return o}min(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return null;let o=new Array(n);if(m(e))for(let r=0;r<n;r++)o[r]=e(t[r]);else for(let r=0;r<n;r++)o[r]=t[r][e];return Math.min(...o)}max(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return null;let o=new Array(n);if(m(e))for(let r=0;r<n;r++)o[r]=e(t[r]);else for(let r=0;r<n;r++)o[r]=t[r][e];return Math.max(...o)}sum(e){let t=this.getLimitedRows(),n=t.length;if(n===0)return 0;let o=new Array(n);if(m(e))for(let r=0;r<n;r++)o[r]=e(t[r]);else for(let r=0;r<n;r++)o[r]=t[r][e];return o.reduce((r,i)=>r+i,0)}average(e){let t=this.count();return t===0?null:(m(e)?this.sum(e):this.sum(e))/t}filterRows(e,t){let n=l(this,a),o=[];if(m(e))for(let r=0;r<n.length;r++){let i=n[r];e(i)&&o.push(i);}else for(let r=0;r<n.length;r++){let i=n[r];w.validate(i,e,t)&&o.push(i);}f(this,a,o);}getFirstColumn(){let e=this.first();if(!e)return null;let t=S(e);return t.length>0?t[0]:null}getLimitedRows(){return l(this,a).slice(l(this,c),l(this,c)+(l(this,y)??l(this,a).length))}cloneStateInto(e){f(e,c,l(this,c)),f(e,y,l(this,y));}};a=new WeakMap,c=new WeakMap,y=new WeakMap,O([j,g(0,C),g(0,P(0))],T.prototype,"skip"),O([j,g(0,C),g(0,P(0))],T.prototype,"limit");var K=T;export{K as Query};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "querier-ts",
3
3
  "type": "module",
4
- "version": "2.4.1",
4
+ "version": "2.5.0",
5
5
  "description": "A lightweight, type-safe in-memory query engine for JavaScript and TypeScript",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/luizfilipezs/query-ts.git"
8
+ "url": "git+https://github.com/luizfilipezs/querier-ts.git"
9
9
  },
10
10
  "keywords": [
11
11
  "query",
@@ -19,9 +19,9 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "bugs": {
22
- "url": "https://github.com/luizfilipezs/query-ts/issues"
22
+ "url": "https://github.com/luizfilipezs/querier-ts/issues"
23
23
  },
24
- "homepage": "https://github.com/luizfilipezs/query-ts#readme",
24
+ "homepage": "https://github.com/luizfilipezs/querier-ts#readme",
25
25
  "files": [
26
26
  "dist",
27
27
  "README.md",