@nxgt/mongo-kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,359 @@
1
+ // src/config/checks.ts
2
+ function isDefinition(value) {
3
+ if (typeof value !== "object" || value === null)
4
+ return false;
5
+ const candidate = value;
6
+ return typeof candidate.name === "string" && typeof candidate.schema === "object" && candidate.schema !== null && Array.isArray(candidate.indexes) && typeof candidate.stamps === "object";
7
+ }
8
+ function definitionsOf(collections) {
9
+ return Object.entries(collections).filter((entry) => isDefinition(entry[1]));
10
+ }
11
+ var refuse = (where, said) => {
12
+ throw new TypeError(`defineConfig: ${where} ${said}`);
13
+ };
14
+ var OWNED = ["db", "session", "actor", "autoSync"];
15
+ function checkOwned(where, what, options) {
16
+ if (typeof options !== "object" || options === null)
17
+ return;
18
+ for (const key of OWNED) {
19
+ if (key in options) {
20
+ refuse(where, `has "${key}" in ${what}, which the kit decides: ` + "a database is named by its key, `as` and `withSession` carry the " + "actor and the session, and `autoSync` is the database's");
21
+ }
22
+ }
23
+ }
24
+ function checkDatabase(name, config) {
25
+ const where = `database "${name}"`;
26
+ if (typeof config !== "object" || config === null) {
27
+ refuse(where, "is not a configuration object");
28
+ }
29
+ const hasUri = config.uri !== undefined;
30
+ const hasClient = config.client !== undefined;
31
+ if (hasUri === hasClient) {
32
+ refuse(where, hasUri ? "has both a uri and a client: pass the one it should use" : "has neither a uri nor a client");
33
+ }
34
+ if (hasUri && (typeof config.uri !== "string" || config.uri === "")) {
35
+ refuse(where, "has a uri that is not a string");
36
+ }
37
+ if (hasClient && typeof config.client?.db !== "function") {
38
+ refuse(where, "has a client that is not a MongoClient");
39
+ }
40
+ if (hasClient && config.clientOptions !== undefined) {
41
+ refuse(where, "has client options beside a client it did not open: pass them where the client is made");
42
+ }
43
+ if (config.database !== undefined && config.database === "") {
44
+ refuse(where, "has an empty database name");
45
+ }
46
+ if (typeof config.collections !== "object" || config.collections === null) {
47
+ refuse(where, "has no collections object");
48
+ }
49
+ const definitions = definitionsOf(config.collections);
50
+ if (definitions.length === 0) {
51
+ refuse(where, "has a collections object with no definition in it: pass the module, as in `import * as collections`");
52
+ }
53
+ const byName = new Map;
54
+ for (const [key, definition] of definitions) {
55
+ const seen = byName.get(definition.name);
56
+ if (seen !== undefined) {
57
+ refuse(where, `wires "${seen}" and "${key}" to the same collection, "${definition.name}"`);
58
+ }
59
+ byName.set(definition.name, key);
60
+ }
61
+ const keys = new Set(definitions.map(([key]) => key));
62
+ for (const key of Object.keys(config.optionsFor ?? {})) {
63
+ if (!keys.has(key)) {
64
+ refuse(where, `has options for "${key}", which it does not wire`);
65
+ }
66
+ }
67
+ checkOwned(where, "options", config.options);
68
+ for (const [key, options] of Object.entries(config.optionsFor ?? {})) {
69
+ checkOwned(where, `the options of "${key}"`, options);
70
+ }
71
+ return definitions;
72
+ }
73
+
74
+ // src/config/define-config.ts
75
+ function databasesOf(config) {
76
+ if (typeof config !== "object" || config === null) {
77
+ throw new TypeError("defineConfig: a configuration object is required");
78
+ }
79
+ if (!("databases" in config)) {
80
+ return { default: config };
81
+ }
82
+ const { databases } = config;
83
+ if (typeof databases !== "object" || databases === null) {
84
+ throw new TypeError("defineConfig: databases is not an object");
85
+ }
86
+ const names = Object.keys(databases);
87
+ if (names.length === 0) {
88
+ throw new TypeError("defineConfig: databases names none");
89
+ }
90
+ return databases;
91
+ }
92
+ function defineConfig(config) {
93
+ const databases = databasesOf(config);
94
+ for (const [name, database] of Object.entries(databases)) {
95
+ checkDatabase(name, database);
96
+ }
97
+ return Object.freeze({
98
+ databases: Object.freeze({ ...databases })
99
+ });
100
+ }
101
+ // src/discover.ts
102
+ async function discoverCollections(options) {
103
+ const { glob, cwd = process.cwd(), export: name } = options;
104
+ if (typeof glob !== "string" || glob === "") {
105
+ throw new TypeError("discoverCollections: a glob is required");
106
+ }
107
+ const paths = await Array.fromAsync(new Bun.Glob(glob).scan({ cwd }));
108
+ const found = [];
109
+ const byName = new Map;
110
+ for (const path of paths.sort()) {
111
+ const module = await import(`${cwd}/${path}`);
112
+ const definitions = name === undefined ? definitionsOf(module) : isDefinition(module[name]) ? [[name, module[name]]] : [];
113
+ if (name !== undefined && definitions.length === 0) {
114
+ throw new TypeError(`discoverCollections: ${path} exports no definition named "${name}"`);
115
+ }
116
+ for (const [, definition] of definitions) {
117
+ const seen = byName.get(definition.name);
118
+ if (seen !== undefined && seen !== path) {
119
+ throw new TypeError(`discoverCollections: ${seen} and ${path} both define the collection "${definition.name}"`);
120
+ }
121
+ byName.set(definition.name, path);
122
+ found.push(definition);
123
+ }
124
+ }
125
+ return found;
126
+ }
127
+ // src/kit/create-kit.ts
128
+ import { connectMongo } from "@nxgt/mongo";
129
+
130
+ // src/kit/context.ts
131
+ function derived(ctx, change) {
132
+ return {
133
+ databases: ctx.databases,
134
+ session: "session" in change ? change.session : ctx.session,
135
+ actor: "actor" in change ? change.actor : ctx.actor,
136
+ cache: new Map,
137
+ root: false
138
+ };
139
+ }
140
+ function databaseOf(ctx, name) {
141
+ const found = ctx.databases.find((database) => database.name === name);
142
+ if (!found) {
143
+ throw new TypeError(`This kit has no database "${name}": it has ${ctx.databases.map((database) => `"${database.name}"`).join(", ")}.`);
144
+ }
145
+ return found;
146
+ }
147
+
148
+ // src/kit/scope.ts
149
+ import { getCollection } from "@nxgt/mongo";
150
+ function collectionAt(ctx, database, key, definition) {
151
+ let built = ctx.cache.get(database.name);
152
+ if (!built) {
153
+ built = new Map;
154
+ ctx.cache.set(database.name, built);
155
+ }
156
+ const found = built.get(key);
157
+ if (found)
158
+ return found;
159
+ const collection = getCollection(database.db, definition, {
160
+ ...database.options,
161
+ ...database.optionsFor[key],
162
+ ...database.autoSync ? { autoSync: true } : {},
163
+ ...ctx.session ? { session: ctx.session } : {},
164
+ ...ctx.actor === undefined ? {} : { actor: ctx.actor }
165
+ });
166
+ built.set(key, collection);
167
+ return collection;
168
+ }
169
+ function scopeOf(ctx, database) {
170
+ const collections = {};
171
+ for (const [key, definition] of database.wired) {
172
+ Object.defineProperty(collections, key, {
173
+ enumerable: true,
174
+ get: () => collectionAt(ctx, database, key, definition)
175
+ });
176
+ }
177
+ return new Proxy(collections, {
178
+ get(target, key, receiver) {
179
+ if (Reflect.has(target, key))
180
+ return Reflect.get(target, key, receiver);
181
+ const value = Reflect.get(database.db, key);
182
+ return typeof value === "function" ? value.bind(database.db) : value;
183
+ },
184
+ has(target, key) {
185
+ return Reflect.has(target, key) || Reflect.has(database.db, key);
186
+ }
187
+ });
188
+ }
189
+
190
+ // src/kit/sync.ts
191
+ import {
192
+ syncCollections
193
+ } from "@nxgt/mongo";
194
+ async function syncKit(ctx, options = {}) {
195
+ const reports = {};
196
+ for (const database of ctx.databases) {
197
+ reports[database.name] = await syncCollections(database.db, database.wired.map(([, definition]) => definition), options);
198
+ }
199
+ return reports;
200
+ }
201
+
202
+ // src/kit/transaction.ts
203
+ import { withTransaction } from "@nxgt/mongo";
204
+ function clientFor(ctx, on) {
205
+ if (on !== undefined)
206
+ return databaseOf(ctx, on).client;
207
+ const clients = new Set(ctx.databases.map((database) => database.client));
208
+ const [only] = clients;
209
+ if (clients.size === 1 && only)
210
+ return only;
211
+ throw new TypeError("transaction: this kit holds more than one client, and a transaction " + "lives on one. Name the database it runs on, as `{ on: 'main' }`.");
212
+ }
213
+ function hostFor(ctx, on) {
214
+ if (!ctx.session)
215
+ return clientFor(ctx, on);
216
+ if (on !== undefined) {
217
+ throw new TypeError("transaction: this kit is already in a session, which this call " + "joins, so `on` has no client left to choose.");
218
+ }
219
+ return ctx.session;
220
+ }
221
+ async function transact(ctx, build, fn, options) {
222
+ const { on, ...rest } = options ?? {};
223
+ const host = hostFor(ctx, on);
224
+ const transactionOptions = Object.keys(rest).length > 0 ? rest : undefined;
225
+ return withTransaction(host, (session) => fn(build(derived(ctx, { session }))), transactionOptions);
226
+ }
227
+
228
+ // src/kit/derive.ts
229
+ async function closeKit(ctx) {
230
+ if (!ctx.root) {
231
+ throw new TypeError("close: this kit came from `as`, `withSession` or a transaction. " + "Close the kit `createKit` returned — the clients are shared.");
232
+ }
233
+ for (const database of ctx.databases) {
234
+ await database.connection?.close();
235
+ }
236
+ }
237
+ function kitOf(ctx) {
238
+ const scopes = new Map;
239
+ const scopeFor = (name) => {
240
+ const found = scopes.get(name);
241
+ if (found)
242
+ return found;
243
+ const scope = scopeOf(ctx, databaseOf(ctx, name));
244
+ scopes.set(name, scope);
245
+ return scope;
246
+ };
247
+ const databases = {};
248
+ const clients = {};
249
+ for (const database of ctx.databases) {
250
+ Object.defineProperty(databases, database.name, {
251
+ enumerable: true,
252
+ get: () => scopeFor(database.name)
253
+ });
254
+ Object.defineProperty(clients, database.name, {
255
+ enumerable: true,
256
+ value: database.client
257
+ });
258
+ }
259
+ const kit = {
260
+ get db() {
261
+ const [only] = ctx.databases;
262
+ if (ctx.databases.length !== 1 || !only) {
263
+ throw new TypeError("kit.db: this kit has several databases. Read the one you mean, " + `as \`kit.databases.${ctx.databases[0]?.name ?? "main"}\`.`);
264
+ }
265
+ return scopeFor(only.name);
266
+ },
267
+ databases,
268
+ clients,
269
+ get actor() {
270
+ return ctx.actor;
271
+ },
272
+ get session() {
273
+ return ctx.session;
274
+ },
275
+ as(actor) {
276
+ return kitOf(derived(ctx, { actor }));
277
+ },
278
+ withSession(session) {
279
+ return kitOf(derived(ctx, { session }));
280
+ },
281
+ transaction(fn, options) {
282
+ return transact(ctx, (next) => kitOf(next), fn, options);
283
+ },
284
+ sync(options) {
285
+ return syncKit(ctx, options);
286
+ },
287
+ close() {
288
+ return closeKit(ctx);
289
+ },
290
+ [Symbol.asyncDispose]() {
291
+ return closeKit(ctx);
292
+ }
293
+ };
294
+ return kit;
295
+ }
296
+
297
+ // src/kit/create-kit.ts
298
+ async function open(config) {
299
+ if (config.client) {
300
+ const client = config.client;
301
+ return {
302
+ db: config.database ? client.db(config.database) : client.db(),
303
+ connection: undefined
304
+ };
305
+ }
306
+ const connection = await connectMongo(config.uri, config.clientOptions);
307
+ return {
308
+ db: config.database ? connection.client.db(config.database) : connection.db,
309
+ connection
310
+ };
311
+ }
312
+ function checkCollisions(name, db, keys) {
313
+ for (const key of keys) {
314
+ if (key in db) {
315
+ throw new TypeError(`createKit: database "${name}" wires a collection under "${key}", ` + "which is a member of the driver's Db: it would be unreachable. " + "Export that definition under another name.");
316
+ }
317
+ }
318
+ }
319
+ async function createKit(config) {
320
+ const entries = Object.entries(config.databases);
321
+ const databases = [];
322
+ try {
323
+ for (const [name, database] of entries) {
324
+ const wired = checkDatabase(name, database);
325
+ const { db, connection } = await open(database);
326
+ databases.push({
327
+ name,
328
+ db,
329
+ client: connection?.client ?? database.client,
330
+ wired,
331
+ options: database.options ?? {},
332
+ optionsFor: database.optionsFor ?? {},
333
+ autoSync: database.autoSync === true,
334
+ connection
335
+ });
336
+ checkCollisions(name, db, wired.map(([key]) => key));
337
+ }
338
+ } catch (error) {
339
+ for (const database of databases)
340
+ await database.connection?.close();
341
+ throw error;
342
+ }
343
+ const ctx = {
344
+ databases,
345
+ session: undefined,
346
+ actor: undefined,
347
+ cache: new Map,
348
+ root: true
349
+ };
350
+ return kitOf(ctx);
351
+ }
352
+ export {
353
+ createKit,
354
+ defineConfig,
355
+ discoverCollections
356
+ };
357
+
358
+ //# debugId=00B9BBA5C20F9E8D64756E2164756E21
359
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/config/checks.ts", "../src/config/define-config.ts", "../src/discover.ts", "../src/kit/create-kit.ts", "../src/kit/context.ts", "../src/kit/scope.ts", "../src/kit/sync.ts", "../src/kit/transaction.ts", "../src/kit/derive.ts"],
4
+ "sourcesContent": [
5
+ "import type { AnyCollectionDefinition } from '@nxgt/mongo';\nimport type { DatabaseConfig } from './types';\n\n/** A definition, told by its shape: `instanceof` has no class to ask. */\nexport function isDefinition(value: unknown): value is AnyCollectionDefinition {\n\tif (typeof value !== 'object' || value === null) return false;\n\tconst candidate = value as Partial<AnyCollectionDefinition>;\n\treturn (\n\t\ttypeof candidate.name === 'string' &&\n\t\ttypeof candidate.schema === 'object' &&\n\t\tcandidate.schema !== null &&\n\t\tArray.isArray(candidate.indexes) &&\n\t\ttypeof candidate.stamps === 'object'\n\t);\n}\n\n/** The definitions of a module object, under the keys they are exported by. */\nexport function definitionsOf(\n\tcollections: object,\n): [string, AnyCollectionDefinition][] {\n\treturn Object.entries(collections).filter(\n\t\t(entry): entry is [string, AnyCollectionDefinition] =>\n\t\t\tisDefinition(entry[1]),\n\t);\n}\n\nconst refuse = (where: string, said: string): never => {\n\tthrow new TypeError(`defineConfig: ${where} ${said}`);\n};\n\n/**\n * The collection options the kit decides itself: the database each collection\n * is on, the session and the actor a derived kit carries, and the sync the\n * database's `autoSync` asks for. The types refuse them in `options`, where\n * the shape is `KitCollectionOptions`; under `optionsFor` they are only\n * refused here, and one of them there would quietly outrank the kit.\n */\nconst OWNED = ['db', 'session', 'actor', 'autoSync'] as const;\n\nfunction checkOwned(where: string, what: string, options: unknown): void {\n\tif (typeof options !== 'object' || options === null) return;\n\tfor (const key of OWNED) {\n\t\tif (key in options) {\n\t\t\trefuse(\n\t\t\t\twhere,\n\t\t\t\t`has \"${key}\" in ${what}, which the kit decides: ` +\n\t\t\t\t\t'a database is named by its key, `as` and `withSession` carry the ' +\n\t\t\t\t\t\"actor and the session, and `autoSync` is the database's\",\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** Everything one database's config must answer before anything connects. */\nexport function checkDatabase(\n\tname: string,\n\tconfig: DatabaseConfig<object>,\n): [string, AnyCollectionDefinition][] {\n\tconst where = `database \"${name}\"`;\n\tif (typeof config !== 'object' || config === null) {\n\t\trefuse(where, 'is not a configuration object');\n\t}\n\tconst hasUri = config.uri !== undefined;\n\tconst hasClient = config.client !== undefined;\n\tif (hasUri === hasClient) {\n\t\trefuse(\n\t\t\twhere,\n\t\t\thasUri\n\t\t\t\t? 'has both a uri and a client: pass the one it should use'\n\t\t\t\t: 'has neither a uri nor a client',\n\t\t);\n\t}\n\tif (hasUri && (typeof config.uri !== 'string' || config.uri === '')) {\n\t\trefuse(where, 'has a uri that is not a string');\n\t}\n\tif (hasClient && typeof config.client?.db !== 'function') {\n\t\trefuse(where, 'has a client that is not a MongoClient');\n\t}\n\tif (hasClient && config.clientOptions !== undefined) {\n\t\trefuse(\n\t\t\twhere,\n\t\t\t'has client options beside a client it did not open: pass them where the client is made',\n\t\t);\n\t}\n\tif (config.database !== undefined && config.database === '') {\n\t\trefuse(where, 'has an empty database name');\n\t}\n\tif (typeof config.collections !== 'object' || config.collections === null) {\n\t\trefuse(where, 'has no collections object');\n\t}\n\tconst definitions = definitionsOf(config.collections);\n\tif (definitions.length === 0) {\n\t\trefuse(\n\t\t\twhere,\n\t\t\t'has a collections object with no definition in it: pass the module, as in `import * as collections`',\n\t\t);\n\t}\n\tconst byName = new Map<string, string>();\n\tfor (const [key, definition] of definitions) {\n\t\tconst seen = byName.get(definition.name);\n\t\tif (seen !== undefined) {\n\t\t\trefuse(\n\t\t\t\twhere,\n\t\t\t\t`wires \"${seen}\" and \"${key}\" to the same collection, \"${definition.name}\"`,\n\t\t\t);\n\t\t}\n\t\tbyName.set(definition.name, key);\n\t}\n\tconst keys = new Set(definitions.map(([key]) => key));\n\tfor (const key of Object.keys(config.optionsFor ?? {})) {\n\t\tif (!keys.has(key)) {\n\t\t\trefuse(where, `has options for \"${key}\", which it does not wire`);\n\t\t}\n\t}\n\tcheckOwned(where, 'options', config.options);\n\tfor (const [key, options] of Object.entries(config.optionsFor ?? {})) {\n\t\tcheckOwned(where, `the options of \"${key}\"`, options);\n\t}\n\treturn definitions;\n}\n",
6
+ "import { checkDatabase } from './checks';\nimport type {\n\tChecked,\n\tDatabaseConfig,\n\tKitConfig,\n\tKitConfigInput,\n} from './types';\n\n/** Whether the config named its databases, or is one database itself. */\nfunction databasesOf(\n\tconfig: KitConfigInput,\n): Record<string, DatabaseConfig<object>> {\n\tif (typeof config !== 'object' || config === null) {\n\t\tthrow new TypeError('defineConfig: a configuration object is required');\n\t}\n\tif (!('databases' in config)) {\n\t\treturn { default: config as DatabaseConfig<object> };\n\t}\n\tconst { databases } = config;\n\tif (typeof databases !== 'object' || databases === null) {\n\t\tthrow new TypeError('defineConfig: databases is not an object');\n\t}\n\tconst names = Object.keys(databases);\n\tif (names.length === 0) {\n\t\tthrow new TypeError('defineConfig: databases names none');\n\t}\n\treturn databases as Record<string, DatabaseConfig<object>>;\n}\n\n/**\n * The configuration of an application's MongoDB, checked once and frozen.\n *\n * ```ts\n * import * as collections from './models';\n *\n * export const config = defineConfig({\n * \turi: process.env.MONGO_URI!,\n * \tcollections,\n * });\n * ```\n *\n * Several databases name themselves:\n *\n * ```ts\n * defineConfig({\n * \tdatabases: {\n * \t\tmain: { uri: process.env.MONGO_URI!, collections },\n * \t\tanalytics: { uri: process.env.ANALYTICS_URI!, collections: events },\n * \t},\n * });\n * ```\n *\n * It connects to nothing and reads no environment variable: what is wrong\n * with the configuration throws here, where the application starts, and the\n * variables are the application's to read.\n */\nexport function defineConfig<const C extends KitConfigInput>(\n\tconfig: C & Checked<C>,\n): KitConfig<C> {\n\tconst databases = databasesOf(config);\n\tfor (const [name, database] of Object.entries(databases)) {\n\t\tcheckDatabase(name, database);\n\t}\n\treturn Object.freeze({\n\t\tdatabases: Object.freeze({ ...databases }),\n\t}) as KitConfig<C>;\n}\n",
7
+ "import type { AnyCollectionDefinition } from '@nxgt/mongo';\nimport { definitionsOf, isDefinition } from './config/checks';\n\n/** What to scan, and what to read in each file it finds. */\nexport interface DiscoverOptions {\n\t/** A glob, relative to `cwd`: `'src/models/*.model.ts'`. */\n\tglob: string;\n\t/** Where the glob starts. Default: the process's working directory. */\n\tcwd?: string;\n\t/**\n\t * The export to read in each file. Default: every export that is a\n\t * definition, which is what `import * as collections` gives.\n\t */\n\texport?: string;\n}\n\n/**\n * The definitions of the files a glob matches, read at run time.\n *\n * For scripts — a sync or a migration run from the repository — and for\n * nothing else: a glob is read from the file system, so it finds nothing\n * once the application is bundled, and it produces **no types**. An\n * application wires its collections with `import * as collections from\n * './models'`, which a bundler follows and the compiler sees.\n *\n * ```ts\n * import { connectMongo, syncCollections } from '@nxgt/mongo';\n * import { discoverCollections } from '@nxgt/mongo-kit';\n *\n * const mongo = await connectMongo(process.env.MONGO_URI!);\n * const definitions = await discoverCollections({ glob: 'src/**\\/*.model.ts' });\n * await syncCollections(mongo.db, definitions);\n * await mongo.close();\n * ```\n *\n * The files are imported, so their top level runs, and the glob is\n * `Bun.Glob`: this one function needs the Bun runtime.\n */\nexport async function discoverCollections(\n\toptions: DiscoverOptions,\n): Promise<AnyCollectionDefinition[]> {\n\tconst { glob, cwd = process.cwd(), export: name } = options;\n\tif (typeof glob !== 'string' || glob === '') {\n\t\tthrow new TypeError('discoverCollections: a glob is required');\n\t}\n\tconst paths = await Array.fromAsync(new Bun.Glob(glob).scan({ cwd }));\n\tconst found: AnyCollectionDefinition[] = [];\n\tconst byName = new Map<string, string>();\n\tfor (const path of paths.sort()) {\n\t\tconst module = (await import(`${cwd}/${path}`)) as Record<string, unknown>;\n\t\tconst definitions =\n\t\t\tname === undefined\n\t\t\t\t? definitionsOf(module)\n\t\t\t\t: isDefinition(module[name])\n\t\t\t\t\t? ([[name, module[name]]] as [string, AnyCollectionDefinition][])\n\t\t\t\t\t: [];\n\t\tif (name !== undefined && definitions.length === 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`discoverCollections: ${path} exports no definition named \"${name}\"`,\n\t\t\t);\n\t\t}\n\t\tfor (const [, definition] of definitions) {\n\t\t\tconst seen = byName.get(definition.name);\n\t\t\tif (seen !== undefined && seen !== path) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`discoverCollections: ${seen} and ${path} both define the collection \"${definition.name}\"`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tbyName.set(definition.name, path);\n\t\t\tfound.push(definition);\n\t\t}\n\t}\n\treturn found;\n}\n",
8
+ "import { connectMongo, type MongoConnection } from '@nxgt/mongo';\nimport type { Db } from 'mongodb';\nimport { checkDatabase } from '../config/checks';\nimport type { DatabaseConfig, KitConfig } from '../config/types';\nimport type { DatabaseContext, KitContext } from './context';\nimport { kitOf } from './derive';\nimport type { MongoKit } from './types';\n\n/** Where one database is, and whether the kit opened it itself. */\nasync function open(\n\tconfig: DatabaseConfig<object>,\n): Promise<{ db: Db; connection: MongoConnection | undefined }> {\n\tif (config.client) {\n\t\tconst client = config.client;\n\t\treturn {\n\t\t\tdb: config.database ? client.db(config.database) : client.db(),\n\t\t\tconnection: undefined,\n\t\t};\n\t}\n\tconst connection = await connectMongo(\n\t\tconfig.uri as string,\n\t\tconfig.clientOptions,\n\t);\n\treturn {\n\t\tdb: config.database ? connection.client.db(config.database) : connection.db,\n\t\tconnection,\n\t};\n}\n\n/**\n * A key the driver's `Db` already answers to would be unreachable on the\n * scope. The types refuse it where the config is written; this asks the\n * object itself, so a member the driver adds in a later release is caught\n * here rather than silently shadowed.\n */\nfunction checkCollisions(name: string, db: Db, keys: readonly string[]): void {\n\tfor (const key of keys) {\n\t\tif (key in db) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`createKit: database \"${name}\" wires a collection under \"${key}\", ` +\n\t\t\t\t\t\"which is a member of the driver's Db: it would be unreachable. \" +\n\t\t\t\t\t'Export that definition under another name.',\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Opens what the configuration describes, and gives the application its\n * collections on their database.\n *\n * ```ts\n * await using kit = await createKit(config);\n * const user = await kit.db.users.create({ email: 'ada@example.com' });\n * ```\n *\n * A database with a `uri` takes a hold on the client `connectMongo` shares\n * for that URI, and `close()` gives it back; a database given a `client` uses\n * it and never closes it. Nothing is built ahead of the connections: a\n * collection is built the first time it is read.\n */\nexport async function createKit<C>(config: KitConfig<C>): Promise<MongoKit<C>> {\n\tconst entries = Object.entries(config.databases) as [\n\t\tstring,\n\t\tDatabaseConfig<object>,\n\t][];\n\tconst databases: DatabaseContext[] = [];\n\ttry {\n\t\tfor (const [name, database] of entries) {\n\t\t\tconst wired = checkDatabase(name, database);\n\t\t\tconst { db, connection } = await open(database);\n\t\t\tdatabases.push({\n\t\t\t\tname,\n\t\t\t\tdb,\n\t\t\t\tclient: connection?.client ?? (database.client as never),\n\t\t\t\twired,\n\t\t\t\toptions: (database.options ?? {}) as never,\n\t\t\t\toptionsFor: (database.optionsFor ?? {}) as never,\n\t\t\t\tautoSync: database.autoSync === true,\n\t\t\t\tconnection,\n\t\t\t});\n\t\t\tcheckCollisions(\n\t\t\t\tname,\n\t\t\t\tdb,\n\t\t\t\twired.map(([key]) => key),\n\t\t\t);\n\t\t}\n\t} catch (error) {\n\t\t// Whatever opened before the failure is this call's to give back.\n\t\tfor (const database of databases) await database.connection?.close();\n\t\tthrow error;\n\t}\n\tconst ctx: KitContext = {\n\t\tdatabases,\n\t\tsession: undefined,\n\t\tactor: undefined,\n\t\tcache: new Map(),\n\t\troot: true,\n\t};\n\treturn kitOf<C>(ctx);\n}\n",
9
+ "import type { AnyCollectionDefinition, MongoConnection } from '@nxgt/mongo';\nimport type { ClientSession, Db, MongoClient } from 'mongodb';\nimport type { KitCollectionOptions } from '../config/types';\n\n/** A collection as the kit holds it: the key it is reached by, and its definition. */\nexport type Wired = readonly [key: string, definition: AnyCollectionDefinition];\n\n/** One database of a kit, resolved once: data, like `@nxgt/mongo`'s own context. */\nexport interface DatabaseContext {\n\t/** The name the config gave it, which is the key on `kit.databases`. */\n\treadonly name: string;\n\treadonly db: Db;\n\treadonly client: MongoClient;\n\treadonly wired: readonly Wired[];\n\treadonly options: KitCollectionOptions<never>;\n\treadonly optionsFor: Readonly<Record<string, KitCollectionOptions<never>>>;\n\treadonly autoSync: boolean;\n\t/**\n\t * The connection the kit opened, or `undefined` when the config gave a\n\t * client: what it did not open is not its to close.\n\t */\n\treadonly connection: MongoConnection | undefined;\n}\n\n/** What one kit works from. A derived kit shares the databases, not the cache. */\nexport interface KitContext {\n\treadonly databases: readonly DatabaseContext[];\n\treadonly session: ClientSession | undefined;\n\treadonly actor: unknown;\n\t/** The collections already built, per database name then per key. */\n\treadonly cache: Map<string, Map<string, unknown>>;\n\t/** Whether this is the kit `createKit` returned, the only one to close. */\n\treadonly root: boolean;\n}\n\n/** The same kit over another session or actor: a fresh cache, the same databases. */\nexport function derived(\n\tctx: KitContext,\n\tchange: { session?: ClientSession | undefined; actor?: unknown },\n): KitContext {\n\treturn {\n\t\tdatabases: ctx.databases,\n\t\tsession: 'session' in change ? change.session : ctx.session,\n\t\tactor: 'actor' in change ? change.actor : ctx.actor,\n\t\tcache: new Map(),\n\t\troot: false,\n\t};\n}\n\n/** The database under this name, or the one there is. */\nexport function databaseOf(ctx: KitContext, name: string): DatabaseContext {\n\tconst found = ctx.databases.find((database) => database.name === name);\n\tif (!found) {\n\t\tthrow new TypeError(\n\t\t\t`This kit has no database \"${name}\": it has ${ctx.databases\n\t\t\t\t.map((database) => `\"${database.name}\"`)\n\t\t\t\t.join(', ')}.`,\n\t\t);\n\t}\n\treturn found;\n}\n",
10
+ "import { getCollection } from '@nxgt/mongo';\nimport type { DatabaseContext, KitContext } from './context';\n\n/**\n * The collection under `key`, built the first time it is read and kept:\n * `getCollection` caches nothing, so a scope that built them all would pay\n * for every collection on every request that derives a kit.\n */\nexport function collectionAt(\n\tctx: KitContext,\n\tdatabase: DatabaseContext,\n\tkey: string,\n\tdefinition: DatabaseContext['wired'][number][1],\n): unknown {\n\tlet built = ctx.cache.get(database.name);\n\tif (!built) {\n\t\tbuilt = new Map();\n\t\tctx.cache.set(database.name, built);\n\t}\n\tconst found = built.get(key);\n\tif (found) return found;\n\tconst collection = getCollection(database.db, definition, {\n\t\t...database.options,\n\t\t...database.optionsFor[key],\n\t\t...(database.autoSync ? { autoSync: true } : {}),\n\t\t...(ctx.session ? { session: ctx.session } : {}),\n\t\t...(ctx.actor === undefined ? {} : { actor: ctx.actor }),\n\t} as never);\n\tbuilt.set(key, collection);\n\treturn collection;\n}\n\n/**\n * A database with its collections on it. The collections are own properties,\n * so `Object.keys` lists them; everything else is the driver's `Db`, read\n * through a proxy — the shape `getCollection` already uses to put this\n * package's methods over the driver's collection.\n *\n * A key the `Db` already answers to never reaches here: `createKit` refuses\n * it, and the types refuse it before that.\n */\nexport function scopeOf(ctx: KitContext, database: DatabaseContext): object {\n\tconst collections: Record<string, unknown> = {};\n\tfor (const [key, definition] of database.wired) {\n\t\tObject.defineProperty(collections, key, {\n\t\t\tenumerable: true,\n\t\t\tget: () => collectionAt(ctx, database, key, definition),\n\t\t});\n\t}\n\treturn new Proxy(collections, {\n\t\tget(target, key, receiver) {\n\t\t\tif (Reflect.has(target, key)) return Reflect.get(target, key, receiver);\n\t\t\tconst value = Reflect.get(database.db, key) as unknown;\n\t\t\treturn typeof value === 'function' ? value.bind(database.db) : value;\n\t\t},\n\t\thas(target, key) {\n\t\t\treturn Reflect.has(target, key) || Reflect.has(database.db, key);\n\t\t},\n\t});\n}\n",
11
+ "import {\n\ttype SyncOptions,\n\ttype SyncReport,\n\tsyncCollections,\n} from '@nxgt/mongo';\nimport type { KitContext } from './context';\n\n/**\n * Syncs exactly the collections the kit wires, database by database — which\n * `syncAll` cannot do, since the registry knows no database.\n *\n * A deployment step: `collMod` needs the `dbAdmin` role, and neither it nor\n * an index build runs in a transaction. The first database that throws stops\n * the rest, so a `dryRun` is the way to see everything at once.\n */\nexport async function syncKit(\n\tctx: KitContext,\n\toptions: SyncOptions = {},\n): Promise<Record<string, SyncReport[]>> {\n\tconst reports: Record<string, SyncReport[]> = {};\n\tfor (const database of ctx.databases) {\n\t\treports[database.name] = await syncCollections(\n\t\t\tdatabase.db,\n\t\t\tdatabase.wired.map(([, definition]) => definition),\n\t\t\toptions,\n\t\t);\n\t}\n\treturn reports;\n}\n",
12
+ "import { type TransactionHost, withTransaction } from '@nxgt/mongo';\nimport type { MongoClient, TransactionOptions } from 'mongodb';\nimport { databaseOf, derived, type KitContext } from './context';\n\n/**\n * The client a transaction runs on. One transaction lives on one client, so\n * a kit holding several has to be told which — there is no transaction\n * across clients to give.\n */\nexport function clientFor(\n\tctx: KitContext,\n\ton: string | undefined,\n): MongoClient {\n\tif (on !== undefined) return databaseOf(ctx, on).client;\n\tconst clients = new Set(ctx.databases.map((database) => database.client));\n\tconst [only] = clients;\n\tif (clients.size === 1 && only) return only;\n\tthrow new TypeError(\n\t\t'transaction: this kit holds more than one client, and a transaction ' +\n\t\t\t\"lives on one. Name the database it runs on, as `{ on: 'main' }`.\",\n\t);\n}\n\n/**\n * What the transaction runs on: the kit's own session when it has one, so\n * that a transaction inside a transaction **joins** the outer one rather than\n * opening a second, independent one beside it; a client otherwise.\n */\nexport function hostFor(\n\tctx: KitContext,\n\ton: string | undefined,\n): TransactionHost {\n\tif (!ctx.session) return clientFor(ctx, on);\n\tif (on !== undefined) {\n\t\tthrow new TypeError(\n\t\t\t'transaction: this kit is already in a session, which this call ' +\n\t\t\t\t'joins, so `on` has no client left to choose.',\n\t\t);\n\t}\n\treturn ctx.session;\n}\n\n/**\n * Runs `fn` in a transaction, with a kit whose collections are all in it.\n * The driver retries `fn` from the start on a transient error, so `fn` must\n * be safe to run twice — `@nxgt/mongo`'s `withTransaction` says the rest.\n */\nexport async function transact<T>(\n\tctx: KitContext,\n\tbuild: (ctx: KitContext) => unknown,\n\tfn: (kit: never) => Promise<T>,\n\toptions: (TransactionOptions & { on?: string }) | undefined,\n): Promise<T> {\n\tconst { on, ...rest } = options ?? {};\n\tconst host = hostFor(ctx, on);\n\tconst transactionOptions =\n\t\tObject.keys(rest).length > 0 ? (rest as TransactionOptions) : undefined;\n\treturn withTransaction(\n\t\thost,\n\t\t(session) => fn(build(derived(ctx, { session })) as never),\n\t\ttransactionOptions,\n\t);\n}\n",
13
+ "import type { SyncOptions } from '@nxgt/mongo';\nimport { databaseOf, derived, type KitContext } from './context';\nimport { scopeOf } from './scope';\nimport { syncKit } from './sync';\nimport { transact } from './transaction';\nimport type { KitTransactionOptions, MongoKit } from './types';\n\n/**\n * Closes what this kit's context opened. Idempotent, because each\n * `MongoConnection` is: a second call awaits the first one's work.\n */\nasync function closeKit(ctx: KitContext): Promise<void> {\n\tif (!ctx.root) {\n\t\tthrow new TypeError(\n\t\t\t'close: this kit came from `as`, `withSession` or a transaction. ' +\n\t\t\t\t'Close the kit `createKit` returned — the clients are shared.',\n\t\t);\n\t}\n\tfor (const database of ctx.databases) {\n\t\tawait database.connection?.close();\n\t}\n}\n\n/**\n * A kit over one context. `as` and `withSession` build another over a new\n * context, sharing the databases and the clients: only the collections are\n * built again, and only the ones a caller reads.\n */\nexport function kitOf<C>(ctx: KitContext): MongoKit<C> {\n\tconst scopes = new Map<string, object>();\n\tconst scopeFor = (name: string): object => {\n\t\tconst found = scopes.get(name);\n\t\tif (found) return found;\n\t\tconst scope = scopeOf(ctx, databaseOf(ctx, name));\n\t\tscopes.set(name, scope);\n\t\treturn scope;\n\t};\n\n\tconst databases = {} as Record<string, object>;\n\tconst clients = {} as Record<string, unknown>;\n\tfor (const database of ctx.databases) {\n\t\tObject.defineProperty(databases, database.name, {\n\t\t\tenumerable: true,\n\t\t\tget: () => scopeFor(database.name),\n\t\t});\n\t\tObject.defineProperty(clients, database.name, {\n\t\t\tenumerable: true,\n\t\t\tvalue: database.client,\n\t\t});\n\t}\n\n\tconst kit: MongoKit<C> = {\n\t\tget db() {\n\t\t\tconst [only] = ctx.databases;\n\t\t\tif (ctx.databases.length !== 1 || !only) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t'kit.db: this kit has several databases. Read the one you mean, ' +\n\t\t\t\t\t\t`as \\`kit.databases.${ctx.databases[0]?.name ?? 'main'}\\`.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn scopeFor(only.name) as never;\n\t\t},\n\t\tdatabases: databases as never,\n\t\tclients: clients as never,\n\t\tget actor() {\n\t\t\treturn ctx.actor as never;\n\t\t},\n\t\tget session() {\n\t\t\treturn ctx.session;\n\t\t},\n\t\tas(actor) {\n\t\t\treturn kitOf<C>(derived(ctx, { actor }));\n\t\t},\n\t\twithSession(session) {\n\t\t\treturn kitOf<C>(derived(ctx, { session }));\n\t\t},\n\t\ttransaction<T>(\n\t\t\tfn: (kit: MongoKit<C>) => Promise<T>,\n\t\t\toptions?: KitTransactionOptions<C>,\n\t\t): Promise<T> {\n\t\t\treturn transact(\n\t\t\t\tctx,\n\t\t\t\t(next) => kitOf<C>(next),\n\t\t\t\tfn as never,\n\t\t\t\toptions as never,\n\t\t\t);\n\t\t},\n\t\tsync(options?: SyncOptions) {\n\t\t\treturn syncKit(ctx, options) as never;\n\t\t},\n\t\tclose() {\n\t\t\treturn closeKit(ctx);\n\t\t},\n\t\t[Symbol.asyncDispose]() {\n\t\t\treturn closeKit(ctx);\n\t\t},\n\t};\n\treturn kit;\n}\n"
14
+ ],
15
+ "mappings": ";AAIO,SAAS,YAAY,CAAC,OAAkD;AAAA,EAC9E,IAAI,OAAO,UAAU,YAAY,UAAU;AAAA,IAAM,OAAO;AAAA,EACxD,MAAM,YAAY;AAAA,EAClB,OACC,OAAO,UAAU,SAAS,YAC1B,OAAO,UAAU,WAAW,YAC5B,UAAU,WAAW,QACrB,MAAM,QAAQ,UAAU,OAAO,KAC/B,OAAO,UAAU,WAAW;AAAA;AAKvB,SAAS,aAAa,CAC5B,aACsC;AAAA,EACtC,OAAO,OAAO,QAAQ,WAAW,EAAE,OAClC,CAAC,UACA,aAAa,MAAM,EAAE,CACvB;AAAA;AAGD,IAAM,SAAS,CAAC,OAAe,SAAwB;AAAA,EACtD,MAAM,IAAI,UAAU,iBAAiB,SAAS,MAAM;AAAA;AAUrD,IAAM,QAAQ,CAAC,MAAM,WAAW,SAAS,UAAU;AAEnD,SAAS,UAAU,CAAC,OAAe,MAAc,SAAwB;AAAA,EACxE,IAAI,OAAO,YAAY,YAAY,YAAY;AAAA,IAAM;AAAA,EACrD,WAAW,OAAO,OAAO;AAAA,IACxB,IAAI,OAAO,SAAS;AAAA,MACnB,OACC,OACA,QAAQ,WAAW,kCACl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ACzE;AAAA,EACD;AAAA;AASD,SAAS,eAAe,CAAC,MAAc,IAAQ,MAA+B;AAAA,EAC7E,WAAW,OAAO,MAAM;AAAA,IACvB,IAAI,OAAO,IAAI;AAAA,MACd,MAAM,IAAI,UACT,wBAAwB,mCAAmC,WAC1D,oEACA,4CACF;AAAA,IACD;AAAA,EACD;AAAA;AAiBD,eAAsB,SAAY,CAAC,QAA4C;AAAA,EAC9E,MAAM,UAAU,OAAO,QAAQ,OAAO,SAAS;AAAA,EAI/C,MAAM,YAA+B,CAAC;AAAA,EACtC,IAAI;AAAA,IACH,YAAY,MAAM,aAAa,SAAS;AAAA,MACvC,MAAM,QAAQ,cAAc,MAAM,QAAQ;AAAA,MAC1C,QAAQ,IAAI,eAAe,MAAM,KAAK,QAAQ;AAAA,MAC9C,UAAU,KAAK;AAAA,QACd;AAAA,QACA;AAAA,QACA,QAAQ,YAAY,UAAW,SAAS;AAAA,QACxC;AAAA,QACA,SAAU,SAAS,WAAW,CAAC;AAAA,QAC/B,YAAa,SAAS,cAAc,CAAC;AAAA,QACrC,UAAU,SAAS,aAAa;AAAA,QAChC;AAAA,MACD,CAAC;AAAA,MACD,gBACC,MACA,IACA,MAAM,IAAI,EAAE,SAAS,GAAG,CACzB;AAAA,IACD;AAAA,IACC,OAAO,OAAO;AAAA,IAEf,WAAW,YAAY;AAAA,MAAW,MAAM,SAAS,YAAY,MAAM;AAAA,IACnE,MAAM;AAAA;AAAA,EAEP,MAAM,MAAkB;AAAA,IACvB;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,IACP,OAAO,IAAI;AAAA,IACX,MAAM;AAAA,EACP;AAAA,EACA,OAAO,MAAS,GAAG;AAAA;",
16
+ "debugId": "00B9BBA5C20F9E8D64756E2164756E21",
17
+ "names": []
18
+ }
@@ -0,0 +1,39 @@
1
+ import type { AnyCollectionDefinition, MongoConnection } from '@nxgt/mongo';
2
+ import type { ClientSession, Db, MongoClient } from 'mongodb';
3
+ import type { KitCollectionOptions } from '../config/types';
4
+ /** A collection as the kit holds it: the key it is reached by, and its definition. */
5
+ export type Wired = readonly [key: string, definition: AnyCollectionDefinition];
6
+ /** One database of a kit, resolved once: data, like `@nxgt/mongo`'s own context. */
7
+ export interface DatabaseContext {
8
+ /** The name the config gave it, which is the key on `kit.databases`. */
9
+ readonly name: string;
10
+ readonly db: Db;
11
+ readonly client: MongoClient;
12
+ readonly wired: readonly Wired[];
13
+ readonly options: KitCollectionOptions<never>;
14
+ readonly optionsFor: Readonly<Record<string, KitCollectionOptions<never>>>;
15
+ readonly autoSync: boolean;
16
+ /**
17
+ * The connection the kit opened, or `undefined` when the config gave a
18
+ * client: what it did not open is not its to close.
19
+ */
20
+ readonly connection: MongoConnection | undefined;
21
+ }
22
+ /** What one kit works from. A derived kit shares the databases, not the cache. */
23
+ export interface KitContext {
24
+ readonly databases: readonly DatabaseContext[];
25
+ readonly session: ClientSession | undefined;
26
+ readonly actor: unknown;
27
+ /** The collections already built, per database name then per key. */
28
+ readonly cache: Map<string, Map<string, unknown>>;
29
+ /** Whether this is the kit `createKit` returned, the only one to close. */
30
+ readonly root: boolean;
31
+ }
32
+ /** The same kit over another session or actor: a fresh cache, the same databases. */
33
+ export declare function derived(ctx: KitContext, change: {
34
+ session?: ClientSession | undefined;
35
+ actor?: unknown;
36
+ }): KitContext;
37
+ /** The database under this name, or the one there is. */
38
+ export declare function databaseOf(ctx: KitContext, name: string): DatabaseContext;
39
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/kit/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,sFAAsF;AACtF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CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAUzE"}
@@ -0,0 +1,18 @@
1
+ import type { KitConfig } from '../config/types';
2
+ import type { MongoKit } from './types';
3
+ /**
4
+ * Opens what the configuration describes, and gives the application its
5
+ * collections on their database.
6
+ *
7
+ * ```ts
8
+ * await using kit = await createKit(config);
9
+ * const user = await kit.db.users.create({ email: 'ada@example.com' });
10
+ * ```
11
+ *
12
+ * A database with a `uri` takes a hold on the client `connectMongo` shares
13
+ * for that URI, and `close()` gives it back; a database given a `client` uses
14
+ * it and never closes it. Nothing is built ahead of the connections: a
15
+ * collection is built the first time it is read.
16
+ */
17
+ export declare function createKit<C>(config: KitConfig<C>): Promise<MongoKit<C>>;
18
+ //# sourceMappingURL=create-kit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-kit.d.ts","sourceRoot":"","sources":["../../src/kit/create-kit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAyCxC;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAuC7E"}
@@ -0,0 +1,9 @@
1
+ import { type KitContext } from './context';
2
+ import type { MongoKit } from './types';
3
+ /**
4
+ * A kit over one context. `as` and `withSession` build another over a new
5
+ * context, sharing the databases and the clients: only the collections are
6
+ * built again, and only the ones a caller reads.
7
+ */
8
+ export declare function kitOf<C>(ctx: KitContext): MongoKit<C>;
9
+ //# sourceMappingURL=derive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../../src/kit/derive.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAIjE,OAAO,KAAK,EAAyB,QAAQ,EAAE,MAAM,SAAS,CAAC;AAkB/D;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,CAsErD"}
@@ -0,0 +1,18 @@
1
+ import type { DatabaseContext, KitContext } from './context';
2
+ /**
3
+ * The collection under `key`, built the first time it is read and kept:
4
+ * `getCollection` caches nothing, so a scope that built them all would pay
5
+ * for every collection on every request that derives a kit.
6
+ */
7
+ export declare function collectionAt(ctx: KitContext, database: DatabaseContext, key: string, definition: DatabaseContext['wired'][number][1]): unknown;
8
+ /**
9
+ * A database with its collections on it. The collections are own properties,
10
+ * so `Object.keys` lists them; everything else is the driver's `Db`, read
11
+ * through a proxy — the shape `getCollection` already uses to put this
12
+ * package's methods over the driver's collection.
13
+ *
14
+ * A key the `Db` already answers to never reaches here: `createKit` refuses
15
+ * it, and the types refuse it before that.
16
+ */
17
+ export declare function scopeOf(ctx: KitContext, database: DatabaseContext): object;
18
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/kit/scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,UAAU,EACf,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAC7C,OAAO,CAiBT;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,GAAG,MAAM,CAkB1E"}
@@ -0,0 +1,12 @@
1
+ import { type SyncOptions, type SyncReport } from '@nxgt/mongo';
2
+ import type { KitContext } from './context';
3
+ /**
4
+ * Syncs exactly the collections the kit wires, database by database — which
5
+ * `syncAll` cannot do, since the registry knows no database.
6
+ *
7
+ * A deployment step: `collMod` needs the `dbAdmin` role, and neither it nor
8
+ * an index build runs in a transaction. The first database that throws stops
9
+ * the rest, so a `dryRun` is the way to see everything at once.
10
+ */
11
+ export declare function syncKit(ctx: KitContext, options?: SyncOptions): Promise<Record<string, SyncReport[]>>;
12
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/kit/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,UAAU,EAEf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAC5B,GAAG,EAAE,UAAU,EACf,OAAO,GAAE,WAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAUvC"}
@@ -0,0 +1,24 @@
1
+ import { type TransactionHost } from '@nxgt/mongo';
2
+ import type { MongoClient, TransactionOptions } from 'mongodb';
3
+ import { type KitContext } from './context';
4
+ /**
5
+ * The client a transaction runs on. One transaction lives on one client, so
6
+ * a kit holding several has to be told which — there is no transaction
7
+ * across clients to give.
8
+ */
9
+ export declare function clientFor(ctx: KitContext, on: string | undefined): MongoClient;
10
+ /**
11
+ * What the transaction runs on: the kit's own session when it has one, so
12
+ * that a transaction inside a transaction **joins** the outer one rather than
13
+ * opening a second, independent one beside it; a client otherwise.
14
+ */
15
+ export declare function hostFor(ctx: KitContext, on: string | undefined): TransactionHost;
16
+ /**
17
+ * Runs `fn` in a transaction, with a kit whose collections are all in it.
18
+ * The driver retries `fn` from the start on a transient error, so `fn` must
19
+ * be safe to run twice — `@nxgt/mongo`'s `withTransaction` says the rest.
20
+ */
21
+ export declare function transact<T>(ctx: KitContext, build: (ctx: KitContext) => unknown, fn: (kit: never) => Promise<T>, options: (TransactionOptions & {
22
+ on?: string;
23
+ }) | undefined): Promise<T>;
24
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/kit/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAmB,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,SAAS,CACxB,GAAG,EAAE,UAAU,EACf,EAAE,EAAE,MAAM,GAAG,SAAS,GACpB,WAAW,CASb;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CACtB,GAAG,EAAE,UAAU,EACf,EAAE,EAAE,MAAM,GAAG,SAAS,GACpB,eAAe,CASjB;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC/B,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,EACnC,EAAE,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9B,OAAO,EAAE,CAAC,kBAAkB,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,GACzD,OAAO,CAAC,CAAC,CAAC,CAUZ"}