querier-ts 2.7.1 → 2.9.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,35 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.9.0
4
+
5
+ ### Summary
6
+
7
+ - [ ] Bug fixes
8
+ - [x] Refactoring
9
+ - [x] New features
10
+ - [ ] Breaking changes
11
+
12
+ ### New features
13
+
14
+ - Updated `Query.from()` method to accept `Iterable` and `ArrayLike` objects as input.
15
+
16
+ ### Refactoring
17
+
18
+ - Simplified `orderBy()` inner implementation without changing behavior.
19
+
20
+ ## v2.8.0
21
+
22
+ ### Summary
23
+
24
+ - [ ] Bug fixes
25
+ - [ ] Code refactoring
26
+ - [x] New features
27
+ - [ ] Breaking changes
28
+
29
+ ### New features
30
+
31
+ - Added row index as argument to `Query.map()` callback.
32
+
3
33
  ## v2.7.1
4
34
 
5
35
  ### Summary
@@ -10,9 +40,9 @@
10
40
  - [ ] New features
11
41
  - [ ] Breaking changes
12
42
 
13
- ### New features
43
+ ### Documentation updates
14
44
 
15
- - Update `README.md` documentation for `orderBy()` method with new overload and examples.
45
+ - Updated `README.md` documentation for `orderBy()` method with new overload and examples.
16
46
 
17
47
  ## v2.7.0
18
48
 
package/README.md CHANGED
@@ -5,7 +5,8 @@ querier-ts
5
5
  A lightweight, type-safe in-memory query engine for JavaScript and TypeScript.
6
6
  <p>
7
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>
8
+ <a href="https://www.npmjs.com/package/querier-ts"><img src="https://img.shields.io/npm/v/querier-ts.svg" alt="current querier-ts version badge"></a>
9
+ <a href="https://codecov.io/gh/luizfilipezs/querier-ts"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/luizfilipezs/querier-ts.svg?style=flat-square"></a>
9
10
  <p>
10
11
 
11
12
  ## `Query`
@@ -116,6 +117,11 @@ Transforms each row into a new object using a callback function.
116
117
 
117
118
  Like `select()`, this method is intended for data projection, but it is more flexible and better suited for complex transformations:
118
119
 
120
+ Callback arguments:
121
+
122
+ - `row`: The current row.
123
+ - `index`: The index of the current row.
124
+
119
125
 
