@jkershaw/mangodb 0.1.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 +23 -0
- package/LICENSE +21 -0
- package/README.md +112 -0
- package/dist/aggregation/accumulators.d.ts +10 -0
- package/dist/aggregation/accumulators.d.ts.map +1 -0
- package/dist/aggregation/accumulators.js +251 -0
- package/dist/aggregation/accumulators.js.map +1 -0
- package/dist/aggregation/cursor.d.ts +116 -0
- package/dist/aggregation/cursor.d.ts.map +1 -0
- package/dist/aggregation/cursor.js +2014 -0
- package/dist/aggregation/cursor.js.map +1 -0
- package/dist/aggregation/date-utils.d.ts +48 -0
- package/dist/aggregation/date-utils.d.ts.map +1 -0
- package/dist/aggregation/date-utils.js +132 -0
- package/dist/aggregation/date-utils.js.map +1 -0
- package/dist/aggregation/expression.d.ts +16 -0
- package/dist/aggregation/expression.d.ts.map +1 -0
- package/dist/aggregation/expression.js +66 -0
- package/dist/aggregation/expression.js.map +1 -0
- package/dist/aggregation/gap-fill.d.ts +41 -0
- package/dist/aggregation/gap-fill.d.ts.map +1 -0
- package/dist/aggregation/gap-fill.js +112 -0
- package/dist/aggregation/gap-fill.js.map +1 -0
- package/dist/aggregation/helpers.d.ts +8 -0
- package/dist/aggregation/helpers.d.ts.map +1 -0
- package/dist/aggregation/helpers.js +31 -0
- package/dist/aggregation/helpers.js.map +1 -0
- package/dist/aggregation/index.d.ts +9 -0
- package/dist/aggregation/index.d.ts.map +1 -0
- package/dist/aggregation/index.js +8 -0
- package/dist/aggregation/index.js.map +1 -0
- package/dist/aggregation/operators/arithmetic.d.ts +50 -0
- package/dist/aggregation/operators/arithmetic.d.ts.map +1 -0
- package/dist/aggregation/operators/arithmetic.js +281 -0
- package/dist/aggregation/operators/arithmetic.js.map +1 -0
- package/dist/aggregation/operators/array.d.ts +113 -0
- package/dist/aggregation/operators/array.d.ts.map +1 -0
- package/dist/aggregation/operators/array.js +795 -0
- package/dist/aggregation/operators/array.js.map +1 -0
- package/dist/aggregation/operators/comparison.d.ts +29 -0
- package/dist/aggregation/operators/comparison.d.ts.map +1 -0
- package/dist/aggregation/operators/comparison.js +88 -0
- package/dist/aggregation/operators/comparison.js.map +1 -0
- package/dist/aggregation/operators/conditional.d.ts +22 -0
- package/dist/aggregation/operators/conditional.d.ts.map +1 -0
- package/dist/aggregation/operators/conditional.js +101 -0
- package/dist/aggregation/operators/conditional.js.map +1 -0
- package/dist/aggregation/operators/date.d.ts +62 -0
- package/dist/aggregation/operators/date.d.ts.map +1 -0
- package/dist/aggregation/operators/date.js +446 -0
- package/dist/aggregation/operators/date.js.map +1 -0
- package/dist/aggregation/operators/index.d.ts +147 -0
- package/dist/aggregation/operators/index.d.ts.map +1 -0
- package/dist/aggregation/operators/index.js +158 -0
- package/dist/aggregation/operators/index.js.map +1 -0
- package/dist/aggregation/operators/object.d.ts +31 -0
- package/dist/aggregation/operators/object.d.ts.map +1 -0
- package/dist/aggregation/operators/object.js +130 -0
- package/dist/aggregation/operators/object.js.map +1 -0
- package/dist/aggregation/operators/string.d.ts +62 -0
- package/dist/aggregation/operators/string.d.ts.map +1 -0
- package/dist/aggregation/operators/string.js +440 -0
- package/dist/aggregation/operators/string.js.map +1 -0
- package/dist/aggregation/operators/trigonometry.d.ts +71 -0
- package/dist/aggregation/operators/trigonometry.d.ts.map +1 -0
- package/dist/aggregation/operators/trigonometry.js +263 -0
- package/dist/aggregation/operators/trigonometry.js.map +1 -0
- package/dist/aggregation/operators/type-conversion.d.ts +34 -0
- package/dist/aggregation/operators/type-conversion.d.ts.map +1 -0
- package/dist/aggregation/operators/type-conversion.js +314 -0
- package/dist/aggregation/operators/type-conversion.js.map +1 -0
- package/dist/aggregation/partition.d.ts +36 -0
- package/dist/aggregation/partition.d.ts.map +1 -0
- package/dist/aggregation/partition.js +73 -0
- package/dist/aggregation/partition.js.map +1 -0
- package/dist/aggregation/system-vars.d.ts +37 -0
- package/dist/aggregation/system-vars.d.ts.map +1 -0
- package/dist/aggregation/system-vars.js +51 -0
- package/dist/aggregation/system-vars.js.map +1 -0
- package/dist/aggregation/traverse.d.ts +22 -0
- package/dist/aggregation/traverse.d.ts.map +1 -0
- package/dist/aggregation/traverse.js +62 -0
- package/dist/aggregation/traverse.js.map +1 -0
- package/dist/aggregation/types.d.ts +39 -0
- package/dist/aggregation/types.d.ts.map +1 -0
- package/dist/aggregation/types.js +2 -0
- package/dist/aggregation/types.js.map +1 -0
- package/dist/client.d.ts +67 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +82 -0
- package/dist/client.js.map +1 -0
- package/dist/collection.d.ts +789 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +1804 -0
- package/dist/collection.js.map +1 -0
- package/dist/cursor.d.ts +221 -0
- package/dist/cursor.d.ts.map +1 -0
- package/dist/cursor.js +292 -0
- package/dist/cursor.js.map +1 -0
- package/dist/db.d.ts +149 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +272 -0
- package/dist/db.js.map +1 -0
- package/dist/document-utils.d.ts +239 -0
- package/dist/document-utils.d.ts.map +1 -0
- package/dist/document-utils.js +543 -0
- package/dist/document-utils.js.map +1 -0
- package/dist/errors.d.ts +295 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +331 -0
- package/dist/errors.js.map +1 -0
- package/dist/geo/calculations.d.ts +133 -0
- package/dist/geo/calculations.d.ts.map +1 -0
- package/dist/geo/calculations.js +428 -0
- package/dist/geo/calculations.js.map +1 -0
- package/dist/geo/errors.d.ts +78 -0
- package/dist/geo/errors.d.ts.map +1 -0
- package/dist/geo/errors.js +106 -0
- package/dist/geo/errors.js.map +1 -0
- package/dist/geo/geometry.d.ts +119 -0
- package/dist/geo/geometry.d.ts.map +1 -0
- package/dist/geo/geometry.js +313 -0
- package/dist/geo/geometry.js.map +1 -0
- package/dist/geo/index.d.ts +14 -0
- package/dist/geo/index.d.ts.map +1 -0
- package/dist/geo/index.js +19 -0
- package/dist/geo/index.js.map +1 -0
- package/dist/geo/operators.d.ts +92 -0
- package/dist/geo/operators.d.ts.map +1 -0
- package/dist/geo/operators.js +220 -0
- package/dist/geo/operators.js.map +1 -0
- package/dist/geo/shapes.d.ts +100 -0
- package/dist/geo/shapes.d.ts.map +1 -0
- package/dist/geo/shapes.js +256 -0
- package/dist/geo/shapes.js.map +1 -0
- package/dist/index-manager.d.ts +169 -0
- package/dist/index-manager.d.ts.map +1 -0
- package/dist/index-manager.js +556 -0
- package/dist/index-manager.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/query-matcher.d.ts +130 -0
- package/dist/query-matcher.d.ts.map +1 -0
- package/dist/query-matcher.js +848 -0
- package/dist/query-matcher.js.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/types.d.ts +78 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +8 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/schema/validator.d.ts +15 -0
- package/dist/schema/validator.d.ts.map +1 -0
- package/dist/schema/validator.js +359 -0
- package/dist/schema/validator.js.map +1 -0
- package/dist/types.d.ts +707 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/update-operators.d.ts +133 -0
- package/dist/update-operators.d.ts.map +1 -0
- package/dist/update-operators.js +683 -0
- package/dist/update-operators.js.map +1 -0
- package/dist/utils.d.ts +194 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +504 -0
- package/dist/utils.js.map +1 -0
- package/package.json +73 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2024-12-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release
|
|
12
|
+
- MongoDB-compatible API for file-based storage
|
|
13
|
+
- Query operators: 31/32 supported (all except `$where`)
|
|
14
|
+
- Update operators: 20/20 (100% coverage)
|
|
15
|
+
- Aggregation stages: 29/34 supported
|
|
16
|
+
- Expression operators: 121/127 supported
|
|
17
|
+
- Index types: single, compound, text, TTL, partial, 2d, 2dsphere, hashed, wildcard
|
|
18
|
+
- Geospatial queries with GeoJSON support
|
|
19
|
+
- Text search with weighted indexes
|
|
20
|
+
- Trigonometry expression operators (15 operators)
|
|
21
|
+
- `$jsonSchema` query operator
|
|
22
|
+
- `$merge` aggregation stage
|
|
23
|
+
- Comprehensive documentation
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 J Kershaw
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# MangoDB 🥭
|
|
2
|
+
|
|
3
|
+
A file-based MongoDB drop-in replacement for TypeScript/Node.js.
|
|
4
|
+
|
|
5
|
+
**SQLite is to SQL as MangoDB is to MongoDB.**
|
|
6
|
+
|
|
7
|
+
MangoDB stores your data as simple JSON files on disk while exposing the same API as the official MongoDB driver. Write your application once, develop locally without any database setup, then deploy to real MongoDB by changing a single environment variable.
|
|
8
|
+
|
|
9
|
+
## Why MangoDB?
|
|
10
|
+
|
|
11
|
+
Working with MongoDB during development often means running local instances, configuring Docker containers, or connecting to cloud databases just to run your tests. MangoDB removes that friction entirely - your data lives in plain JSON files that you can inspect, version control, or simply delete between test runs.
|
|
12
|
+
|
|
13
|
+
The best part: when you're ready for production, your code doesn't change. Just point to a real MongoDB instance and everything works.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @jkershaw/mangodb
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires Node.js >= 22.0.0
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { MangoClient } from '@jkershaw/mangodb';
|
|
27
|
+
|
|
28
|
+
const client = new MangoClient('./data');
|
|
29
|
+
await client.connect();
|
|
30
|
+
|
|
31
|
+
const db = client.db('myapp');
|
|
32
|
+
const users = db.collection('users');
|
|
33
|
+
|
|
34
|
+
// Same API as MongoDB driver
|
|
35
|
+
await users.insertOne({ name: 'Alice', email: 'alice@example.com' });
|
|
36
|
+
const user = await users.findOne({ name: 'Alice' });
|
|
37
|
+
|
|
38
|
+
await client.close();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Switching to MongoDB
|
|
42
|
+
|
|
43
|
+
The API is identical. Only initialization differs:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { MongoClient } from 'mongodb';
|
|
47
|
+
import { MangoClient } from '@jkershaw/mangodb';
|
|
48
|
+
|
|
49
|
+
// Environment-based switching
|
|
50
|
+
const client = process.env.MONGODB_URI
|
|
51
|
+
? new MongoClient(process.env.MONGODB_URI)
|
|
52
|
+
: new MangoClient('./data');
|
|
53
|
+
|
|
54
|
+
await client.connect();
|
|
55
|
+
// ... rest of your code works unchanged
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Documentation
|
|
59
|
+
|
|
60
|
+
| Document | Description |
|
|
61
|
+
|----------|-------------|
|
|
62
|
+
| [Compatibility](./docs/COMPATIBILITY.md) | What's supported, what's not |
|
|
63
|
+
| [Migration](./docs/MIGRATION.md) | Switching between MangoDB and MongoDB |
|
|
64
|
+
| [Testing](./docs/TESTING.md) | Test patterns and best practices |
|
|
65
|
+
| [Edge Cases](./docs/EDGE-CASES.md) | Behavioral quirks and gotchas |
|
|
66
|
+
| [Examples](./docs/EXAMPLES.md) | Framework integration examples |
|
|
67
|
+
| [API Reference](./docs/API.md) | Quick reference for all operations |
|
|
68
|
+
| [Troubleshooting](./docs/TROUBLESHOOTING.md) | Common issues and solutions |
|
|
69
|
+
| [Initial Prompt](./docs/INITIAL-PROMPT.md) | The original AI prompt that started this project |
|
|
70
|
+
|
|
71
|
+
## Feature Coverage
|
|
72
|
+
|
|
73
|
+
| Category | Coverage |
|
|
74
|
+
|----------|----------|
|
|
75
|
+
| Query Operators | 31/32 (97%) |
|
|
76
|
+
| Update Operators | 20/20 (100%) |
|
|
77
|
+
| Aggregation Stages | 29/34 (85%) |
|
|
78
|
+
| Expression Operators | 121/127 (95%) |
|
|
79
|
+
| Index Types | 9/9 (100%) |
|
|
80
|
+
|
|
81
|
+
See [COMPATIBILITY.md](./docs/COMPATIBILITY.md) for details.
|
|
82
|
+
|
|
83
|
+
## When to Use MangoDB
|
|
84
|
+
|
|
85
|
+
**Ideal for:**
|
|
86
|
+
- Local development without MongoDB setup
|
|
87
|
+
- Unit and integration testing
|
|
88
|
+
- CI/CD pipelines (no database service needed)
|
|
89
|
+
- Prototyping and learning
|
|
90
|
+
- Small datasets (< 10,000 documents)
|
|
91
|
+
|
|
92
|
+
**Not recommended for:**
|
|
93
|
+
- Production deployments
|
|
94
|
+
- Large datasets
|
|
95
|
+
- Multi-process access
|
|
96
|
+
- Applications requiring transactions
|
|
97
|
+
|
|
98
|
+
## Running Tests
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Run against MangoDB
|
|
102
|
+
npm test
|
|
103
|
+
|
|
104
|
+
# Run against MongoDB (requires MongoDB instance)
|
|
105
|
+
MONGODB_URI=mongodb://localhost:27017 npm test
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Both modes should pass for full compatibility.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accumulator classes for $group stage.
|
|
3
|
+
*/
|
|
4
|
+
import type { Document } from '../types.ts';
|
|
5
|
+
export interface Accumulator {
|
|
6
|
+
accumulate(doc: Document): void;
|
|
7
|
+
getResult(): unknown;
|
|
8
|
+
}
|
|
9
|
+
export declare function createAccumulator(op: string, expr: unknown): Accumulator;
|
|
10
|
+
//# sourceMappingURL=accumulators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accumulators.d.ts","sourceRoot":"","sources":["../../src/aggregation/accumulators.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK5C,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAC;IAChC,SAAS,IAAI,OAAO,CAAC;CACtB;AA8QD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,WAAW,CA6BxE"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { compareValuesForSort } from "../utils.js";
|
|
2
|
+
import { valuesEqual } from "../document-utils.js";
|
|
3
|
+
import { evaluateExpression } from "./expression.js";
|
|
4
|
+
class SumAccumulator {
|
|
5
|
+
sum = 0;
|
|
6
|
+
expr;
|
|
7
|
+
constructor(expr) {
|
|
8
|
+
this.expr = expr;
|
|
9
|
+
}
|
|
10
|
+
accumulate(doc) {
|
|
11
|
+
const value = evaluateExpression(this.expr, doc);
|
|
12
|
+
if (typeof value === 'number') {
|
|
13
|
+
this.sum += value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
getResult() {
|
|
17
|
+
return this.sum;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class AvgAccumulator {
|
|
21
|
+
sum = 0;
|
|
22
|
+
count = 0;
|
|
23
|
+
expr;
|
|
24
|
+
constructor(expr) {
|
|
25
|
+
this.expr = expr;
|
|
26
|
+
}
|
|
27
|
+
accumulate(doc) {
|
|
28
|
+
const value = evaluateExpression(this.expr, doc);
|
|
29
|
+
if (typeof value === 'number') {
|
|
30
|
+
this.sum += value;
|
|
31
|
+
this.count++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
getResult() {
|
|
35
|
+
return this.count > 0 ? this.sum / this.count : null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
class MinAccumulator {
|
|
39
|
+
min = undefined;
|
|
40
|
+
expr;
|
|
41
|
+
constructor(expr) {
|
|
42
|
+
this.expr = expr;
|
|
43
|
+
}
|
|
44
|
+
accumulate(doc) {
|
|
45
|
+
const value = evaluateExpression(this.expr, doc);
|
|
46
|
+
if (value !== null && value !== undefined) {
|
|
47
|
+
if (this.min === undefined || compareValuesForSort(value, this.min, 1) < 0) {
|
|
48
|
+
this.min = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getResult() {
|
|
53
|
+
return this.min === undefined ? null : this.min;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class MaxAccumulator {
|
|
57
|
+
max = undefined;
|
|
58
|
+
expr;
|
|
59
|
+
constructor(expr) {
|
|
60
|
+
this.expr = expr;
|
|
61
|
+
}
|
|
62
|
+
accumulate(doc) {
|
|
63
|
+
const value = evaluateExpression(this.expr, doc);
|
|
64
|
+
if (value !== null && value !== undefined) {
|
|
65
|
+
if (this.max === undefined || compareValuesForSort(value, this.max, 1) > 0) {
|
|
66
|
+
this.max = value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
getResult() {
|
|
71
|
+
return this.max === undefined ? null : this.max;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class FirstAccumulator {
|
|
75
|
+
first = undefined;
|
|
76
|
+
hasValue = false;
|
|
77
|
+
expr;
|
|
78
|
+
constructor(expr) {
|
|
79
|
+
this.expr = expr;
|
|
80
|
+
}
|
|
81
|
+
accumulate(doc) {
|
|
82
|
+
if (!this.hasValue) {
|
|
83
|
+
this.first = evaluateExpression(this.expr, doc);
|
|
84
|
+
this.hasValue = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
getResult() {
|
|
88
|
+
return this.first;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class LastAccumulator {
|
|
92
|
+
last = undefined;
|
|
93
|
+
expr;
|
|
94
|
+
constructor(expr) {
|
|
95
|
+
this.expr = expr;
|
|
96
|
+
}
|
|
97
|
+
accumulate(doc) {
|
|
98
|
+
this.last = evaluateExpression(this.expr, doc);
|
|
99
|
+
}
|
|
100
|
+
getResult() {
|
|
101
|
+
return this.last;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
class PushAccumulator {
|
|
105
|
+
values = [];
|
|
106
|
+
expr;
|
|
107
|
+
constructor(expr) {
|
|
108
|
+
this.expr = expr;
|
|
109
|
+
}
|
|
110
|
+
accumulate(doc) {
|
|
111
|
+
const value = evaluateExpression(this.expr, doc);
|
|
112
|
+
this.values.push(value);
|
|
113
|
+
}
|
|
114
|
+
getResult() {
|
|
115
|
+
return this.values;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
class AddToSetAccumulator {
|
|
119
|
+
values = [];
|
|
120
|
+
expr;
|
|
121
|
+
constructor(expr) {
|
|
122
|
+
this.expr = expr;
|
|
123
|
+
}
|
|
124
|
+
accumulate(doc) {
|
|
125
|
+
const value = evaluateExpression(this.expr, doc);
|
|
126
|
+
if (!this.values.some((v) => valuesEqual(v, value))) {
|
|
127
|
+
this.values.push(value);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
getResult() {
|
|
131
|
+
return this.values;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* $count accumulator - counts the number of documents in a group.
|
|
136
|
+
* Note: This is the accumulator form, not the $count stage.
|
|
137
|
+
*/
|
|
138
|
+
class CountAccumulator {
|
|
139
|
+
count = 0;
|
|
140
|
+
accumulate(_doc) {
|
|
141
|
+
this.count++;
|
|
142
|
+
}
|
|
143
|
+
getResult() {
|
|
144
|
+
return this.count;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* $mergeObjects accumulator - merges documents into a single document.
|
|
149
|
+
*/
|
|
150
|
+
class MergeObjectsAccumulator {
|
|
151
|
+
result = {};
|
|
152
|
+
expr;
|
|
153
|
+
constructor(expr) {
|
|
154
|
+
this.expr = expr;
|
|
155
|
+
}
|
|
156
|
+
accumulate(doc) {
|
|
157
|
+
const value = evaluateExpression(this.expr, doc);
|
|
158
|
+
if (value !== null &&
|
|
159
|
+
value !== undefined &&
|
|
160
|
+
typeof value === 'object' &&
|
|
161
|
+
!Array.isArray(value)) {
|
|
162
|
+
Object.assign(this.result, value);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
getResult() {
|
|
166
|
+
return this.result;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* $stdDevPop accumulator - calculates the population standard deviation.
|
|
171
|
+
*/
|
|
172
|
+
class StdDevPopAccumulator {
|
|
173
|
+
values = [];
|
|
174
|
+
expr;
|
|
175
|
+
constructor(expr) {
|
|
176
|
+
this.expr = expr;
|
|
177
|
+
}
|
|
178
|
+
accumulate(doc) {
|
|
179
|
+
const value = evaluateExpression(this.expr, doc);
|
|
180
|
+
if (typeof value === 'number' && !isNaN(value)) {
|
|
181
|
+
this.values.push(value);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
getResult() {
|
|
185
|
+
if (this.values.length === 0) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
const n = this.values.length;
|
|
189
|
+
const mean = this.values.reduce((a, b) => a + b, 0) / n;
|
|
190
|
+
const squaredDiffs = this.values.map((v) => Math.pow(v - mean, 2));
|
|
191
|
+
const variance = squaredDiffs.reduce((a, b) => a + b, 0) / n;
|
|
192
|
+
return Math.sqrt(variance);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* $stdDevSamp accumulator - calculates the sample standard deviation.
|
|
197
|
+
*/
|
|
198
|
+
class StdDevSampAccumulator {
|
|
199
|
+
values = [];
|
|
200
|
+
expr;
|
|
201
|
+
constructor(expr) {
|
|
202
|
+
this.expr = expr;
|
|
203
|
+
}
|
|
204
|
+
accumulate(doc) {
|
|
205
|
+
const value = evaluateExpression(this.expr, doc);
|
|
206
|
+
if (typeof value === 'number' && !isNaN(value)) {
|
|
207
|
+
this.values.push(value);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
getResult() {
|
|
211
|
+
if (this.values.length < 2) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
const n = this.values.length;
|
|
215
|
+
const mean = this.values.reduce((a, b) => a + b, 0) / n;
|
|
216
|
+
const squaredDiffs = this.values.map((v) => Math.pow(v - mean, 2));
|
|
217
|
+
const variance = squaredDiffs.reduce((a, b) => a + b, 0) / (n - 1);
|
|
218
|
+
return Math.sqrt(variance);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export function createAccumulator(op, expr) {
|
|
222
|
+
switch (op) {
|
|
223
|
+
case '$sum':
|
|
224
|
+
return new SumAccumulator(expr);
|
|
225
|
+
case '$avg':
|
|
226
|
+
return new AvgAccumulator(expr);
|
|
227
|
+
case '$min':
|
|
228
|
+
return new MinAccumulator(expr);
|
|
229
|
+
case '$max':
|
|
230
|
+
return new MaxAccumulator(expr);
|
|
231
|
+
case '$first':
|
|
232
|
+
return new FirstAccumulator(expr);
|
|
233
|
+
case '$last':
|
|
234
|
+
return new LastAccumulator(expr);
|
|
235
|
+
case '$push':
|
|
236
|
+
return new PushAccumulator(expr);
|
|
237
|
+
case '$addToSet':
|
|
238
|
+
return new AddToSetAccumulator(expr);
|
|
239
|
+
case '$count':
|
|
240
|
+
return new CountAccumulator();
|
|
241
|
+
case '$mergeObjects':
|
|
242
|
+
return new MergeObjectsAccumulator(expr);
|
|
243
|
+
case '$stdDevPop':
|
|
244
|
+
return new StdDevPopAccumulator(expr);
|
|
245
|
+
case '$stdDevSamp':
|
|
246
|
+
return new StdDevSampAccumulator(expr);
|
|
247
|
+
default:
|
|
248
|
+
throw new Error(`unknown group operator '${op}'`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=accumulators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accumulators.js","sourceRoot":"","sources":["../../src/aggregation/accumulators.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC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IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,MAAM;YACT,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACpC,KAAK,OAAO;YACV,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACnC,KAAK,OAAO;YACV,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACnC,KAAK,WAAW;YACd,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACvC,KAAK,QAAQ;YACX,OAAO,IAAI,gBAAgB,EAAE,CAAC;QAChC,KAAK,eAAe;YAClB,OAAO,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC;QAC3C,KAAK,YAAY;YACf,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACxC,KAAK,aAAa;YAChB,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACzC;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Document, PipelineStage } from '../types.ts';
|
|
2
|
+
import type { AggregationDbContext } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* AggregationCursor represents a cursor over aggregation pipeline results.
|
|
5
|
+
*/
|
|
6
|
+
export declare class AggregationCursor<T extends Document = Document> {
|
|
7
|
+
private readonly source;
|
|
8
|
+
private readonly pipeline;
|
|
9
|
+
private readonly dbContext?;
|
|
10
|
+
private pipelineNow?;
|
|
11
|
+
constructor(source: () => Promise<T[]>, pipeline: PipelineStage[], dbContext?: AggregationDbContext);
|
|
12
|
+
/**
|
|
13
|
+
* Get system variables for a document.
|
|
14
|
+
* Uses shared $$NOW date for consistency across pipeline.
|
|
15
|
+
*/
|
|
16
|
+
private getSystemVars;
|
|
17
|
+
toArray(): Promise<Document[]>;
|
|
18
|
+
private executeStage;
|
|
19
|
+
private execMatch;
|
|
20
|
+
private execProject;
|
|
21
|
+
/**
|
|
22
|
+
* $redact - field-level access control with recursive traversal.
|
|
23
|
+
*/
|
|
24
|
+
private execRedact;
|
|
25
|
+
/**
|
|
26
|
+
* $documents - injects literal documents into the pipeline.
|
|
27
|
+
* Must be the first stage.
|
|
28
|
+
*/
|
|
29
|
+
private execDocuments;
|
|
30
|
+
/**
|
|
31
|
+
* $unset - removes specified fields from documents.
|
|
32
|
+
* Alias for $project with field exclusion.
|
|
33
|
+
*/
|
|
34
|
+
private execUnset;
|
|
35
|
+
private isLiteralExpression;
|
|
36
|
+
private projectDocument;
|
|
37
|
+
private execSort;
|
|
38
|
+
private execLimit;
|
|
39
|
+
private execSkip;
|
|
40
|
+
private execCount;
|
|
41
|
+
private execUnwind;
|
|
42
|
+
private execGroup;
|
|
43
|
+
private execLookup;
|
|
44
|
+
/**
|
|
45
|
+
* MongoDB system variables that should not be substituted.
|
|
46
|
+
*/
|
|
47
|
+
private static readonly SYSTEM_VARIABLES;
|
|
48
|
+
/**
|
|
49
|
+
* Recursively substitute $$varName references with actual values.
|
|
50
|
+
* Supports dotted paths like $$varName.field.subfield.
|
|
51
|
+
*/
|
|
52
|
+
private substituteLetVars;
|
|
53
|
+
/**
|
|
54
|
+
* $graphLookup - recursive lookup for graph traversal.
|
|
55
|
+
*/
|
|
56
|
+
private execGraphLookup;
|
|
57
|
+
/**
|
|
58
|
+
* $densify - fills gaps in numeric or date sequences.
|
|
59
|
+
*/
|
|
60
|
+
private execDensify;
|
|
61
|
+
/**
|
|
62
|
+
* $fill - fills null/missing values with various strategies.
|
|
63
|
+
*/
|
|
64
|
+
private execFill;
|
|
65
|
+
/**
|
|
66
|
+
* $setWindowFields - window functions for analytics.
|
|
67
|
+
*/
|
|
68
|
+
private execSetWindowFields;
|
|
69
|
+
/**
|
|
70
|
+
* Get documents within the specified window bounds.
|
|
71
|
+
*/
|
|
72
|
+
private getWindowDocuments;
|
|
73
|
+
/**
|
|
74
|
+
* Apply a window operator to the current document.
|
|
75
|
+
*/
|
|
76
|
+
private applyWindowOperator;
|
|
77
|
+
private execAddFields;
|
|
78
|
+
private execReplaceRoot;
|
|
79
|
+
private execOut;
|
|
80
|
+
/**
|
|
81
|
+
* $merge - Writes documents to a collection, with options for handling matches.
|
|
82
|
+
*/
|
|
83
|
+
private execMerge;
|
|
84
|
+
/**
|
|
85
|
+
* $sortByCount - Groups by expression and counts, sorted by count descending.
|
|
86
|
+
* Equivalent to: { $group: { _id: <expression>, count: { $sum: 1 } } }, { $sort: { count: -1 } }
|
|
87
|
+
*/
|
|
88
|
+
private execSortByCount;
|
|
89
|
+
/**
|
|
90
|
+
* $sample - Randomly selects the specified number of documents.
|
|
91
|
+
*/
|
|
92
|
+
private execSample;
|
|
93
|
+
/**
|
|
94
|
+
* $facet - Processes multiple aggregation pipelines within a single stage.
|
|
95
|
+
* Returns a single document where each field contains the array of results from its pipeline.
|
|
96
|
+
*/
|
|
97
|
+
private execFacet;
|
|
98
|
+
/**
|
|
99
|
+
* $bucket - Categorizes documents into groups (buckets) based on boundaries.
|
|
100
|
+
*/
|
|
101
|
+
private execBucket;
|
|
102
|
+
/**
|
|
103
|
+
* $bucketAuto - Automatically creates bucket boundaries.
|
|
104
|
+
*/
|
|
105
|
+
private execBucketAuto;
|
|
106
|
+
/**
|
|
107
|
+
* $unionWith - Combines documents from two collections.
|
|
108
|
+
*/
|
|
109
|
+
private execUnionWith;
|
|
110
|
+
/**
|
|
111
|
+
* Execute $geoNear stage.
|
|
112
|
+
* Returns documents sorted by distance from the specified point.
|
|
113
|
+
*/
|
|
114
|
+
private execGeoNear;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=cursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/aggregation/cursor.ts"],"names":[],"mappings":"AAMA,OAAO,KA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