@procedures/mongo 0.2.3 → 0.4.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 +65 -0
- package/README.md +74 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +9 -0
- package/dist/module.js.map +1 -1
- package/dist/procedures/documents.aggregate.d.ts +5 -0
- package/dist/procedures/documents.aggregate.d.ts.map +1 -1
- package/dist/procedures/documents.aggregate.js +36 -3
- package/dist/procedures/documents.aggregate.js.map +1 -1
- package/dist/procedures/documents.bulk.d.ts +42 -0
- package/dist/procedures/documents.bulk.d.ts.map +1 -0
- package/dist/procedures/documents.bulk.js +159 -0
- package/dist/procedures/documents.bulk.js.map +1 -0
- package/dist/procedures/documents.distinct.d.ts +22 -0
- package/dist/procedures/documents.distinct.d.ts.map +1 -0
- package/dist/procedures/documents.distinct.js +33 -0
- package/dist/procedures/documents.distinct.js.map +1 -0
- package/dist/procedures/documents.explain.d.ts +41 -0
- package/dist/procedures/documents.explain.d.ts.map +1 -0
- package/dist/procedures/documents.explain.js +111 -0
- package/dist/procedures/documents.explain.js.map +1 -0
- package/dist/procedures/index.d.ts +4 -0
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +5 -0
- package/dist/procedures/index.js.map +1 -1
- package/dist/procedures/watch.d.ts +59 -0
- package/dist/procedures/watch.d.ts.map +1 -0
- package/dist/procedures/watch.js +149 -0
- package/dist/procedures/watch.js.map +1 -0
- package/dist/procedures.types.d.ts +24 -3
- package/dist/procedures.types.d.ts.map +1 -1
- package/dist/storage/mongo-storage.d.ts +1 -0
- package/dist/storage/mongo-storage.d.ts.map +1 -1
- package/dist/storage/mongo-storage.js +4 -0
- package/dist/storage/mongo-storage.js.map +1 -1
- package/dist/types.d.ts +20 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +10 -0
- package/src/module.ts +9 -0
- package/src/procedures/documents.aggregate.ts +34 -3
- package/src/procedures/documents.bulk.ts +192 -0
- package/src/procedures/documents.distinct.ts +57 -0
- package/src/procedures/documents.explain.ts +144 -0
- package/src/procedures/index.ts +6 -0
- package/src/procedures/watch.ts +184 -0
- package/src/procedures.types.ts +25 -0
- package/src/storage/mongo-storage.ts +5 -0
- package/src/types.ts +22 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# @procedures/mongo
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d919678]
|
|
8
|
+
- Updated dependencies [057d69a]
|
|
9
|
+
- Updated dependencies [b2a1a1e]
|
|
10
|
+
- Updated dependencies [057d69a]
|
|
11
|
+
- Updated dependencies [057d69a]
|
|
12
|
+
- Updated dependencies [057d69a]
|
|
13
|
+
- Updated dependencies [057d69a]
|
|
14
|
+
- Updated dependencies [057d69a]
|
|
15
|
+
- Updated dependencies [afd6a19]
|
|
16
|
+
- Updated dependencies [057d69a]
|
|
17
|
+
- Updated dependencies [0abf2ec]
|
|
18
|
+
- Updated dependencies [4e751da]
|
|
19
|
+
- @procedures/client@0.4.0
|
|
20
|
+
- @procedures/collections@0.4.0
|
|
21
|
+
|
|
22
|
+
## 0.3.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- c799cdd: `HybridStorage` cannot lose data (roadmap R2). A sync gets the ids of the remote items from the new `getEntries()` of a storage (the collection procedure `collections.<name>.entries`), or else from `keyOf`. A remote item without a key stops the sync with `MissingKeysError` before any change: before, such a list emptied the local cache. A write-through that the remote cannot take waits in the queue and throws `PendingWriteError`, and a timer sends the queue. A write that the remote refuses is undone in the local cache. A full queue refuses a write with `QueueFullError`: before, it dropped the oldest operation. A second try of a write replaces its queued operation. A write-through sends the older queued operations first. The reads wait for the first sync.
|
|
27
|
+
- 3aa6495: Four procedures (roadmap R44). `mongo.documents.distinct` gives the distinct values of a field. `mongo.documents.bulk` sends `insertOne`, `updateOne`, `updateMany`, `deleteOne` and `deleteMany` operations in one request, in order by default. An empty filter of an update or a delete needs `confirm: true`. `mongo.documents.explain` gives the plan of a find or an aggregation, and refuses `$out` and `$merge`.
|
|
28
|
+
|
|
29
|
+
`mongo.watch` gives the changes of a collection or a database as a stream without an end. The stream closes when the reader stops or the call aborts. A change stream needs a replica set. The type `BulkOperation` also has `BulkUpdateMany` and `BulkDeleteMany`.
|
|
30
|
+
- 89d8a4a: Three procedures only read now (CAP-1, CAP-2, CAP-3, roadmap R7), so a read-only session (`mark mcp --read-only`) serves them. `db.query` refuses a statement that changes data (`PRAGMA query_only`), and the file keeps its bytes. `mongo.documents.aggregate` refuses `$out` and `$merge`, also in the pipelines of `$facet`, `$lookup` and `$unionWith`. `logs.query` gives no entries for a missing file or table, and does not make them.
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [ddea529]
|
|
35
|
+
- Updated dependencies [b2a3e3a]
|
|
36
|
+
- Updated dependencies [a8c47f1]
|
|
37
|
+
- Updated dependencies [381ce3a]
|
|
38
|
+
- Updated dependencies [0c627f8]
|
|
39
|
+
- Updated dependencies [ae7f05f]
|
|
40
|
+
- Updated dependencies [7873940]
|
|
41
|
+
- Updated dependencies [a70d445]
|
|
42
|
+
- Updated dependencies [bc70357]
|
|
43
|
+
- Updated dependencies [07cc998]
|
|
44
|
+
- Updated dependencies [a6b01a9]
|
|
45
|
+
- Updated dependencies [c799cdd]
|
|
46
|
+
- Updated dependencies [540f8d9]
|
|
47
|
+
- Updated dependencies [b6daaec]
|
|
48
|
+
- Updated dependencies [5b9264e]
|
|
49
|
+
- Updated dependencies [956e88b]
|
|
50
|
+
- Updated dependencies [ff62281]
|
|
51
|
+
- Updated dependencies [d81d0ed]
|
|
52
|
+
- Updated dependencies [aa67cc7]
|
|
53
|
+
- Updated dependencies [061fa22]
|
|
54
|
+
- Updated dependencies [cfb9d69]
|
|
55
|
+
- Updated dependencies [43f7de5]
|
|
56
|
+
- Updated dependencies [b07bb50]
|
|
57
|
+
- Updated dependencies [4a3bfa1]
|
|
58
|
+
- Updated dependencies [bd0b626]
|
|
59
|
+
- Updated dependencies [a6be873]
|
|
60
|
+
- Updated dependencies [fb30718]
|
|
61
|
+
- Updated dependencies [c5528e4]
|
|
62
|
+
- Updated dependencies [fee5d9c]
|
|
63
|
+
- Updated dependencies [21f7743]
|
|
64
|
+
- Updated dependencies [31a0b46]
|
|
65
|
+
- @procedures/client@0.3.0
|
|
66
|
+
- @procedures/collections@0.3.0
|
|
67
|
+
|
|
3
68
|
## 0.2.3
|
|
4
69
|
|
|
5
70
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -13,11 +13,12 @@ MongoDB client wrapper with client procedures for local or RPC access. Provides
|
|
|
13
13
|
- **Local usage**: Direct MongoDB connection with native driver
|
|
14
14
|
- **RPC usage**: Remote procedure calls via `client.call()`
|
|
15
15
|
|
|
16
|
-
The package follows the client procedure pattern, with
|
|
16
|
+
The package follows the client procedure pattern, with 20 procedures in 5 categories. Its register entry (`import "@procedures/mongo/register"`) registers them:
|
|
17
17
|
- **Database**: `ping`, `info`
|
|
18
18
|
- **Collections**: `list`, `create`, `drop`, `stats`
|
|
19
|
-
- **Documents**: `find`, `get`, `insert`, `update`, `delete`, `count`, `aggregate`
|
|
19
|
+
- **Documents**: `find`, `get`, `insert`, `update`, `delete`, `count`, `aggregate`, `distinct`, `bulk`, `explain`
|
|
20
20
|
- **Indexes**: `list`, `create`, `drop`
|
|
21
|
+
- **Change streams**: `mongo.watch`
|
|
21
22
|
|
|
22
23
|
## Architecture
|
|
23
24
|
|
|
@@ -735,6 +736,52 @@ interface AggregateOutput {
|
|
|
735
736
|
}
|
|
736
737
|
```
|
|
737
738
|
|
|
739
|
+
##### `mongo.documents.distinct`
|
|
740
|
+
|
|
741
|
+
The procedure gives the distinct values of one field in the documents that match `query`. The default `query` matches all documents. An array field gives each of its elements. Use dots for an embedded field, for example `address.city`.
|
|
742
|
+
|
|
743
|
+
```typescript
|
|
744
|
+
const { values } = await client.exec(
|
|
745
|
+
["mongo", "documents", "distinct"],
|
|
746
|
+
{ collection: "users", field: "country", query: { status: "active" } }
|
|
747
|
+
);
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
##### `mongo.documents.bulk`
|
|
751
|
+
|
|
752
|
+
The procedure sends several writes in one request. The operations have the form of the `bulkWrite` of the driver: `insertOne`, `updateOne`, `updateMany`, `deleteOne` and `deleteMany`. By default, the operations run in order, and the first failure stops the rest. With `ordered: false`, the server tries each operation, and the error tells which ones failed.
|
|
753
|
+
|
|
754
|
+
The rules of `update` and `delete` apply to each operation. An empty filter of an update or a delete needs `confirm: true` on the call. An unknown operation or field is an error.
|
|
755
|
+
|
|
756
|
+
```typescript
|
|
757
|
+
const result = await client.exec(["mongo", "documents", "bulk"], {
|
|
758
|
+
collection: "users",
|
|
759
|
+
operations: [
|
|
760
|
+
{ insertOne: { document: { name: "Di" } } },
|
|
761
|
+
{ updateOne: { filter: { name: "Ann" }, update: { $set: { status: "active" } } } },
|
|
762
|
+
{ updateMany: { filter: { status: "new" }, update: { $set: { status: "active" } } } },
|
|
763
|
+
{ deleteOne: { filter: { name: "Bob" } } },
|
|
764
|
+
{ deleteMany: { filter: { status: "deleted" } } },
|
|
765
|
+
],
|
|
766
|
+
});
|
|
767
|
+
// result: { ok, insertedCount, matchedCount, modifiedCount, deletedCount, upsertedCount, insertedIds, upsertedIds }
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
The ids in `insertedIds` and `upsertedIds` are text, and their keys are the indexes of the operations.
|
|
771
|
+
|
|
772
|
+
##### `mongo.documents.explain`
|
|
773
|
+
|
|
774
|
+
The procedure gives the plan of a find or of an aggregation pipeline. With `pipeline`, it explains an aggregation. Without `pipeline`, it explains a find with `query`, `projection`, `sort` and `limit`. The verbosity `queryPlanner` (the default) gives the plan only. With the verbosities `executionStats` and `allPlansExecution`, the server also does the plan and gives its statistics. As `documents.aggregate` does, the procedure refuses `$out` and `$merge`.
|
|
775
|
+
|
|
776
|
+
```typescript
|
|
777
|
+
const { operation, plan } = await client.exec(["mongo", "documents", "explain"], {
|
|
778
|
+
collection: "users",
|
|
779
|
+
query: { email: "ann@example.com" },
|
|
780
|
+
verbosity: "executionStats",
|
|
781
|
+
});
|
|
782
|
+
console.log(plan.queryPlanner.winningPlan);
|
|
783
|
+
```
|
|
784
|
+
|
|
738
785
|
#### Index Procedures
|
|
739
786
|
|
|
740
787
|
##### `mongo.indexes.list`
|
|
@@ -856,6 +903,26 @@ interface DropIndexOutput {
|
|
|
856
903
|
}
|
|
857
904
|
```
|
|
858
905
|
|
|
906
|
+
#### Change Streams
|
|
907
|
+
|
|
908
|
+
##### `mongo.watch`
|
|
909
|
+
|
|
910
|
+
The procedure gives the changes of a collection as a stream. Without `collection`, it gives the changes of each collection of the database. The stream has no end (`metadata.stream: { unbounded: true }`). It stops when the reader stops or the call aborts, and the procedure then closes the change stream.
|
|
911
|
+
|
|
912
|
+
A change stream needs a replica set or a sharded cluster. A standalone server refuses it, and the reader gets that error.
|
|
913
|
+
|
|
914
|
+
```typescript
|
|
915
|
+
for await (const change of client.execStream(["mongo", "watch"], {
|
|
916
|
+
collection: "orders",
|
|
917
|
+
pipeline: [{ $match: { operationType: { $in: ["insert", "update"] } } }],
|
|
918
|
+
fullDocument: "updateLookup",
|
|
919
|
+
})) {
|
|
920
|
+
console.log(change.operationType, change.documentKey, change.resumeToken);
|
|
921
|
+
}
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
Each item has the `operationType`, the namespace `ns`, the `documentKey` and the `resumeToken`. An insert gives the `fullDocument`, and an update gives the `updateDescription`. With `fullDocument: "updateLookup"`, an update also gives the current document. To continue after a stop, give the last `resumeToken` as `resumeAfter`. The `pipeline` accepts only the stages of a change stream: `$match`, `$project`, `$addFields`, `$set`, `$unset`, `$replaceRoot`, `$replaceWith` and `$redact`.
|
|
925
|
+
|
|
859
926
|
### Type Definitions
|
|
860
927
|
|
|
861
928
|
#### Core Types
|
|
@@ -1278,9 +1345,13 @@ client-mongo/
|
|
|
1278
1345
|
│ │ ├── documents.delete.ts
|
|
1279
1346
|
│ │ ├── documents.count.ts
|
|
1280
1347
|
│ │ ├── documents.aggregate.ts
|
|
1348
|
+
│ │ ├── documents.distinct.ts
|
|
1349
|
+
│ │ ├── documents.bulk.ts
|
|
1350
|
+
│ │ ├── documents.explain.ts
|
|
1281
1351
|
│ │ ├── indexes.list.ts
|
|
1282
1352
|
│ │ ├── indexes.create.ts
|
|
1283
|
-
│ │
|
|
1353
|
+
│ │ ├── indexes.drop.ts
|
|
1354
|
+
│ │ └── watch.ts # mongo.watch
|
|
1284
1355
|
├── dist/ # Compiled output
|
|
1285
1356
|
├── package.json
|
|
1286
1357
|
├── tsconfig.json
|