querier-ts 2.4.0 → 2.4.1

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,27 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.4.1
4
+
5
+ ### Summary
6
+
7
+ - [ ] Bug fixes
8
+ - [x] Code refactoring
9
+ - [ ] New features
10
+ - [x] Compatibility fixes
11
+ - [ ] Breaking changes
12
+
13
+ ### Code refactoring
14
+
15
+ - Removed redundant conditions and unecessary code.
16
+ - Optimized array iteration performance:
17
+ - Pre-allocate arrays to avoid dynamic resizing.
18
+ - Replace Array.map() and `for...of` with indexed `for` loops.
19
+ - Updated JSDoc for `Query`.
20
+
21
+ ### Compatibility fixes
22
+
23
+ - Updated development dependencies.
24
+
3
25
  ## v2.4.0
4
26
 
5
27
  ### Changes
@@ -1 +1 @@
1
- 'use strict';var S=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var F=n=>{throw TypeError(n)};var x=(n,e,t,r)=>{for(var o=$(e,t),i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(s(e,t,o))||o);return o&&S(e,t,o),o},h=(n,e)=>(t,r)=>e(t,r,n);var N=(n,e,t)=>e.has(n)||F("Cannot "+t);var l=(n,e,t)=>(N(n,e,"read from private field"),t?t.call(n):e.get(n)),y=(n,e,t)=>e.has(n)?F("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),p=(n,e,t,r)=>(N(n,e,"write to private field"),e.set(n,t),t);var O=n=>typeof n=="number";var b=class extends Error{constructor(e){super(e),this.name="InvalidArgumentError";}};var v=new WeakMap;function V(n,e){let t=v.get(n);t||(t=new Map,v.set(n,t));let r=t.get(e);return r||(r=[],t.set(e,r)),r}function k(n){return function(e,t,r){let o=V(e,t),i=o.find(s=>s.index===r);i?i.min=n:o.push({index:r,min:n});}}function P(n,e,t){let r=V(n,e),o=r.find(i=>i.index===t);o?o.integer=true:r.push({index:t,integer:true});}function C(n,e,t){let r=t.value;t.value=function(...o){let i=v.get(n)?.get(e)??[];for(let s of i){let u=o[s.index];if(s.min!==void 0&&(!O(u)||u<s.min))throw new b(`${String(u)} is not a valid argument to param ${s.index} on ${e}(). Expected value to be equal or greater than ${s.min}.`);if(s.max!==void 0&&(!O(u)||u>s.max))throw new b(`${String(u)} is not a valid argument to param ${s.index} on ${e}(). Expected value to be equal or less than ${s.max}.`);if(s.integer&&!Number.isSafeInteger(u))throw new b(`${String(u)} is not a valid argument to param ${s.index} on ${e}(). Expected value to be an integer.`)}return r.apply(this,o)};}var d=n=>typeof n=="object"&&n!==null;var j=(n,e)=>{if(n===e)return true;if(!d(n)||!d(e)||Array.isArray(n)!==Array.isArray(e))return false;let t=Object.keys(n),r=Object.keys(e);return t.length!==r.length?false:t.every(o=>Object.prototype.hasOwnProperty.call(e,o)&&j(n[o],e[o]))};var A=(n,e)=>n.length===e.length&&n.every((t,r)=>j(t,e[r]));function G(n){return Object.entries(n)}var m=n=>typeof n=="function";var w,g=class{static validate(e,t,r){for(let[o,i]of G(t))if(!this.validateColumnCondition(e,o,i,r??l(this,w)))return false;return true}static validateColumnCondition(e,t,r,o){if(o.ignoreNullValues&&r==null)return true;let i=e[t];return m(r)?r(i):Array.isArray(r)?Array.isArray(i)?A(i,r):false:d(r)?d(i)?this.validate(i,r):false:i===r}};w=new WeakMap,y(g,w,{ignoreNullValues:false});function B(n){return Object.keys(n).filter(e=>typeof n[e]!="function")}function L(n){let e=1,t=n;t.startsWith("-")&&(e=-1,t=t.slice(1));let r=t;return (o,i)=>{let s=o[r],u=i[r];return s==null&&u==null?0:s==null?1*e:u==null||s<u?-1*e:s>u?1*e:0}}function M(...n){return (e,t)=>{if(n.length===0)return 0;for(let r of n){let o=L(r)(e,t);if(o!==0)return o}return 0}}var a,f,T,c=class c{constructor(e){y(this,a,[]);y(this,f,0);y(this,T,null);p(this,a,[...e]);}static from(e){return new c(e)}select(...e){let t=[];for(let o of l(this,a)){let i={};for(let s of e)i[s]=o[s];t.push(i);}let r=new c(t);return this.cloneStateInto(r),r}map(e){let t=[];for(let o of l(this,a))t.push(e(o));let r=new c(t);return this.cloneStateInto(r),r}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(M(...e))),this}skip(e){return p(this,f,e),this}limit(e){return p(this,T,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 t=this.getFirstColumn();if(!t)return [];e=t;}return this.getLimitedRows().map(t=>t[e])}values(){let e=[];for(let t of this.getLimitedRows())e.push(Object.values(t));return e}groupBy(e,t){let r=this.getLimitedRows(),o=new Map,i=m(e);for(let s of r){let u=i?e(s):s[e],K=t?t(s):s;o.has(u)?o.get(u).push(K):o.set(u,[K]);}return o}min(e){let t=this.getLimitedRows();if(t.length===0)return null;let r=m(e)?t.map(o=>e(o)):t.map(o=>o[e]);return r.length===0?null:Math.min(...r)}max(e){let t=this.getLimitedRows();if(t.length===0)return null;let r=m(e)?t.map(o=>e(o)):t.map(o=>o[e]);return r.length===0?null:Math.max(...r)}sum(e){let t=this.getLimitedRows();return t.length===0?0:(m(e)?t.map(o=>e(o)):t.map(o=>o[e])).reduce((o,i)=>o+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 i=0;i<r.length;i++){let s=r[i];e(s)&&o.push(s);}else for(let i=0;i<r.length;i++){let s=r[i];g.validate(s,e,t)&&o.push(s);}p(this,a,o);}getFirstColumn(){let e=this.first();if(!e)return null;let t=B(e);return t.length>0?t[0]:null}getLimitedRows(){let e=[...l(this,a)];return e.slice(l(this,f),l(this,f)+(l(this,T)??e.length))}cloneStateInto(e){p(e,f,l(this,f)),p(e,T,l(this,T));}};a=new WeakMap,f=new WeakMap,T=new WeakMap,x([C,h(0,P),h(0,k(0))],c.prototype,"skip"),x([C,h(0,P),h(0,k(0))],c.prototype,"limit");var R=c;exports.Query=R;
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;
@@ -34,50 +34,49 @@ type KeysOfType<T, TValue> = {
34
34
  }[keyof T];
35
35
 
36
36
  /**
37
- * Allows filtering data from an array of objects.
37
+ * A fluent, immutable-like query builder for in-memory collections.
38
38
  *
39
- * @example
40
- * ```ts
41
- * interface User {
42
- * id: string;
43
- * email: string;
44
- * isActive: boolean;
45
- * createdAt: string;
46
- * updatedAt: string;
47
- * }
39
+ * Provides a set of methods to filter, transform, group, aggregate and
40
+ * retrieve data from an array of objects, inspired by database query APIs.
48
41
  *
49
- * const users: User[] = [];
42
+ * All transformation methods (e.g. `select`, `map`) return a new `Query`
43
+ * instance, preserving the original query state. Filtering and stateful
44
+ * operations (e.g. `where`, `orderBy`, `skip`, `limit`) mutate the current instance.
50
45
  *
51
- * // Filtering objects
46
+ * @typeParam T - The shape of the objects being queried.
52
47
  *
53
- * const activeGmailUsers = Query.from(users)
48
+ * @example
49
+ * ```ts
50
+ * const results = Query.from(users)
54
51
  * .where({
55
- * isActive: true,
56
- * email: (email) => email.endsWith('@gmail.com'),
57
- * })
58
- * .all();
59
- *
60
- * // Selecting specific data
61
- *
62
- * const userEmails = Query.from(users)
63
- * .select('email')
64
- * .column();
65
- *
66
- * const lastUserId = Query.from(users)
67
- * .select('id')
52
+ * active: true,
53
+ * email: (email) => email.endsWith('@example.com'),
54
+ * })
68
55
  * .orderBy('-createdAt')
69
- * .scalar();
70
- *
71
- * // Checking information
56
+ * .select('id', 'name')
57
+ * .skip(10)
58
+ * .limit(5)
59
+ * .all();
60
+ * ```
72
61
  *
73
- * const userExists = Query.from(users)
74
- * .where({
75
- * id: 'some-id',
76
- * })
77
- * .exists();
62
+ * @example
63
+ * ```ts
64
+ * const total = Query.from(products)
65
+ * .where(p => p.category === 'books')
66
+ * .sum('price');
67
+ * ```
78
68
  *
79
- * const numberOfUsers = Query.from(users).count();
69
+ * @example
70
+ * ```ts
71
+ * const grouped = Query.from(users)
72
+ * .groupBy('role');
73
+ * // Map<Role, User[]>
80
74
  * ```
75
+ *
76
+ * @remarks
77
+ * - All operations are performed in memory.
78
+ * - Ordering is applied to the current dataset at the moment `orderBy` is called.
79
+ * - `skip` and `limit` are only applied when retrieving results (`all`, `first`, etc.).
81
80
  */
82
81
  declare class Query<T extends object> {
83
82
  #private;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- var S=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var F=n=>{throw TypeError(n)};var x=(n,e,t,r)=>{for(var o=$(e,t),i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(s(e,t,o))||o);return o&&S(e,t,o),o},h=(n,e)=>(t,r)=>e(t,r,n);var N=(n,e,t)=>e.has(n)||F("Cannot "+t);var l=(n,e,t)=>(N(n,e,"read from private field"),t?t.call(n):e.get(n)),y=(n,e,t)=>e.has(n)?F("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),p=(n,e,t,r)=>(N(n,e,"write to private field"),e.set(n,t),t);var O=n=>typeof n=="number";var b=class extends Error{constructor(e){super(e),this.name="InvalidArgumentError";}};var v=new WeakMap;function V(n,e){let t=v.get(n);t||(t=new Map,v.set(n,t));let r=t.get(e);return r||(r=[],t.set(e,r)),r}function k(n){return function(e,t,r){let o=V(e,t),i=o.find(s=>s.index===r);i?i.min=n:o.push({index:r,min:n});}}function P(n,e,t){let r=V(n,e),o=r.find(i=>i.index===t);o?o.integer=true:r.push({index:t,integer:true});}function C(n,e,t){let r=t.value;t.value=function(...o){let i=v.get(n)?.get(e)??[];for(let s of i){let u=o[s.index];if(s.min!==void 0&&(!O(u)||u<s.min))throw new b(`${String(u)} is not a valid argument to param ${s.index} on ${e}(). Expected value to be equal or greater than ${s.min}.`);if(s.max!==void 0&&(!O(u)||u>s.max))throw new b(`${String(u)} is not a valid argument to param ${s.index} on ${e}(). Expected value to be equal or less than ${s.max}.`);if(s.integer&&!Number.isSafeInteger(u))throw new b(`${String(u)} is not a valid argument to param ${s.index} on ${e}(). Expected value to be an integer.`)}return r.apply(this,o)};}var d=n=>typeof n=="object"&&n!==null;var j=(n,e)=>{if(n===e)return true;if(!d(n)||!d(e)||Array.isArray(n)!==Array.isArray(e))return false;let t=Object.keys(n),r=Object.keys(e);return t.length!==r.length?false:t.every(o=>Object.prototype.hasOwnProperty.call(e,o)&&j(n[o],e[o]))};var A=(n,e)=>n.length===e.length&&n.every((t,r)=>j(t,e[r]));function G(n){return Object.entries(n)}var m=n=>typeof n=="function";var w,g=class{static validate(e,t,r){for(let[o,i]of G(t))if(!this.validateColumnCondition(e,o,i,r??l(this,w)))return false;return true}static validateColumnCondition(e,t,r,o){if(o.ignoreNullValues&&r==null)return true;let i=e[t];return m(r)?r(i):Array.isArray(r)?Array.isArray(i)?A(i,r):false:d(r)?d(i)?this.validate(i,r):false:i===r}};w=new WeakMap,y(g,w,{ignoreNullValues:false});function B(n){return Object.keys(n).filter(e=>typeof n[e]!="function")}function L(n){let e=1,t=n;t.startsWith("-")&&(e=-1,t=t.slice(1));let r=t;return (o,i)=>{let s=o[r],u=i[r];return s==null&&u==null?0:s==null?1*e:u==null||s<u?-1*e:s>u?1*e:0}}function M(...n){return (e,t)=>{if(n.length===0)return 0;for(let r of n){let o=L(r)(e,t);if(o!==0)return o}return 0}}var a,f,T,c=class c{constructor(e){y(this,a,[]);y(this,f,0);y(this,T,null);p(this,a,[...e]);}static from(e){return new c(e)}select(...e){let t=[];for(let o of l(this,a)){let i={};for(let s of e)i[s]=o[s];t.push(i);}let r=new c(t);return this.cloneStateInto(r),r}map(e){let t=[];for(let o of l(this,a))t.push(e(o));let r=new c(t);return this.cloneStateInto(r),r}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(M(...e))),this}skip(e){return p(this,f,e),this}limit(e){return p(this,T,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 t=this.getFirstColumn();if(!t)return [];e=t;}return this.getLimitedRows().map(t=>t[e])}values(){let e=[];for(let t of this.getLimitedRows())e.push(Object.values(t));return e}groupBy(e,t){let r=this.getLimitedRows(),o=new Map,i=m(e);for(let s of r){let u=i?e(s):s[e],K=t?t(s):s;o.has(u)?o.get(u).push(K):o.set(u,[K]);}return o}min(e){let t=this.getLimitedRows();if(t.length===0)return null;let r=m(e)?t.map(o=>e(o)):t.map(o=>o[e]);return r.length===0?null:Math.min(...r)}max(e){let t=this.getLimitedRows();if(t.length===0)return null;let r=m(e)?t.map(o=>e(o)):t.map(o=>o[e]);return r.length===0?null:Math.max(...r)}sum(e){let t=this.getLimitedRows();return t.length===0?0:(m(e)?t.map(o=>e(o)):t.map(o=>o[e])).reduce((o,i)=>o+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 i=0;i<r.length;i++){let s=r[i];e(s)&&o.push(s);}else for(let i=0;i<r.length;i++){let s=r[i];g.validate(s,e,t)&&o.push(s);}p(this,a,o);}getFirstColumn(){let e=this.first();if(!e)return null;let t=B(e);return t.length>0?t[0]:null}getLimitedRows(){let e=[...l(this,a)];return e.slice(l(this,f),l(this,f)+(l(this,T)??e.length))}cloneStateInto(e){p(e,f,l(this,f)),p(e,T,l(this,T));}};a=new WeakMap,f=new WeakMap,T=new WeakMap,x([C,h(0,P),h(0,k(0))],c.prototype,"skip"),x([C,h(0,P),h(0,k(0))],c.prototype,"limit");var R=c;export{R as Query};
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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "querier-ts",
3
3
  "type": "module",
4
- "version": "2.4.0",
4
+ "version": "2.4.1",
5
5
  "description": "A lightweight, type-safe in-memory query engine for JavaScript and TypeScript",
6
6
  "repository": {
7
7
  "type": "git",
@@ -61,7 +61,7 @@
61
61
  "devDependencies": {
62
62
  "@eslint/js": "^10.0.1",
63
63
  "@vitest/coverage-v8": "^4.1.2",
64
- "eslint": "^10.0.3",
64
+ "eslint": "^10.1.0",
65
65
  "eslint-config-prettier": "^10.1.8",
66
66
  "eslint-plugin-prettier": "^5.5.5",
67
67
  "globals": "^17.4.0",
@@ -72,7 +72,8 @@
72
72
  "prettier-plugin-organize-imports": "^4.3.0",
73
73
  "tsup": "^8.5.1",
74
74
  "typescript": "~5.9.3",
75
- "typescript-eslint": "^8.57.1",
75
+ "typescript-eslint": "^8.58.0",
76
76
  "vitest": "^4.1.2"
77
- }
77
+ },
78
+ "packageManager": "pnpm@10.33.0"
78
79
  }