querier-ts 1.0.2 → 2.0.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/README.md CHANGED
@@ -1,49 +1,29 @@
1
- # query-ts
2
-
3
- A package that allows you to query data from an array of objects.
4
-
5
- ## Introduction
6
-
7
- The following data will be used in the samples of this documentation:
8
-
9
- ```ts
10
- interface UserPermissions {
11
- useCookies: boolean;
12
- sendNotifications: boolean;
13
- }
14
-
15
- class User {
16
- id: number;
17
- name: string;
18
- permissions: UserPermissions;
19
- isActive: boolean;
20
- createdAt: Date;
21
- updatedAt: Date;
22
-
23
- isAdmin(): boolean {
24
- ...
25
- }
26
- }
27
-
28
- const users: User[] = [
29
- ...
30
- ];
31
- ```
1
+ <h1 align="center">
2
+ querier-ts
3
+ </h1>
4
+ <p align="center">
5
+ A lightweight, type-safe in-memory query engine for JavaScript and TypeScript.
6
+ <p>
7
+ <p align="center">
8
+ <a href="https://npmx.dev/package/querier-ts"><img src="https://img.shields.io/npm/v/querier-ts?color=729B1B&label=" alt="current querier-ts version badge"></a>
9
+ <p>
32
10
 
33
11
  ## `Query`
34
12
 
35
- A `Query` can be created this way:
13
+ You can create a `Query` instance like this:
36
14
 
37
15
  ```ts
38
16
  const usersQuery = Query.from(users);
39
17
  ```
40
18
 
41
- TypeScript will automatically assume that the query data type is `User`. You can make it explicit:
19
+ TypeScript will automatically infer the query data type. You can also make it explicit:
42
20
 
43
21
  ```ts
44
22
  const usersQuery = Query.from<User>(users);
45
23
  ```
46
24
 
25
+ ---
26
+
47
27
  ### Getting results
48
28
 
49
29
  #### `all()`
@@ -66,16 +46,18 @@ Returns the number of results.
66
46
 
67
47
  Returns a boolean indicating whether any results exist.
68
48
 
49
+ ---
50
+
69
51
  ### Filtering data
70
52
 
71
53
  #### `where(condition)`
72
54
 
73
- There are two types of parameters:
55
+ This method accepts two types of parameters:
74
56
 
75
- 1. An object where each property represents an attribute to be validated.
76
- 2. A callback function that returns a boolean validating the object.
57
+ 1. An object, where each property represents a field to be validated.
58
+ 2. A callback function that returns a boolean.
77
59
 
78
- When the condition is an object, you can pass literal values or callback functions to each attribute that needs to be validated.
60
+ When passing an object, each property can be either a literal value or a callback function used for validation.
79
61
 
80
62
  ```ts
81
63
  const activeGmailUsers = Query.from(users)
@@ -83,60 +65,68 @@ const activeGmailUsers = Query.from(users)
83
65
  isActive: true,
84
66
  email: (email) => email.endsWith('@gmail.com'),
85
67
  })
86
- .where((user) => (
87
- !user.isAdmin()
88
- ))
68
+ .where((user) => !user.isAdmin())
89
69
  .all();
90
70
  ```
91
71
 
92
- It also works on inner objects:
72
+ It also supports nested objects:
93
73
 
94
74
  ```ts
95
- .where({
96
- permissions: {
97
- sendNotifications: true,
98
- },
99
- })
75
+ .where({
76
+ permissions: {
77
+ sendNotifications: true,
78
+ },
79
+ })
100
80
  ```
101
81
 
82
+ ---
83
+
102
84
  #### `filterWhere(condition)`
103
85
 
104
- The difference of `filterWhere` is that it only accepts an object and it ignores conditions whose values are `null` or `undefined`.
86
+ Unlike `where()`, `filterWhere()`:
87
+
88
+ * Accepts only an object
89
+ * Ignores properties whose values are `null` or `undefined`
105
90
 
