@ahrowe/mongo 0.1.3 → 0.2.1
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 +76 -0
- package/README.md +50 -23
- package/dist/db.d.ts +31 -13
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +163 -130
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/outboxRelay.d.ts +18 -26
- package/dist/outboxRelay.d.ts.map +1 -1
- package/dist/outboxRelay.js +78 -56
- package/dist/outboxRelay.js.map +1 -1
- package/dist/types/outbox.d.ts +13 -2
- package/dist/types/outbox.d.ts.map +1 -1
- package/dist/types/outbox.js +4 -1
- package/dist/types/outbox.js.map +1 -1
- package/docs/CLAUDE.md +112 -86
- package/package.json +5 -2
- package/dist/batchify.d.ts +0 -36
- package/dist/batchify.d.ts.map +0 -1
- package/dist/batchify.js +0 -57
- package/dist/batchify.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @ahrowe/mongo
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 003d7d0: CHANGELOG.md covers 0.0.1 to 0.1.3
|
|
8
|
+
- 003d7d0: The relay's claim index is `{ status, collectionName, nextAttemptAt }`, so a claim no longer reads past every pending row of collections the relay has no service for; drop the old `status_1_nextAttemptAt_1` index once (see "Upgrading" in docs/CLAUDE.md)
|
|
9
|
+
- 003d7d0: On a service with `emitOutboxEvents: false`, `upsertOne`, `updateOne` and a single `insert` that validate nothing (no validator, or `skipValidation`) run without a transaction of their own, which cost a commit per call and WriteConflict retries on a contended document such as a counter; they still join the caller's transaction
|
|
10
|
+
- 003d7d0: The relay warns on start about rows that have been due for over an hour, of collections it has no service for: no relay may ever claim them, and pending rows never expire
|
|
11
|
+
- 003d7d0: The upgrade steps in docs/CLAUDE.md give done rows a 0.1.2 relay settled the expiry they lost with the `processedOn` index
|
|
12
|
+
|
|
13
|
+
## 0.2.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 53e6119: `bulkWrite` throws on a service that emits outbox events (the default), whose listeners would miss its writes; use the write methods, or a service with `emitOutboxEvents: false`
|
|
18
|
+
- 53e6119: `keepFailedMs` defaults to 90 days instead of forever; pass `Infinity` to keep dead-lettered rows
|
|
19
|
+
- 53e6119: On a service with `emitOutboxEvents: false` and a validator, `updateMany` validates every updated document instead of one, so it can now fail on documents that were invalid before
|
|
20
|
+
- 53e6119: `.on(...)` and `.onPropertiesUpdated(...)` return a function that removes the listener instead of an `EventEmitter`, and `.on` only takes `'created' | 'updated' | 'removed'`
|
|
21
|
+
- 53e6119: `OutboxStatus.Processing` and `OutboxRow.leasedUntil` are gone: a claimed row stays `pending`, with `leasedBy` set and `nextAttemptAt` at the end of its lease; run the one-time database commands under "Upgrading" in docs/CLAUDE.md once no 0.1 relay runs any more
|
|
22
|
+
- 53e6119: `upsertOne`, `updateOne`, `removeOne` and `removeMany` throw on `projection` and `includeResultMetadata`, since writes validate and record the full document; read the fields you need with `find`/`findOne` afterwards
|
|
23
|
+
- 53e6119: `getServiceBus` and `service.eventBus` are gone: register listeners with `.on(...)`, and deliver events that reach a process another way with the new `dispatchEvent(collectionName, event)`
|
|
24
|
+
- 53e6119: New `toOutboxDoc` service option decides what outbox rows hold of a document, e.g. to keep a secret out of what listeners store; `ServiceOptions` and `OutboxEvent` are exported
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- 53e6119: `updateMany`/`removeMany` on a service with outbox events work through 500 documents per round trip instead of one at a time, still in one transaction
|
|
29
|
+
- 53e6119: The relay dead-letters a row whose lease ran out on every attempt (a listener that crashes the process or outlasts `leaseMs`) instead of claiming it again forever
|
|
30
|
+
|
|
31
|
+
## 0.1.3
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- c602387: Outbox rows expire through a TTL index on `expireAt`, which the relay sets when it settles a row, from the new `keepDoneMs` (default 7 days) and `keepFailedMs` (default forever) options; the relay drops 0.1.2's TTL index on `processedOn`, so done rows a 0.1.2 relay settled no longer expire (see "Upgrading" in docs/CLAUDE.md)
|
|
36
|
+
- c602387: The relay only claims rows of collections with a service in its own process and leaves other rows pending for a relay that has their listeners; 0.1.2 marked them done without notifying anyone
|
|
37
|
+
- c602387: A relay whose lease ran out can no longer overwrite the result of the relay that claimed the row after it
|
|
38
|
+
- c602387: The relay claims rows in `nextAttemptAt` order through its index, instead of sorting every due row in memory for each claim
|
|
39
|
+
- c602387: A rejecting `onPropertiesUpdated` listener is retried like any other listener; 0.1.2 lost the rejection
|
|
40
|
+
- c602387: `updateOne` with `returnOriginal` on a service with `emitOutboxEvents: false` validates the written document, not the returned original
|
|
41
|
+
- eb157b0: A write passed a session without a transaction runs in a transaction on that session, so its data and outbox row commit together; 0.1.2 wrote without one
|
|
42
|
+
- eb157b0: `upsertOne` on a service with `emitOutboxEvents: false` runs in a transaction, so a write that fails validation rolls back
|
|
43
|
+
|
|
44
|
+
## 0.1.2
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- 0e3f9e6: `createIndex` accepts index paths deeper than 4 levels again, unchecked, instead of rejecting them
|
|
49
|
+
|
|
50
|
+
## 0.1.1
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 33705c0: `createService`'s declarations name `NestedPaths` instead of inlining it, which cost `tsc` seconds per entity type and never finished for a generic wrapper around `createService`; index paths are checked up to 4 levels deep
|
|
55
|
+
|
|
56
|
+
## 0.1.0
|
|
57
|
+
|
|
58
|
+
### Minor Changes
|
|
59
|
+
|
|
60
|
+
- 64664a8: New `dropIndex(indexName, options?)`
|
|
61
|
+
|
|
62
|
+
## 0.0.3
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- 7fe3a99: Services created for the same collection share their listeners, so a listener registered on either instance receives the events
|
|
67
|
+
|
|
68
|
+
## 0.0.2
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- 8e1fb73: New `upsertOne`
|
|
73
|
+
|
|
74
|
+
## 0.0.1
|
|
75
|
+
|
|
76
|
+
- First release
|
package/README.md
CHANGED
|
@@ -26,15 +26,15 @@ await users.updateOne({ _id: user._id }, { $set: { email: 'c@d.com' } });
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Call `createService` once per collection and reuse that instance everywhere.
|
|
29
|
-
Calling it again for the same collection name is supported (it
|
|
30
|
-
first call's
|
|
29
|
+
Calling it again for the same collection name is supported (it shares the
|
|
30
|
+
first call's listeners and logs a warning, so listeners on either instance
|
|
31
31
|
still fire) but other per-instance options are **not** shared: a mismatched
|
|
32
32
|
`emitOutboxEvents` means writes through one instance never fire events at all
|
|
33
33
|
(not a bus issue — no outbox row is written), a mismatched `validate` means
|
|
34
34
|
the two instances enforce different schemas on the same collection, and a
|
|
35
35
|
mismatched `addCreatedOnField`/`addUpdatedOnField` means only some documents
|
|
36
|
-
get timestamped
|
|
37
|
-
|
|
36
|
+
get timestamped, and a mismatched `toOutboxDoc` means a field one instance keeps
|
|
37
|
+
out of the outbox reaches listeners through the other. Prefer sharing one instance unless one
|
|
38
38
|
of these divergences is what you actually want (e.g. a backfill instance with
|
|
39
39
|
`emitOutboxEvents: false`).
|
|
40
40
|
|
|
@@ -83,11 +83,11 @@ across multiple pods racing the same row (claims are leased atomically).
|
|
|
83
83
|
`updateOne`/`updateMany` only enqueue `'updated'` for documents that actually
|
|
84
84
|
changed.
|
|
85
85
|
|
|
86
|
-
`updateMany`/`removeMany`
|
|
87
|
-
one
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
`updateMany`/`removeMany` work through the matched documents in chunks of 500,
|
|
87
|
+
all inside one transaction: a failure in any chunk rolls back every chunk. Each
|
|
88
|
+
outbox row's `{ prevDoc, doc }` pair is exact, because nothing else can change a
|
|
89
|
+
document between the transaction reading it and writing it. Run the relay to
|
|
90
|
+
drain the outbox:
|
|
91
91
|
|
|
92
92
|
```ts
|
|
93
93
|
import { startOutboxRelay } from '@ahrowe/mongo';
|
|
@@ -96,10 +96,11 @@ const relay = startOutboxRelay({ instanceId: process.env.HOSTNAME ?? 'local' });
|
|
|
96
96
|
// relay.stop() on shutdown
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
Processed rows are kept for 7 days (`keepDoneMs`), dead-lettered rows
|
|
100
|
-
(`keepFailedMs`), then removed by a TTL index. Both are relay options
|
|
99
|
+
Processed rows are kept for 7 days (`keepDoneMs`), dead-lettered rows for 90
|
|
100
|
+
days (`keepFailedMs`), then removed by a TTL index. Both are relay options, and
|
|
101
|
+
`Infinity` keeps rows forever. A row no relay processes stays until one does.
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
`updateMany`/`removeMany` have **no size cap by default**, but a single
|
|
103
104
|
transaction processing a very large matched set risks hitting MongoDB's
|
|
104
105
|
transaction lifetime limit. Pass `{ maxBatchSize }` (per-call, or as a
|
|
105
106
|
`createService` option for a service-wide default) to enforce one and fail fast
|
|
@@ -109,8 +110,28 @@ instead:
|
|
|
109
110
|
await users.updateMany({}, { $set: { plan: 'pro' } }, { maxBatchSize: 500 });
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
Past that limit it throws
|
|
113
|
-
transaction
|
|
113
|
+
Past that limit it throws before writing anything; it never processes a partial
|
|
114
|
+
batch. For more than fits one transaction, split the work into several calls,
|
|
115
|
+
each committing on its own. For a rerunnable migration, select by a condition the
|
|
116
|
+
update itself clears:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
for (;;) {
|
|
120
|
+
const batch = await beans.find({ roastLevel: { $exists: false } }, { projection: { _id: 1 }, limit: 1000 });
|
|
121
|
+
if (!batch.length) break;
|
|
122
|
+
await beans.updateMany({ _id: { $in: batch.map((b) => b._id) } }, { $set: { roastLevel: 'medium' } });
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Rows reach every listener, and whatever those store. Decide what they hold of a
|
|
127
|
+
document with `toOutboxDoc`, e.g. to keep a secret out:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const hooks = createService<Hook>('webhooks', null, { toOutboxDoc: ({ secret, ...hook }) => hook });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`bulkWrite` has no transaction, validation or events, so it refuses a service
|
|
134
|
+
that emits outbox events.
|
|
114
135
|
|
|
115
136
|
Pass `{ meta: {...} }` on a call to thread arbitrary data through to listeners,
|
|
116
137
|
so a specific handler can decide to skip its own side effect without anyone else
|
|
@@ -125,8 +146,8 @@ users.on('updated', ({ doc, meta }) => {
|
|
|
125
146
|
});
|
|
126
147
|
```
|
|
127
148
|
|
|
128
|
-
Infra collections with no listeners (sequences, the outbox itself,
|
|
129
|
-
skip outbox writes entirely by passing `{ emitOutboxEvents: false }` to
|
|
149
|
+
Infra collections with no listeners (sequences, counters, the outbox itself,
|
|
150
|
+
etc.) and one-off scripts such as migrations can skip outbox writes entirely by passing `{ emitOutboxEvents: false }` to
|
|
130
151
|
`createService` — writes take a leaner fast path with no pre-reads or
|
|
131
152
|
transaction-wrapped outbox insert.
|
|
132
153
|
|
|
@@ -154,8 +175,10 @@ await session.withTransaction(async () => {
|
|
|
154
175
|
```
|
|
155
176
|
|
|
156
177
|
Write methods run in a transaction: the passed `session`'s if it has one active,
|
|
157
|
-
otherwise their own. Exceptions: `bulkWrite`, and
|
|
158
|
-
|
|
178
|
+
otherwise their own. Exceptions: `bulkWrite`, and on a service with
|
|
179
|
+
`emitOutboxEvents: false` the writes that have nothing to roll back:
|
|
180
|
+
`removeOne`/`removeMany`, and `upsertOne`/`updateOne`/a single `insert` that
|
|
181
|
+
validate nothing (no validator, or `skipValidation`).
|
|
159
182
|
|
|
160
183
|
### Connection health
|
|
161
184
|
|
|
@@ -187,15 +210,19 @@ first so it releases any leases it's holding.
|
|
|
187
210
|
## API
|
|
188
211
|
|
|
189
212
|
- `connect(connectionString, databaseName?) → { createService, on }`
|
|
190
|
-
- `createService<T>(collectionName, validate?, { addCreatedOnField?, addUpdatedOnField?, maxLimit?, maxBatchSize?, emitOutboxEvents? }) → DbService<T>`
|
|
213
|
+
- `createService<T>(collectionName, validate?, { addCreatedOnField?, addUpdatedOnField?, maxLimit?, maxBatchSize?, emitOutboxEvents?, toOutboxDoc? }) → DbService<T>` (options type: `ServiceOptions<T>`)
|
|
191
214
|
- `withSession(cb)`, `startSession(options?)`, `disconnect()`
|
|
192
215
|
- `setOutboxContextProvider(fn)` — capture request/actor context at write time for outbox rows
|
|
193
216
|
- `startOutboxRelay({ instanceId, pollIntervalMs?, batchSize?, leaseMs?, maxAttempts?, backoffMs?, keepDoneMs?, keepFailedMs?, autoStart? }) → { stop, tick, drain }`
|
|
194
|
-
- `
|
|
195
|
-
- `
|
|
217
|
+
- `dispatchEvent(collectionName, event)`: deliver an event to this process's listeners, when events arrive from somewhere other than the relay (e.g. a broker)
|
|
218
|
+
- `getRegisteredCollections()`, `getOutboxCollection()`: relay/advanced internals
|
|
219
|
+
- `OutboxEvent`, `OutboxOp`, `OutboxStatus`, `OutboxRow`, `OUTBOX_COLLECTION`: event and outbox row shapes, for tooling/inspection
|
|
196
220
|
- `DbService<T>` methods: `find`, `findOne`, `findCursor`, `insert`, `updateOne`,
|
|
197
|
-
`updateMany`, `removeOne`, `removeMany`, `count`, `exists`, `aggregate`, `distinct`,
|
|
198
|
-
`createIndex`, `dropIndex`, `bulkWrite`, `on`, `onPropertiesUpdated`, `
|
|
221
|
+
`upsertOne`, `updateMany`, `removeOne`, `removeMany`, `count`, `exists`, `aggregate`, `distinct`,
|
|
222
|
+
`createIndex`, `dropIndex`, `bulkWrite`, `on`, `onPropertiesUpdated`, `generateId`, `name`
|
|
223
|
+
|
|
224
|
+
What changed in each version is in [CHANGELOG.md](CHANGELOG.md). Some upgrades
|
|
225
|
+
also take one-time database commands, in [docs/CLAUDE.md](docs/CLAUDE.md#upgrading).
|
|
199
226
|
|
|
200
227
|
See [docs/CLAUDE.md](docs/CLAUDE.md) for gotchas (upserts are rejected, `findOne`
|
|
201
228
|
strictness, the opt-in `maxLimit`/`maxBatchSize` caps, `bulkWrite` safety gate).
|
package/dist/db.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { ObjectId, ClientSession, UpdateFilter, FindOptions, Filter, UpdateOptions, FindOneAndUpdateOptions, FindOneAndDeleteOptions, BulkWriteOptions, BulkWriteResult, AggregateOptions, ClientSessionOptions, type Document, type WithId, type InferIdType, type FindCursor, Collection as MongoCollection } from 'mongodb';
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
-
import { type OutboxRow } from './types/outbox.js';
|
|
3
|
+
import { OutboxOp, type OutboxEvent, type OutboxRow } from './types/outbox.js';
|
|
4
4
|
type ContextProvider = () => unknown;
|
|
5
5
|
export declare const setOutboxContextProvider: (fn: ContextProvider) => void;
|
|
6
|
-
|
|
6
|
+
/** Collections with a service in this process. The relay only claims rows for these. */
|
|
7
7
|
export declare const getRegisteredCollections: () => string[];
|
|
8
|
+
/**
|
|
9
|
+
* Delivers one event to every listener registered for its collection and op in this process,
|
|
10
|
+
* waits for all of them, then rejects with the first failure, if any. The relay calls this per
|
|
11
|
+
* outbox row. Call it yourself only when events reach this process another way, e.g. from a broker.
|
|
12
|
+
*/
|
|
13
|
+
export declare const dispatchEvent: (collectionName: string, event: OutboxEvent) => Promise<void>;
|
|
14
|
+
/** Test-only: drops every listener on a collection. Not part of the public barrel. */
|
|
15
|
+
export declare const removeAllListeners: (collectionName: string) => void;
|
|
8
16
|
/** Raw outbox collection — used by the relay to claim/mark rows WITHOUT emitting. */
|
|
9
17
|
export declare const getOutboxCollection: () => MongoCollection<OutboxRow>;
|
|
10
|
-
|
|
18
|
+
/** Write options that would return a partial or wrapped document instead of the full one. */
|
|
19
|
+
type PartialResultOptions = 'projection' | 'includeResultMetadata';
|
|
20
|
+
export interface ServiceOptions<T> {
|
|
11
21
|
addCreatedOnField?: boolean;
|
|
12
22
|
addUpdatedOnField?: boolean;
|
|
13
23
|
/** Ceiling for findCursor's `limit` option. No cap by default. Overridable per-call. */
|
|
@@ -20,6 +30,14 @@ interface ServiceOptions {
|
|
|
20
30
|
* listeners and would only churn the outbox.
|
|
21
31
|
*/
|
|
22
32
|
emitOutboxEvents?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* What this collection's outbox rows hold of a document, `doc` and `prevDoc` alike, e.g.
|
|
35
|
+
* `({ secret, ...hook }) => hook`. Rows are copied to every listener, so a secret in them leaks
|
|
36
|
+
* into whatever those store. An update records a row only if this result changed. Must be pure
|
|
37
|
+
* and must not modify the document it gets. It also gets stored documents that were never
|
|
38
|
+
* validated against `T` (older ones, skipValidation writes), and a throw fails the write.
|
|
39
|
+
*/
|
|
40
|
+
toOutboxDoc?: (doc: T) => object;
|
|
23
41
|
}
|
|
24
42
|
interface FindOptionsWithReadPref extends FindOptions {
|
|
25
43
|
preferReadFromSecondary?: boolean;
|
|
@@ -74,12 +92,12 @@ export interface DbService<T extends WithEntityFields> {
|
|
|
74
92
|
find: (query: Filter<T>, options?: FindOptions) => Promise<WithId<T>[]>;
|
|
75
93
|
findCursor: (query: Filter<T>, options?: FindOptionsWithReadPref) => FindCursor<WithId<T>>;
|
|
76
94
|
findOne: (query: Filter<T>, options?: FindOptions) => Promise<WithId<T>>;
|
|
77
|
-
updateOne: (query: Filter<T>, updateBody: UpdateFilter<T>, options?: Omit<FindOneAndUpdateOptions, 'upsert'> & {
|
|
95
|
+
updateOne: (query: Filter<T>, updateBody: UpdateFilter<T>, options?: Omit<FindOneAndUpdateOptions, 'upsert' | PartialResultOptions> & {
|
|
78
96
|
returnOriginal?: boolean;
|
|
79
97
|
skipValidation?: boolean;
|
|
80
98
|
meta?: Record<string, unknown>;
|
|
81
99
|
}) => Promise<T | null>;
|
|
82
|
-
upsertOne: (query: Filter<T>, updateBody: UpdateFilter<T>, options?: Omit<FindOneAndUpdateOptions, 'upsert' | 'returnDocument'> & {
|
|
100
|
+
upsertOne: (query: Filter<T>, updateBody: UpdateFilter<T>, options?: Omit<FindOneAndUpdateOptions, 'upsert' | 'returnDocument' | PartialResultOptions> & {
|
|
83
101
|
skipValidation?: boolean;
|
|
84
102
|
meta?: Record<string, unknown>;
|
|
85
103
|
}) => Promise<T>;
|
|
@@ -95,7 +113,7 @@ export interface DbService<T extends WithEntityFields> {
|
|
|
95
113
|
upsertedCount: number;
|
|
96
114
|
upsertedId: InferIdType<T> | null;
|
|
97
115
|
}>;
|
|
98
|
-
removeOne: (query: Filter<T>, options?: FindOneAndDeleteOptions & {
|
|
116
|
+
removeOne: (query: Filter<T>, options?: Omit<FindOneAndDeleteOptions, PartialResultOptions> & {
|
|
99
117
|
meta?: Record<string, unknown>;
|
|
100
118
|
}) => Promise<WithId<T> | null>;
|
|
101
119
|
removeMany: (query: Filter<T>, options?: any) => Promise<{
|
|
@@ -127,20 +145,20 @@ export interface DbService<T extends WithEntityFields> {
|
|
|
127
145
|
name: string;
|
|
128
146
|
createIndex: (fields: IndexSpec<T>, options?: any) => Promise<string>;
|
|
129
147
|
dropIndex: (indexName: string, options?: any) => Promise<Document>;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
/** Registers a listener the relay (or `dispatchEvent`) delivers to. Returns a function that removes it. */
|
|
149
|
+
on: (event: `${OutboxOp}`, callback: (...args: any[]) => unknown) => () => void;
|
|
150
|
+
onPropertiesUpdated: (properties: Array<string | ReadonlyArray<string>>, callback: (...args: any[]) => unknown) => () => void;
|
|
133
151
|
bulkWrite: (operations: any[], options?: BulkWriteOptions & {
|
|
134
152
|
allowBulkwrite?: boolean;
|
|
135
153
|
}) => Promise<BulkWriteResult>;
|
|
136
154
|
}
|
|
137
155
|
declare const createService: <T extends WithEntityFields>(collectionName: string, validate?: ((entity: T) => {
|
|
138
156
|
error?: unknown;
|
|
139
|
-
}) | null, options?: ServiceOptions) => DbService<T>;
|
|
157
|
+
}) | null, options?: ServiceOptions<T>) => DbService<T>;
|
|
140
158
|
declare const connect: (connectionString: string, databaseName?: string) => {
|
|
141
159
|
createService: <T extends WithEntityFields>(collectionName: string, validate?: ((entity: T) => {
|
|
142
160
|
error?: unknown;
|
|
143
|
-
}) | null, options?: ServiceOptions) => DbService<T>;
|
|
161
|
+
}) | null, options?: ServiceOptions<T>) => DbService<T>;
|
|
144
162
|
on: (eventName: string, callback: (...args: any[]) => void) => EventEmitter<[never]>;
|
|
145
163
|
};
|
|
146
164
|
export declare const disconnect: () => Promise<void>;
|
|
@@ -151,12 +169,12 @@ declare const _default: {
|
|
|
151
169
|
connect: (connectionString: string, databaseName?: string) => {
|
|
152
170
|
createService: <T extends WithEntityFields>(collectionName: string, validate?: ((entity: T) => {
|
|
153
171
|
error?: unknown;
|
|
154
|
-
}) | null, options?: ServiceOptions) => DbService<T>;
|
|
172
|
+
}) | null, options?: ServiceOptions<T>) => DbService<T>;
|
|
155
173
|
on: (eventName: string, callback: (...args: any[]) => void) => EventEmitter<[never]>;
|
|
156
174
|
};
|
|
157
175
|
createService: <T extends WithEntityFields>(collectionName: string, validate?: ((entity: T) => {
|
|
158
176
|
error?: unknown;
|
|
159
|
-
}) | null, options?: ServiceOptions) => DbService<T>;
|
|
177
|
+
}) | null, options?: ServiceOptions<T>) => DbService<T>;
|
|
160
178
|
withSession: <R>(callback: (session: ClientSession) => Promise<R>) => Promise<R>;
|
|
161
179
|
startSession: (options?: ClientSessionOptions) => Promise<ClientSession>;
|
|
162
180
|
disconnect: () => Promise<void>;
|
package/dist/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AACA,OAAO,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