@seedcord/plugins 0.6.1 → 0.7.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.
- package/README.md +1 -1
- package/dist/index.cjs +29 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +65 -49
- package/dist/index.mjs +9 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -13
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { Logger } from "@seedcord/services";
|
|
1
2
|
import mongoose, { Mongoose } from "mongoose";
|
|
2
|
-
import { Core,
|
|
3
|
+
import { Core, Plugin } from "seedcord";
|
|
3
4
|
import { Kysely, KyselyConfig } from "kysely";
|
|
4
5
|
import { Pool, PoolConfig } from "pg";
|
|
5
6
|
import { MigrationInfo, NoMigrations } from "kysely/migration";
|
|
6
7
|
import { HmrUpdateEvent } from "@seedcord/types/internal";
|
|
8
|
+
import { TypedConstructor } from "@seedcord/types";
|
|
9
|
+
|
|
7
10
|
//#region src/mongo/types/MongoOptions.d.ts
|
|
8
11
|
/**
|
|
9
12
|
* Configuration options for MongoDB connection and service loading.
|
|
@@ -157,7 +160,7 @@ declare abstract class MongoService<Doc extends MongoDocument = MongoDocument> {
|
|
|
157
160
|
*/
|
|
158
161
|
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
162
|
//#endregion
|
|
160
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
163
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/primitive.d.ts
|
|
161
164
|
/**
|
|
162
165
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
163
166
|
|
|
@@ -165,7 +168,7 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
|
|
|
165
168
|
*/
|
|
166
169
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
167
170
|
//#endregion
|
|
168
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
171
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/basic.d.ts
|
|
169
172
|
/**
|
|
170
173
|
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
171
174
|
|
|
@@ -173,7 +176,7 @@ Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/Jav
|
|
|
173
176
|
*/
|
|
174
177
|
type Constructor<T, Arguments extends unknown[] = any[]> = new (...arguments_: Arguments) => T;
|
|
175
178
|
//#endregion
|
|
176
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
179
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/is-any.d.ts
|
|
177
180
|
/**
|
|
178
181
|
Returns a boolean for whether the given type is `any`.
|
|
179
182
|
|
|
@@ -204,7 +207,7 @@ const anyA = get(anyObject, 'a');
|
|
|
204
207
|
*/
|
|
205
208
|
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
206
209
|
//#endregion
|
|
207
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
210
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
208
211
|
/**
|
|
209
212
|
Returns a boolean for whether the given key is an optional key of type.
|
|
210
213
|
|
|
@@ -247,7 +250,7 @@ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
|
247
250
|
*/
|
|
248
251
|
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
252
|
//#endregion
|
|
250
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
253
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
251
254
|
/**
|
|
252
255
|
Extract all optional keys from the given type.
|
|
253
256
|
|
|
@@ -285,7 +288,7 @@ type OptionalKeysOf<Type extends object> = Type extends unknown // For distribut
|
|
|
285
288
|
? (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
289
|
: never;
|
|
287
290
|
//#endregion
|
|
288
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
291
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
289
292
|
/**
|
|
290
293
|
Extract all required keys from the given type.
|
|
291
294
|
|
|
@@ -319,7 +322,7 @@ const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
|
319
322
|
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
320
323
|
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
321
324
|
//#endregion
|
|
322
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
325
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/is-never.d.ts
|
|
323
326
|
/**
|
|
324
327
|
Returns a boolean for whether the given type is `never`.
|
|
325
328
|
|
|
@@ -375,7 +378,7 @@ type B = IsTrueFixed<never>;
|
|
|
375
378
|
*/
|
|
376
379
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
377
380
|
//#endregion
|
|
378
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
381
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/if.d.ts
|
|
379
382
|
/**
|
|
380
383
|
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
381
384
|
|
|
@@ -470,7 +473,7 @@ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
|
470
473
|
*/
|
|
471
474
|
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
472
475
|
//#endregion
|
|
473
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
476
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/simplify.d.ts
|
|
474
477
|
/**
|
|
475
478
|
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
479
|
|
|
@@ -531,7 +534,7 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
|
|
|
531
534
|
*/
|
|
532
535
|
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
533
536
|
//#endregion
|
|
534
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
537
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/is-equal.d.ts
|
|
535
538
|
/**
|
|
536
539
|
Returns a boolean for whether the two given types are equal.
|
|
537
540
|
|
|
@@ -562,7 +565,7 @@ type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false
|
|
|
562
565
|
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
563
566
|
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
564
567
|
//#endregion
|
|
565
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
568
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
566
569
|
/**
|
|
567
570
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
568
571
|
|
|
@@ -656,7 +659,7 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
656
659
|
*/
|
|
657
660
|
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
658
661
|
//#endregion
|
|
659
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
662
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
660
663
|
/**
|
|
661
664
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
662
665
|
|
|
@@ -704,7 +707,7 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
704
707
|
*/
|
|
705
708
|
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
706
709
|
//#endregion
|
|
707
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
710
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/merge.d.ts
|
|
708
711
|
// Merges two objects without worrying about index signatures.
|
|
709
712
|
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
|
|
710
713
|
/**
|
|
@@ -776,7 +779,7 @@ type Merge<Destination, Source> = Destination extends unknown // For distributin
|
|
|
776
779
|
// Should never happen
|
|
777
780
|
type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
778
781
|
//#endregion
|
|
779
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
782
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/internal/object.d.ts
|
|
780
783
|
/**
|
|
781
784
|
Merges user specified options with default options.
|
|
782
785
|
|
|
@@ -829,9 +832,38 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
829
832
|
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
830
833
|
```
|
|
831
834
|
*/
|
|
832
|
-
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> =
|
|
835
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> extends infer Result extends Required<Options> // `extends Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
836
|
+
? Result : never;
|
|
837
|
+
type _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Merge<Defaults, { [Key in keyof SpecifiedOptions as undefined extends Required<Options>[Key & keyof Options] ? Key : undefined extends SpecifiedOptions[Key] ? never : Key]: SpecifiedOptions[Key] }>>>;
|
|
838
|
+
/**
|
|
839
|
+
Collapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.
|
|
840
|
+
|
|
841
|
+
Note: This doesn't collapse literals within tagged types. For example, `CollapseLiterals<Tagged<'foo' | (string & {}), 'Tag'>>` returns `("foo" & Tag<"Tag", never>) | (string & Tag<"Tag", never>)` and not `string & Tag<"Tag", never>`.
|
|
842
|
+
|
|
843
|
+
Use-case: For collapsing unions created using {@link LiteralUnion}.
|
|
844
|
+
|
|
845
|
+
@example
|
|
846
|
+
```
|
|
847
|
+
import type {LiteralUnion} from 'type-fest';
|
|
848
|
+
|
|
849
|
+
type A = CollapseLiterals<'foo' | 'bar' | (string & {})>;
|
|
850
|
+
//=> string
|
|
851
|
+
|
|
852
|
+
type B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;
|
|
853
|
+
//=> number
|
|
854
|
+
|
|
855
|
+
type C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;
|
|
856
|
+
//=> `on${string}`
|
|
857
|
+
|
|
858
|
+
type D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;
|
|
859
|
+
//=> 'click' | 'change' | `on${string}`
|
|
860
|
+
|
|
861
|
+
type E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;
|
|
862
|
+
//=> string | null | undefined
|
|
863
|
+
```
|
|
864
|
+
*/
|
|
833
865
|
//#endregion
|
|
834
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
866
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/except.d.ts
|
|
835
867
|
/**
|
|
836
868
|
Filter out keys from an object.
|
|
837
869
|
|
|
@@ -929,7 +961,7 @@ type PostPayloadFixed = Except<UserData, 'email'>;
|
|
|
929
961
|
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
930
962
|
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
963
|
//#endregion
|
|
932
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
964
|
+
//#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/literal-union.d.ts
|
|
933
965
|
/**
|
|
934
966
|
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
967
|
|
|
@@ -1036,9 +1068,17 @@ type MigrationTarget = string | NoMigrations;
|
|
|
1036
1068
|
* database connection is established.
|
|
1037
1069
|
*/
|
|
1038
1070
|
interface MigrationOptions {
|
|
1039
|
-
/**
|
|
1071
|
+
/**
|
|
1072
|
+
* Optional target migration to reach.
|
|
1073
|
+
*
|
|
1074
|
+
* @defaultValue the latest migration
|
|
1075
|
+
*/
|
|
1040
1076
|
readonly target?: MigrationTarget;
|
|
1041
|
-
/**
|
|
1077
|
+
/**
|
|
1078
|
+
* Direction to move along the migration timeline.
|
|
1079
|
+
*
|
|
1080
|
+
* @defaultValue `'latest'`
|
|
1081
|
+
*/
|
|
1042
1082
|
readonly direction?: 'latest' | 'up' | 'down';
|
|
1043
1083
|
/** Number of steps to apply when direction is `up` or `down`. */
|
|
1044
1084
|
readonly steps?: number;
|
|
@@ -1118,7 +1158,7 @@ declare class KyselyPg<Database extends object> extends Plugin {
|
|
|
1118
1158
|
private connect;
|
|
1119
1159
|
private disconnect;
|
|
1120
1160
|
/**
|
|
1121
|
-
* Runs migrations using the supplied options
|
|
1161
|
+
* Runs migrations using the supplied options.
|
|
1122
1162
|
*
|
|
1123
1163
|
* @param options - Target migration or direction overrides
|
|
1124
1164
|
*/
|
|
@@ -1208,9 +1248,11 @@ type KyselyServiceConstructor<Database extends object = object> = TypedConstruct
|
|
|
1208
1248
|
*/
|
|
1209
1249
|
interface KpgServiceRegistrationOptions {
|
|
1210
1250
|
/**
|
|
1211
|
-
* Optional override for the table name exposed via the service.
|
|
1251
|
+
* Optional override for the table name exposed via the service.
|
|
1212
1252
|
*
|
|
1213
1253
|
* You should set this if your table name does not match the service key.
|
|
1254
|
+
*
|
|
1255
|
+
* @defaultValue the provided key
|
|
1214
1256
|
*/
|
|
1215
1257
|
table?: string;
|
|
1216
1258
|
}
|
|
@@ -1239,35 +1281,9 @@ interface KpgServiceRegistrationOptions {
|
|
|
1239
1281
|
*/
|
|
1240
1282
|
declare function RegisterKpgService<TKey extends KpgServiceKeys>(key: TKey, options?: KpgServiceRegistrationOptions): <Ctor extends Constructor<KpgServices[TKey]>>(ctor: Ctor) => void;
|
|
1241
1283
|
//#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
1284
|
//#region src/index.d.ts
|
|
1269
1285
|
/** Package version */
|
|
1270
1286
|
declare const version: string;
|
|
1271
1287
|
//#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,
|
|
1288
|
+
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, version };
|
|
1273
1289
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import {
|
|
2
|
+
import { SeedcordErrorCode } from "@seedcord/errors";
|
|
3
|
+
import { SeedcordError, SeedcordRangeError } from "@seedcord/errors/internal";
|
|
4
|
+
import { Logger, ShutdownPhase } from "@seedcord/services";
|
|
5
|
+
import { keepDefined, traverseDirectory } from "@seedcord/utils";
|
|
3
6
|
import chalk from "chalk";
|
|
4
7
|
import { Envapter } from "envapt";
|
|
5
8
|
import mongoose from "mongoose";
|
|
6
|
-
import {
|
|
9
|
+
import { HmrModuleHandler, Plugin } from "seedcord";
|
|
7
10
|
import { Kysely, PostgresDialect } from "kysely";
|
|
8
11
|
import { Pool } from "pg";
|
|
9
12
|
import { promises } from "node:fs";
|
|
10
13
|
import path from "node:path";
|
|
11
14
|
import { pathToFileURL } from "node:url";
|
|
12
15
|
import { inspect } from "node:util";
|
|
13
|
-
import { keepDefined as keepDefined$1 } from "@seedcord/utils";
|
|
14
16
|
import { FileMigrationProvider, Migrator, NO_MIGRATIONS } from "kysely/migration";
|
|
15
|
-
import { DatabaseError, SeedcordError as SeedcordError$1 } from "seedcord/internal";
|
|
16
|
-
import { randomUUID } from "node:crypto";
|
|
17
|
-
import { Logger as Logger$1 } from "@seedcord/services";
|
|
18
17
|
|
|
19
18
|
//#region src/mongo/decorators/RegisterMongoModel.ts
|
|
20
19
|
const ModelMetadataKey = Symbol("db:model");
|
|
@@ -536,7 +535,7 @@ var KpgMigrationManager = class {
|
|
|
536
535
|
db: this.ctx.db,
|
|
537
536
|
provider,
|
|
538
537
|
allowUnorderedMigrations: config.allowUnorderedMigrations ?? false,
|
|
539
|
-
...keepDefined
|
|
538
|
+
...keepDefined(config, "migrationTableName", "migrationLockTableName", "migrationTableSchema")
|
|
540
539
|
});
|
|
541
540
|
}
|
|
542
541
|
async getMigrationProvider() {
|
|
@@ -799,7 +798,7 @@ var KyselyPg = class extends Plugin {
|
|
|
799
798
|
this.logger.info(chalk.red.bold("Disconnected from Postgres"));
|
|
800
799
|
}
|
|
801
800
|
/**
|
|
802
|
-
* Runs migrations using the supplied options
|
|
801
|
+
* Runs migrations using the supplied options.
|
|
803
802
|
*
|
|
804
803
|
* @param options - Target migration or direction overrides
|
|
805
804
|
*/
|
|
@@ -897,69 +896,11 @@ var KyselyPg = class extends Plugin {
|
|
|
897
896
|
}
|
|
898
897
|
};
|
|
899
898
|
|
|
900
|
-
//#endregion
|
|
901
|
-
//#region src/shared/throwDatabaseError.ts
|
|
902
|
-
const logger = new Logger$1("DatabaseError");
|
|
903
|
-
/**
|
|
904
|
-
* Wraps an unknown error in a {@link DatabaseError} with a generated UUID for correlation, then
|
|
905
|
-
* throws it. Used by `@WrapDatabaseError` to normalize raw database failures.
|
|
906
|
-
*
|
|
907
|
-
* @param error - The original error or value
|
|
908
|
-
* @param message - Fallback message used when `error` is not an `Error`
|
|
909
|
-
* @throws A {@link DatabaseError} carrying the message and a fresh UUID
|
|
910
|
-
*
|
|
911
|
-
* @internal
|
|
912
|
-
*/
|
|
913
|
-
function throwDatabaseError(error, message) {
|
|
914
|
-
logger.error("Throwing DatabaseError", error instanceof Error ? error.name : String(error));
|
|
915
|
-
throw new DatabaseError(error instanceof Error ? error.message : message, randomUUID());
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
//#endregion
|
|
919
|
-
//#region src/shared/WrapDatabaseError.ts
|
|
920
|
-
/**
|
|
921
|
-
* Catches and wraps database operation errors.
|
|
922
|
-
*
|
|
923
|
-
* Wraps non-CustomError exceptions in DatabaseError instances
|
|
924
|
-
* with UUID tracking. Should be applied to database service methods.
|
|
925
|
-
*
|
|
926
|
-
* @typeParam TypeReturn - The return type of the decorated method
|
|
927
|
-
* @param errorMessage - Message to include when wrapping errors
|
|
928
|
-
* @decorator
|
|
929
|
-
* @example
|
|
930
|
-
* ```typescript
|
|
931
|
-
* class UserService extends MongoService<IUser> {
|
|
932
|
-
* \@WrapDatabaseError('Failed to find user')
|
|
933
|
-
* async findById(id: string) {
|
|
934
|
-
* return this.model.findById(id);
|
|
935
|
-
* }
|
|
936
|
-
* }
|
|
937
|
-
* ```
|
|
938
|
-
*
|
|
939
|
-
* @see {@link DatabaseError}
|
|
940
|
-
* @see {@link CustomError}
|
|
941
|
-
* @see {@link MongoService}
|
|
942
|
-
*/
|
|
943
|
-
function WrapDatabaseError(errorMessage) {
|
|
944
|
-
return function(_target, _propertyKey, descriptor) {
|
|
945
|
-
const originalMethod = descriptor.value;
|
|
946
|
-
descriptor.value = async function(...args) {
|
|
947
|
-
if (!originalMethod) throw new SeedcordError$1(SeedcordErrorCode.DecoratorMethodNotFound);
|
|
948
|
-
try {
|
|
949
|
-
return await originalMethod.apply(this, args);
|
|
950
|
-
} catch (error) {
|
|
951
|
-
if (!(error instanceof CustomError)) throwDatabaseError(error, errorMessage);
|
|
952
|
-
else throw error;
|
|
953
|
-
}
|
|
954
|
-
};
|
|
955
|
-
};
|
|
956
|
-
}
|
|
957
|
-
|
|
958
899
|
//#endregion
|
|
959
900
|
//#region src/index.ts
|
|
960
901
|
/** Package version */
|
|
961
|
-
const version = "0.
|
|
902
|
+
const version = "0.7.0-next.0";
|
|
962
903
|
|
|
963
904
|
//#endregion
|
|
964
|
-
export { KpgService, KyselyPg, Mongo, MongoService, RegisterKpgService, RegisterMongoModel, RegisterMongoService,
|
|
905
|
+
export { KpgService, KyselyPg, Mongo, MongoService, RegisterKpgService, RegisterMongoModel, RegisterMongoService, version };
|
|
965
906
|
//# sourceMappingURL=index.mjs.map
|