106
91
  ```ts
107
- let isActive: bool;
92
+ let isActive: boolean; // undefined
108
93
 
109
94
  const filteredUsers = Query.from(users)
110
95
  .filterWhere({
111
96
  id: 1,
112
- isActive: isActive, // condition for "isActive" will be ignored, because the variable is still undefined
97
+ isActive: isActive, // ignored
113
98
  })
114
99
  .all();
115
100
  ```
116
101
 
117
- >**Remember**: if you want to check if a value is really `null` or `undefined`, use `where()`.
102
+ > **Note:** If you need to explicitly check for `null` or `undefined`, use `where()` instead.
103
+
104
+ ---
118
105
 
119
106
  ### Selecting specific data
120
107
 
121
108
  #### `select(columns)`
122
109
 
123
- This method can be combined with `scalar()`, `column()`, or `values()`. It determines which columns should be selected.
110
+ Defines which columns should be selected.
111
+ It can be combined with `scalar()`, `column()`, or `values()`.
124
112
 
125
- It accepts a string containing a single column name or an array of column names.
113
+ Accepts either a string (single column) or an array of column names.
126
114
 
127
115
  ```ts
128
- .select('id')
116
+ .select('id')
129
117
  ```
130
118
 
119
+ ---
120
+
131
121
  #### `scalar()`
132
122
 
133
- It returns the value of the first property of the first object.
123
+ Returns the value of the first property of the first result.
134
124
 
135
125
  ```ts
136
126
  const firstId = Query.from(users).scalar();
137
127
  ```
138
128
 
139
- As mentioned above, it is possible to combine it with `select()` in order to get the value of another property.
129
+ You can combine it with `select()` to retrieve a specific property:
140
130
 
141
131
  ```ts
142
132
  const firstEmail = Query.from(users)
@@ -144,17 +134,25 @@ const firstEmail = Query.from(users)
144
134
  .scalar();
145
135
  ```
146
136
 
147
- `false` is returned where there is no value.
137
+ Returns `false` if no value is found.
138
+
139
+ ---
148
140
 
149
141
  #### `column()`
150
142
 
151
- It returns the values of the first properties of all objects.
143
+ Returns the values of the first property from all results by default.
152
144
 
153
145
  ```ts
154
146
  const ids = Query.from(users).column();
155
147
  ```
156
148
 
157
- You can also use it with `select()`:
149
+ You can specify a column:
150
+
151
+ ```ts
152
+ const emails = Query.from(users).column('email');
153
+ ```
154
+
155
+ Or combine it with `select()`:
158
156
 
159
157
  ```ts
160
158
  const emails = Query.from(users)
@@ -162,9 +160,11 @@ const emails = Query.from(users)
162
160
  .column();
163
161
  ```
164
162
 
163
+ ---
164
+
165
165
  #### `values()`
166
166
 
167
- It returns the values of all objects as arrays.
167
+ Returns all results as arrays of values.
168
168
 
169
169
  ```ts
170
170
  const data = Query.from(users)
@@ -172,7 +172,7 @@ const data = Query.from(users)
172
172
  .values();
173
173
  ```
174
174
 
175
- `data` would be something like this:
175
+ Example output:
176
176
 
177
177
  ```ts
178
178
  [
@@ -181,19 +181,21 @@ const data = Query.from(users)
181
181
  ]
182
182
  ```
183
183
 
184
+ ---
185
+
184
186
  ### Ordering results
185
187
 
186
188
  #### `orderBy(...columns)`
187
189
 
188
- Sorts the results. You can pass multiple arguments to it.
190
+ Sorts the results. You can pass multiple columns.
189
191
 
190
192
  ```ts
191
- .orderBy('name', 'id')
193
+ .orderBy('name', 'id')
192
194
  ```
193
195
 
194
- In the example above, `name` will have more priority than `id`.
196
+ In this example, `name` has higher priority than `id`.
195
197
 
196
- It is also possible to apply descending order:
198
+ You can also sort in descending order by prefixing the column with `-`:
197
199
 
198
200
  ```ts
199
201
  const lastId = Query.from(users)
@@ -202,24 +204,28 @@ const lastId = Query.from(users)
202
204
  .scalar();
203
205
  ```
204
206
 
207
+ ---
208
+
205
209
  ### Limiting results
