@seedcord/plugins 0.5.0 → 0.6.0-next.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.
@@ -0,0 +1,1273 @@
1
+ import mongoose, { Mongoose } from "mongoose";
2
+ import { Core, Logger, Plugin, TypedConstructor } from "seedcord";
3
+ import { Kysely, KyselyConfig } from "kysely";
4
+ import { Pool, PoolConfig } from "pg";
5
+ import { MigrationInfo, NoMigrations } from "kysely/migration";
6
+ import { HmrUpdateEvent } from "@seedcord/cli";
7
+ //#region src/mongo/types/MongoOptions.d.ts
8
+ /**
9
+ * Configuration options for MongoDB connection and service loading.
10
+ */
11
+ interface MongoOptions {
12
+ /** Directory path containing database service classes */
13
+ dir: string;
14
+ /** MongoDB connection URI */
15
+ uri: string;
16
+ /** Database name to use */
17
+ name: string;
18
+ /** mongoose connection options */
19
+ connectionOptions?: mongoose.ConnectOptions | undefined;
20
+ /** Plugin timeout in milliseconds */
21
+ timeout?: number;
22
+ }
23
+ //#endregion
24
+ //#region src/mongo/types/MongoServices.d.ts
25
+ /**
26
+ * Registry of available database services.
27
+ *
28
+ * This interface can be augmented via declaration merging to add
29
+ * type-safe service definitions when using the \@RegisterMongoService and \@RegisterMongoModel decorator.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * declare module '@seedcord/plugins' {
34
+ * interface MongoServices {
35
+ * 'user': Users;
36
+ * 'guild': Guilds;
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ interface MongoServices {}
42
+ /**
43
+ * Helper type to extract service keys from the Services interface.
44
+ */
45
+ type MongoServiceKeys = keyof MongoServices;
46
+ //#endregion
47
+ //#region src/mongo/Mongo.d.ts
48
+ /**
49
+ * MongoDB integration plugin for Seedcord.
50
+ *
51
+ * Manages MongoDB connections, service loading, and provides type-safe
52
+ * access to database services through service registration decorators.
53
+ */
54
+ declare class Mongo extends Plugin {
55
+ readonly core: Core;
56
+ private readonly options;
57
+ readonly logger: Logger;
58
+ private isInitialised;
59
+ private servicesReady;
60
+ private readonly uri;
61
+ private readonly _services;
62
+ /**
63
+ * Map of all loaded services. Keys come from `@RegisterMongoService('key')`.
64
+ *
65
+ * @throws A {@link SeedcordError} if accessed before the plugin finishes initializing (e.g. from
66
+ * a plugin that starts in an earlier phase).
67
+ */
68
+ get services(): MongoServices;
69
+ /** Exposed Mongoose instance once `init` completes. */
70
+ connection: Mongoose;
71
+ private readonly hmrHandler?;
72
+ constructor(core: Core, options: MongoOptions);
73
+ private getArtifacts;
74
+ /** @internal For use in dev mode */
75
+ onHmr(event: HmrUpdateEvent): Promise<void>;
76
+ init(): Promise<void>;
77
+ stop(): Promise<void>;
78
+ private connect;
79
+ private clearModels;
80
+ private disconnect;
81
+ private loadServices;
82
+ private initializeService;
83
+ private isServiceClass;
84
+ /**
85
+ * Register hook used by decorated services.
86
+ *
87
+ * @internal
88
+ */
89
+ _register(key: string, instance: unknown): void;
90
+ private unregister;
91
+ }
92
+ //#endregion
93
+ //#region src/mongo/types/MongoDocument.d.ts
94
+ /**
95
+ * Basic document interface with MongoDB ObjectId field.
96
+ *
97
+ * Represents the minimal structure of a MongoDB document
98
+ * with the required `_id` field.
99
+ */
100
+ interface MongoDocument {
101
+ /** MongoDB document identifier */
102
+ _id: string;
103
+ }
104
+ //#endregion
105
+ //#region src/mongo/MongoService.d.ts
106
+ /**
107
+ * Base class for MongoDB service layers
108
+ *
109
+ * Provides typed access to MongoDB collections through Mongoose models.
110
+ * Services are automatically registered with the Mongo plugin when instantiated.
111
+ *
112
+ * @typeParam Doc - The document type this service manages
113
+ * @example
114
+ * ```typescript
115
+ * \@RegisterMongoService('users')
116
+ * export class Users extends MongoService<IUser> {
117
+ * \@RegisterMongoModel('users')
118
+ * public static schema = new mongoose.Schema<IUser>({
119
+ * username: { type: String, required: true, unique: true }
120
+ * });
121
+ *
122
+ * // Custom methods here
123
+ * public async findByUsername(username: string) {
124
+ * return this.model.findOne({ username });
125
+ * }
126
+ * }
127
+ * ```
128
+ */
129
+ declare abstract class MongoService<Doc extends MongoDocument = MongoDocument> {
130
+ protected readonly db: Mongo;
131
+ protected readonly core: Core;
132
+ readonly model: mongoose.Model<Doc>;
133
+ constructor(db: Mongo, core: Core);
134
+ }
135
+ //#endregion
136
+ //#region src/mongo/decorators/RegisterMongoModel.d.ts
137
+ /**
138
+ * Associates a Mongoose model with a database service
139
+ *
140
+ * Creates a Mongoose model from the decorated static schema property and stores it
141
+ * for service registration. The model becomes available as `this.model` in the service.
142
+ * Must be applied to a `public static schema` property in the service class.
143
+ *
144
+ * @typeParam TService - The service key type
145
+ * @param collection - Collection name for the Mongoose model
146
+ * @decorator
147
+ * @example
148
+ * ```typescript
149
+ * \@RegisterMongoService('users')
150
+ * export class Users extends MongoService<IUser> {
151
+ * \@RegisterMongoModel('users')
152
+ * public static schema = new mongoose.Schema<IUser>({
153
+ * username: { type: String, required: true, unique: true }
154
+ * });
155
+ * }
156
+ * ```
157
+ */
158
+ declare function RegisterMongoModel<TService extends MongoServiceKeys>(collection: TService): <SchemaObj extends Record<KeyOfSchema, mongoose.Schema>, KeyOfSchema extends keyof SchemaObj & (string | symbol)>(target: SchemaObj, propertyKey: KeyOfSchema) => void;
159
+ //#endregion
160
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/primitive.d.ts
161
+ /**
162
+ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
163
+
164
+ @category Type
165
+ */
166
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
167
+ //#endregion
168
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/basic.d.ts
169
+ /**
170
+ Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
171
+
172
+ @category Class
173
+ */
174
+ type Constructor<T, Arguments extends unknown[] = any[]> = new (...arguments_: Arguments) => T;
175
+ //#endregion
176
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-any.d.ts
177
+ /**
178
+ Returns a boolean for whether the given type is `any`.
179
+
180
+ @link https://stackoverflow.com/a/49928360/1490091
181
+
182
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
183
+
184
+ @example
185
+ ```
186
+ import type {IsAny} from 'type-fest';
187
+
188
+ const typedObject = {a: 1, b: 2} as const;
189
+ const anyObject: any = {a: 1, b: 2};
190
+
191
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
192
+ return object[key];
193
+ }
194
+
195
+ const typedA = get(typedObject, 'a');
196
+ //=> 1
197
+
198
+ const anyA = get(anyObject, 'a');
199
+ //=> any
200
+ ```
201
+
202
+ @category Type Guard
203
+ @category Utilities
204
+ */
205
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
206
+ //#endregion
207
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-optional-key-of.d.ts
208
+ /**
209
+ Returns a boolean for whether the given key is an optional key of type.
210
+
211
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
212
+
213
+ @example
214
+ ```
215
+ import type {IsOptionalKeyOf} from 'type-fest';
216
+
217
+ type User = {
218
+ name: string;
219
+ surname: string;
220
+
221
+ luckyNumber?: number;
222
+ };
223
+
224
+ type Admin = {
225
+ name: string;
226
+ surname?: string;
227
+ };
228
+
229
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
230
+ //=> true
231
+
232
+ type T2 = IsOptionalKeyOf<User, 'name'>;
233
+ //=> false
234
+
235
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
236
+ //=> boolean
237
+
238
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
239
+ //=> false
240
+
241
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
242
+ //=> boolean
243
+ ```
244
+
245
+ @category Type Guard
246
+ @category Utilities
247
+ */
248
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
249
+ //#endregion
250
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/optional-keys-of.d.ts
251
+ /**
252
+ Extract all optional keys from the given type.
253
+
254
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
255
+
256
+ @example
257
+ ```
258
+ import type {OptionalKeysOf, Except} from 'type-fest';
259
+
260
+ type User = {
261
+ name: string;
262
+ surname: string;
263
+
264
+ luckyNumber?: number;
265
+ };
266
+
267
+ const REMOVE_FIELD = Symbol('remove field symbol');
268
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
269
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
270
+ };
271
+
272
+ const update1: UpdateOperation<User> = {
273
+ name: 'Alice',
274
+ };
275
+
276
+ const update2: UpdateOperation<User> = {
277
+ name: 'Bob',
278
+ luckyNumber: REMOVE_FIELD,
279
+ };
280
+ ```
281
+
282
+ @category Utilities
283
+ */
284
+ type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
285
+ ? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
286
+ : never;
287
+ //#endregion
288
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/required-keys-of.d.ts
289
+ /**
290
+ Extract all required keys from the given type.
291
+
292
+ This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
293
+
294
+ @example
295
+ ```
296
+ import type {RequiredKeysOf} from 'type-fest';
297
+
298
+ declare function createValidation<
299
+ Entity extends object,
300
+ Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
301
+ >(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
302
+
303
+ type User = {
304
+ name: string;
305
+ surname: string;
306
+ luckyNumber?: number;
307
+ };
308
+
309
+ const validator1 = createValidation<User>('name', value => value.length < 25);
310
+ const validator2 = createValidation<User>('surname', value => value.length < 25);
311
+
312
+ // @ts-expect-error
313
+ const validator3 = createValidation<User>('luckyNumber', value => value > 0);
314
+ // Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
315
+ ```
316
+
317
+ @category Utilities
318
+ */
319
+ type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
320
+ ? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
321
+ //#endregion
322
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-never.d.ts
323
+ /**
324
+ Returns a boolean for whether the given type is `never`.
325
+
326
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
327
+ @link https://stackoverflow.com/a/53984913/10292952
328
+ @link https://www.zhenghao.io/posts/ts-never
329
+
330
+ Useful in type utilities, such as checking if something does not occur.
331
+
332
+ @example
333
+ ```
334
+ import type {IsNever, And} from 'type-fest';
335
+
336
+ type A = IsNever<never>;
337
+ //=> true
338
+
339
+ type B = IsNever<any>;
340
+ //=> false
341
+
342
+ type C = IsNever<unknown>;
343
+ //=> false
344
+
345
+ type D = IsNever<never[]>;
346
+ //=> false
347
+
348
+ type E = IsNever<object>;
349
+ //=> false
350
+
351
+ type F = IsNever<string>;
352
+ //=> false
353
+ ```
354
+
355
+ @example
356
+ ```
357
+ import type {IsNever} from 'type-fest';
358
+
359
+ type IsTrue<T> = T extends true ? true : false;
360
+
361
+ // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
362
+ type A = IsTrue<never>;
363
+ //=> never
364
+
365
+ // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
366
+ type IsTrueFixed<T> =
367
+ IsNever<T> extends true ? false : T extends true ? true : false;
368
+
369
+ type B = IsTrueFixed<never>;
370
+ //=> false
371
+ ```
372
+
373
+ @category Type Guard
374
+ @category Utilities
375
+ */
376
+ type IsNever<T> = [T] extends [never] ? true : false;
377
+ //#endregion
378
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/if.d.ts
379
+ /**
380
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
381
+
382
+ Use-cases:
383
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
384
+
385
+ Note:
386
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
387
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
388
+
389
+ @example
390
+ ```
391
+ import type {If} from 'type-fest';
392
+
393
+ type A = If<true, 'yes', 'no'>;
394
+ //=> 'yes'
395
+
396
+ type B = If<false, 'yes', 'no'>;
397
+ //=> 'no'
398
+
399
+ type C = If<boolean, 'yes', 'no'>;
400
+ //=> 'yes' | 'no'
401
+
402
+ type D = If<any, 'yes', 'no'>;
403
+ //=> 'yes' | 'no'
404
+
405
+ type E = If<never, 'yes', 'no'>;
406
+ //=> 'no'
407
+ ```
408
+
409
+ @example
410
+ ```
411
+ import type {If, IsAny, IsNever} from 'type-fest';
412
+
413
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
414
+ //=> 'not any'
415
+
416
+ type B = If<IsNever<never>, 'is never', 'not never'>;
417
+ //=> 'is never'
418
+ ```
419
+
420
+ @example
421
+ ```
422
+ import type {If, IsEqual} from 'type-fest';
423
+
424
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
425
+
426
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
427
+ //=> 'equal'
428
+
429
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
430
+ //=> 'not equal'
431
+ ```
432
+
433
+ Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
434
+
435
+ @example
436
+ ```
437
+ import type {If, IsEqual, StringRepeat} from 'type-fest';
438
+
439
+ type HundredZeroes = StringRepeat<'0', 100>;
440
+
441
+ // The following implementation is not tail recursive
442
+ type Includes<S extends string, Char extends string> =
443
+ S extends `${infer First}${infer Rest}`
444
+ ? If<IsEqual<First, Char>,
445
+ 'found',
446
+ Includes<Rest, Char>>
447
+ : 'not found';
448
+
449
+ // Hence, instantiations with long strings will fail
450
+ // @ts-expect-error
451
+ type Fails = Includes<HundredZeroes, '1'>;
452
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
453
+ // Error: Type instantiation is excessively deep and possibly infinite.
454
+
455
+ // However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
456
+ type IncludesWithoutIf<S extends string, Char extends string> =
457
+ S extends `${infer First}${infer Rest}`
458
+ ? IsEqual<First, Char> extends true
459
+ ? 'found'
460
+ : IncludesWithoutIf<Rest, Char>
461
+ : 'not found';
462
+
463
+ // Now, instantiations with long strings will work
464
+ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
465
+ //=> 'not found'
466
+ ```
467
+
468
+ @category Type Guard
469
+ @category Utilities
470
+ */
471
+ type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
472
+ //#endregion
473
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/simplify.d.ts
474
+ /**
475
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
476
+
477
+ @example
478
+ ```
479
+ import type {Simplify} from 'type-fest';
480
+
481
+ type PositionProps = {
482
+ top: number;
483
+ left: number;
484
+ };
485
+
486
+ type SizeProps = {
487
+ width: number;
488
+ height: number;
489
+ };
490
+
491
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
492
+ type Props = Simplify<PositionProps & SizeProps>;
493
+ ```
494
+
495
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
496
+
497
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
498
+
499
+ @example
500
+ ```
501
+ import type {Simplify} from 'type-fest';
502
+
503
+ interface SomeInterface {
504
+ foo: number;
505
+ bar?: string;
506
+ baz: number | undefined;
507
+ }
508
+
509
+ type SomeType = {
510
+ foo: number;
511
+ bar?: string;
512
+ baz: number | undefined;
513
+ };
514
+
515
+ const literal = {foo: 123, bar: 'hello', baz: 456};
516
+ const someType: SomeType = literal;
517
+ const someInterface: SomeInterface = literal;
518
+
519
+ declare function fn(object: Record<string, unknown>): void;
520
+
521
+ fn(literal); // Good: literal object type is sealed
522
+ fn(someType); // Good: type is sealed
523
+ // @ts-expect-error
524
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
525
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
526
+ ```
527
+
528
+ @link https://github.com/microsoft/TypeScript/issues/15300
529
+ @see {@link SimplifyDeep}
530
+ @category Object
531
+ */
532
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
533
+ //#endregion
534
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-equal.d.ts
535
+ /**
536
+ Returns a boolean for whether the two given types are equal.
537
+
538
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
539
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
540
+
541
+ Use-cases:
542
+ - If you want to make a conditional branch based on the result of a comparison of two types.
543
+
544
+ @example
545
+ ```
546
+ import type {IsEqual} from 'type-fest';
547
+
548
+ // This type returns a boolean for whether the given array includes the given item.
549
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
550
+ type Includes<Value extends readonly any[], Item> =
551
+ Value extends readonly [Value[0], ...infer rest]
552
+ ? IsEqual<Value[0], Item> extends true
553
+ ? true
554
+ : Includes<rest, Item>
555
+ : false;
556
+ ```
557
+
558
+ @category Type Guard
559
+ @category Utilities
560
+ */
561
+ type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
562
+ // This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
563
+ type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
564
+ //#endregion
565
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/omit-index-signature.d.ts
566
+ /**
567
+ Omit any index signatures from the given object type, leaving only explicitly defined properties.
568
+
569
+ This is the counterpart of `PickIndexSignature`.
570
+
571
+ Use-cases:
572
+ - Remove overly permissive signatures from third-party types.
573
+
574
+ This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
575
+
576
+ It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
577
+
578
+ (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
579
+
580
+ ```
581
+ const indexed: Record<string, unknown> = {}; // Allowed
582
+
583
+ // @ts-expect-error
584
+ const keyed: Record<'foo', unknown> = {}; // Error
585
+ // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
586
+ ```
587
+
588
+ Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
589
+
590
+ ```
591
+ type Indexed = {} extends Record<string, unknown>
592
+ ? '✅ `{}` is assignable to `Record<string, unknown>`'
593
+ : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
594
+
595
+ type IndexedResult = Indexed;
596
+ //=> '✅ `{}` is assignable to `Record<string, unknown>`'
597
+
598
+ type Keyed = {} extends Record<'foo' | 'bar', unknown>
599
+ ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
600
+ : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
601
+
602
+ type KeyedResult = Keyed;
603
+ //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
604
+ ```
605
+
606
+ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
607
+
608
+ ```
609
+ type OmitIndexSignature<ObjectType> = {
610
+ [KeyType in keyof ObjectType // Map each key of `ObjectType`...
611
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
612
+ };
613
+ ```
614
+
615
+ ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
616
+
617
+ ```
618
+ type OmitIndexSignature<ObjectType> = {
619
+ [KeyType in keyof ObjectType
620
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
621
+ as {} extends Record<KeyType, unknown>
622
+ ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
623
+ : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
624
+ ]: ObjectType[KeyType];
625
+ };
626
+ ```
627
+
628
+ If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
629
+
630
+ @example
631
+ ```
632
+ import type {OmitIndexSignature} from 'type-fest';
633
+
634
+ type Example = {
635
+ // These index signatures will be removed.
636
+ [x: string]: any;
637
+ [x: number]: any;
638
+ [x: symbol]: any;
639
+ [x: `head-${string}`]: string;
640
+ [x: `${string}-tail`]: string;
641
+ [x: `head-${string}-tail`]: string;
642
+ [x: `${bigint}`]: string;
643
+ [x: `embedded-${number}`]: string;
644
+
645
+ // These explicitly defined keys will remain.
646
+ foo: 'bar';
647
+ qux?: 'baz';
648
+ };
649
+
650
+ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
651
+ //=> {foo: 'bar'; qux?: 'baz'}
652
+ ```
653
+
654
+ @see {@link PickIndexSignature}
655
+ @category Object
656
+ */
657
+ type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
658
+ //#endregion
659
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/pick-index-signature.d.ts
660
+ /**
661
+ Pick only index signatures from the given object type, leaving out all explicitly defined properties.
662
+
663
+ This is the counterpart of `OmitIndexSignature`.
664
+
665
+ @example
666
+ ```
667
+ import type {PickIndexSignature} from 'type-fest';
668
+
669
+ declare const symbolKey: unique symbol;
670
+
671
+ type Example = {
672
+ // These index signatures will remain.
673
+ [x: string]: unknown;
674
+ [x: number]: unknown;
675
+ [x: symbol]: unknown;
676
+ [x: `head-${string}`]: string;
677
+ [x: `${string}-tail`]: string;
678
+ [x: `head-${string}-tail`]: string;
679
+ [x: `${bigint}`]: string;
680
+ [x: `embedded-${number}`]: string;
681
+
682
+ // These explicitly defined keys will be removed.
683
+ ['kebab-case-key']: string;
684
+ [symbolKey]: string;
685
+ foo: 'bar';
686
+ qux?: 'baz';
687
+ };
688
+
689
+ type ExampleIndexSignature = PickIndexSignature<Example>;
690
+ // {
691
+ // [x: string]: unknown;
692
+ // [x: number]: unknown;
693
+ // [x: symbol]: unknown;
694
+ // [x: `head-${string}`]: string;
695
+ // [x: `${string}-tail`]: string;
696
+ // [x: `head-${string}-tail`]: string;
697
+ // [x: `${bigint}`]: string;
698
+ // [x: `embedded-${number}`]: string;
699
+ // }
700
+ ```
701
+
702
+ @see {@link OmitIndexSignature}
703
+ @category Object
704
+ */
705
+ type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
706
+ //#endregion
707
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/merge.d.ts
708
+ // Merges two objects without worrying about index signatures.
709
+ type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
710
+ /**
711
+ Merge two types into a new type. Keys of the second type overrides keys of the first type.
712
+
713
+ This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
714
+
715
+ @example
716
+ ```
717
+ import type {Merge} from 'type-fest';
718
+
719
+ type Foo = {
720
+ a: string;
721
+ b: number;
722
+ };
723
+
724
+ type Bar = {
725
+ a: number; // Conflicts with Foo['a']
726
+ c: boolean;
727
+ };
728
+
729
+ // With `&`, `a` becomes `string & number` which is `never`. Not what you want.
730
+ type WithIntersection = (Foo & Bar)['a'];
731
+ //=> never
732
+
733
+ // With `Merge`, `a` is cleanly overridden to `number`.
734
+ type WithMerge = Merge<Foo, Bar>['a'];
735
+ //=> number
736
+ ```
737
+
738
+ @example
739
+ ```
740
+ import type {Merge} from 'type-fest';
741
+
742
+ type Foo = {
743
+ [x: string]: unknown;
744
+ [x: number]: unknown;
745
+ foo: string;
746
+ bar: symbol;
747
+ };
748
+
749
+ type Bar = {
750
+ [x: number]: number;
751
+ [x: symbol]: unknown;
752
+ bar: Date;
753
+ baz: boolean;
754
+ };
755
+
756
+ export type FooBar = Merge<Foo, Bar>;
757
+ //=> {
758
+ // [x: string]: unknown;
759
+ // [x: number]: number;
760
+ // [x: symbol]: unknown;
761
+ // foo: string;
762
+ // bar: Date;
763
+ // baz: boolean;
764
+ // }
765
+ ```
766
+
767
+ Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
768
+
769
+ @see {@link ObjectMerge}
770
+ @category Object
771
+ */
772
+ type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
773
+ ? Source extends unknown // For distributing `Source`
774
+ ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
775
+ : never;
776
+ // Should never happen
777
+ type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
778
+ //#endregion
779
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/object.d.ts
780
+ /**
781
+ Merges user specified options with default options.
782
+
783
+ @example
784
+ ```
785
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
786
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
787
+ type SpecifiedOptions = {leavesOnly: true};
788
+
789
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
790
+ //=> {maxRecursionDepth: 10; leavesOnly: true}
791
+ ```
792
+
793
+ @example
794
+ ```
795
+ // Complains if default values are not provided for optional options
796
+
797
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
798
+ type DefaultPathsOptions = {maxRecursionDepth: 10};
799
+ type SpecifiedOptions = {};
800
+
801
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
802
+ // ~~~~~~~~~~~~~~~~~~~
803
+ // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
804
+ ```
805
+
806
+ @example
807
+ ```
808
+ // Complains if an option's default type does not conform to the expected type
809
+
810
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
811
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
812
+ type SpecifiedOptions = {};
813
+
814
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
815
+ // ~~~~~~~~~~~~~~~~~~~
816
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
817
+ ```
818
+
819
+ @example
820
+ ```
821
+ // Complains if an option's specified type does not conform to the expected type
822
+
823
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
824
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
825
+ type SpecifiedOptions = {leavesOnly: 'yes'};
826
+
827
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
828
+ // ~~~~~~~~~~~~~~~~
829
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
830
+ ```
831
+ */
832
+ type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
833
+ //#endregion
834
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/except.d.ts
835
+ /**
836
+ Filter out keys from an object.
837
+
838
+ Returns `never` if `Exclude` is strictly equal to `Key`.
839
+ Returns `never` if `Key` extends `Exclude`.
840
+ Returns `Key` otherwise.
841
+
842
+ @example
843
+ ```
844
+ type Filtered = Filter<'foo', 'foo'>;
845
+ //=> never
846
+ ```
847
+
848
+ @example
849
+ ```
850
+ type Filtered = Filter<'bar', string>;
851
+ //=> never
852
+ ```
853
+
854
+ @example
855
+ ```
856
+ type Filtered = Filter<'bar', 'foo'>;
857
+ //=> 'bar'
858
+ ```
859
+
860
+ @see {Except}
861
+ */
862
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
863
+ type ExceptOptions = {
864
+ /**
865
+ Disallow assigning non-specified properties.
866
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
867
+ @default false
868
+ */
869
+ requireExactProps?: boolean;
870
+ };
871
+ type DefaultExceptOptions = {
872
+ requireExactProps: false;
873
+ };
874
+ /**
875
+ Create a type from an object type without certain keys.
876
+
877
+ We recommend setting the `requireExactProps` option to `true`.
878
+
879
+ This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
880
+
881
+ This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
882
+
883
+ @example
884
+ ```
885
+ import type {Except} from 'type-fest';
886
+
887
+ type Foo = {
888
+ a: number;
889
+ b: string;
890
+ };
891
+
892
+ type FooWithoutA = Except<Foo, 'a'>;
893
+ //=> {b: string}
894
+
895
+ // @ts-expect-error
896
+ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
897
+ // errors: 'a' does not exist in type '{ b: string; }'
898
+
899
+ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
900
+ //=> {a: number} & Partial<Record<'b', never>>
901
+
902
+ // @ts-expect-error
903
+ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
904
+ // errors at 'b': Type 'string' is not assignable to type 'undefined'.
905
+
906
+ // The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
907
+
908
+ // Consider the following example:
909
+
910
+ type UserData = {
911
+ [metadata: string]: string;
912
+ email: string;
913
+ name: string;
914
+ role: 'admin' | 'user';
915
+ };
916
+
917
+ // `Omit` clearly doesn't behave as expected in this case:
918
+ type PostPayload = Omit<UserData, 'email'>;
919
+ //=> {[x: string]: string; [x: number]: string}
920
+
921
+ // In situations like this, `Except` works better.
922
+ // It simply removes the `email` key while preserving all the other keys.
923
+ type PostPayloadFixed = Except<UserData, 'email'>;
924
+ //=> {[x: string]: string; name: string; role: 'admin' | 'user'}
925
+ ```
926
+
927
+ @category Object
928
+ */
929
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
930
+ type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
931
+ //#endregion
932
+ //#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/literal-union.d.ts
933
+ /**
934
+ Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
935
+
936
+ Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
937
+
938
+ This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
939
+
940
+ @example
941
+ ```
942
+ import type {LiteralUnion} from 'type-fest';
943
+
944
+ // Before
945
+
946
+ type Pet = 'dog' | 'cat' | string;
947
+
948
+ const petWithoutAutocomplete: Pet = '';
949
+ // Start typing in your TypeScript-enabled IDE.
950
+ // You **will not** get auto-completion for `dog` and `cat` literals.
951
+
952
+ // After
953
+
954
+ type Pet2 = LiteralUnion<'dog' | 'cat', string>;
955
+
956
+ const petWithAutoComplete: Pet2 = '';
957
+ // You **will** get auto-completion for `dog` and `cat` literals.
958
+ ```
959
+
960
+ @category Type
961
+ */
962
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
963
+ //#endregion
964
+ //#region src/mongo/decorators/RegisterMongoService.d.ts
965
+ /**
966
+ * Registers a database service with a typed key
967
+ *
968
+ * Associates a service class with a key for dependency injection.
969
+ * The service becomes available via `core.db.services[key]`.
970
+ *
971
+ * @typeParam TService - The service key type
972
+ * @param key - Service key for registration and type-safe access
973
+ * @decorator
974
+ * @example
975
+ * ```typescript
976
+ * \@RegisterMongoService('users')
977
+ * export class Users<Doc extends IUser = IUser> extends MongoService<Doc> {
978
+ * // Some code
979
+ * }
980
+ * ```
981
+ */
982
+ declare function RegisterMongoService<TService extends MongoServiceKeys>(key: TService): <DatabaseCtor extends Constructor<unknown> & {
983
+ prototype: MongoService;
984
+ }>(ctor: DatabaseCtor) => void;
985
+ //#endregion
986
+ //#region src/kysely-pg/types/KpgOptions.d.ts
987
+ /**
988
+ * Options that describe where migrations live and how the migrator should
989
+ * behave.
990
+ */
991
+ interface KpgMigrationsOptions {
992
+ /** Directory path, single file path, or array of migration files */
993
+ readonly path: string | string[];
994
+ /** Allow running migrations even if new ones are inserted out of order */
995
+ readonly allowUnorderedMigrations?: boolean;
996
+ /** Custom table name used to track executed migrations */
997
+ readonly migrationTableName?: string;
998
+ /** Custom lock table name used by the migrator */
999
+ readonly migrationLockTableName?: string;
1000
+ /** Schema that contains the migration bookkeeping tables */
1001
+ readonly migrationTableSchema?: string;
1002
+ /** Comparator that determines execution order for migrations */
1003
+ readonly nameComparator?: (nameA: string, nameB: string) => number;
1004
+ /** Behavior when the plugin connects. `true`/`undefined` runs to latest. */
1005
+ readonly onStartup?: boolean | MigrationOptions;
1006
+ }
1007
+ /**
1008
+ * Configuration options for Postgres connection and service discovery.
1009
+ */
1010
+ interface KpgOptions {
1011
+ /** Directory containing service classes. Make sure file(s)/folder(s) are built to `.js` in dist and aren't merged into a single file. */
1012
+ readonly dir: string;
1013
+ /** Migration settings */
1014
+ readonly migrations: KpgMigrationsOptions;
1015
+ /** Optional existing Pool instance or configuration overrides */
1016
+ readonly pool?: Pool | PoolConfig;
1017
+ /** Optional connection string used when a pool config is provided */
1018
+ readonly connectionString?: string;
1019
+ /** Optional SQL statements executed for each new connection */
1020
+ readonly onConnectSQL?: string[];
1021
+ /** Force using insecure SSL*/
1022
+ readonly forceInsecureSSL?: boolean;
1023
+ /** Kysely config (excludes dialect because it's Postgres for this plugin) */
1024
+ readonly kysely?: Except<KyselyConfig, 'dialect'>;
1025
+ /** Plugin timeout in milliseconds */
1026
+ timeout?: number;
1027
+ }
1028
+ //#endregion
1029
+ //#region src/kysely-pg/types/KpgMigration.d.ts
1030
+ /**
1031
+ * Target migration identifier used to indicate no migrations should be run. Uses Kysely's built-in `NO_MIGRATIONS` constant.
1032
+ */
1033
+ type MigrationTarget = string | NoMigrations;
1034
+ /**
1035
+ * Behavior configuration for migrations that should run automatically when a
1036
+ * database connection is established.
1037
+ */
1038
+ interface MigrationOptions {
1039
+ /** Optional target migration to reach. Defaults to latest if omitted. */
1040
+ readonly target?: MigrationTarget;
1041
+ /** Direction to move along the migration timeline. Defaults to `latest`. */
1042
+ readonly direction?: 'latest' | 'up' | 'down';
1043
+ /** Number of steps to apply when direction is `up` or `down`. */
1044
+ readonly steps?: number;
1045
+ }
1046
+ /**
1047
+ * Behavior configuration for step-based migrations.
1048
+ */
1049
+ interface StepMigrationOptions {
1050
+ /** Number of steps to apply when direction is `up` or `down`. */
1051
+ readonly steps?: number | undefined;
1052
+ }
1053
+ //#endregion
1054
+ //#region src/kysely-pg/types/KpgServices.d.ts
1055
+ /**
1056
+ * Namespace interface that gets augmented by individual service packages.
1057
+ *
1058
+ * This interface can be augmented via declaration merging to add
1059
+ * type-safe service definitions when using the `@RegisterKpgService` decorator.
1060
+ *
1061
+ * @example
1062
+ * ```typescript
1063
+ * declare module '@seedcord/plugins' {
1064
+ * interface KpgServices {
1065
+ * 'users': Users;
1066
+ * }
1067
+ * }
1068
+ * ```
1069
+ */
1070
+ interface KpgServices {}
1071
+ /**
1072
+ * Union of all registered service keys.
1073
+ *
1074
+ * @internal
1075
+ */
1076
+ type KpgServiceKeys = keyof KpgServices;
1077
+ //#endregion
1078
+ //#region src/kysely-pg/KyselyPg.d.ts
1079
+ /**
1080
+ * Postgres plugin using Kysely.
1081
+ *
1082
+ * Handles setting up the connection pool, applying migrations, and
1083
+ * registering decorated services so they can be resolved from the core.
1084
+ */
1085
+ declare class KyselyPg<Database extends object> extends Plugin {
1086
+ readonly core: Core;
1087
+ private readonly options;
1088
+ readonly logger: Logger;
1089
+ private isInitialised;
1090
+ private servicesReady;
1091
+ /** Exposed Kysely instance once `init` completes. */
1092
+ connection: Kysely<Database>;
1093
+ private pool;
1094
+ private onConnectHandler;
1095
+ private migrationManager;
1096
+ private readonly serviceRegistry;
1097
+ private readonly databaseBootstrapper;
1098
+ private databaseName;
1099
+ private readonly hmrHandler?;
1100
+ /**
1101
+ * Map of all services registered with the plugin, keyed by their decorator name.
1102
+ */
1103
+ get services(): KpgServices;
1104
+ constructor(core: Core, options: KpgOptions);
1105
+ private getArtifacts;
1106
+ /** @internal For use in dev mode */
1107
+ onHmr(event: HmrUpdateEvent): Promise<void>;
1108
+ /**
1109
+ * Connects to Postgres, runs any startup migrations, and loads decorated services.
1110
+ *
1111
+ * Safe to call multiple times; subsequent calls exit early.
1112
+ */
1113
+ init(): Promise<void>;
1114
+ /**
1115
+ * Tears down the connection pool and clears the migration manager reference.
1116
+ */
1117
+ stop(): Promise<void>;
1118
+ private connect;
1119
+ private disconnect;
1120
+ /**
1121
+ * Runs migrations using the supplied options or defaults to `latest`.
1122
+ *
1123
+ * @param options - Target migration or direction overrides
1124
+ */
1125
+ migrate(options?: MigrationOptions): Promise<void>;
1126
+ /**
1127
+ * Runs a single upwards migration step unless a custom count is provided.
1128
+ *
1129
+ * @param options - Optional configuration for step-based execution
1130
+ */
1131
+ migrateUp(options?: StepMigrationOptions): Promise<void>;
1132
+ /**
1133
+ * Runs a single downwards migration step unless a custom count is provided.
1134
+ *
1135
+ * @param options - Optional configuration for step-based execution
1136
+ */
1137
+ migrateDown(options?: StepMigrationOptions): Promise<void>;
1138
+ /**
1139
+ * Lists every migration registered with the manager along with its execution state.
1140
+ */
1141
+ listMigrations(): Promise<readonly MigrationInfo[]>;
1142
+ /**
1143
+ * Lists unapplied migrations.
1144
+ */
1145
+ listPendingMigrations(): Promise<MigrationInfo[]>;
1146
+ private getMigrationManager;
1147
+ /**
1148
+ * Register hook used by decorated services.
1149
+ *
1150
+ * @internal
1151
+ */
1152
+ _register(key: string, instance: unknown): void;
1153
+ /**
1154
+ * Tracks a service file with the HMR handler so dev reloads can swap it. No-op outside dev.
1155
+ *
1156
+ * @internal Lets {@link KpgServiceRegistry} reach the dev-only HMR handler without poking a
1157
+ * private field.
1158
+ */
1159
+ trackServiceFile(filePath: string, ctor: KyselyServiceConstructor<Database>): void;
1160
+ private resolvePool;
1161
+ private createPoolConfig;
1162
+ private registerOnConnectStatements;
1163
+ private testPoolConnection;
1164
+ }
1165
+ //#endregion
1166
+ //#region src/kysely-pg/KpgService.d.ts
1167
+ /**
1168
+ * Base class for KyselyPg services.
1169
+ *
1170
+ * Provides a small, typed shim around the shared Kysely instance and ensures
1171
+ * that subclasses have been decorated with `@RegisterKpgService`.
1172
+ *
1173
+ * @typeParam Database - The database shape used by Kysely (tables as keys).
1174
+ * @typeParam TTable - The specific table key from `Database` this service works with.
1175
+ *
1176
+ * @example
1177
+ * ```typescript
1178
+ * \@RegisterKpgService('users')
1179
+ * export class UsersService extends KpgService<ImportedDatabaseInterface, 'users'> {
1180
+ * public async findById(id: string) {
1181
+ * return this.entity
1182
+ * .selectFrom(this.table)
1183
+ * .selectAll().where('id', '=', id)
1184
+ * .executeTakeFirst();
1185
+ * }
1186
+ * }
1187
+ *
1188
+ * // Usage inside handlers:
1189
+ * const user = await this.core.db.services.users.findById('abc');
1190
+ * ```
1191
+ */
1192
+ declare abstract class KpgService<Database extends object, TTable extends LiteralUnion<keyof Database, string>> {
1193
+ protected readonly kysely: KyselyPg<Database>;
1194
+ protected readonly core: Core;
1195
+ readonly table: TTable;
1196
+ constructor(kysely: KyselyPg<Database>, core: Core);
1197
+ /**
1198
+ * Shared Kysely instance used to interact with the Postgres database.
1199
+ */
1200
+ get db(): Kysely<Database>;
1201
+ }
1202
+ /** Constructor type for {@link KpgService} classes */
1203
+ type KyselyServiceConstructor<Database extends object = object> = TypedConstructor<typeof KpgService<Database, keyof Database & string>>;
1204
+ //#endregion
1205
+ //#region src/kysely-pg/types/KpgServiceRegistrationOptions.d.ts
1206
+ /**
1207
+ * Extra configuration supplied to `@RegisterKpgService`.
1208
+ */
1209
+ interface KpgServiceRegistrationOptions {
1210
+ /**
1211
+ * Optional override for the table name exposed via the service. Defaults to the provided key.
1212
+ *
1213
+ * You should set this if your table name does not match the service key.
1214
+ */
1215
+ table?: string;
1216
+ }
1217
+ //#endregion
1218
+ //#region src/kysely-pg/decorators/RegisterKpgService.d.ts
1219
+ /**
1220
+ *
1221
+ * Registers a Kysely PG service with the specified key and options.
1222
+ *
1223
+ * Associates a service class with a key for dependency injection.
1224
+ * The service becomes available via `core.db.services[key]`.
1225
+ *
1226
+ * @typeParam TKey - The service key type
1227
+ * @param key - Service key for registration and type-safe access
1228
+ * @param options - Additional registration options
1229
+ * @decorator
1230
+ * @example
1231
+ * ```typescript
1232
+ * \@RegisterKpgService('users', { table: 'app_users' })
1233
+ * export class UsersService extends KpgService<{ users: IUser }, 'users'> {
1234
+ * // Some code
1235
+ * }
1236
+ * ```
1237
+ *
1238
+ * @see {@link KpgService}
1239
+ */
1240
+ declare function RegisterKpgService<TKey extends KpgServiceKeys>(key: TKey, options?: KpgServiceRegistrationOptions): <Ctor extends Constructor<KpgServices[TKey]>>(ctor: Ctor) => void;
1241
+ //#endregion
1242
+ //#region src/shared/WrapDatabaseError.d.ts
1243
+ /**
1244
+ * Catches and wraps database operation errors.
1245
+ *
1246
+ * Wraps non-CustomError exceptions in DatabaseError instances
1247
+ * with UUID tracking. Should be applied to database service methods.
1248
+ *
1249
+ * @typeParam TypeReturn - The return type of the decorated method
1250
+ * @param errorMessage - Message to include when wrapping errors
1251
+ * @decorator
1252
+ * @example
1253
+ * ```typescript
1254
+ * class UserService extends MongoService<IUser> {
1255
+ * \@WrapDatabaseError('Failed to find user')
1256
+ * async findById(id: string) {
1257
+ * return this.model.findById(id);
1258
+ * }
1259
+ * }
1260
+ * ```
1261
+ *
1262
+ * @see {@link DatabaseError}
1263
+ * @see {@link CustomError}
1264
+ * @see {@link MongoService}
1265
+ */
1266
+ declare function WrapDatabaseError<TypeReturn>(errorMessage: string): (_target: unknown, _propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<TypeReturn>>) => void;
1267
+ //#endregion
1268
+ //#region src/index.d.ts
1269
+ /** Package version */
1270
+ declare const version: string;
1271
+ //#endregion
1272
+ export { type KpgMigrationsOptions, type KpgOptions, KpgService, type KpgServiceRegistrationOptions, type KpgServices, KyselyPg, type MigrationOptions, type MigrationTarget, Mongo, type MongoDocument, MongoService, type MongoServices, RegisterKpgService, RegisterMongoModel, RegisterMongoService, type StepMigrationOptions, WrapDatabaseError, version };
1273
+ //# sourceMappingURL=index.d.mts.map