@medyll/idae-query 0.120.1 → 0.122.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/README.md CHANGED
@@ -1,78 +1,78 @@
1
- # @medyll/idae-query
2
-
3
- A powerful and flexible query library for TypeScript and JavaScript applications.
4
-
5
- ## Features
6
-
7
- - Chainable and iterable result sets
8
- - Sorting, grouping, and pagination support
9
- - Dot path resolution for nested properties
10
- - Integration with `@medyll/idae-engine` for data operations
11
-
12
- ## Installation
13
-
14
- ```bash
15
- npm install @medyll/idae-query
16
- ```
17
-
18
- ## Quick Start
19
-
20
- Here's a quick example to get you started:
21
-
22
- ```typescript
23
- import { getResultset } from '@medyll/idae-query';
24
-
25
- const data = [
26
- { id: 1, name: 'John', age: 25, metadata: { order: 1 } },
27
- { id: 2, name: 'Jane', age: 30, metadata: { order: 2 } },
28
- { id: 3, name: 'Bob', age: 35, metadata: { order: 3 } },
29
- { id: 4, name: 'Alice', age: 40, metadata: { order: 4 } },
30
- ];
31
-
32
- const resultSet = getResultset(data);
33
-
34
- // Sorting
35
- const sortedData = resultSet.sortBy({ age: 'asc' });
36
-
37
- // Grouping
38
- const groupedData = resultSet.groupBy('age');
39
-
40
- // Pagination
41
- const pageData = resultSet.getPage(1, 2);
42
-
43
- console.log(sortedData);
44
- console.log(groupedData);
45
- console.log(pageData);
46
- ```
47
-
48
- ## API
49
-
50
- ### `getResultset(data: any[]): ResultSet`
51
-
52
- Creates a new result set from the provided data.
53
-
54
- ### `ResultSet`
55
-
56
- A chainable and iterable result set of data.
57
-
58
- #### Methods
59
-
60
- - `setOptions(options: ResultsetOptions): ResultSet` - Sets options for the result set.
61
- - `sortBy(sortOptions: Record<DotPath, 'asc' | 'desc'>): ResultSet` - Sorts the result set by the specified options.
62
- - `groupBy(groupBy: DotPath): Record<string, any[]>` - Groups the result set by the specified property.
63
- - `getPage(page: number, pageSize: number): any[]` - Gets the specified page of data.
64
-
65
- ## Testing
66
-
67
- To run the tests:
68
-
69
- 1. Clone the repository
70
- 2. Install dependencies: `npm install` or `yarn install`
71
- 3. Run tests: `npm test` or `yarn test`
72
-
73
- The tests cover various scenarios for each method, ensuring the reliability and correctness of the `ResultSet` class.
74
-
75
- ## License
76
-
77
- This project is licensed under the MIT License.
78
-
1
+ # @medyll/idae-query
2
+
3
+ A powerful and flexible query library for TypeScript and JavaScript applications.
4
+
5
+ ## Features
6
+
7
+ - Chainable and iterable result sets
8
+ - Sorting, grouping, and pagination support
9
+ - Dot path resolution for nested properties
10
+ - Integration with `@medyll/idae-engine` for data operations
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @medyll/idae-query
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ Here's a quick example to get you started:
21
+
22
+ ```typescript
23
+ import { getResultset } from '@medyll/idae-query';
24
+
25
+ const data = [
26
+ { id: 1, name: 'John', age: 25, metadata: { order: 1 } },
27
+ { id: 2, name: 'Jane', age: 30, metadata: { order: 2 } },
28
+ { id: 3, name: 'Bob', age: 35, metadata: { order: 3 } },
29
+ { id: 4, name: 'Alice', age: 40, metadata: { order: 4 } },
30
+ ];
31
+
32
+ const resultSet = getResultset(data);
33
+
34
+ // Sorting
35
+ const sortedData = resultSet.sortBy({ age: 'asc' });
36
+
37
+ // Grouping
38
+ const groupedData = resultSet.groupBy('age');
39
+
40
+ // Pagination
41
+ const pageData = resultSet.getPage(1, 2);
42
+
43
+ console.log(sortedData);
44
+ console.log(groupedData);
45
+ console.log(pageData);
46
+ ```
47
+
48
+ ## API
49
+
50
+ ### `getResultset(data: any[]): ResultSet`
51
+
52
+ Creates a new result set from the provided data.
53
+
54
+ ### `ResultSet`
55
+
56
+ A chainable and iterable result set of data.
57
+
58
+ #### Methods
59
+
60
+ - `setOptions(options: ResultsetOptions): ResultSet` - Sets options for the result set.
61
+ - `sortBy(sortOptions: Record<DotPath, 'asc' | 'desc'>): ResultSet` - Sorts the result set by the specified options.
62
+ - `groupBy(groupBy: DotPath): Record<string, any[]>` - Groups the result set by the specified property.
63
+ - `getPage(page: number, pageSize: number): any[]` - Gets the specified page of data.
64
+
65
+ ## Testing
66
+
67
+ To run the tests:
68
+
69
+ 1. Clone the repository
70
+ 2. Install dependencies: `npm install` or `yarn install`
71
+ 3. Run tests: `npm test` or `yarn test`
72
+
73
+ The tests cover various scenarios for each method, ensuring the reliability and correctness of the `ResultSet` class.
74
+
75
+ ## License
76
+
77
+ This project is licensed under the MIT License.
78
+
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './types.js';
2
- export * from './query/query.js';
3
2
  export * from './resultSet/resultset.js';
