liwi-mongo 13.4.0 → 14.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/README.md +143 -2
- package/dist/definitions/MongoConnection.d.ts +6 -1
- package/dist/definitions/MongoConnection.d.ts.map +1 -1
- package/dist/definitions/MongoCursor.d.ts.map +1 -1
- package/dist/definitions/MongoQuerySingleItem.d.ts +1 -0
- package/dist/definitions/MongoQuerySingleItem.d.ts.map +1 -1
- package/dist/definitions/MongoQuerySingleItem.test.d.ts +2 -0
- package/dist/definitions/MongoQuerySingleItem.test.d.ts.map +1 -0
- package/dist/definitions/MongoStore.d.ts +18 -4
- package/dist/definitions/MongoStore.d.ts.map +1 -1
- package/dist/definitions/SubscribeStore.integration.test.d.ts +2 -0
- package/dist/definitions/SubscribeStore.integration.test.d.ts.map +1 -0
- package/dist/definitions/index.d.ts +1 -1
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/definitions/memory/applyUpdate.d.ts +23 -0
- package/dist/definitions/memory/applyUpdate.d.ts.map +1 -0
- package/dist/definitions/memory/cloneAsStored.d.ts +10 -0
- package/dist/definitions/memory/cloneAsStored.d.ts.map +1 -0
- package/dist/definitions/memory/cloneAsStored.test.d.ts +2 -0
- package/dist/definitions/memory/cloneAsStored.test.d.ts.map +1 -0
- package/dist/definitions/memory/contract.test.d.ts +2 -0
- package/dist/definitions/memory/contract.test.d.ts.map +1 -0
- package/dist/definitions/memory/createMemoryCollection.d.ts +19 -0
- package/dist/definitions/memory/createMemoryCollection.d.ts.map +1 -0
- package/dist/definitions/memory/createMemoryCursor.d.ts +29 -0
- package/dist/definitions/memory/createMemoryCursor.d.ts.map +1 -0
- package/dist/definitions/memory/createMemoryCursor.test.d.ts +2 -0
- package/dist/definitions/memory/createMemoryCursor.test.d.ts.map +1 -0
- package/dist/definitions/memory/createMemoryDb.d.ts +7 -0
- package/dist/definitions/memory/createMemoryDb.d.ts.map +1 -0
- package/dist/definitions/memory/createMemoryMongoClient.d.ts +13 -0
- package/dist/definitions/memory/createMemoryMongoClient.d.ts.map +1 -0
- package/dist/definitions/memory/createMemoryMongoClient.test.d.ts +2 -0
- package/dist/definitions/memory/createMemoryMongoClient.test.d.ts.map +1 -0
- package/dist/definitions/memory/errors.d.ts +20 -0
- package/dist/definitions/memory/errors.d.ts.map +1 -0
- package/dist/definitions/memory/guardUnsupported.d.ts +3 -0
- package/dist/definitions/memory/guardUnsupported.d.ts.map +1 -0
- package/dist/definitions/memory/indexes/createIndexInfo.d.ts +5 -0
- package/dist/definitions/memory/indexes/createIndexInfo.d.ts.map +1 -0
- package/dist/definitions/memory/indexes/createIndexInfo.test.d.ts +2 -0
- package/dist/definitions/memory/indexes/createIndexInfo.test.d.ts.map +1 -0
- package/dist/definitions/memory/indexes/createMemoryIndexes.d.ts +19 -0
- package/dist/definitions/memory/indexes/createMemoryIndexes.d.ts.map +1 -0
- package/dist/definitions/memory/indexes/createUniqueConstraint.d.ts +16 -0
- package/dist/definitions/memory/indexes/createUniqueConstraint.d.ts.map +1 -0
- package/dist/definitions/memory/normalizeSort.d.ts +4 -0
- package/dist/definitions/memory/normalizeSort.d.ts.map +1 -0
- package/dist/definitions/memory/normalizeSort.test.d.ts +2 -0
- package/dist/definitions/memory/normalizeSort.test.d.ts.map +1 -0
- package/dist/definitions/memory/queryOptions.d.ts +3 -0
- package/dist/definitions/memory/queryOptions.d.ts.map +1 -0
- package/dist/definitions/memory/serializeKey.d.ts +6 -0
- package/dist/definitions/memory/serializeKey.d.ts.map +1 -0
- package/dist/definitions/memory/settle.d.ts +3 -0
- package/dist/definitions/memory/settle.d.ts.map +1 -0
- package/dist/definitions/memory.d.ts +2 -0
- package/dist/definitions/memory.d.ts.map +1 -0
- package/dist/definitions/writes/createReplacePipeline.d.ts +10 -0
- package/dist/definitions/writes/createReplacePipeline.d.ts.map +1 -0
- package/dist/definitions/writes/stampPartialUpdate.d.ts +9 -0
- package/dist/definitions/writes/stampPartialUpdate.d.ts.map +1 -0
- package/dist/definitions/writes/stampPartialUpdate.test.d.ts +2 -0
- package/dist/definitions/writes/stampPartialUpdate.test.d.ts.map +1 -0
- package/dist/index-node.mjs +235 -105
- package/dist/index-node.mjs.map +1 -1
- package/dist/memory-node.mjs +849 -0
- package/dist/memory-node.mjs.map +1 -0
- package/package.json +15 -8
- package/src/MongoConnection.test.ts +24 -2
- package/src/MongoConnection.ts +44 -28
- package/src/MongoCursor.ts +2 -4
- package/src/MongoQuerySingleItem.test.ts +162 -0
- package/src/MongoQuerySingleItem.ts +56 -50
- package/src/MongoStore.test.ts +250 -0
- package/src/MongoStore.ts +122 -26
- package/src/SubscribeStore.integration.test.ts +414 -0
- package/src/index.ts +1 -0
- package/src/indexes/diffIndexes.test.ts +2 -2
- package/src/indexes/normalizeIndex.test.ts +2 -2
- package/src/indexes/normalizeIndex.ts +2 -2
- package/src/memory/applyUpdate.ts +146 -0
- package/src/memory/cloneAsStored.test.ts +55 -0
- package/src/memory/cloneAsStored.ts +34 -0
- package/src/memory/contract.test.ts +967 -0
- package/src/memory/createMemoryCollection.ts +405 -0
- package/src/memory/createMemoryCursor.test.ts +78 -0
- package/src/memory/createMemoryCursor.ts +90 -0
- package/src/memory/createMemoryDb.ts +66 -0
- package/src/memory/createMemoryMongoClient.test.ts +85 -0
- package/src/memory/createMemoryMongoClient.ts +47 -0
- package/src/memory/errors.ts +85 -0
- package/src/memory/guardUnsupported.ts +25 -0
- package/src/memory/indexes/createIndexInfo.test.ts +36 -0
- package/src/memory/indexes/createIndexInfo.ts +82 -0
- package/src/memory/indexes/createMemoryIndexes.ts +178 -0
- package/src/memory/indexes/createUniqueConstraint.ts +151 -0
- package/src/memory/normalizeSort.test.ts +37 -0
- package/src/memory/normalizeSort.ts +56 -0
- package/src/memory/queryOptions.ts +3 -0
- package/src/memory/serializeKey.ts +10 -0
- package/src/memory/settle.ts +5 -0
- package/src/memory.ts +5 -0
- package/src/writes/createReplacePipeline.ts +23 -0
- package/src/writes/stampPartialUpdate.test.ts +93 -0
- package/src/writes/stampPartialUpdate.ts +84 -0
package/README.md
CHANGED
|
@@ -81,7 +81,9 @@ interface MongoBaseModel<KeyValue extends AllowedKeyValue = string> {
|
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
The key path is always `_id`. `MongoInsertType<Model>` makes `_id`, `created` and `updated` optional
|
|
84
|
+
The key path is always `_id`. `MongoInsertType<Model>` makes `_id`, `created` and `updated` optional. Every write sets `updated` to the write time from the app clock, and an update or a replace never changes `created`: see [`created` and `updated`](../liwi-store#created-and-updated) for the rule of each method. `insertOne` and `upsertOne` mutate and return the object you passed; `replaceOne` leaves it untouched and returns the stored document.
|
|
85
|
+
|
|
86
|
+
Requires MongoDB ≥ 4.2: replaces are update pipelines.
|
|
85
87
|
|
|
86
88
|
## `MongoConnection`
|
|
87
89
|
|
|
@@ -91,6 +93,12 @@ new MongoConnection({ host, port, database, user, password });
|
|
|
91
93
|
|
|
92
94
|
`host` defaults to `localhost` and `port` to `27017`; `database` is required. Connecting starts immediately in the constructor and is awaited lazily by store operations, so no explicit `connect()` call is needed. Credentials are redacted from logs. Call `connection.close()` on shutdown.
|
|
93
95
|
|
|
96
|
+
```ts
|
|
97
|
+
new MongoConnection({ client });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Uses a `MongoClient` you created yourself, connected or connecting: a connection string or client options `MongoConfig` does not cover, or the [in-memory client](#in-memory). `close()` closes it.
|
|
101
|
+
|
|
94
102
|
## `MongoStore`
|
|
95
103
|
|
|
96
104
|
```ts
|
|
@@ -111,6 +119,29 @@ const set: Update<Task>["$set"] = { completed: true };
|
|
|
111
119
|
|
|
112
120
|
The store also exposes the underlying driver handles when you need them: `store.collection` resolves the `mongodb` collection.
|
|
113
121
|
|
|
122
|
+
### Writes and their cost
|
|
123
|
+
|
|
124
|
+
The plain methods do one round trip and do not read the previous document:
|
|
125
|
+
|
|
126
|
+
| Method | Driver call | Missing key |
|
|
127
|
+
| -------------------- | --------------------------------------------------------------------- | ---------------------- |
|
|
128
|
+
| `partialUpdateByKey` | `findOneAndUpdate` with `returnDocument: "after"` | throws `NotFoundError` |
|
|
129
|
+
| `partialUpdateMany` | one `updateMany`; every document gets the same `updated` | — |
|
|
130
|
+
| `replaceOne` | `findOneAndUpdate` with a replace pipeline, `returnDocument: "after"` | throws `NotFoundError` |
|
|
131
|
+
| `deleteByKey` | `deleteOne` | no-op |
|
|
132
|
+
|
|
133
|
+
The replace pipeline is `$replaceWith` of the object (wrapped in `$literal`, so string values starting with `$` stay data) merged with the stored `created`. A plain `replaceOne` command could not keep `created`.
|
|
134
|
+
|
|
135
|
+
The [`…WithInfo` variants](../liwi-store#writes-with-info) also return the previous document, read atomically with the write. The subscribe store uses them:
|
|
136
|
+
|
|
137
|
+
| Method | Driver calls |
|
|
138
|
+
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
139
|
+
| `partialUpdateByKeyWithInfo` | `findOneAndUpdate` with `returnDocument: "before"`, then `findOne` for `next` |
|
|
140
|
+
| `replaceOneWithInfo` | the replace pipeline with `returnDocument: "before"`; `next` is the replacement with the stored `created`, no read back |
|
|
141
|
+
| `deleteByKeyWithInfo` | `findOneAndDelete` |
|
|
142
|
+
|
|
143
|
+
Mongo cannot return both the before and after documents of one update, so `partialUpdateByKeyWithInfo` reads `next` back. That read may already include a later concurrent write (which emits its own change), and it finds nothing if a concurrent delete landed first: `next` is then `undefined` although the update was applied.
|
|
144
|
+
|
|
114
145
|
## Indexes
|
|
115
146
|
|
|
116
147
|
Indexes are declared on the store and applied by an explicit sync step. The declaration is validated eagerly in the constructor (empty key, a name resolving to `_id_`, duplicate names, more than one text index).
|
|
@@ -259,7 +290,7 @@ const subscription = query.fetchAndSubscribe((error, changes) => {
|
|
|
259
290
|
subscription.stop();
|
|
260
291
|
```
|
|
261
292
|
|
|
262
|
-
`createQuerySingleItem` behaves the same but resolves a single item.
|
|
293
|
+
`createQuerySingleItem` behaves the same but resolves a single item. Without `sort`, its criteria must match at most one document: when one update moves several matching documents, the subscription reports the error `should not match more than 1, use sort if you can have multiple match` through its callback. With `sort`, it refetches on every relevant update.
|
|
263
294
|
|
|
264
295
|
Subscriptions are driven in-process: writes going through the subscribe store are matched against the query criteria with [mingo](https://github.com/kofrasa/mingo).
|
|
265
296
|
|
|
@@ -268,3 +299,113 @@ Caveats:
|
|
|
268
299
|
- Writes performed outside this process (other services, mongo shell, migrations) are not detected.
|
|
269
300
|
- `$text` criteria cannot be matched in memory: such queries fetch correctly but never emit updates.
|
|
270
301
|
- Queries returned by the subscribe store are fixed — `changeParams` throws; build a new query when parameters change.
|
|
302
|
+
|
|
303
|
+
## Testing
|
|
304
|
+
|
|
305
|
+
Two ways to give tests a database, both behind the same `MongoConnection`, so the stores and the app code under test do not change.
|
|
306
|
+
|
|
307
|
+
### A real mongod
|
|
308
|
+
|
|
309
|
+
The behaviour is mongod's by definition. Start one per test run with [`mongodb-memory-server`](https://github.com/typegoose/mongodb-memory-server) (it downloads a mongod binary once, then starts in about a second) or point at a mongod you already run:
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import { MongoMemoryServer } from "mongodb-memory-server-core";
|
|
313
|
+
import { MongoConnection, MongoRegistry } from "liwi-mongo";
|
|
314
|
+
|
|
315
|
+
const mongod = await MongoMemoryServer.create();
|
|
316
|
+
const connection = new MongoConnection({
|
|
317
|
+
host: "127.0.0.1",
|
|
318
|
+
port: mongod.instanceInfo!.port,
|
|
319
|
+
database: "app-test",
|
|
320
|
+
});
|
|
321
|
+
const stores = createStores(connection); // your app's MongoStore instances
|
|
322
|
+
await new MongoRegistry(stores).syncIndexes();
|
|
323
|
+
|
|
324
|
+
// between tests
|
|
325
|
+
await Promise.all(stores.map((store) => store.deleteMany({})));
|
|
326
|
+
|
|
327
|
+
// teardown
|
|
328
|
+
await connection.close();
|
|
329
|
+
await mongod.stop();
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Nothing in liwi is needed for this. Every write is a round trip to another process, which is what makes a large e2e suite slow.
|
|
333
|
+
|
|
334
|
+
### In memory
|
|
335
|
+
|
|
336
|
+
`liwi-mongo/memory` is a mongo client that keeps the data in the test process: no binary, no port, no round trip. `MongoStore`, its queries, subscriptions and `MongoRegistry.syncIndexes` run unchanged on top of it; queries, sorts, projections, update operators and pipelines are evaluated by [mingo](https://github.com/kofrasa/mingo).
|
|
337
|
+
|
|
338
|
+
```ts
|
|
339
|
+
import { MongoConnection, MongoRegistry } from "liwi-mongo";
|
|
340
|
+
import { createMemoryMongoClient } from "liwi-mongo/memory";
|
|
341
|
+
|
|
342
|
+
const memory = createMemoryMongoClient();
|
|
343
|
+
const connection = new MongoConnection({ client: memory.client });
|
|
344
|
+
const stores = createStores(connection);
|
|
345
|
+
await new MongoRegistry(stores).syncIndexes();
|
|
346
|
+
|
|
347
|
+
// between tests: empties every collection, indexes stay
|
|
348
|
+
memory.clear();
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
An e2e server can switch on an environment variable, and import the entry only in that mode:
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
const connection = process.env.E2E_MEMORY_DATABASE
|
|
355
|
+
? new MongoConnection({
|
|
356
|
+
client: (await import("liwi-mongo/memory")).createMemoryMongoClient()
|
|
357
|
+
.client,
|
|
358
|
+
})
|
|
359
|
+
: new MongoConnection(config.mongo);
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Sync the indexes as production does: the memory client only enforces the unique indexes it was asked to create.
|
|
363
|
+
|
|
364
|
+
`createMemoryMongoClient({ database })` — `database` (default `liwi-memory`) is the one `client.db()` returns. Every client has its own data.
|
|
365
|
+
|
|
366
|
+
#### Behaviour
|
|
367
|
+
|
|
368
|
+
Documents are written and read back the way the driver serializes them: `undefined` becomes `null`, functions are dropped, a `Buffer` becomes a `Binary`, a class instance or a `Map` becomes a plain document. Every read returns a copy. A missing `_id` is generated as an `ObjectId`, set on the object passed in, as the driver does.
|
|
369
|
+
|
|
370
|
+
Indexes are listed as mongod lists them, so a second `syncIndexes` plans nothing. Unique indexes are enforced, with `sparse`, `partialFilterExpression`, compound and array (multikey) keys, and a case-insensitive `collation` (strength 1 or 2). A violation throws a `MongoServerError` with code `11000`, `keyPattern` and `keyValue`.
|
|
371
|
+
|
|
372
|
+
Errors carry mongod's codes where code reads them: `26` (missing collection on `listIndexes` / `dropIndex`), `27` (missing index), `40` (conflicting update paths), `66` (`_id` change), `85` / `86` (index conflicts), `11000` (duplicate key).
|
|
373
|
+
|
|
374
|
+
Implemented driver methods:
|
|
375
|
+
|
|
376
|
+
- client: `db`, `connect`, `close`, `on`
|
|
377
|
+
- db: `collection`, `command` (`ping`, `collMod` of an index), `dropDatabase`
|
|
378
|
+
- collection: `insertOne`, `insertMany`, `findOne`, `find` (`sort`, `project`, `skip`, `limit`), `countDocuments`, `estimatedDocumentCount`, `aggregate` (with `$lookup` on other collections of the database), `updateOne`, `updateMany`, `findOneAndUpdate` (`upsert`, `arrayFilters`, `sort`, `returnDocument`, `projection`), `deleteOne`, `deleteMany`, `findOneAndDelete`, `createIndex`, `createIndexes`, `listIndexes`, `indexes`, `dropIndex`, `drop`
|
|
379
|
+
|
|
380
|
+
Reading any other method throws `liwi-mongo/memory: collection(<name>).<method> is not supported` rather than `undefined is not a function`.
|
|
381
|
+
|
|
382
|
+
#### What differs from mongod
|
|
383
|
+
|
|
384
|
+
- `$text` queries and `$meta` sorts throw; text indexes are created and listed, not searched.
|
|
385
|
+
- TTL indexes (`expireAfterSeconds`) never expire documents.
|
|
386
|
+
- No transactions, sessions, change streams (`watch`) or `bulkWrite`. Options such as `session`, `writeConcern` or `collation` on a query are ignored.
|
|
387
|
+
- Writes are never concurrent: each operation runs to completion before the next one starts. Code relying on mongod interleaving two writes is not exercised.
|
|
388
|
+
- `insertMany` stops at the first error and throws it as is, not as a `MongoBulkWriteError`.
|
|
389
|
+
- `$out` and `$merge` stages do not write.
|
|
390
|
+
- `$currentDate` reads this process clock.
|
|
391
|
+
- Data is lost when the process exits, and invisible to any other process: an e2e test that reads the database directly must do so through the server.
|
|
392
|
+
|
|
393
|
+
#### Contract suite
|
|
394
|
+
|
|
395
|
+
[`src/memory/contract.test.ts`](src/memory/contract.test.ts) runs the same scenarios against the memory client and against a real mongod started with `mongodb-memory-server`. The mongod run is opt-in:
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
pnpm --filter liwi-mongo run test:integration
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
A behaviour difference found in an app belongs there first, as a scenario that passes on mongod and fails in memory.
|
|
402
|
+
|
|
403
|
+
### Choosing
|
|
404
|
+
|
|
405
|
+
| | Real mongod | In memory |
|
|
406
|
+
| ---------------- | --------------------------------------------- | -------------------------------------- |
|
|
407
|
+
| Fidelity | exact | the [contract suite](#contract-suite) |
|
|
408
|
+
| Setup | binary download (cache it in CI), a free port | none |
|
|
409
|
+
| Speed | a round trip per operation | a function call |
|
|
410
|
+
| Data shared with | any process connecting to it | the process that created it |
|
|
411
|
+
| Not covered | | [see above](#what-differs-from-mongod) |
|
|
@@ -8,6 +8,10 @@ export interface MongoConfig {
|
|
|
8
8
|
password?: string;
|
|
9
9
|
authSource?: string;
|
|
10
10
|
}
|
|
11
|
+
export interface MongoClientConfig {
|
|
12
|
+
/** Used as is, connected or connecting: `close()` closes it. */
|
|
13
|
+
client: mongodb.MongoClient;
|
|
14
|
+
}
|
|
11
15
|
interface BuildMongoConnectionStringParams extends MongoConfig {
|
|
12
16
|
redactCredentials: boolean;
|
|
13
17
|
}
|
|
@@ -16,8 +20,9 @@ export default class MongoConnection extends AbstractConnection {
|
|
|
16
20
|
_connection?: mongodb.MongoClient;
|
|
17
21
|
_connecting?: Promise<mongodb.MongoClient>;
|
|
18
22
|
connectionFailed?: boolean;
|
|
19
|
-
constructor(config: MongoConfig);
|
|
23
|
+
constructor(config: MongoClientConfig | MongoConfig);
|
|
20
24
|
connect(connectionString: string, connectionStringRedacted: string): void;
|
|
25
|
+
private useClient;
|
|
21
26
|
getConnection(): Promise<mongodb.MongoClient>;
|
|
22
27
|
close(): Promise<void>;
|
|
23
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoConnection.d.ts","sourceRoot":"","sources":["../../src/MongoConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,gCAAiC,SAAQ,WAAW;IAC5D,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,eAAO,MAAM,0BAA0B,6EAQpC,gCAAgC,KAAG,MAalC,CAAC;AAEL,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,kBAAkB;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAElC,WAAW,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE3C,gBAAgB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MongoConnection.d.ts","sourceRoot":"","sources":["../../src/MongoConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAA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,CAAC,GAAG,KAAK,EACrC,QAAQ,SAAS,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,CAC/C,SAAQ,mBAAmB,CAC3B,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAC3B,QAAQ,EACR,KAAK,EACL,MAAM,CACP;IAGC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C,OAAO,CAAC,OAAO,CAAC,CAAgB;IAEhC,YAAY,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAGzE;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE3B;IAED,IAAI,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAMpC;IAEc,OAAO,CACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GACjD,OAAO,CAAC,IAAI,CAAC,CAIf;IAED,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrC;IAEQ,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAGjC;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAI3B;IAED,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAE3B;CACF"}
|
|
@@ -11,6 +11,7 @@ export default class MongoQuerySingleItem<Model extends MongoBaseModel<KeyValue>
|
|
|
11
11
|
constructor(store: MongoStore<Model, KeyValue>, options: QueryOptions<Model>, transformer?: Transformer<Model, Result>);
|
|
12
12
|
createMingoTestCriteria(): TestCriteria;
|
|
13
13
|
fetch<T>(onFulfilled: (result: QueryResult<Result>) => T): Promise<T>;
|
|
14
|
+
private computeChanges;
|
|
14
15
|
_subscribe(callback: SubscribeCallback<KeyValue, Result>, _includeInitial: boolean): QuerySubscription;
|
|
15
16
|
private createMongoCursor;
|
|
16
17
|
}
|
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D,YACE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAClC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,EAC5B,WAAW,GAAE,WAAW,CAAC,KAAK,EAAE,MAAM,CAAuB,EAM9D;IAED,uBAAuB,IAAI,YAAY,CAWtC;IAEK,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAe1E;YAEa,cAAc;IAkD5B,UAAU,CACR,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,EAC7C,eAAe,EAAE,OAAO,GACvB,iBAAiB,CAuCnB;YAEa,iBAAiB;CAehC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoQuerySingleItem.test.d.ts","sourceRoot":"","sources":["../../src/MongoQuerySingleItem.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AllowedKeyValue, CreateQueryOptions, Criteria, Fields, OptionalBaseModelKeysForInsert, QueryParams, Sort, SubscribableStore, Update, UpsertPartialObject, UpsertResult } from "liwi-store";
|
|
1
|
+
import type { AllowedKeyValue, CreateQueryOptions, Criteria, DeleteResult, Fields, OptionalBaseModelKeysForInsert, PartialUpdateOptions, PartialUpdateResult, QueryParams, Sort, SubscribableStore, Update, UpsertPartialObject, UpsertResult, WriteResult } from "liwi-store";
|
|
2
2
|
import type { Collection } from "mongodb";
|
|
3
3
|
import type { MongoBaseModel, MongoInsertType, MongoKeyPath } from "./MongoBaseModel.ts";
|
|
4
4
|
import type MongoConnection from "./MongoConnection.ts";
|
|
@@ -23,14 +23,28 @@ export default class MongoStore<Model extends MongoBaseModel<KeyValue>, KeyValue
|
|
|
23
23
|
createQuerySingleItem<Result extends Record<MongoKeyPath, KeyValue> = Model, Params extends QueryParams<Params> = never>({ transformer, ...options }: CreateQueryOptions<Model, Result>): MongoQuerySingleItem<Model, Params, Result, KeyValue>;
|
|
24
24
|
createQueryCollection<Item extends Record<MongoKeyPath, KeyValue> = Model, Params extends QueryParams<Params> = never>({ transformer, ...options }: CreateQueryOptions<Model, Item>): MongoQueryCollection<Model, Params, Model["_id"], Item>;
|
|
25
25
|
insertOne(object: MongoInsertType<Model>): Promise<Model>;
|
|
26
|
+
/**
|
|
27
|
+
* Always sets `updated` to the write time and keeps the stored `created`: the
|
|
28
|
+
* object's own `created` and `updated` are ignored. The object is not mutated.
|
|
29
|
+
*/
|
|
26
30
|
replaceOne(object: Model): Promise<Model>;
|
|
31
|
+
/** Same rules as `replaceOne`; `next` is derived from the atomic `prev`, no read back. */
|
|
32
|
+
replaceOneWithInfo(object: Model): Promise<WriteResult<Model> | undefined>;
|
|
27
33
|
upsertOne<K extends Exclude<keyof Model, MongoKeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>["$setOnInsert"]): Promise<Model>;
|
|
28
34
|
upsertOneWithInfo<K extends Exclude<keyof Model, MongoKeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>["$setOnInsert"]): Promise<MongoUpsertResult<KeyValue, Model>>;
|
|
29
35
|
replaceSeveral(objects: Model[]): Promise<Model[]>;
|
|
30
|
-
partialUpdateByKey(key: KeyValue, partialUpdate: Update<Model>, criteria?: Criteria<Model
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
partialUpdateByKey(key: KeyValue, partialUpdate: Update<Model>, criteria?: Criteria<Model>, options?: PartialUpdateOptions): Promise<Model>;
|
|
37
|
+
/**
|
|
38
|
+
* `prev` is read atomically with the write. `next` is read right after it,
|
|
39
|
+
* so it may already include a later concurrent write, which emits its own change.
|
|
40
|
+
* Resolves `undefined` when no document matches.
|
|
41
|
+
*/
|
|
42
|
+
partialUpdateByKeyWithInfo(key: KeyValue, partialUpdate: Update<Model>, criteria?: Criteria<Model>, options?: PartialUpdateOptions): Promise<PartialUpdateResult<Model> | undefined>;
|
|
43
|
+
partialUpdateOne(object: Model, partialUpdate: Update<Model>, options?: PartialUpdateOptions): Promise<Model>;
|
|
44
|
+
/** One `updateMany` command; every document gets the same `updated`. */
|
|
45
|
+
partialUpdateMany(criteria: Criteria<Model>, partialUpdate: Update<Model>, options?: PartialUpdateOptions): Promise<void>;
|
|
33
46
|
deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void>;
|
|
47
|
+
deleteByKeyWithInfo(key: KeyValue, criteria?: Criteria<Model>): Promise<DeleteResult<Model> | undefined>;
|
|
34
48
|
deleteOne(object: Model): Promise<void>;
|
|
35
49
|
deleteMany(selector: Criteria<Model>): Promise<void>;
|
|
36
50
|
count(filter?: Criteria<Model>): Promise<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoStore.d.ts","sourceRoot":"","sources":["../../src/MongoStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MongoStore.d.ts","sourceRoot":"","sources":["../../src/MongoStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,8BAA8B,EAC9B,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,IAAI,EACJ,iBAAiB,EACjB,MAAM,EACN,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,UAAU,EAKX,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7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ceRoot":"","sources":["../../src/SubscribeStore.integration.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { MongoBaseModel, MongoKeyPath, MongoInsertType, } from "./MongoBaseModel";
|
|
2
2
|
export type { Update } from "liwi-store";
|
|
3
3
|
export { default as MongoStore, type MongoStoreOptions } from "./MongoStore.ts";
|
|
4
|
-
export { default as MongoConnection, type MongoConfig, } from "./MongoConnection.ts";
|
|
4
|
+
export { default as MongoConnection, type MongoClientConfig, type MongoConfig, } from "./MongoConnection.ts";
|
|
5
5
|
export { default as createMongoSubscribeStore, type SubscribeStore, } from "./createMongoSubscribeStore.ts";
|
|
6
6
|
export { default as MongoRegistry, type MongoRegistryOptions, } from "./MongoRegistry.ts";
|
|
7
7
|
export type { MongoRegistryStore } from "./MongoRegistryStore.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EACL,OAAO,IAAI,eAAe,EAC1B,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,OAAO,IAAI,yBAAyB,EACpC,KAAK,cAAc,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,YAAY,EACV,UAAU,EACV,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,GACnB,MAA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,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Document } from "mongodb";
|
|
2
|
+
export type MemoryUpdate = Document | Document[];
|
|
3
|
+
/** The driver rejects these before sending them. */
|
|
4
|
+
export declare const assertUpdate: (update: MemoryUpdate) => void;
|
|
5
|
+
/** The document an upsert starts from: the equality conditions of its filter. */
|
|
6
|
+
export declare const createUpsertBase: (filter: Document) => Document;
|
|
7
|
+
interface ApplyUpdateOptions {
|
|
8
|
+
/** The filter that matched `document`: the positional `$` resolves against it. */
|
|
9
|
+
filter: Document;
|
|
10
|
+
arrayFilters?: Document[];
|
|
11
|
+
isInsert: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface AppliedUpdate {
|
|
14
|
+
next: Document;
|
|
15
|
+
isModified: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Applies `update` to a copy: `document` is never mutated. The update is read as
|
|
19
|
+
* the driver serializes it, `undefined` as `null`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const applyUpdate: (document: Document, update: MemoryUpdate, { filter, arrayFilters, isInsert }: ApplyUpdateOptions) => AppliedUpdate;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=applyUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyUpdate.d.ts","sourceRoot":"","sources":["../../../src/memory/applyUpdate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAOxC,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;AAWjD,oDAAoD;AACpD,eAAO,MAAM,YAAY,WAAY,YAAY,KAAG,IAWnD,CAAC;AAiDF,iFAAiF;AACjF,eAAO,MAAM,gBAAgB,WAAY,QAAQ,KAAG,QAkBnD,CAAC;AAEF,UAAU,kBAAkB;IAC1B,kFAAkF;IAClF,MAAM,EAAE,QAAQ,CAAC;IACjB,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC1B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,aACZ,QAAQ,UACV,YAAY,sCACgB,kBAAkB,KACrD,aAwBF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Document } from "mongodb";
|
|
2
|
+
/**
|
|
3
|
+
* Copies a value the way the driver writes it then reads it back: `undefined`
|
|
4
|
+
* becomes `null` (`ignoreUndefined` is off), functions are dropped, bytes become
|
|
5
|
+
* a `Binary`, a `Map` or a class instance becomes a plain document.
|
|
6
|
+
* BSON values (`ObjectId`, `Decimal128`...) are immutable and kept as is.
|
|
7
|
+
*/
|
|
8
|
+
export declare const cloneAsStored: (value: unknown) => unknown;
|
|
9
|
+
export declare const cloneDocument: <T extends Document>(document: T) => T;
|
|
10
|
+
//# sourceMappingURL=cloneAsStored.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloneAsStored.d.ts","sourceRoot":"","sources":["../../../src/memory/cloneAsStored.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAUxC;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,OAc9C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,QAAQ,YAAY,CAAC,KAAG,CAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloneAsStored.test.d.ts","sourceRoot":"","sources":["../../../src/memory/cloneAsStored.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.test.d.ts","sourceRoot":"","sources":["../../../src/memory/contract.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Document } from "mongodb";
|
|
2
|
+
import type { MemoryIndexChanges } from "./indexes/createMemoryIndexes.ts";
|
|
3
|
+
export interface MemoryCollection {
|
|
4
|
+
/** The driver's `Collection`, for the methods this package implements. */
|
|
5
|
+
readonly api: object;
|
|
6
|
+
readonly listDocuments: () => Document[];
|
|
7
|
+
readonly modifyIndex: (changes: MemoryIndexChanges) => void;
|
|
8
|
+
readonly clear: () => void;
|
|
9
|
+
readonly drop: () => void;
|
|
10
|
+
}
|
|
11
|
+
interface CreateMemoryCollectionParams {
|
|
12
|
+
databaseName: string;
|
|
13
|
+
collectionName: string;
|
|
14
|
+
/** `$lookup`, `$graphLookup` and `$unionWith` read other collections of the database. */
|
|
15
|
+
resolveCollection: (collectionName: string) => Document[];
|
|
16
|
+
}
|
|
17
|
+
export declare const createMemoryCollection: ({ databaseName, collectionName, resolveCollection, }: CreateMemoryCollectionParams) => MemoryCollection;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=createMemoryCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemoryCollection.d.ts","sourceRoot":"","sources":["../../../src/memory/createMemoryCollection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EAKT,MAAM,SAAS,CAAC;AAgBjB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AA6B3E,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,aAAa,EAAE,MAAM,QAAQ,EAAE,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,UAAU,4BAA4B;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,yFAAyF;IACzF,iBAAiB,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;CAC3D;AAWD,eAAO,MAAM,sBAAsB,yDAIhC,4BAA4B,KAAG,gBAmUjC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Document, Sort } from "mongodb";
|
|
2
|
+
export interface MemoryCursor<T> {
|
|
3
|
+
next: () => Promise<T | null>;
|
|
4
|
+
tryNext: () => Promise<T | null>;
|
|
5
|
+
hasNext: () => Promise<boolean>;
|
|
6
|
+
toArray: () => Promise<T[]>;
|
|
7
|
+
/** Stops when `iterator` returns `false`. */
|
|
8
|
+
forEach: (iterator: (document: T) => unknown) => Promise<void>;
|
|
9
|
+
close: () => Promise<void>;
|
|
10
|
+
[Symbol.asyncIterator]: () => AsyncGenerator<T, void>;
|
|
11
|
+
}
|
|
12
|
+
/** Runs `run` on the first read: the results are a snapshot, as a single batch would be. */
|
|
13
|
+
export declare const createMemoryCursor: <T>(run: () => T[]) => MemoryCursor<T> & {
|
|
14
|
+
isStarted: () => boolean;
|
|
15
|
+
};
|
|
16
|
+
export interface MemoryFindOptions {
|
|
17
|
+
sort?: Sort;
|
|
18
|
+
projection?: Document;
|
|
19
|
+
skip?: number;
|
|
20
|
+
limit?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MemoryFindCursor<T> extends MemoryCursor<T> {
|
|
23
|
+
sort: (sort: Sort) => MemoryFindCursor<T>;
|
|
24
|
+
project: (projection: Document) => MemoryFindCursor<T>;
|
|
25
|
+
skip: (skip: number) => MemoryFindCursor<T>;
|
|
26
|
+
limit: (limit: number) => MemoryFindCursor<T>;
|
|
27
|
+
}
|
|
28
|
+
export declare const createMemoryFindCursor: <T>(run: (options: MemoryFindOptions) => T[], initialOptions: MemoryFindOptions) => MemoryFindCursor<T>;
|
|
29
|
+
//# source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IAAI,KAAK,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC1C,OAAO,EAAE,CAAC,UAAU,EAAE,QAAQ,KAAK,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACvD,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC5C,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAC/C;AAED,eAAO,MAAM,sBAAsB,GAAI,CAAC,OACjC,CAAC,OAAO,EAAE,iBAAiB,KAAK,CAAC,EAAE,kBACxB,iBAAiB,KAChC,gBAAgB,CAAC,CAAC,CAsBpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemoryCursor.test.d.ts","sourceRoot":"","sources":["../../../src/memory/createMemoryCursor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface MemoryDb {
|
|
2
|
+
/** The driver's `Db`, for the methods this package implements. */
|
|
3
|
+
readonly api: object;
|
|
4
|
+
readonly clear: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const createMemoryDb: (databaseName: string) => MemoryDb;
|
|
7
|
+
//# sourceMappingURL=createMemoryDb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemoryDb.d.ts","sourceRoot":"","sources":["../../../src/memory/createMemoryDb.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,QAAQ;IACvB,kEAAkE;IAClE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,eAAO,MAAM,cAAc,iBAAkB,MAAM,KAAG,QAkDrD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MongoClient } from "mongodb";
|
|
2
|
+
export interface MemoryMongoClient {
|
|
3
|
+
/** For `new MongoConnection({ client })`. A driver method it does not implement throws when read. */
|
|
4
|
+
client: MongoClient;
|
|
5
|
+
/** Empties every collection of every database; indexes stay. */
|
|
6
|
+
clear: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface MemoryMongoClientOptions {
|
|
9
|
+
/** The database `client.db()` returns. */
|
|
10
|
+
database?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const createMemoryMongoClient: ({ database, }?: MemoryMongoClientOptions) => MemoryMongoClient;
|
|
13
|
+
//# sourceMappingURL=createMemoryMongoClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemoryMongoClient.d.ts","sourceRoot":"","sources":["../../../src/memory/createMemoryMongoClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK3C,MAAM,WAAW,iBAAiB;IAChC,qGAAqG;IACrG,MAAM,EAAE,WAAW,CAAC;IACpB,gEAAgE;IAChE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,uBAAuB,mBAEjC,wBAAwB,KAAQ,iBA2BlC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemoryMongoClient.test.d.ts","sourceRoot":"","sources":["../../../src/memory/createMemoryMongoClient.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Document } from "mongodb";
|
|
2
|
+
import mongodb from "mongodb";
|
|
3
|
+
interface DuplicateKeyErrorParams {
|
|
4
|
+
namespace: string;
|
|
5
|
+
indexName: string;
|
|
6
|
+
keyPattern: Document;
|
|
7
|
+
keyValue: Document;
|
|
8
|
+
}
|
|
9
|
+
export declare const createDuplicateKeyError: ({ namespace, indexName, keyPattern, keyValue, }: DuplicateKeyErrorParams) => mongodb.MongoServerError;
|
|
10
|
+
export declare const createNamespaceNotFoundError: (namespace: string) => mongodb.MongoServerError;
|
|
11
|
+
export declare const createIndexNotFoundError: (name: string) => mongodb.MongoServerError;
|
|
12
|
+
export declare const createInvalidOptionsError: (message: string) => mongodb.MongoServerError;
|
|
13
|
+
export declare const createIndexOptionsConflictError: (message: string) => mongodb.MongoServerError;
|
|
14
|
+
export declare const createIndexKeySpecsConflictError: (message: string) => mongodb.MongoServerError;
|
|
15
|
+
export declare const createImmutableIdError: () => mongodb.MongoServerError;
|
|
16
|
+
/** The server error mongod answers for an update mingo rejects. */
|
|
17
|
+
export declare const toServerError: (error: unknown) => unknown;
|
|
18
|
+
export declare const createUnsupportedError: (feature: string) => TypeError;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/memory/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,OAAO,MAAM,SAAS,CAAC;AAe9B,UAAU,uBAAuB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,eAAO,MAAM,uBAAuB,oDAKjC,uBAAuB,KAAG,OAAO,CAAC,gBAMlC,CAAC;AAEJ,eAAO,MAAM,4BAA4B,cAC5B,MAAM,KAChB,OAAO,CAAC,gBACoE,CAAC;AAEhF,eAAO,MAAM,wBAAwB,SAC7B,MAAM,KACX,OAAO,CAAC,gBACoE,CAAC;AAEhF,eAAO,MAAM,yBAAyB,YAC3B,MAAM,KACd,OAAO,CAAC,gBAAoE,CAAC;AAEhF,eAAO,MAAM,+BAA+B,YACjC,MAAM,KACd,OAAO,CAAC,gBAC6C,CAAC;AAEzD,eAAO,MAAM,gCAAgC,YAClC,MAAM,KACd,OAAO,CAAC,gBAC8C,CAAC;AAE1D,eAAO,MAAM,sBAAsB,QAAO,OAAO,CAAC,gBAK/C,CAAC;AAQJ,mEAAmE;AACnE,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,OAM9C,CAAC;AAEF,eAAO,MAAM,sBAAsB,YAAa,MAAM,KAAG,SACQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardUnsupported.d.ts","sourceRoot":"","sources":["../../../src/memory/guardUnsupported.ts"],"names":[],"mappings":"AAWA,gHAAgH;AAChH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,UACvC,CAAC,SACF,MAAM,KACZ,CASC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IndexDescription, IndexDescriptionInfo } from "mongodb";
|
|
2
|
+
/** The index as `listIndexes` returns it once created from `description`. */
|
|
3
|
+
export declare const createIndexInfo: (description: IndexDescription) => IndexDescriptionInfo;
|
|
4
|
+
export declare const idIndexInfo: IndexDescriptionInfo;
|
|
5
|
+
//# sourceMappingURL=createIndexInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIndexInfo.d.ts","sourceRoot":"","sources":["../../../../src/memory/indexes/createIndexInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AA0DhF,6EAA6E;AAC7E,eAAO,MAAM,eAAe,gBACb,gBAAgB,KAC5B,oBAcF,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,oBAIzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIndexInfo.test.d.ts","sourceRoot":"","sources":["../../../../src/memory/indexes/createIndexInfo.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Document, IndexDescription, IndexDescriptionInfo } from "mongodb";
|
|
2
|
+
export interface MemoryIndexChanges {
|
|
3
|
+
name: string;
|
|
4
|
+
hidden?: boolean;
|
|
5
|
+
expireAfterSeconds?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface MemoryIndexes {
|
|
8
|
+
list: () => IndexDescriptionInfo[];
|
|
9
|
+
/** Validates every description first, like `createIndexes`: nothing is created on a conflict. */
|
|
10
|
+
create: (descriptions: readonly IndexDescription[], documents: ReadonlyMap<string, Document>) => string[];
|
|
11
|
+
drop: (name: string) => void;
|
|
12
|
+
dropAll: () => void;
|
|
13
|
+
modify: (changes: MemoryIndexChanges) => void;
|
|
14
|
+
assertCanWrite: (documentKey: string, document: Document) => void;
|
|
15
|
+
write: (documentKey: string, previous: Document | undefined, next: Document | undefined) => void;
|
|
16
|
+
clearDocuments: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare const createMemoryIndexes: (namespace: string) => MemoryIndexes;
|
|
19
|
+
//# sourceMappingURL=createMemoryIndexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemoryIndexes.d.ts","sourceRoot":"","sources":["../../../../src/memory/indexes/createMemoryIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAiBhF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,oBAAoB,EAAE,CAAC;IACnC,iGAAiG;IACjG,MAAM,EAAE,CACN,YAAY,EAAE,SAAS,gBAAgB,EAAE,EACzC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,KACrC,MAAM,EAAE,CAAC;IACd,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC9C,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAClE,KAAK,EAAE,CACL,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,IAAI,EAAE,QAAQ,GAAG,SAAS,KACvB,IAAI,CAAC;IACV,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B;AAyBD,eAAO,MAAM,mBAAmB,cAAe,MAAM,KAAG,aAgHvD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Document, IndexDescription } from "mongodb";
|
|
2
|
+
export interface UniqueConstraint {
|
|
3
|
+
/** Throws mongod's duplicate key error when another document holds one of its keys. */
|
|
4
|
+
assertCanWrite: (documentKey: string, document: Document) => void;
|
|
5
|
+
/** Moves the keys of `previous` to `next`; either is `undefined` on insert / delete. */
|
|
6
|
+
write: (documentKey: string, previous: Document | undefined, next: Document | undefined) => void;
|
|
7
|
+
clear: () => void;
|
|
8
|
+
}
|
|
9
|
+
interface CreateUniqueConstraintParams {
|
|
10
|
+
namespace: string;
|
|
11
|
+
indexName: string;
|
|
12
|
+
description: IndexDescription;
|
|
13
|
+
}
|
|
14
|
+
export declare const createUniqueConstraint: ({ namespace, indexName, description, }: CreateUniqueConstraintParams) => UniqueConstraint;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=createUniqueConstraint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createUniqueConstraint.d.ts","sourceRoot":"","sources":["../../../../src/memory/indexes/createUniqueConstraint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,QAAQ,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAW5E,MAAM,WAAW,gBAAgB;IAC/B,uFAAuF;IACvF,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAClE,wFAAwF;IACxF,KAAK,EAAE,CACL,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,IAAI,EAAE,QAAQ,GAAG,SAAS,KACvB,IAAI,CAAC;IACV,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAgDD,UAAU,4BAA4B;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAED,eAAO,MAAM,sBAAsB,2CAIhC,4BAA4B,KAAG,gBAsEjC,CAAC"}
|