206
210
 
207
211
  #### `limit(limit)`
208
212
 
209
- This method can be used to set a limit of results.
213
+ Limits the number of results returned.
210
214
 
211
215
  ```ts
212
- .limit(100)
216
+ .limit(100)
213
217
  ```
214
218
 
215
- >Passing a float or a negative number will throw an `InvalidArgumentError`.
219
+ > Passing a non-integer or a negative number will throw an `InvalidArgumentError`.
220
+
221
+ ---
216
222
 
217
223
  #### `skip(numberOfRows)`
218
224
 
219
225
  Skips the first results.
220
226
 
221
227
  ```ts
222
- .skip(5)
228
+ .skip(5)
223
229
  ```
224
230
 
225
231
  Example:
@@ -227,8 +233,8 @@ Example:
227
233
  ```ts
228
234
  const secondId = Query.from(users)
229
235
  .select('id')
230
- .skip(1) // skips the first user
236
+ .skip(1)
231
237
  .scalar();
232
238
  ```
233
239
 
234
- >Passing a float or a negative number will throw an `InvalidArgumentError`.
240
+ > Passing a non-integer or a negative number will throw an `InvalidArgumentError`.
@@ -0,0 +1,3 @@
1
+ import type { addPrefixToObject, PropertyOnly, PropOf } from '../../utils/types';
2
+ export type OrderingColumn<T extends object> = PropOf<T> | keyof addPrefixToObject<PropertyOnly<T>, '-'>;
3
+ //# sourceMappingURL=ordering-column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordering-column.d.ts","sourceRoot":"","sources":["../../../src/core/types/ordering-column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,MAAM,EACP,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IACvC,MAAM,CAAC,CAAC,CAAC,GACT,MAAM,iBAAiB,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ordering-column.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordering-column.js","sourceRoot":"","sources":["../../../src/core/types/ordering-column.ts"],"names":[],"mappings":""}
package/lib/query.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { QueryConditionsGroup, QueryConditionsGroupNullable } from './core/types';
2
- import type { addPrefixToObject, PropertyOnly, PropOf } from './utils/types';
2
+ import type { OrderingColumn } from './core/types/ordering-column';
3
+ import type { PropOf } from './utils/types';
3
4
  /**
4
5
  * Allows filtering data from an array of objects.
5
6
  *
@@ -74,7 +75,9 @@ export declare class Query<T extends object> {
74
75
  *
75
76
  * @returns Current query.
76
77
  */
77
- select(columns: PropOf<T> | PropOf<T>[]): this;
78
+ select<TColumns extends PropOf<T>[]>(...columns: TColumns): Query<{
79
+ [P in TColumns[number]]: T[P];
80
+ }>;
78
81
  /**
79
82
  * Applies conditions to the query.
80
83
  *
@@ -104,12 +107,36 @@ export declare class Query<T extends object> {
104
107
  /**
105
108
  * Adds ordering to the results.
106
109
  *
110
+ * This method should be called after `select()`; otherwise, the ordering will
111
+ * be applied only to the selected columns.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * // ❌ "age" will not be ordered, because it is not part of the selected columns
116
+ * const query = Query.from(users)
117
+ * .orderBy('-age')
118
+ * .select('name');
119
+ *
120
+ * // ✅ "age" will be ordered
121
+ * const query = Query.from(users)
122
+ * .select('name', 'age')
123
+ * .orderBy('-age');
124
+ * ```
125
+ *
107
126
  * @param columns Ascending or descending columns. To mark a field as
108
- * descending, use `-` before its name.
127
+ * descending, prefix it with `-`.
109
128
  *
110
129
  * @returns Current query.
111
130
  */
112
- orderBy(...columns: (PropOf<T> | keyof addPrefixToObject<PropertyOnly<T>, '-'>)[]): this;
131
+ orderBy(...columns: OrderingColumn<T>[]): this;
132
+ /**
133
+ * Groups the results by a specific key.
134
+ *
135
+ * @param key The key to group the results by.
136
+ *
137
+ * @returns A map with the grouped results.
138
+ */
139
+ groupBy<K extends keyof T>(key: K): Map<T[K], T[]>;
113
140
  /**
114
141
  * Returns the current number of rows.
115
142
  *
@@ -152,6 +179,7 @@ export declare class Query<T extends object> {
152
179
  * @returns Values from the first (selected) column.
153
180
  */