3
+ export * from './query/query.js';
4
4
  export * from './path/pathResolver.js';
5
5
  export * from './operators/operators.js';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // auto exports of entry components
2
2
  export * from './types.js';
3
- export * from './query/query.js';
4
3
  export * from './resultSet/resultset.js';
4
+ export * from './query/query.js';
5
5
  export * from './path/pathResolver.js';
6
6
  export * from './operators/operators.js';
@@ -2,7 +2,7 @@ import type { Where } from '../types.js';
2
2
  export declare class Query<T extends object> {
3
3
  data: T[];
4
4
  constructor(data: T[]);
5
- where(qy: Where<T>): import("../resultset/resultset.js").ResultSet<T>;
5
+ where(qy: Where<T>): any;
6
6
  private matchesQuery;
7
7
  private matchesField;
8
8
  }
@@ -1,39 +1,39 @@
1
- ## ResultSet.ts
2
-
3
- This class `ResultSet` is used to manipulate and iterate over a set of data. The class is iterable, meaning it can be spread into an array or iterated over with a `for...of` loop.
4
-
5
- ### Methods
6
-
7
-
8
-
9
- #### setOptions<T>(options: OptionsType)
10
-
11
- - Action: Sets the options for the result set in one pass.
12
- - Arguments: An `OptionsType` object which can contain `sort`, `page`, and `groupBy` properties.
13
- - `sort`: An object where the keys represent the properties to sort by, and the values represent the sort order ("asc" for ascending, "desc" for descending).
14
- - `page`: An object with `size` and `number` properties, representing the number of items per page and the page number to retrieve, respectively.
15
- - `groupBy`: A string or an array of strings, representing the field names to group by.
16
- - Return: The updated result set.
17
-
18
-
19
- #### sortBy(args: Record<string, "asc" | "desc">)
20
-
21
- - Action: Sorts the data in the result set based on the provided sorting criteria.
22
- - Arguments: An object where the keys represent the properties to sort by, and the values represent the sort order ("asc" for ascending, "desc" for descending).
23
- - Return: The sorted result set.
24
-
25
- #### getPage(size: number, page: number)
26
-
27
- - Action: Retrieves a specific page of data from the result set.
28
- - Arguments: The `size` parameter specifies the number of items per page, and the `page` parameter specifies the page number to retrieve.
29
- - Return: A new result set containing the specified page of data.
30
-
31
- #### groupBy(fieldName: string | string[], transform?: (value: any) => void)
32
-
33
- - Action: Groups the result set by the specified field name(s).
34
- - Arguments: The `fieldName` parameter can be a string or an array of strings, representing the field names to group by. The `transform` parameter is an optional transformation function to apply to each grouped value.
35
- - Return: An object representing the grouped result set.
36
-
37
- ### Iterability
38
-
39
- The `ResultSet` class is iterable, meaning it can be spread into an array or iterated over with a `for...of` loop. This is achieved by implementing the `[Symbol.iterator]` method.
1
+ ## ResultSet.ts
2
+
3
+ This class `ResultSet` is used to manipulate and iterate over a set of data. The class is iterable, meaning it can be spread into an array or iterated over with a `for...of` loop.
4
+
5
+ ### Methods
6
+
7
+
8
+
9
+ #### setOptions<T>(options: OptionsType)
10
+
11
+ - Action: Sets the options for the result set in one pass.
12
+ - Arguments: An `OptionsType` object which can contain `sort`, `page`, and `groupBy` properties.
13
+ - `sort`: An object where the keys represent the properties to sort by, and the values represent the sort order ("asc" for ascending, "desc" for descending).
14
+ - `page`: An object with `size` and `number` properties, representing the number of items per page and the page number to retrieve, respectively.
15
+ - `groupBy`: A string or an array of strings, representing the field names to group by.
16
+ - Return: The updated result set.
17
+
18
+
19
+ #### sortBy(args: Record<string, "asc" | "desc">)
20
+
21
+ - Action: Sorts the data in the result set based on the provided sorting criteria.
22
+ - Arguments: An object where the keys represent the properties to sort by, and the values represent the sort order ("asc" for ascending, "desc" for descending).
23
+ - Return: The sorted result set.
24
+
25
+ #### getPage(size: number, page: number)
26
+
27
+ - Action: Retrieves a specific page of data from the result set.
28
+ - Arguments: The `size` parameter specifies the number of items per page, and the `page` parameter specifies the page number to retrieve.
29
+ - Return: A new result set containing the specified page of data.
30
+
31
+ #### groupBy(fieldName: string | string[], transform?: (value: any) => void)
32
+
33
+ - Action: Groups the result set by the specified field name(s).
34
+ - Arguments: The `fieldName` parameter can be a string or an array of strings, representing the field names to group by. The `transform` parameter is an optional transformation function to apply to each grouped value.
35
+ - Return: An object representing the grouped result set.
36
+
37
+ ### Iterability
38
+
39
+ The `ResultSet` class is iterable, meaning it can be spread into an array or iterated over with a `for...of` loop. This is achieved by implementing the `[Symbol.iterator]` method.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@medyll/idae-query",
3
3
  "scope": "@medyll",
4
- "version": "0.120.1",
4
+ "version": "0.122.0",
5
5
  "description": "A powerful and flexible query library for TypeScript and JavaScript applications, featuring a MongoDB-like query interface, strong TypeScript support, and easy integration with front-end frameworks.",
6
6
  "scripts": {
7
7
  "dev": "vite dev",