querier-ts 2.7.0 → 2.8.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 +27 -0
- package/README.md +25 -12
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.8.0
|
|
4
|
+
|
|
5
|
+
### Summary
|
|
6
|
+
|
|
7
|
+
- [ ] Bug fixes
|
|
8
|
+
- [ ] Code refactoring
|
|
9
|
+
- [x] New features
|
|
10
|
+
- [ ] Breaking changes
|
|
11
|
+
|
|
12
|
+
### New features
|
|
13
|
+
|
|
14
|
+
- Added row index as argument to `Query.map()` callback.
|
|
15
|
+
|
|
16
|
+
## v2.7.1
|
|
17
|
+
|
|
18
|
+
### Summary
|
|
19
|
+
|
|
20
|
+
- [x] Documentation updates
|
|
21
|
+
- [ ] Bug fixes
|
|
22
|
+
- [ ] Code refactoring
|
|
23
|
+
- [ ] New features
|
|
24
|
+
- [ ] Breaking changes
|
|
25
|
+
|
|
26
|
+
### Documentation updates
|
|
27
|
+
|
|
28
|
+
- Update `README.md` documentation for `orderBy()` method with new overload and examples.
|
|
29
|
+
|
|
3
30
|
## v2.7.0
|
|
4
31
|
|
|
5
32
|
### Summary
|
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://
|
|
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)
|
|
@@ -144,23 +150,30 @@ const query = Query.from()
|
|
|
144
150
|
|
|
145
151
|
### Ordering results
|
|
146
152
|
|
|
147
|
-
#### `orderBy(...columns)`
|
|
153
|
+
#### `orderBy(...columns | (callback, order?))`
|
|
148
154
|
|
|
149
|
-
Sorts the results.
|
|
155
|
+
Sorts the results.
|
|
150
156
|
|
|
151
|
-
|
|
152
|
-
.
|
|
153
|
-
|
|
157
|
+
- `columns`: the columns to order by.
|
|
158
|
+
- `callback`: A function that maps each row to a value.
|
|
159
|
+
- `order`: The order to sort in.
|
|
154
160
|
|
|
155
|
-
|
|
161
|
+
You can specify column names or a callback function to map each row to a value.
|
|
156
162
|
|
|
157
|
-
|
|
163
|
+
Examples:
|
|
158
164
|
|
|
159
165
|
```ts
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
166
|
+
// Column names with ASC and DESC (-) order
|
|
167
|
+
.orderBy('name', '-createdAt')
|
|
168
|
+
|
|
169
|
+
// callback with ASC order by default
|
|
170
|
+
.orderBy((user) => user.address.country)
|
|
171
|
+
|
|
172
|
+
// callback with ASC order set explicitly
|
|
173
|
+
.orderBy((user) => user.address.country, 'asc')
|
|
174
|
+
|
|
175
|
+
// callback with DESC order
|
|
176
|
+
.orderBy((user) => user.address.country, 'desc')
|
|
164
177
|
```
|
|
165
178
|
|
|
166
179
|
---
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -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);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ declare class Query<T extends object> {
|
|
|
110
110
|
* @param callback Function to be called for each row.
|
|
111
111
|
* @returns New query with the mapped rows.
|
|
112
112
|
*/
|
|
113
|
-
map<TReturn extends object>(callback: (
|
|
113
|
+
map<TReturn extends object>(callback: (row: T, index: number) => TReturn): Query<TReturn>;
|
|
114
114
|
/**
|
|
115
115
|
* Removes duplicate rows based on a key.
|
|
116
116
|
*
|
package/dist/esm/index.js
CHANGED
|
@@ -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);
|