154
181
  column(): T[PropOf<T>][];
182
+ column<TColumn extends PropOf<T>>(column: TColumn): T[TColumn][];
155
183
  /**
156
184
  * Returns the values of the rows. If there are selected columns, only their
157
185
  * values will be returned.
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,MAAM,EAEP,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,KAAK,CAAC,CAAC,SAAS,MAAM;;IA0BjC;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAkB;IAE1C;;;;OAIG;IACH,OAAO;IAIP;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;IAIlD;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAM9C;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CA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;IAIjB;;;;OAIG;IACH,KAAK,IAAI,CAAC,GAAG,IAAI;IAMjB;;;;OAIG;IACH,IAAI,IAAI,CAAC,GAAG,IAAI;IAMhB;;;;OAIG;IACH,GAAG,IAAI,CAAC,EAAE;IAIV;;;;OAIG;IACH,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;IAO9B;;;;OAIG;IACH,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;IACxB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE;IAehE;;;;;OAKG;IACH,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;IAM1B;;;;;;;;;OASG;IAEH,IAAI,CAAkB,YAAY,EAAE,MAAM,GAAG,IAAI;IAMjD;;;;;;;;OAQG;IAEH,KAAK,CAAkB,KAAK,EAAE,MAAM,GAAG,IAAI;IAM3C;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAUtB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAgBtB;;;;OAIG;IACH,OAAO,CAAC,UAAU;IAUlB;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;CASpB"}
package/lib/query.js CHANGED
@@ -18,9 +18,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
18
18
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
19
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
20
  };
21
- var _Query_rows, _Query_columns, _Query_startAt, _Query_limit, _Query_sortFunction;
21
+ var _Query_rows, _Query_startAt, _Query_orderBy, _Query_limit;
22
22
  import { QueryRowValidator } from './core/validation';
23
23
  import { integer, min, validateNumbers } from './core/validation/decorators';
24
+ import { getObjectPropertyNames } from './utils/functions/generic/get-object-property-names';
24
25
  import { sortByProperties } from './utils/functions/sort';
25
26
  import { isFunction } from './utils/functions/type-guards';
26
27
  /**
@@ -80,22 +81,18 @@ export class Query {
80
81
  * Rows to be queried.
81
82
  */
82
83
  _Query_rows.set(this, []);
83
- /**
84
- * Selected columns.
85
- */
86
- _Query_columns.set(this, []);
87
84
  /**
88
85
  * Number of results to skip.
89
86
  */
90
87
  _Query_startAt.set(this, 0);
91
88
  /**
92
- * Limit of results.
89
+ * Columns to order the results by.
93
90
  */
94
- _Query_limit.set(this, void 0);
91
+ _Query_orderBy.set(this, []);
95
92
  /**
96
- * Function to order the results.
93
+ * Limit of results.
97
94
  */
98
- _Query_sortFunction.set(this, null);
95
+ _Query_limit.set(this, null);
99
96
  /**
100
97
  * Indicates whether conditions with `null` and `undefined` values should be
101
98
  * skipped.
@@ -120,9 +117,40 @@ export class Query {
120
117
  *
121
118
  * @returns Current query.
122
119
  */
