flongo 1.1.0 → 1.2.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/dist/flongoQuery.d.ts +28 -0
- package/dist/flongoQuery.js +49 -5
- package/package.json +1 -1
package/dist/flongoQuery.d.ts
CHANGED
|
@@ -123,6 +123,34 @@ export declare class FlongoQuery implements ICollectionQuery {
|
|
|
123
123
|
* @returns This query instance for chaining
|
|
124
124
|
*/
|
|
125
125
|
arrContainsAny(val?: any[]): FlongoQuery;
|
|
126
|
+
/**
|
|
127
|
+
* Matches array elements that satisfy all specified conditions.
|
|
128
|
+
* Use this to query objects within arrays by their properties.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // Find users with a contextRole where orgId is 'org1'
|
|
132
|
+
* query.where('contextRoles').elemMatch({ orgId: 'org1' })
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* // Find users with a contextRole where orgId is 'org1' AND role is 'admin'
|
|
136
|
+
* query.where('contextRoles').elemMatch({ orgId: 'org1', role: 'admin' })
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* // Using fluent API for conditions (supports all FlongoQuery operators)
|
|
140
|
+
* query.where('contextRoles').elemMatch(
|
|
141
|
+
* new FlongoQuery().where('orgId').eq('org1').and('role').eq('admin')
|
|
142
|
+
* )
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Using comparison operators
|
|
146
|
+
* query.where('scores').elemMatch(
|
|
147
|
+
* new FlongoQuery().where('value').gtEq(80).and('subject').eq('math')
|
|
148
|
+
* )
|
|
149
|
+
*
|
|
150
|
+
* @param conditions - Object with field/value pairs or a FlongoQuery instance
|
|
151
|
+
* @returns This query instance for chaining
|
|
152
|
+
*/
|
|
153
|
+
elemMatch(conditions?: Record<string, any> | FlongoQuery): FlongoQuery;
|
|
126
154
|
/**
|
|
127
155
|
* Adds case-insensitive string starts-with constraint
|
|
128
156
|
* @param val - String prefix to match
|
package/dist/flongoQuery.js
CHANGED
|
@@ -175,6 +175,36 @@ class FlongoQuery {
|
|
|
175
175
|
arrContainsAny(val) {
|
|
176
176
|
return val?.length ? this.set("$in", val) : this.handleEmptyValue();
|
|
177
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Matches array elements that satisfy all specified conditions.
|
|
180
|
+
* Use this to query objects within arrays by their properties.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* // Find users with a contextRole where orgId is 'org1'
|
|
184
|
+
* query.where('contextRoles').elemMatch({ orgId: 'org1' })
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* // Find users with a contextRole where orgId is 'org1' AND role is 'admin'
|
|
188
|
+
* query.where('contextRoles').elemMatch({ orgId: 'org1', role: 'admin' })
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* // Using fluent API for conditions (supports all FlongoQuery operators)
|
|
192
|
+
* query.where('contextRoles').elemMatch(
|
|
193
|
+
* new FlongoQuery().where('orgId').eq('org1').and('role').eq('admin')
|
|
194
|
+
* )
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* // Using comparison operators
|
|
198
|
+
* query.where('scores').elemMatch(
|
|
199
|
+
* new FlongoQuery().where('value').gtEq(80).and('subject').eq('math')
|
|
200
|
+
* )
|
|
201
|
+
*
|
|
202
|
+
* @param conditions - Object with field/value pairs or a FlongoQuery instance
|
|
203
|
+
* @returns This query instance for chaining
|
|
204
|
+
*/
|
|
205
|
+
elemMatch(conditions) {
|
|
206
|
+
return this.set("$elemMatch", conditions);
|
|
207
|
+
}
|
|
178
208
|
// ===========================================
|
|
179
209
|
// STRING OPERATORS
|
|
180
210
|
// ===========================================
|
|
@@ -366,11 +396,25 @@ class FlongoQuery {
|
|
|
366
396
|
break; // _id queries are typically exclusive
|
|
367
397
|
}
|
|
368
398
|
// Build query object for non-_id fields
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
399
|
+
let fieldValue;
|
|
400
|
+
if (!expression.op) {
|
|
401
|
+
// Direct value assignment for simple equality (arrContains)
|
|
402
|
+
fieldValue = expression.val;
|
|
403
|
+
}
|
|
404
|
+
else if (expression.op === "$regex") {
|
|
405
|
+
// Case-insensitive regex
|
|
406
|
+
fieldValue = { [expression.op]: expression.val, ["$options"]: "i" };
|
|
407
|
+
}
|
|
408
|
+
else if (expression.op === "$elemMatch") {
|
|
409
|
+
// Handle FlongoQuery or raw object for $elemMatch
|
|
410
|
+
fieldValue = {
|
|
411
|
+
[expression.op]: expression.val instanceof FlongoQuery ? expression.val.build() : expression.val
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
// Standard operator
|
|
416
|
+
fieldValue = { [expression.op]: expression.val };
|
|
417
|
+
}
|
|
374
418
|
// Merge operators for the same field (e.g., range queries)
|
|
375
419
|
if (mongodbQuery[expression.key] &&
|
|
376
420
|
typeof mongodbQuery[expression.key] === "object" &&
|