@medyll/idae-query 0.68.0 → 0.69.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,184 +1,78 @@
1
- # @medyll/idae-idbql
1
+ # @medyll/idae-query
2
2
 
3
- A powerful and flexible IndexedDB query library for TypeScript and JavaScript applications.
3
+ A powerful and flexible query library for TypeScript and JavaScript applications.
4
4
 
5
5
  ## Features
6
6
 
7
- - MongoDB-like query interface for IndexedDB
8
- - Strong TypeScript support with full type inference
9
- - Reactive state management for real-time UI updates
10
- - Support for complex CRUD operations and advanced querying
11
- - Flexible data modeling with automatic schema creation
12
- - Built-in indexing and optimization features
13
- - Easy integration with front-end frameworks, especially Svelte
14
- - Robust error handling and logging
15
- - Versioning and database migration support
16
- - Support for svelte 5 state
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
17
11
 
18
12
  ## Installation
19
13
 
20
14
  ```bash
21
- npm install @medyll/idae-idbql
15
+ npm install @medyll/idae-query
22
16
  ```
23
17
 
24
18
  ## Quick Start
25
19
 
26
- ```typescript
27
- import { createIdbqDb } from '@medyll/idae-idbql';
28
-
29
- // Define your data model
30
- const exampleModel = {
31
- messages: {
32
- keyPath: "++id, chatId, created_at",
33
- ts: {} as ChatMessage,
34
- },
35
- chat: {
36
- keyPath: "&chatId, created_at, dateLastMessage",
37
- ts: {} as Chat,
38
- template: {},
39
- },
40
- };
41
-
42
- // Create a database instance
43
- const idbqStore = createIdbqDb(exampleModel, 1);
44
- const { idbql, idbqlState, idbDatabase, idbqModel } = idbqStore.create("myDatabase");
45
-
46
- // Perform database operations
47
- async function fetchMessages() {
48
- const messages = await idbql.messages.where({ chatId: "123" }).toArray();
49
- console.log(messages);
50
- }
51
-
52
- fetchMessages();
53
- ```
54
-
55
- ## API Reference
56
-
57
- ### createIdbqDb(model, version)
58
-
59
- Creates an IndexedDB database instance with the specified model and version.
60
-
61
- ### idbql
62
-
63
- The main interface for database operations. Provides methods for each collection defined in your model.
64
-
65
- ### idbqlState
66
-
67
- A reactive state object that reflects the current state of your database.
68
-
69
- ### idbDatabase
70
-
71
- Provides low-level access to the IndexedDB instance.
72
-
73
- ### idbqModel
74
-
75
- Contains the database model definition.
76
-
77
- ## Query Operations
20
+ Here's a quick example to get you started:
78
21
 
79
22
  ```typescript
80
- // Add a new item
81
- await idbql.messages.add({ chatId: "123", content: "Hello" });
23
+ import { getResultset } from '@medyll/idae-query';
82
24
 
83
- // Update an item
84
- await idbql.messages.put({ id: 1, content: "Updated message" });
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
+ ];
85
31
 
86
- // Delete an item
87
- await idbql.messages.delete(1);
32
+ const resultSet = getResultset(data);
88
33
 
89
- // Query items
90
- const recentMessages = await idbql.messages
91
- .where({ created_at: { gt: new Date(Date.now() - 86400000) } })
92
- .toArray();
93
- ```
94
-
95
- ## Transactions
34
+ // Sorting
35
+ const sortedData = resultSet.sortBy({ age: 'asc' });
96
36
 
97
- idbql supports complex transactions across multiple object stores:
37
+ // Grouping
38
+ const groupedData = resultSet.groupBy('age');
98
39
 
99
- ```typescript
100
- const result = await idbql.transaction(
101
- ["users", "posts"],
102
- "readwrite",
103
- async (tx) => {
104
- const userStore = tx.objectStore("users");
105
- const postStore = tx.objectStore("posts");
106
-
107
- const userId = await userStore.add({ name: "Alice", email: "alice@example.com" });
108
- const postId = await postStore.add({ userId, title: "Alice's First Post", content: "Hello, World!" });
109
-
110
- return { userId, postId };
111
- }
112
- );
113
- ```
114
-
115
- ## Reactive State Management
116
-
117
- ```typescript
118
- import { derived } from 'svelte/store';
40
+ // Pagination
41
+ const pageData = resultSet.getPage(1, 2);
119
42
 
120
- const activeUsers = $derived(idbqlState.users.where({ isActive: true }));
43
+ console.log(sortedData);
44
+ console.log(groupedData);
45
+ console.log(pageData);
121
46
  ```
122
47
 