123
- select(columns) {
124
- __classPrivateFieldSet(this, _Query_columns, Array.isArray(columns) ? columns : [columns], "f");
125
- return this;
120
+ select(...columns) {
121
+ // extract selected columns
122
+ const rows = [];
123
+ for (const row of __classPrivateFieldGet(this, _Query_rows, "f")) {
124
+ const result = {};
125
+ for (const column of columns) {
126
+ result[column] = row[column];
127
+ }
128
+ rows.push(result);
129
+ }
130
+ // create new query
131
+ const query = new Query(rows);
132
+ // copy ordering columns that are part of the selected columns
133
+ if (__classPrivateFieldGet(this, _Query_orderBy, "f").length > 0) {
134
+ const orderBy = [];
135
+ for (const orderingColumn of __classPrivateFieldGet(this, _Query_orderBy, "f")) {
136
+ if (columns.includes(orderingColumn)) {
137
+ orderBy.push(orderingColumn);
138
+ continue;
139
+ }
140
+ let normalizedColumn = orderingColumn.toString();
141
+ if (normalizedColumn.startsWith('-')) {
142
+ normalizedColumn = normalizedColumn.slice(1);
143
+ }
144
+ if (columns.includes(normalizedColumn)) {
145
+ orderBy.push(orderingColumn);
146
+ }
147
+ }
148
+ __classPrivateFieldSet(query, _Query_orderBy, orderBy, "f");
149
+ }
150
+ // copy the remaining query properties
151
+ __classPrivateFieldSet(query, _Query_startAt, __classPrivateFieldGet(this, _Query_startAt, "f"), "f");
152
+ __classPrivateFieldSet(query, _Query_limit, __classPrivateFieldGet(this, _Query_limit, "f"), "f");
153
+ return query;
126
154
  }
127
155
  /**
128
156
  * Applies conditions to the query.
@@ -161,15 +189,52 @@ export class Query {
161
189
  /**
162
190
  * Adds ordering to the results.
163
191
  *
192
+ * This method should be called after `select()`; otherwise, the ordering will
193
+ * be applied only to the selected columns.
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * // ❌ "age" will not be ordered, because it is not part of the selected columns
198
+ * const query = Query.from(users)
199
+ * .orderBy('-age')
200
+ * .select('name');
201
+ *
202
+ * // ✅ "age" will be ordered
203
+ * const query = Query.from(users)
204
+ * .select('name', 'age')
205
+ * .orderBy('-age');
206
+ * ```
207
+ *
164
208
  * @param columns Ascending or descending columns. To mark a field as
165
- * descending, use `-` before its name.
209
+ * descending, prefix it with `-`.
166
210
  *
167
211
  * @returns Current query.
168
212
  */
169
213
  orderBy(...columns) {
170
- __classPrivateFieldSet(this, _Query_sortFunction, columns.length > 0 ? sortByProperties(...columns) : null, "f");
214
+ __classPrivateFieldSet(this, _Query_orderBy, columns, "f");
171
215
  return this;
172
216
  }
217
+ /**
218
+ * Groups the results by a specific key.
219
+ *
220
+ * @param key The key to group the results by.
221
+ *
222
+ * @returns A map with the grouped results.
223
+ */
224
+ groupBy(key) {
225
+ const rows = this.getLimitedRows();
226
+ const map = new Map();
227
+ for (const row of rows) {
228
+ const index = row[key];
229
+ if (map.has(index)) {
230
+ map.get(index).push(row);
231
+ }
232
+ else {
233
+ map.set(index, [row]);
234
+ }
235
+ }
236
+ return map;
237
+ }
173
238
  /**
174
239
  * Returns the current number of rows.
175
240
  *
@@ -202,7 +267,7 @@ export class Query {
202
267
  */
203
268
  last() {
204
269
  const rows = this.getLimitedRows();
205
- return rows[this.count() - 1] ?? null;
270
+ return rows[rows.length - 1] ?? null;
206
271
  }
207
272
  /**
208
273
  * Returns all results.
@@ -220,21 +285,17 @@ export class Query {
220
285
  scalar() {
221
286
  const firstObject = this.first();
222
287
  const firstColumn = this.getFirstColumn();
223
- return firstObject && firstColumn
224
- ? (firstObject[firstColumn] ?? false)
225
- : false;
288
+ return firstObject && firstColumn ? firstObject[firstColumn] : false;
226
289
  }
227
- /**
228
- * Returns the values of the first (selected) column of all rows.
229
- *
230
- * @returns Values from the first (selected) column.
231
- */
232
- column() {
233
- const firstColumn = this.getFirstColumn();
234
- if (!firstColumn) {
235
- return [];
290
+ column(column) {
291
+ if (column === undefined) {
292
+ const firstColumn = this.getFirstColumn();
293
+ if (!firstColumn) {
294
+ return [];
295
+ }
296
+ column = firstColumn;
236
297
  }
237
- return this.getLimitedRows().map((row) => row[firstColumn]);
298
+ return this.getLimitedRows().map((row) => row[column]);
238
299
  }
239
300
  /**
240
301
  * Returns the values of the rows. If there are selected columns, only their
@@ -243,9 +304,7 @@ export class Query {
243
304
  * @returns Array with the values of all rows.
244
305
  */
245
306
  values() {
246
- return this.getLimitedRows().map((row) => __classPrivateFieldGet(this, _Query_columns, "f").length > 0
247
- ? __classPrivateFieldGet(this, _Query_columns, "f").map((column) => row[column])
248
- : Object.values(row));
307
+ return this.getLimitedRows().map((row) => Object.values(row));
249
308
  }
250
309
  /**
251
310
  * Defines the number of rows to skip.
@@ -281,10 +340,10 @@ export class Query {
281
340
  */
282
341
  getLimitedRows() {
283
342
  const rows = [...__classPrivateFieldGet(this, _Query_rows, "f")];
284
- if (__classPrivateFieldGet(this, _Query_sortFunction, "f") !== null) {
285
- rows.sort(__classPrivateFieldGet(this, _Query_sortFunction, "f"));
343
+ if (__classPrivateFieldGet(this, _Query_orderBy, "f").length > 0) {
344
+ rows.sort(sortByProperties(...__classPrivateFieldGet(this, _Query_orderBy, "f")));
286
345
  }
287
- return rows.slice(__classPrivateFieldGet(this, _Query_startAt, "f")).slice(0, __classPrivateFieldGet(this, _Query_limit, "f"));
346
+ return rows.slice(__classPrivateFieldGet(this, _Query_startAt, "f")).slice(0, __classPrivateFieldGet(this, _Query_limit, "f") ?? undefined);
288
347
  }
289
348
  /**
290
349
  * Returns the first selected column or the first key of some row.
@@ -292,11 +351,15 @@ export class Query {
292
351
  * @returns The first column or `null`, if none is selected or there is no row.
293
352
  */
294
353
  getFirstColumn() {
295
- if (__classPrivateFieldGet(this, _Query_columns, "f").length > 0) {
296
- return __classPrivateFieldGet(this, _Query_columns, "f")[0];
354
+ const firstRow = this.first();
355
+ if (!firstRow) {
356
+ return null;
297
357
  }
298
- const firstObject = this.first();
299
- return firstObject ? Object.keys(firstObject)[0] : null;
358
+ const columns = getObjectPropertyNames(firstRow);
359
+ if (columns.length > 0) {
360
+ return columns[0];
361
+ }
362
+ return null;
300
363
  }
301
364
  /**
302
365
  * Filters the rows according to the given conditions.
@@ -323,7 +386,7 @@ export class Query {
323
386
  });
324
387
  }
325
388
  }
326
- _Query_rows = new WeakMap(), _Query_columns = new WeakMap(), _Query_startAt = new WeakMap(), _Query_limit = new WeakMap(), _Query_sortFunction = new WeakMap();
389
+ _Query_rows = new WeakMap(), _Query_startAt = new WeakMap(), _Query_orderBy = new WeakMap(), _Query_limit = new WeakMap();
327
390
  __decorate([
328
391
  validateNumbers,
329
392
  __param(0, integer),
package/lib/query.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAQ3D;;;;;;;;;;;;;;;;;;;;;;;;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,oBAAO,IAAI,SAAS,CAAC,CAAC;IACtE,CAAC;IAED;;;;OAIG;IACK,cAAc;QACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAE9B,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;QAEjD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACK,UAAU,CAChB,SAAkE;QAElE,uBAAA,IAAI,eAAS,uBAAA,IAAI,mBAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CACrC,UAAU,CAAsB,SAAS,CAAC;YACxC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;YAChB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CACrC,MAAA,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACK,WAAW,CACjB,GAAM,EACN,SAA0C;QAE1C,OAAO,iBAAiB,CAAC,QAAQ,CAAC,GAAG,EAAE;YACrC,gBAAgB,EAAE,SAAS;YAC3B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;SACxC,CAAC,CAAC;IACL,CAAC;CACF;;AA1FC;IADC,eAAe;IACV,WAAA,OAAO,CAAA;IAAE,WAAA,GAAG,CAAC,CAAC,CAAC,CAAA;iCAIpB;AAYD;IADC,eAAe;IACT,WAAA,OAAO,CAAA;IAAE,WAAA,GAAG,CAAC,CAAC,CAAC,CAAA;kCAIrB"}
@@ -0,0 +1,3 @@
1
+ import type { PropOf } from '../../types';
2
+ export declare function getObjectPropertyNames<T extends object>(obj: T): PropOf<T>[];
3
+ //# sourceMappingURL=get-object-property-names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-object-property-names.d.ts","sourceRoot":"","sources":["../../../../src/utils/functions/generic/get-object-property-names.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAI5E"}
@@ -0,0 +1,4 @@
1
+ export function getObjectPropertyNames(obj) {
2
+ return Object.keys(obj).filter((key) => typeof obj[key] !== 'function');
3
+ }
4
+ //# sourceMappingURL=get-object-property-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-object-property-names.js","sourceRoot":"","sources":["../../../../src/utils/functions/generic/get-object-property-names.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,sBAAsB,CAAmB,GAAM;IAC7D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAC5B,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,CAAC,GAAc,CAAC,KAAK,UAAU,CACpC,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,23 +1,17 @@
1
1
  {
2
2
  "name": "querier-ts",
3
- "version": "1.0.2",
3
+ "version": "2.0.1",
4
4
  "description": "Query tool for analysing arrays of objects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
8
8
  "lib/**/*"
9
9
  ],
10
- "scripts": {
11
- "test": "jest --config jest.config.ts",
12
- "build": "tsc",
13
- "type-check": "tsc --noEmit",
14
- "format": "prettier --write \"src/**/*.ts\"",
15
- "lint": "eslint \"src/**/*.ts\" --fix",
16
- "prepare": "pnpm build",
17
- "prepublishOnly": "pnpm test && pnpm lint",
18
- "preversion": "pnpm lint",
19
- "version": "pnpm format && git add -A src",
20
- "postversion": "git push && git push --tags"
10
+ "lint-staged": {
11
+ "src/**/*.ts": [
12
+ "prettier --write",
13
+ "eslint --fix"
14
+ ]
21
15
  },
22
16
  "repository": {
23
17
  "type": "git",
@@ -42,17 +36,29 @@
42
36
  },
43
37
  "devDependencies": {
44
38
  "@eslint/js": "^10.0.1",
45
- "@types/jest": "^30.0.0",
39
+ "@vitest/coverage-v8": "^4.1.2",
46
40
  "eslint": "^10.0.3",
47
41
  "eslint-config-prettier": "^10.1.8",
48
42
  "eslint-plugin-prettier": "^5.5.5",
49
43
  "globals": "^17.4.0",
50
- "jest": "^30.3.0",
44
+ "husky": "^9.1.7",
51
45
  "jiti": "^2.6.1",
46
+ "lint-staged": "^16.4.0",
52
47
  "prettier": "^3.8.1",
53
48
  "prettier-plugin-organize-imports": "^4.3.0",
54
- "ts-jest": "^29.4.6",
55
49
  "typescript": "~5.9.3",
56
- "typescript-eslint": "^8.57.1"
50
+ "typescript-eslint": "^8.57.1",
51
+ "vitest": "^4.1.2"
52
+ },
53
+ "scripts": {
54
+ "test": "vitest",
55
+ "test:cov": "vitest --coverage",
56
+ "build": "tsc",
57
+ "type-check": "tsc --noEmit",
58
+ "format": "prettier --write \"src/**/*.ts\"",
59
+ "lint": "eslint \"src/**/*.ts\" --fix",
60
+ "preversion": "pnpm lint",
61
+ "version": "pnpm format && git add -A src",
62
+ "postversion": "git push && git push --tags"
57
63
  }
58
- }
64
+ }