120
126
  ```ts
121
127
  const authorsWithFirstPostQuery = Query.from(authors)
@@ -262,7 +262,7 @@ var _Query = class _Query {
262
262
  * @returns Query to the given rows.
263
263
  */
264
264
  static from(rows) {
265
- return new _Query(rows);
265
+ return new _Query(Array.from(rows));
266
266
  }
267
267
  /**
268
268
  * Defines specific columns to be returned on the final results.
@@ -295,7 +295,7 @@ var _Query = class _Query {
295
295
  const source = this.#rows;
296
296
  const rows = [];
297
297
  for (let i = 0; i < source.length; i++) {
298
- rows.push(callback(source[i]));
298
+ rows.push(callback(source[i], i));
299
299
  }
300
300
  const query = new _Query(rows);
301
301
  this.cloneStateInto(query);
@@ -350,16 +350,9 @@ var _Query = class _Query {
350
350
  return this;
351
351
  }
352
352
  orderBy(...arg) {
353
- if (arg.length === 0) {
354
- return this;
355
- }
356
- if (isFunction(arg[0])) {
357
- this.#rows = this.#rows.sort(
358
- sortByCallback(arg[0], arg[1] === "desc" ? -1 : 1)
359
- );
360
- } else {
353
+ if (arg.length > 0) {
361
354
  this.#rows = this.#rows.sort(
362
- sortByProperties(...arg)
355
+ isFunction(arg[0]) ? sortByCallback(arg[0], arg[1] === "desc" ? -1 : 1) : sortByProperties(...arg)
363
356
  );
364
357
  }
365
358
  return this;
@@ -1,3 +1,7 @@
1
+ type NotTuple<T> = T extends readonly [unknown, unknown] ? never : T;
2
+
3
+ type ArraySource<T> = Array<T> | Iterable<NotTuple<T>>;
4
+
1
5
  type addPrefixToObject<T, P extends string> = {
2
6
  [K in keyof T as K extends string ? `${P}${K}` : never]: T[K];
3
7
  };
@@ -93,7 +97,7 @@ declare class Query<T extends object> {
93
97
  *
94
98
  * @returns Query to the given rows.
95
99
  */
96
- static from<T extends object>(rows: T[]): Query<T>;
100
+ static from<T extends object>(rows: ArraySource<T>): Query<T>;
97
101
  /**
98
102
  * Defines specific columns to be returned on the final results.
99
103
  *
@@ -110,7 +114,7 @@ declare class Query<T extends object> {
110
114
  * @param callback Function to be called for each row.
111
115
  * @returns New query with the mapped rows.
112
116
  */
113
- map<TReturn extends object>(callback: (obj: T) => TReturn): Query<TReturn>;
117
+ map<TReturn extends object>(callback: (row: T, index: number) => TReturn): Query<TReturn>;
114
118
  /**
115
119
  * Removes duplicate rows based on a key.
116
120
  *
package/dist/esm/index.js CHANGED
@@ -260,7 +260,7 @@ var _Query = class _Query {
260
260
  * @returns Query to the given rows.
261
261
  */
262
262
  static from(rows) {
263
- return new _Query(rows);
263
+ return new _Query(Array.from(rows));
264
264
  }
265
265
  /**
266
266
  * Defines specific columns to be returned on the final results.
@@ -293,7 +293,7 @@ var _Query = class _Query {
293
293
  const source = this.#rows;
294
294
  const rows = [];
295
295
  for (let i = 0; i < source.length; i++) {
296
- rows.push(callback(source[i]));
296
+ rows.push(callback(source[i], i));
297
297
  }
298
298
  const query = new _Query(rows);
299
299
  this.cloneStateInto(query);
@@ -348,16 +348,9 @@ var _Query = class _Query {
348
348
  return this;
349
349
  }
350
350
  orderBy(...arg) {
351
- if (arg.length === 0) {
352
- return this;
353
- }
354
- if (isFunction(arg[0])) {
355
- this.#rows = this.#rows.sort(
356
- sortByCallback(arg[0], arg[1] === "desc" ? -1 : 1)
357
- );
358
- } else {
351
+ if (arg.length > 0) {
359
352
  this.#rows = this.#rows.sort(
360
- sortByProperties(...arg)
353
+ isFunction(arg[0]) ? sortByCallback(arg[0], arg[1] === "desc" ? -1 : 1) : sortByProperties(...arg)
361
354
  );
362
355
  }
363
356
  return this;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "querier-ts",
3
3
  "type": "module",
4
- "version": "2.7.1",
4
+ "version": "2.9.0",
5
5
  "description": "A lightweight, type-safe in-memory query engine for JavaScript and TypeScript",
6
6
  "repository": {
7
7
  "type": "git",
@@ -64,15 +64,16 @@
64
64
  "eslint": "^10.2.0",
65
65
  "eslint-config-prettier": "^10.1.8",
66
66
  "eslint-plugin-prettier": "^5.5.5",
67
- "globals": "^17.4.0",
67
+ "globals": "^17.5.0",
68
68
  "husky": "^9.1.7",
69
69
  "jiti": "^2.6.1",
70
70
  "lint-staged": "^16.4.0",
71
- "prettier": "^3.8.2",
71
+ "prettier": "^3.8.3",
72
72
  "prettier-plugin-organize-imports": "^4.3.0",
73
+ "tsd": "^0.33.0",
73
74
  "tsup": "^8.5.1",
74
75
  "typescript": "~5.9.3",
75
- "typescript-eslint": "^8.58.1",
76
+ "typescript-eslint": "^8.58.2",
76
77
  "vitest": "^4.1.4"
77
78
  },
78
79
  "packageManager": "pnpm@10.33.0"