liwi-mongo 13.1.1 → 13.3.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 +245 -3
- package/dist/definitions/MongoRegistry.d.ts +20 -0
- package/dist/definitions/MongoRegistry.d.ts.map +1 -0
- package/dist/definitions/MongoRegistry.test.d.ts +2 -0
- package/dist/definitions/MongoRegistry.test.d.ts.map +1 -0
- package/dist/definitions/MongoRegistryStore.d.ts +7 -0
- package/dist/definitions/MongoRegistryStore.d.ts.map +1 -0
- package/dist/definitions/MongoStore.d.ts +9 -1
- package/dist/definitions/MongoStore.d.ts.map +1 -1
- package/dist/definitions/MongoStoreIndexes.test.d.ts +2 -0
- package/dist/definitions/MongoStoreIndexes.test.d.ts.map +1 -0
- package/dist/definitions/index.d.ts +8 -1
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/definitions/indexes/applyIndexPlan.d.ts +11 -0
- package/dist/definitions/indexes/applyIndexPlan.d.ts.map +1 -0
- package/dist/definitions/indexes/buildIndexName.d.ts +3 -0
- package/dist/definitions/indexes/buildIndexName.d.ts.map +1 -0
- package/dist/definitions/indexes/buildIndexName.test.d.ts +2 -0
- package/dist/definitions/indexes/buildIndexName.test.d.ts.map +1 -0
- package/dist/definitions/indexes/deepEqualUnordered.d.ts +2 -0
- package/dist/definitions/indexes/deepEqualUnordered.d.ts.map +1 -0
- package/dist/definitions/indexes/diffIndexes.d.ts +13 -0
- package/dist/definitions/indexes/diffIndexes.d.ts.map +1 -0
- package/dist/definitions/indexes/diffIndexes.test.d.ts +2 -0
- package/dist/definitions/indexes/diffIndexes.test.d.ts.map +1 -0
- package/dist/definitions/indexes/formatIndexPlan.d.ts +5 -0
- package/dist/definitions/indexes/formatIndexPlan.d.ts.map +1 -0
- package/dist/definitions/indexes/formatIndexPlan.test.d.ts +2 -0
- package/dist/definitions/indexes/formatIndexPlan.test.d.ts.map +1 -0
- package/dist/definitions/indexes/isIndexConflictError.d.ts +4 -0
- package/dist/definitions/indexes/isIndexConflictError.d.ts.map +1 -0
- package/dist/definitions/indexes/normalizeIndex.d.ts +34 -0
- package/dist/definitions/indexes/normalizeIndex.d.ts.map +1 -0
- package/dist/definitions/indexes/normalizeIndex.test.d.ts +2 -0
- package/dist/definitions/indexes/normalizeIndex.test.d.ts.map +1 -0
- package/dist/definitions/indexes/runIndexesCli.d.ts +11 -0
- package/dist/definitions/indexes/runIndexesCli.d.ts.map +1 -0
- package/dist/definitions/indexes/runIndexesCli.test.d.ts +2 -0
- package/dist/definitions/indexes/runIndexesCli.test.d.ts.map +1 -0
- package/dist/definitions/indexes/syncIndexes.integration.test.d.ts +2 -0
- package/dist/definitions/indexes/syncIndexes.integration.test.d.ts.map +1 -0
- package/dist/definitions/indexes/types.d.ts +72 -0
- package/dist/definitions/indexes/types.d.ts.map +1 -0
- package/dist/index-node.mjs +626 -10
- package/dist/index-node.mjs.map +1 -1
- package/package.json +7 -5
- package/src/MongoRegistry.test.ts +136 -0
- package/src/MongoRegistry.ts +108 -0
- package/src/MongoRegistryStore.ts +11 -0
- package/src/MongoStore.ts +63 -1
- package/src/MongoStoreIndexes.test.ts +259 -0
- package/src/index.ts +26 -1
- package/src/indexes/applyIndexPlan.ts +149 -0
- package/src/indexes/buildIndexName.test.ts +34 -0
- package/src/indexes/buildIndexName.ts +8 -0
- package/src/indexes/deepEqualUnordered.ts +36 -0
- package/src/indexes/diffIndexes.test.ts +290 -0
- package/src/indexes/diffIndexes.ts +234 -0
- package/src/indexes/formatIndexPlan.test.ts +105 -0
- package/src/indexes/formatIndexPlan.ts +71 -0
- package/src/indexes/isIndexConflictError.ts +20 -0
- package/src/indexes/normalizeIndex.test.ts +154 -0
- package/src/indexes/normalizeIndex.ts +191 -0
- package/src/indexes/runIndexesCli.test.ts +119 -0
- package/src/indexes/runIndexesCli.ts +74 -0
- package/src/indexes/syncIndexes.integration.test.ts +182 -0
- package/src/indexes/types.ts +115 -0
package/README.md
CHANGED
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
<a href="https://npmjs.org/package/liwi-mongo"><img src="https://img.shields.io/npm/types/liwi-mongo.svg?style=flat-square" alt="types"></a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
|
+
## About
|
|
17
|
+
|
|
18
|
+
MongoDB implementation of the [`liwi-store`](../liwi-store) contract, plus live queries when wrapped in a subscribe store.
|
|
19
|
+
|
|
16
20
|
## Install
|
|
17
21
|
|
|
18
22
|
```bash
|
|
@@ -21,8 +25,246 @@ npm install --save liwi-mongo
|
|
|
21
25
|
|
|
22
26
|
## Usage
|
|
23
27
|
|
|
24
|
-
```
|
|
25
|
-
import
|
|
28
|
+
```ts
|
|
29
|
+
import { MongoConnection, MongoStore } from "liwi-mongo";
|
|
30
|
+
import type { MongoBaseModel, MongoInsertType } from "liwi-mongo";
|
|
31
|
+
|
|
32
|
+
interface User extends MongoBaseModel {
|
|
33
|
+
firstname: string;
|
|
34
|
+
lastname: string;
|
|
35
|
+
groups: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const connection = new MongoConnection({ database: "liwi-mongo-example" });
|
|
39
|
+
const users = new MongoStore<User>(connection, "users");
|
|
40
|
+
|
|
41
|
+
const user: MongoInsertType<User> = {
|
|
42
|
+
firstname: "John",
|
|
43
|
+
lastname: "Doe",
|
|
44
|
+
groups: [],
|
|
45
|
+
};
|
|
46
|
+
const insertedUser = await users.insertOne(user); // created / updated are set
|
|
47
|
+
|
|
48
|
+
await users.partialUpdateMany(
|
|
49
|
+
{ firstname: "John" },
|
|
50
|
+
{ $set: { firstname: "Johnny" }, $push: { groups: "Music" } },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const found = await users.findByKey(insertedUser._id);
|
|
54
|
+
|
|
55
|
+
await connection.close();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A runnable version of this lives in [`liwi-mongo-example`](../liwi-mongo-example).
|
|
59
|
+
|
|
60
|
+
## Connection, store, registry
|
|
61
|
+
|
|
62
|
+
Three objects, deliberately not one:
|
|
63
|
+
|
|
64
|
+
- **`MongoConnection`** — one per database. Owns the `MongoClient` and its lifecycle; every store shares it and none of them opens its own. Your app closes it, nothing else does.
|
|
65
|
+
- **`MongoStore`** — one per collection. Carries the model type (criteria, sorts and updates are checked against it), the reads and writes, and the [index declaration](#indexes). Bound to a connection at construction.
|
|
66
|
+
- **`MongoRegistry`** — one per app. A list of stores and nothing more: no connection, no data access. It exists so the index step can visit every collection from one place.
|
|
67
|
+
|
|
68
|
+
Consequences worth knowing:
|
|
69
|
+
|
|
70
|
+
- The registry belongs next to the connection, not inside the module of any one store. Both are app-wide; a store module is not.
|
|
71
|
+
- Registering a store changes nothing about queries. An unregistered store works exactly the same — it just never gets its indexes synced.
|
|
72
|
+
- `runIndexesCli` takes the connection separately from the registry because the registry has no handle on it, and something has to close it for the process to exit.
|
|
73
|
+
|
|
74
|
+
## Models
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
interface MongoBaseModel<KeyValue extends AllowedKeyValue = string> {
|
|
78
|
+
_id: KeyValue;
|
|
79
|
+
created: Date;
|
|
80
|
+
updated: Date;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The key path is always `_id`. `MongoInsertType<Model>` makes `_id`, `created` and `updated` optional; the store fills `created` / `updated` on insert and `updated` on every update. `insertOne` mutates and returns the object you passed.
|
|
85
|
+
|
|
86
|
+
## `MongoConnection`
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
new MongoConnection({ host, port, database, user, password });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`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
|
+
|
|
94
|
+
## `MongoStore`
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const store = new MongoStore<Model>(connection, "collectionName", {
|
|
98
|
+
indexes: [{ key: { completed: 1, created: 1 } }],
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The third argument is optional and currently only carries the [index declaration](#indexes).
|
|
103
|
+
|
|
104
|
+
Implements the whole [`Store`](../liwi-store#store) interface (`findAll`, `findByKey`, `findOne`, `count`, `cursor`, `insertOne`, `replaceOne`, `replaceSeveral`, `upsertOne`, `upsertOneWithInfo`, `partialUpdateByKey`, `partialUpdateOne`, `partialUpdateMany`, `deleteByKey`, `deleteOne`, `deleteMany`), with criteria, sorts and updates typed against the model. `Update<Model>` is re-exported for typing `$set` / `$push` payloads:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import type { Update } from "liwi-mongo";
|
|
108
|
+
|
|
109
|
+
const set: Update<Task>["$set"] = { completed: true };
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The store also exposes the underlying driver handles when you need them: `store.collection` resolves the `mongodb` collection.
|
|
113
|
+
|
|
114
|
+
## Indexes
|
|
115
|
+
|
|
116
|
+
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).
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { MongoRegistry, MongoStore } from "liwi-mongo";
|
|
120
|
+
|
|
121
|
+
const tasksStore = new MongoStore<Task>(connection, "tasks", {
|
|
122
|
+
indexes: [
|
|
123
|
+
{ key: { completed: 1, created: 1 } },
|
|
124
|
+
{ key: { label: "text" } },
|
|
125
|
+
{ key: { sessionEnd: 1 }, expireAfterSeconds: 3600 },
|
|
126
|
+
{ key: { tenant: 1 }, partialFilterExpression: { completed: true } },
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export const mongoRegistry = new MongoRegistry([tasksStore, usersStore]);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`key` is typed against the model's dotted paths, so a typo is a compile error rather than an unused index. Index names follow mongo's own algorithm (`completed_1_created_1`, `label_text`) unless `name` is given.
|
|
134
|
+
|
|
135
|
+
### Syncing
|
|
136
|
+
|
|
137
|
+
Nothing runs implicitly. Call the sync from a deploy or migration step, never on every boot and never in a request path — `createIndexes` does not return until the build finishes.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
await mongoRegistry.syncIndexes();
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Stores are visited sequentially, sorted by collection name. A failing collection does not stop the others; the failures surface together as an `AggregateError`.
|
|
144
|
+
|
|
145
|
+
Sync converges the collection on the declaration:
|
|
146
|
+
|
|
147
|
+
- missing index: created (all creates for a collection go in one batched `createIndexes`);
|
|
148
|
+
- changed key or an option that cannot be changed in place: dropped, then recreated;
|
|
149
|
+
- changed `expireAfterSeconds` (when the index is already TTL) or `hidden`: applied in place with `collMod`;
|
|
150
|
+
- present but not declared: dropped — see below.
|
|
151
|
+
|
|
152
|
+
Drops run before creates, so a rename (same key, new name) needs no special handling and frees a slot against the 64-index cap.
|
|
153
|
+
|
|
154
|
+
### The declared list is the whole truth
|
|
155
|
+
|
|
156
|
+
Any index that is not declared is dropped, `_id_` excepted. Turn it off on the registry, or per call:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
new MongoRegistry(stores, { dropUndeclaredIndexes: false });
|
|
160
|
+
await mongoRegistry.syncIndexes({ dropUndeclaredIndexes: false });
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Resolution order is per-call option, then registry option, then `true`.
|
|
164
|
+
|
|
165
|
+
### Dry run and CI check
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { formatIndexPlans, isMongoIndexPlanEmpty } from "liwi-mongo";
|
|
169
|
+
|
|
170
|
+
const plans = await mongoRegistry.planIndexes();
|
|
171
|
+
console.log(formatIndexPlans(plans));
|
|
172
|
+
if (!plans.every(isMongoIndexPlanEmpty)) process.exit(1);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`planIndexes` only reads. `syncIndexes({ dryRun: true })` returns the same plan wrapped in a `MongoIndexSyncResult` and mutates nothing.
|
|
176
|
+
|
|
177
|
+
### `runIndexesCli`
|
|
178
|
+
|
|
179
|
+
That script is the same in every app, so it ships here. Point an entry at your registry:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
// scripts/syncIndexes.ts
|
|
183
|
+
import { runIndexesCli } from "liwi-mongo";
|
|
184
|
+
import { mongoConnection, mongoRegistry } from "../src/stores/index.ts";
|
|
185
|
+
|
|
186
|
+
process.exitCode = await runIndexesCli({
|
|
187
|
+
registry: mongoRegistry,
|
|
188
|
+
connection: mongoConnection,
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
node scripts/syncIndexes.ts # plan, prints and changes nothing
|
|
194
|
+
node scripts/syncIndexes.ts plan --check # exit 1 when the plan is not empty
|
|
195
|
+
node scripts/syncIndexes.ts sync [--dry-run] # apply
|
|
196
|
+
node scripts/syncIndexes.ts sync --keep-undeclared
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Exit codes: `0` done, `1` drift under `--check`, `2` unknown command. `connection` is optional and only closed so the process can exit; `argv` defaults to `process.argv.slice(2)`, and `log` / `logError` default to `console`. Only stores that have been registered are visited, so the entry must import the module graph that creates them.
|
|
26
200
|
|
|
27
|
-
console.log(liwiMongo);
|
|
28
201
|
```
|
|
202
|
+
tasks
|
|
203
|
+
+ create completed_1_created_1 {"completed":1,"created":1}
|
|
204
|
+
~ recreate label_text key: {"title":"text"} -> {"label":"text"}
|
|
205
|
+
! modify sessions_ttl expireAfterSeconds: 3600 -> 60
|
|
206
|
+
- drop legacy_status_1
|
|
207
|
+
= 2 unchanged
|
|
208
|
+
users
|
|
209
|
+
= 3 unchanged, nothing to do
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Supported options
|
|
213
|
+
|
|
214
|
+
`name`, `unique`, `sparse`, `hidden`, `expireAfterSeconds`, `partialFilterExpression`, `collation`, `weights`, `default_language`, `language_override`, `wildcardProjection`.
|
|
215
|
+
|
|
216
|
+
Deliberately excluded: `background` (a no-op since 4.2), `v` / `textIndexVersion` / `2dsphereIndexVersion` (server-managed — comparing them would cause endless recreates), `storageEngine`, `commitQuorum`, legacy 2d `bits` / `min` / `max` / `bucketSize`, and `prepareUnique`. Use `store.collection` directly for those.
|
|
217
|
+
|
|
218
|
+
Comparison ignores server-added fields, compares only the collation keys you declared (the server echoes a fully expanded collation), and is insensitive to key order inside `partialFilterExpression` / `wildcardProjection`.
|
|
219
|
+
|
|
220
|
+
### Caveats
|
|
221
|
+
|
|
222
|
+
- **Run it from one place.** Two processes syncing at once can drop what the other just created. `IndexNotFound` on drop is swallowed and a conflicting create is retried once, but this is not a substitute for a single migration step.
|
|
223
|
+
- **Recreate leaves a window.** A rebuilt index is absent while it builds, so a hot query can fall back to a collection scan. For large collections, create under a new name, deploy the declaration, then let a later sync drop the old one.
|
|
224
|
+
- **Adding `unique: true` is a drop and recreate**, and fails outright if duplicates exist.
|
|
225
|
+
- **Atlas.** Atlas Search indexes are not returned by `listIndexes` and are safe, but indexes created by Performance Advisor or another service _will_ be dropped. Use `dropUndeclaredIndexes: false` where that matters.
|
|
226
|
+
- **A store that is never registered is never synced.** That is the price of explicit registration; declare and register in the same place.
|
|
227
|
+
- Two stores on the same collection with different declarations will fight; `MongoRegistry.add` warns on a duplicate collection name.
|
|
228
|
+
- `Object.entries` hoists integer-like keys, so a model field literally named `"0"` would silently reorder a compound key.
|
|
229
|
+
|
|
230
|
+
## Queries and subscriptions
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
import { createMongoSubscribeStore } from "liwi-mongo";
|
|
234
|
+
|
|
235
|
+
export const tasksStore = createMongoSubscribeStore<Task>(
|
|
236
|
+
new MongoStore<Task>(connection, "tasks"),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const query = tasksStore.createQueryCollection({
|
|
240
|
+
criteria: { completed: false },
|
|
241
|
+
sort: { created: 1 },
|
|
242
|
+
fields: { completed: 1, created: 1, label: 1 },
|
|
243
|
+
transformer: ({ _id, completed, created, label }) => ({
|
|
244
|
+
_id,
|
|
245
|
+
completed,
|
|
246
|
+
created,
|
|
247
|
+
label,
|
|
248
|
+
}),
|
|
249
|
+
limit: 20,
|
|
250
|
+
skip: 0,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const { result, meta } = await query.fetch((queryResult) => queryResult);
|
|
254
|
+
// meta.total is the count ignoring limit/skip
|
|
255
|
+
|
|
256
|
+
const subscription = query.fetchAndSubscribe((error, changes) => {
|
|
257
|
+
// "initial", then "inserted" / "updated" / "deleted"
|
|
258
|
+
});
|
|
259
|
+
subscription.stop();
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
`createQuerySingleItem` behaves the same but resolves a single item.
|
|
263
|
+
|
|
264
|
+
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
|
+
|
|
266
|
+
Caveats:
|
|
267
|
+
|
|
268
|
+
- Writes performed outside this process (other services, mongo shell, migrations) are not detected.
|
|
269
|
+
- `$text` criteria cannot be matched in memory: such queries fetch correctly but never emit updates.
|
|
270
|
+
- Queries returned by the subscribe store are fixed — `changeParams` throws; build a new query when parameters change.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MongoRegistryStore } from "./MongoRegistryStore.ts";
|
|
2
|
+
import type { MongoIndexPlan, MongoIndexSyncResult, SyncIndexesOptions } from "./indexes/types.ts";
|
|
3
|
+
export interface MongoRegistryOptions {
|
|
4
|
+
dropUndeclaredIndexes?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export default class MongoRegistry {
|
|
7
|
+
private readonly _stores;
|
|
8
|
+
private readonly dropUndeclaredIndexes;
|
|
9
|
+
constructor(stores?: readonly MongoRegistryStore[], { dropUndeclaredIndexes }?: MongoRegistryOptions);
|
|
10
|
+
get stores(): readonly MongoRegistryStore[];
|
|
11
|
+
add(store: MongoRegistryStore): this;
|
|
12
|
+
remove(store: MongoRegistryStore): this;
|
|
13
|
+
getStore(collectionName: string): MongoRegistryStore | undefined;
|
|
14
|
+
private resolveOptions;
|
|
15
|
+
private sortedStores;
|
|
16
|
+
private runSequentially;
|
|
17
|
+
planIndexes(options?: SyncIndexesOptions): Promise<MongoIndexPlan[]>;
|
|
18
|
+
syncIndexes(options?: SyncIndexesOptions): Promise<MongoIndexSyncResult[]>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=MongoRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoRegistry.d.ts","sourceRoot":"","sources":["../../src/MongoRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAI5B,MAAM,WAAW,oBAAoB;IACnC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAE/C,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAU;IAEhD,YACE,MAAM,GAAE,SAAS,kBAAkB,EAAO,EAC1C,EAAE,qBAA4B,EAAE,GAAE,oBAAyB,EAK5D;IAED,IAAI,MAAM,IAAI,SAAS,kBAAkB,EAAE,CAE1C;IAED,GAAG,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAQnC;IAED,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAItC;IAED,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAI/D;IAED,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,YAAY;YAMN,eAAe;IA0B7B,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAKnE;IAED,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAKzE;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoRegistry.test.d.ts","sourceRoot":"","sources":["../../src/MongoRegistry.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MongoIndexPlan, MongoIndexSyncResult, SyncIndexesOptions } from "./indexes/types.ts";
|
|
2
|
+
export interface MongoRegistryStore {
|
|
3
|
+
readonly collectionName: string;
|
|
4
|
+
planIndexes: (options?: SyncIndexesOptions) => Promise<MongoIndexPlan>;
|
|
5
|
+
syncIndexes: (options?: SyncIndexesOptions) => Promise<MongoIndexSyncResult>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=MongoRegistryStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoRegistryStore.d.ts","sourceRoot":"","sources":["../../src/MongoRegistryStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IACvE,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC9E"}
|
|
@@ -5,16 +5,24 @@ import type MongoConnection from "./MongoConnection.ts";
|
|
|
5
5
|
import MongoCursor from "./MongoCursor.ts";
|
|
6
6
|
import MongoQueryCollection from "./MongoQueryCollection.ts";
|
|
7
7
|
import MongoQuerySingleItem from "./MongoQuerySingleItem.ts";
|
|
8
|
+
import type { MongoIndex, MongoIndexPlan, MongoIndexSyncResult, SyncIndexesOptions } from "./indexes/types.ts";
|
|
8
9
|
export interface MongoUpsertResult<KeyValue extends AllowedKeyValue, Model extends MongoBaseModel<KeyValue>> extends UpsertResult<Model> {
|
|
9
10
|
object: Model;
|
|
10
11
|
inserted: boolean;
|
|
11
12
|
}
|
|
13
|
+
export interface MongoStoreOptions<Model extends MongoBaseModel<any>> {
|
|
14
|
+
indexes?: readonly MongoIndex<Model>[];
|
|
15
|
+
}
|
|
12
16
|
export default class MongoStore<Model extends MongoBaseModel<KeyValue>, KeyValue extends AllowedKeyValue = Model[MongoKeyPath]> implements SubscribableStore<MongoKeyPath, KeyValue, Model, MongoInsertType<Model>, MongoConnection> {
|
|
13
17
|
readonly keyPath: MongoKeyPath;
|
|
14
18
|
readonly connection: MongoConnection;
|
|
19
|
+
readonly collectionName: string;
|
|
20
|
+
private readonly declaredIndexes;
|
|
15
21
|
private _collection;
|
|
16
|
-
constructor(connection: MongoConnection, collectionName: string);
|
|
22
|
+
constructor(connection: MongoConnection, collectionName: string, { indexes }?: MongoStoreOptions<Model>);
|
|
17
23
|
get collection(): Promise<Collection<Model>>;
|
|
24
|
+
planIndexes({ dropUndeclaredIndexes, }?: SyncIndexesOptions): Promise<MongoIndexPlan>;
|
|
25
|
+
syncIndexes(options?: SyncIndexesOptions): Promise<MongoIndexSyncResult>;
|
|
18
26
|
createQuerySingleItem<Result extends Record<MongoKeyPath, KeyValue> = Model, Params extends QueryParams<Params> = never>({ transformer, ...options }: CreateQueryOptions<Model, Result>): MongoQuerySingleItem<Model, Params, Result, KeyValue>;
|
|
19
27
|
createQueryCollection<Item extends Record<MongoKeyPath, KeyValue> = Model, Params extends QueryParams<Params> = never>({ transformer, ...options }: CreateQueryOptions<Model, Item>): MongoQueryCollection<Model, Params, Model["_id"], Item>;
|
|
20
28
|
insertOne(object: MongoInsertType<Model>): Promise<Model>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoStore.d.ts","sourceRoot":"","sources":["../../src/MongoStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,MAAM,EACN,8BAA8B,EAC9B,WAAW,EACX,IAAI,EACJ,iBAAiB,EACjB,MAAM,EACN,mBAAmB,EACnB,YAAY,EACb,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;AAC7D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"MongoStore.d.ts","sourceRoot":"","sources":["../../src/MongoStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,MAAM,EACN,8BAA8B,EAC9B,WAAW,EACX,IAAI,EACJ,iBAAiB,EACjB,MAAM,EACN,mBAAmB,EACnB,YAAY,EACb,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;AAC7D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAK7D,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,iBAAiB,CAChC,QAAQ,SAAS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,QAAQ,CAAC,KAAK,CAAC,GACzB,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAO5B;IAED,OAAO,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAIxE;IAEK,OAAO,CACX,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,EACvB,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GACjB,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAM5B;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoStoreIndexes.test.d.ts","sourceRoot":"","sources":["../../src/MongoStoreIndexes.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export type { MongoBaseModel, MongoKeyPath, MongoInsertType, } from "./MongoBaseModel";
|
|
2
2
|
export type { Update } from "liwi-store";
|
|
3
|
-
export { default as MongoStore } from "./MongoStore.ts";
|
|
3
|
+
export { default as MongoStore, type MongoStoreOptions } from "./MongoStore.ts";
|
|
4
4
|
export { default as MongoConnection, type MongoConfig, } from "./MongoConnection.ts";
|
|
5
5
|
export { default as createMongoSubscribeStore, type SubscribeStore, } from "./createMongoSubscribeStore.ts";
|
|
6
|
+
export { default as MongoRegistry, type MongoRegistryOptions, } from "./MongoRegistry.ts";
|
|
7
|
+
export type { MongoRegistryStore } from "./MongoRegistryStore.ts";
|
|
8
|
+
export type { MongoIndex, MongoIndexDirection, MongoIndexKey, MongoIndexOptions, MongoIndexPlan, MongoIndexSyncResult, SyncIndexesOptions, } from "./indexes/types.ts";
|
|
9
|
+
export { buildIndexName } from "./indexes/buildIndexName.ts";
|
|
10
|
+
export { diffIndexes, isMongoIndexPlanEmpty } from "./indexes/diffIndexes.ts";
|
|
11
|
+
export { formatIndexPlan, formatIndexPlans, } from "./indexes/formatIndexPlan.ts";
|
|
12
|
+
export { runIndexesCli, type RunIndexesCliParams, } from "./indexes/runIndexesCli.ts";
|
|
6
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,MAAM,iBAAiB,CAAC;
|
|
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,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EACL,eAAe,EACf,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,GACzB,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Collection, Db } from "mongodb";
|
|
2
|
+
import type { MongoIndexPlan, MongoIndexSyncResult } from "./types.ts";
|
|
3
|
+
interface ApplyIndexPlanParams {
|
|
4
|
+
plan: MongoIndexPlan;
|
|
5
|
+
collection: Collection<any>;
|
|
6
|
+
db: Db;
|
|
7
|
+
dryRun: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const applyIndexPlan: ({ plan, collection, db, dryRun, }: ApplyIndexPlanParams) => Promise<MongoIndexSyncResult>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=applyIndexPlan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyIndexPlan.d.ts","sourceRoot":"","sources":["../../../src/indexes/applyIndexPlan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,EAAE,EAGH,MAAM,SAAS,CAAC;AAMjB,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAwDvE,UAAU,oBAAoB;IAC5B,IAAI,EAAE,cAAc,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5B,EAAE,EAAE,EAAE,CAAC;IACP,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,cAAc,sCAKxB,oBAAoB,KAAG,OAAO,CAAC,oBAAoB,CAqErD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildIndexName.d.ts","sourceRoot":"","sources":["../../../src/indexes/buildIndexName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAO,MAAM,cAAc,QACpB,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,KACvC,MAGW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildIndexName.test.d.ts","sourceRoot":"","sources":["../../../src/indexes/buildIndexName.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepEqualUnordered.d.ts","sourceRoot":"","sources":["../../../src/indexes/deepEqualUnordered.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,kBAAkB,MAAO,OAAO,KAAK,OAAO,KAAG,OA4B3D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IndexDescriptionInfo } from "mongodb";
|
|
2
|
+
import type { MongoBaseModel } from "../MongoBaseModel.ts";
|
|
3
|
+
import type { MongoIndex, MongoIndexPlan } from "./types.ts";
|
|
4
|
+
interface DiffIndexesParams<Model extends MongoBaseModel<any>> {
|
|
5
|
+
collectionName: string;
|
|
6
|
+
declaredIndexes: readonly MongoIndex<Model>[];
|
|
7
|
+
existingIndexes: readonly IndexDescriptionInfo[];
|
|
8
|
+
dropUndeclaredIndexes: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const diffIndexes: <Model extends MongoBaseModel<any>>({ collectionName, declaredIndexes, existingIndexes, dropUndeclaredIndexes, }: DiffIndexesParams<Model>) => MongoIndexPlan;
|
|
11
|
+
export declare const isMongoIndexPlanEmpty: (plan: MongoIndexPlan) => boolean;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=diffIndexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diffIndexes.d.ts","sourceRoot":"","sources":["../../../src/indexes/diffIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAO3D,OAAO,KAAK,EACV,UAAU,EAGV,cAAc,EACf,MAAM,YAAY,CAAC;AAsHpB,UAAU,iBAAiB,CAAC,KAAK,SAAS,cAAc,CAAC,GAAG,CAAC;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,SAAS,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;IAC9C,eAAe,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACjD,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,SAAS,cAAc,CAAC,GAAG,CAAC,gFAK1D,iBAAiB,CAAC,KAAK,CAAC,KAAG,cAoF7B,CAAC;AAEF,eAAO,MAAM,qBAAqB,SAAU,cAAc,KAAG,OAInC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diffIndexes.test.d.ts","sourceRoot":"","sources":["../../../src/indexes/diffIndexes.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MongoIndexPlan } from "./types.ts";
|
|
2
|
+
export declare const formatIndexPlan: (plan: MongoIndexPlan) => string;
|
|
3
|
+
export declare const formatIndexPlans: (plans: readonly MongoIndexPlan[]) => string;
|
|
4
|
+
export { isMongoIndexPlanEmpty } from "./diffIndexes.ts";
|
|
5
|
+
//# sourceMappingURL=formatIndexPlan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatIndexPlan.d.ts","sourceRoot":"","sources":["../../../src/indexes/formatIndexPlan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,cAAc,EAAE,MAAM,YAAY,CAAC;AA4CvE,eAAO,MAAM,eAAe,SAAU,cAAc,KAAG,MAqBtD,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAAW,SAAS,cAAc,EAAE,KAAG,MACb,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatIndexPlan.test.d.ts","sourceRoot":"","sources":["../../../src/indexes/formatIndexPlan.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const isIndexConflictError: (error: unknown) => boolean;
|
|
2
|
+
export declare const isIndexNotFoundError: (error: unknown) => boolean;
|
|
3
|
+
export declare const isNamespaceNotFoundError: (error: unknown) => boolean;
|
|
4
|
+
//# sourceMappingURL=isIndexConflictError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isIndexConflictError.d.ts","sourceRoot":"","sources":["../../../src/indexes/isIndexConflictError.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,OAGrD,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,OACf,CAAC;AAExC,eAAO,MAAM,wBAAwB,UAAW,OAAO,KAAG,OACf,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CollationOptions, Document, IndexDescription, IndexDescriptionInfo } from "mongodb";
|
|
2
|
+
import type { MongoBaseModel } from "../MongoBaseModel.ts";
|
|
3
|
+
import type { MongoIndex, MongoIndexDirection } from "./types.ts";
|
|
4
|
+
export interface NormalizedIndexOptions {
|
|
5
|
+
unique: boolean;
|
|
6
|
+
sparse: boolean;
|
|
7
|
+
hidden: boolean;
|
|
8
|
+
expireAfterSeconds?: number;
|
|
9
|
+
partialFilterExpression?: Document;
|
|
10
|
+
collation?: CollationOptions;
|
|
11
|
+
weights?: Record<string, number>;
|
|
12
|
+
defaultLanguage?: string;
|
|
13
|
+
languageOverride?: string;
|
|
14
|
+
wildcardProjection?: Document;
|
|
15
|
+
}
|
|
16
|
+
export interface NormalizedIndex {
|
|
17
|
+
name: string;
|
|
18
|
+
key: Record<string, MongoIndexDirection>;
|
|
19
|
+
keyEntries: [string, MongoIndexDirection][];
|
|
20
|
+
isText: boolean;
|
|
21
|
+
options: NormalizedIndexOptions;
|
|
22
|
+
}
|
|
23
|
+
export interface NormalizedDeclaredIndex extends NormalizedIndex {
|
|
24
|
+
description: IndexDescription;
|
|
25
|
+
}
|
|
26
|
+
export declare const normalizeDeclaredIndex: <Model extends MongoBaseModel<any>>(index: MongoIndex<Model>) => NormalizedDeclaredIndex;
|
|
27
|
+
export declare const normalizeExistingIndex: (existing: IndexDescriptionInfo) => NormalizedIndex;
|
|
28
|
+
interface NormalizeDeclaredIndexesParams<Model extends MongoBaseModel<any>> {
|
|
29
|
+
collectionName: string;
|
|
30
|
+
indexes: readonly MongoIndex<Model>[];
|
|
31
|
+
}
|
|
32
|
+
export declare const normalizeDeclaredIndexes: <Model extends MongoBaseModel<any>>({ collectionName, indexes, }: NormalizeDeclaredIndexesParams<Model>) => NormalizedDeclaredIndex[];
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=normalizeIndex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeIndex.d.ts","sourceRoot":"","sources":["../../../src/indexes/normalizeIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAKlE,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,uBAAuB,CAAC,EAAE,QAAQ,CAAC;IACnC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,QAAQ,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACzC,UAAU,EAAE,CAAC,MAAM,EAAE,mBAAmB,CAAC,EAAE,CAAC;IAC5C,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAED,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAqCD,eAAO,MAAM,sBAAsB,GAAI,KAAK,SAAS,cAAc,CAAC,GAAG,CAAC,SAC/D,UAAU,CAAC,KAAK,CAAC,KACvB,uBAmDF,CAAC;AAEF,eAAO,MAAM,sBAAsB,aACvB,oBAAoB,KAC7B,eA6BF,CAAC;AAEF,UAAU,8BAA8B,CAAC,KAAK,SAAS,cAAc,CAAC,GAAG,CAAC;IACxE,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,SAAS,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;CACvC;AAED,eAAO,MAAM,wBAAwB,GAAI,KAAK,SAAS,cAAc,CAAC,GAAG,CAAC,gCAGvE,8BAA8B,CAAC,KAAK,CAAC,KAAG,uBAAuB,EAqBjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeIndex.test.d.ts","sourceRoot":"","sources":["../../../src/indexes/normalizeIndex.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type MongoConnection from "../MongoConnection.ts";
|
|
2
|
+
import type MongoRegistry from "../MongoRegistry.ts";
|
|
3
|
+
export interface RunIndexesCliParams {
|
|
4
|
+
registry: MongoRegistry;
|
|
5
|
+
argv?: readonly string[];
|
|
6
|
+
connection?: MongoConnection;
|
|
7
|
+
log?: (message: string) => void;
|
|
8
|
+
logError?: (message: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const runIndexesCli: ({ registry, argv, connection, log, logError, }: RunIndexesCliParams) => Promise<number>;
|
|
11
|
+
//# sourceMappingURL=runIndexesCli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runIndexesCli.d.ts","sourceRoot":"","sources":["../../../src/indexes/runIndexesCli.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAsBrD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,aAAa,mDAMvB,mBAAmB,KAAG,OAAO,CAAC,MAAM,CAoCtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runIndexesCli.test.d.ts","sourceRoot":"","sources":["../../../src/indexes/runIndexesCli.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncIndexes.integration.test.d.ts","sourceRoot":"","sources":["../../../src/indexes/syncIndexes.integration.test.ts"],"names":[],"mappings":""}
|