123
- ## Integration with Svelte
48
+ ## API
124
49
 
125
- ```svelte
126
- <script>
127
- import { derived } from 'svelte/store';
128
- import { idbqlState } from './store';
50
+ ### `getResultset(data: any[]): ResultSet`
129
51
 
130
- const messages = $derived(idbqlState.messages.where({ chatId: "123" }));
131
- </script>
52
+ Creates a new result set from the provided data.
132
53
 
133
- {#each $messages as message}
134
- <p>{message.content}</p>
135
- {/each}
136
- ```
54
+ ### `ResultSet`
137
55
 
138
- ## Versioning and Migrations
56
+ A chainable and iterable result set of data.
139
57
 
140
- ```typescript
141
- const idbqStore = createIdbqDb(myModel, 2);
142
- const { idbDatabase } = idbqStore.create("myDb", {
143
- upgrade(oldVersion, newVersion, transaction) {
144
- if (oldVersion < 2) {
145
- const userStore = transaction.objectStore("users");
146
- userStore.createIndex("emailIndex", "email", { unique: true });
147
- }
148
- },
149
- });
150
- ```
58
+ #### Methods
151
59
 
152
- ## Error Handling
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.
153
64
 
154
- ```typescript
155
- try {
156
- await idbql.users.add({ username: "existing_user" });
157
- } catch (error) {
158
- if (error instanceof UniqueConstraintError) {
159
- console.error("Username already exists");
160
- } else {
161
- console.error("An unexpected error occurred", error);
162
- }
163
- }
164
- ```
165
-
166
- ## Performance Tips
65
+ ## Testing
167
66
 
168
- - Use appropriate indexes
169
- - Limit result sets with `.limit(n)`
170
- - Use `.count()` instead of `.toArray().length`
171
- - Optimize queries to use indexes effectively
67
+ To run the tests:
172
68
 
173
- ## Contributing
69
+ 1. Clone the repository
70
+ 2. Install dependencies: `npm install` or `yarn install`
71
+ 3. Run tests: `npm test` or `yarn test`
174
72
 
175
- Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
73
+ The tests cover various scenarios for each method, ensuring the reliability and correctness of the `ResultSet` class.
176
74
 
177
75
  ## License
178
76
 
179
- This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
180
-
181
- ## Support
77
+ This project is licensed under the MIT License.
182
78
 
183
- If you encounter any issues or have questions, please file an issue on the GitHub repository.
184
-
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './types.js';
2
2
  export * from './resultSet/resultset.js';
3
- export * from './query/query.js';
4
3
  export * from './path/pathResolver.js';
4
+ export * from './query/query.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
3
  export * from './resultSet/resultset.js';
4
- export * from './query/query.js';
5
4
  export * from './path/pathResolver.js';
5
+ export * from './query/query.js';
6
6
  export * from './operators/operators.js';
@@ -47,23 +47,11 @@ export function getResultset(data) {
47
47
  },
48
48
  groupBy: {
49
49
  value: function (fieldName, keepUngroupedData = true) {
50
- return dataOp.groupBy({ dataList: this, groupBy: fieldName });
51
- /* const finalFieldName =
52
- typeof fieldName === "string" ? [fieldName] : fieldName;
53
- return this.reduce(
54
- (acc: { [x: string]: any[] }, curr: Record<string, any>) => {
55
- let key = "";
56
- for (let i = 0; i < finalFieldName.length; i++) {
57
- key += dotPath<typeof curr>(curr, finalFieldName[i]);
58
- }
59
- if (!acc[key]) {
60
- acc[key] = [];
61
- }
62
- acc[key].push(curr);
63
- return acc;
64
- },
65
- {},
66
- ); */
50
+ return dataOp.groupBy({
51
+ dataList: this,
52
+ groupBy: fieldName,
53
+ keepUngroupedData,
54
+ });
67
55
  },
68
56
  enumerable: true,
69
57
  configurable: true,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@medyll/idae-query",
3
3
  "scope": "@medyll",
4
- "version": "0.68.0",
5
- "description": "A powerful and flexible IndexedDB query library for TypeScript and JavaScript applications, featuring a MongoDB-like query interface, strong TypeScript support, reactive state management, and easy integration with front-end frameworks like Svelte.",
4
+ "version": "0.69.0",
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",
8
8
  "build": "vite build && npm run package",
@@ -28,6 +28,9 @@
28
28
  "!dist/**/*.test.*",
29
29
  "!dist/**/*.spec.*"
30
30
  ],
31
+ "dependencies": {
32
+ "@medyll/idae-engine": "next"
33
+ },
31
34
  "peerDependencies": {
32
35
  "svelte": "^5.0.0-next"
33
36
  },