@solid-nestjs/common 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decorators/wrapped.decorator.d.ts +24 -0
- package/dist/decorators/wrapped.decorator.d.ts.map +1 -1
- package/dist/decorators/wrapped.decorator.js +36 -0
- package/dist/decorators/wrapped.decorator.js.map +1 -1
- package/dist/helpers/pipe-transform.helper.d.ts +10 -0
- package/dist/helpers/pipe-transform.helper.d.ts.map +1 -1
- package/dist/helpers/pipe-transform.helper.js +13 -0
- package/dist/helpers/pipe-transform.helper.js.map +1 -1
- package/dist/helpers/types.helper.d.ts +18 -0
- package/dist/helpers/types.helper.d.ts.map +1 -1
- package/dist/helpers/types.helper.js +19 -0
- package/dist/helpers/types.helper.js.map +1 -1
- package/dist/interfaces/services/crud-service.interface.d.ts +47 -0
- package/dist/interfaces/services/crud-service.interface.d.ts.map +1 -1
- package/dist/interfaces/services/data-service.interface.d.ts +19 -0
- package/dist/interfaces/services/data-service.interface.d.ts.map +1 -1
- package/dist/pipes/query-transform.pipe.d.ts +18 -0
- package/dist/pipes/query-transform.pipe.d.ts.map +1 -1
- package/dist/pipes/query-transform.pipe.js +19 -0
- package/dist/pipes/query-transform.pipe.js.map +1 -1
- package/dist/types/boolean.type.d.ts +18 -0
- package/dist/types/boolean.type.d.ts.map +1 -1
- package/dist/types/constructor.type.d.ts +12 -0
- package/dist/types/constructor.type.d.ts.map +1 -1
- package/dist/types/deep-partial.type.d.ts +11 -0
- package/dist/types/deep-partial.type.d.ts.map +1 -1
- package/dist/types/find-args.type.d.ts +43 -1
- package/dist/types/find-args.type.d.ts.map +1 -1
- package/dist/utils/decorators.utils.d.ts +30 -0
- package/dist/utils/decorators.utils.d.ts.map +1 -1
- package/dist/utils/decorators.utils.js +42 -0
- package/dist/utils/decorators.utils.js.map +1 -1
- package/dist/utils/http-status.utils.d.ts +9 -0
- package/dist/utils/http-status.utils.d.ts.map +1 -1
- package/dist/utils/http-status.utils.js +9 -0
- package/dist/utils/http-status.utils.js.map +1 -1
- package/package.json +1 -1
@@ -1,2 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* Method decorator that wraps the target method with a custom asynchronous wrapper function.
|
3
|
+
*
|
4
|
+
* @param wrapper - An asynchronous function that receives the injectable object,
|
5
|
+
* a `next` function to invoke the original method, and the method arguments.
|
6
|
+
* It should return a Promise with the result.
|
7
|
+
* @param options - Optional configuration object that will be merged with an `injectable` reference.
|
8
|
+
* @returns A method decorator that replaces the original method with the wrapped version.
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* ```typescript
|
12
|
+
* class ExampleService {
|
13
|
+
* @WrappedBy(async (obj, next, args) => {
|
14
|
+
* // Pre-processing
|
15
|
+
* const result = await next(...args);
|
16
|
+
* // Post-processing
|
17
|
+
* return result;
|
18
|
+
* })
|
19
|
+
* async myMethod(param: string) {
|
20
|
+
* // ...
|
21
|
+
* }
|
22
|
+
* }
|
23
|
+
* ```
|
24
|
+
*/
|
1
25
|
export declare function WrappedBy(wrapper: (obj: any, next: (...args: any[]) => Promise<any>, args: any[]) => Promise<any>, options?: any): MethodDecorator;
|
2
26
|
//# sourceMappingURL=wrapped.decorator.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wrapped.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/wrapped.decorator.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"wrapped.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/wrapped.decorator.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CACrB,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EACxF,OAAO,CAAC,EAAE,GAAG,GACd,eAAe,CAgBjB"}
|
@@ -1,11 +1,47 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.WrappedBy = WrappedBy;
|
4
|
+
/**
|
5
|
+
* Wraps a function with a custom asynchronous wrapper, allowing additional logic to be executed
|
6
|
+
* before or after the original function call.
|
7
|
+
*
|
8
|
+
* @template T - The type of the function to wrap.
|
9
|
+
* @param options - Arbitrary options to be passed to the wrapper.
|
10
|
+
* @param fn - The original function to be wrapped.
|
11
|
+
* @param wrapper - An asynchronous function that receives the options, a `next` function to invoke the original function,
|
12
|
+
* and the arguments for the original function. It should return a Promise of the original function's return type.
|
13
|
+
* @returns A Promise that resolves to a new function. When invoked, this function calls the wrapper with the provided options,
|
14
|
+
* a `next` function to execute the original function, and the arguments.
|
15
|
+
*/
|
4
16
|
async function wrap(options, fn, wrapper) {
|
5
17
|
return async (...args) => {
|
6
18
|
return wrapper(options, () => Promise.resolve(fn(...args)), args);
|
7
19
|
};
|
8
20
|
}
|
21
|
+
/**
|
22
|
+
* Method decorator that wraps the target method with a custom asynchronous wrapper function.
|
23
|
+
*
|
24
|
+
* @param wrapper - An asynchronous function that receives the injectable object,
|
25
|
+
* a `next` function to invoke the original method, and the method arguments.
|
26
|
+
* It should return a Promise with the result.
|
27
|
+
* @param options - Optional configuration object that will be merged with an `injectable` reference.
|
28
|
+
* @returns A method decorator that replaces the original method with the wrapped version.
|
29
|
+
*
|
30
|
+
* @example
|
31
|
+
* ```typescript
|
32
|
+
* class ExampleService {
|
33
|
+
* @WrappedBy(async (obj, next, args) => {
|
34
|
+
* // Pre-processing
|
35
|
+
* const result = await next(...args);
|
36
|
+
* // Post-processing
|
37
|
+
* return result;
|
38
|
+
* })
|
39
|
+
* async myMethod(param: string) {
|
40
|
+
* // ...
|
41
|
+
* }
|
42
|
+
* }
|
43
|
+
* ```
|
44
|
+
*/
|
9
45
|
function WrappedBy(wrapper, options) {
|
10
46
|
return function (target, propertyKey, descriptor) {
|
11
47
|
const originalMethod = descriptor.value;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wrapped.decorator.js","sourceRoot":"","sources":["../../src/decorators/wrapped.decorator.ts"],"names":[],"mappings":";;AA+CA,8BAmBC;
|
1
|
+
{"version":3,"file":"wrapped.decorator.js","sourceRoot":"","sources":["../../src/decorators/wrapped.decorator.ts"],"names":[],"mappings":";;AA+CA,8BAmBC;AAjED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,IAAI,CACf,OAAY,EACZ,EAAK,EACL,OAAoH;IAEpH,OAAO,KAAK,EAAE,GAAG,IAAmB,EAAE,EAAE;QACpC,OAAO,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACtE,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,SAAS,CACrB,OAAwF,EACxF,OAAa;IAGb,OAAO,UAAU,MAAM,EAAE,WAAW,EAAE,UAA8B;QAEhE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAE7C,MAAM,UAAU,GAAG,IAAI,CAAC;YACxB,MAAM,UAAU,GAAG,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAA;YAE7C,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;YAC/E,OAAO,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;QAEhC,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
|
@@ -1,6 +1,16 @@
|
|
1
1
|
import { Type, PipeTransform } from '@nestjs/common';
|
2
2
|
import { Constructor } from '../types';
|
3
3
|
type ConstructorOrFunction = Function | Constructor;
|
4
|
+
/**
|
5
|
+
* Retrieves the appropriate `PipeTransform` type for a given constructor or function type.
|
6
|
+
*
|
7
|
+
* @param type - The constructor or function to get the pipe transform for.
|
8
|
+
* @returns The corresponding `PipeTransform` type if found; otherwise, `undefined`.
|
9
|
+
*
|
10
|
+
* @remarks
|
11
|
+
* - Special handling is provided for UUID strings, returning `ParseUUIDPipe` if the type is `String` and matches a UUID type.
|
12
|
+
* - Otherwise, the function looks up the type in the `TypePipeMap`.
|
13
|
+
*/
|
4
14
|
export declare function getPipeTransformForType(type: ConstructorOrFunction): Type<PipeTransform> | undefined;
|
5
15
|
export {};
|
6
16
|
//# sourceMappingURL=pipe-transform.helper.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pipe-transform.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/pipe-transform.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,IAAI,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,KAAK,qBAAqB,GAAG,QAAQ,GAAG,WAAW,CAAC;
|
1
|
+
{"version":3,"file":"pipe-transform.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/pipe-transform.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,IAAI,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,KAAK,qBAAqB,GAAG,QAAQ,GAAG,WAAW,CAAC;AASpD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,SAAS,CAOpG"}
|
@@ -8,13 +8,26 @@ const TypePipeMap = new Map([
|
|
8
8
|
[String, undefined],
|
9
9
|
[Boolean, common_1.ParseBoolPipe],
|
10
10
|
]);
|
11
|
+
/**
|
12
|
+
* Retrieves the appropriate `PipeTransform` type for a given constructor or function type.
|
13
|
+
*
|
14
|
+
* @param type - The constructor or function to get the pipe transform for.
|
15
|
+
* @returns The corresponding `PipeTransform` type if found; otherwise, `undefined`.
|
16
|
+
*
|
17
|
+
* @remarks
|
18
|
+
* - Special handling is provided for UUID strings, returning `ParseUUIDPipe` if the type is `String` and matches a UUID type.
|
19
|
+
* - Otherwise, the function looks up the type in the `TypePipeMap`.
|
20
|
+
*/
|
11
21
|
function getPipeTransformForType(type) {
|
22
|
+
// Handle UUID strings
|
12
23
|
if (type === String && isUUIDType(type)) {
|
13
24
|
return common_1.ParseUUIDPipe;
|
14
25
|
}
|
15
26
|
return TypePipeMap.get(type);
|
16
27
|
}
|
17
28
|
function isUUIDType(type) {
|
29
|
+
// You might want to implement your own logic to detect UUID types
|
30
|
+
// For example, checking for decorators or metadata
|
18
31
|
return false;
|
19
32
|
}
|
20
33
|
//# sourceMappingURL=pipe-transform.helper.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pipe-transform.helper.js","sourceRoot":"","sources":["../../src/helpers/pipe-transform.helper.ts"],"names":[],"mappings":";;AAuBA,0DAOC;AA9BD,2CAAiG;AAMjG,MAAM,WAAW,GAAG,IAAI,GAAG,CAA2C;IAClE,CAAC,MAAM,EAAE,qBAAY,CAAC;IACtB,CAAC,MAAM,EAAE,qBAAY,CAAC;IACtB,CAAC,MAAM,EAAE,SAAS,CAAC;IACnB,CAAC,OAAO,EAAE,sBAAa,CAAC;CAC3B,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"pipe-transform.helper.js","sourceRoot":"","sources":["../../src/helpers/pipe-transform.helper.ts"],"names":[],"mappings":";;AAuBA,0DAOC;AA9BD,2CAAiG;AAMjG,MAAM,WAAW,GAAG,IAAI,GAAG,CAA2C;IAClE,CAAC,MAAM,EAAE,qBAAY,CAAC;IACtB,CAAC,MAAM,EAAE,qBAAY,CAAC;IACtB,CAAC,MAAM,EAAE,SAAS,CAAC;IACnB,CAAC,OAAO,EAAE,sBAAa,CAAC;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,SAAgB,uBAAuB,CAAC,IAA2B;IAC/D,sBAAsB;IACtB,IAAI,IAAI,KAAK,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,OAAO,sBAAa,CAAC;IACzB,CAAC;IAED,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,UAAU,CAAC,IAA2B;IAC3C,kEAAkE;IAClE,mDAAmD;IACnD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
@@ -1,4 +1,22 @@
|
|
1
1
|
import { Constructor } from "../types";
|
2
|
+
/**
|
3
|
+
* Returns the name of a type, given either a string or a constructor function.
|
4
|
+
*
|
5
|
+
* @param type - The type to get the name of. Can be a string or a constructor function.
|
6
|
+
* @returns The name of the type as a string.
|
7
|
+
* @throws {Error} If the provided type is neither a string nor a constructor function.
|
8
|
+
*/
|
2
9
|
export declare function getTypeName(type: string | Function): string;
|
10
|
+
/**
|
11
|
+
* Retrieves the design type metadata of a specified property from a class constructor.
|
12
|
+
*
|
13
|
+
* @param constructor - The class constructor from which to retrieve the property type.
|
14
|
+
* @param field - The name of the property whose type metadata is to be retrieved.
|
15
|
+
* @returns The type metadata of the specified property, or `undefined` if not found.
|
16
|
+
*
|
17
|
+
* @remarks
|
18
|
+
* This function relies on TypeScript's "emitDecoratorMetadata" feature and the Reflect Metadata API.
|
19
|
+
* Ensure that the "reflect-metadata" polyfill is imported and that "emitDecoratorMetadata" is enabled in your tsconfig.
|
20
|
+
*/
|
3
21
|
export declare function getPropertyType(constructor: Constructor, field: string): any;
|
4
22
|
//# sourceMappingURL=types.helper.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/types.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"types.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/types.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAWzD;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAC,WAAW,EAAE,KAAK,EAAC,MAAM,OAGpE"}
|
@@ -2,15 +2,34 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getTypeName = getTypeName;
|
4
4
|
exports.getPropertyType = getPropertyType;
|
5
|
+
/**
|
6
|
+
* Returns the name of a type, given either a string or a constructor function.
|
7
|
+
*
|
8
|
+
* @param type - The type to get the name of. Can be a string or a constructor function.
|
9
|
+
* @returns The name of the type as a string.
|
10
|
+
* @throws {Error} If the provided type is neither a string nor a constructor function.
|
11
|
+
*/
|
5
12
|
function getTypeName(type) {
|
6
13
|
if (typeof type === 'string') {
|
7
14
|
return type;
|
8
15
|
}
|
16
|
+
// Handle constructor functions/classes
|
9
17
|
if (typeof type === 'function') {
|
10
18
|
return type.name;
|
11
19
|
}
|
12
20
|
throw new Error('Type must be a string or a constructor function');
|
13
21
|
}
|
22
|
+
/**
|
23
|
+
* Retrieves the design type metadata of a specified property from a class constructor.
|
24
|
+
*
|
25
|
+
* @param constructor - The class constructor from which to retrieve the property type.
|
26
|
+
* @param field - The name of the property whose type metadata is to be retrieved.
|
27
|
+
* @returns The type metadata of the specified property, or `undefined` if not found.
|
28
|
+
*
|
29
|
+
* @remarks
|
30
|
+
* This function relies on TypeScript's "emitDecoratorMetadata" feature and the Reflect Metadata API.
|
31
|
+
* Ensure that the "reflect-metadata" polyfill is imported and that "emitDecoratorMetadata" is enabled in your tsconfig.
|
32
|
+
*/
|
14
33
|
function getPropertyType(constructor, field) {
|
15
34
|
return Reflect.getMetadata('design:type', constructor.prototype, field);
|
16
35
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.helper.js","sourceRoot":"","sources":["../../src/helpers/types.helper.ts"],"names":[],"mappings":";;AASA,kCAWG;AAaH,0CAGC;
|
1
|
+
{"version":3,"file":"types.helper.js","sourceRoot":"","sources":["../../src/helpers/types.helper.ts"],"names":[],"mappings":";;AASA,kCAWG;AAaH,0CAGC;AAlCD;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,IAAuB;IAC/C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uCAAuC;IACvC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;AACrE,CAAC;AAEH;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAAC,WAAuB,EAAE,KAAY;IAEnE,OAAO,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC1E,CAAC"}
|
@@ -1,12 +1,59 @@
|
|
1
1
|
import { DeepPartial } from '../../types';
|
2
2
|
import { Context, IdTypeFrom, Entity } from "../misc";
|
3
3
|
import { DataService } from "./data-service.interface";
|
4
|
+
/**
|
5
|
+
* Interface defining Create, Update, and Delete (CUD) operations for a service.
|
6
|
+
*
|
7
|
+
* @typeParam IdType - The type of the entity's identifier.
|
8
|
+
* @typeParam EntityType - The type of the entity managed by the service.
|
9
|
+
* @typeParam CreateInputType - The type of the input used for creating an entity.
|
10
|
+
* @typeParam UpdateInputType - The type of the input used for updating an entity.
|
11
|
+
* @typeParam ContextType - The type of the context passed to each operation (defaults to `Context`).
|
12
|
+
*
|
13
|
+
* @remarks
|
14
|
+
* This interface abstracts the basic CUD operations for entities, allowing implementations to define
|
15
|
+
* how entities are created, updated, and removed (both soft and hard deletes).
|
16
|
+
*
|
17
|
+
* @method create - Creates a new entity using the provided input and context.
|
18
|
+
* @param context - The operation context.
|
19
|
+
* @param createInput - The data required to create the entity.
|
20
|
+
* @returns A promise resolving to the created entity.
|
21
|
+
*
|
22
|
+
* @method update - Updates an existing entity identified by `id` with the provided input and context.
|
23
|
+
* @param context - The operation context.
|
24
|
+
* @param id - The identifier of the entity to update.
|
25
|
+
* @param updateInput - The data to update the entity with.
|
26
|
+
* @returns A promise resolving to the updated entity.
|
27
|
+
*
|
28
|
+
* @method remove - Performs a soft delete of the entity identified by `id` in the given context.
|
29
|
+
* @param context - The operation context.
|
30
|
+
* @param id - The identifier of the entity to remove.
|
31
|
+
* @returns A promise resolving to the removed entity.
|
32
|
+
*
|
33
|
+
* @method hardRemove - Permanently deletes the entity identified by `id` in the given context.
|
34
|
+
* @param context - The operation context.
|
35
|
+
* @param id - The identifier of the entity to hard remove.
|
36
|
+
* @returns A promise resolving to the hard-removed entity.
|
37
|
+
*/
|
4
38
|
export interface CudService<IdType extends IdTypeFrom<EntityType>, EntityType extends Entity<unknown>, CreateInputType extends DeepPartial<EntityType>, UpdateInputType extends DeepPartial<EntityType>, ContextType extends Context = Context> {
|
5
39
|
create(context: ContextType, createInput: CreateInputType): Promise<EntityType>;
|
6
40
|
update(context: ContextType, id: IdType, updateInput: UpdateInputType): Promise<EntityType>;
|
7
41
|
remove(context: ContextType, id: IdType): Promise<EntityType>;
|
8
42
|
hardRemove(context: ContextType, id: IdType): Promise<EntityType>;
|
9
43
|
}
|
44
|
+
/**
|
45
|
+
* Generic interface for a CRUD (Create, Read, Update, Delete) service.
|
46
|
+
*
|
47
|
+
* @typeParam IdType - The type of the entity's identifier, derived from the entity type.
|
48
|
+
* @typeParam EntityType - The type of the entity managed by the service, extending `Entity<unknown>`.
|
49
|
+
* @typeParam CreateInputType - The type used for creating new entities, typically a partial of `EntityType`.
|
50
|
+
* @typeParam UpdateInputType - The type used for updating entities, typically a partial of `EntityType`.
|
51
|
+
* @typeParam ContextType - The context type for the service, defaults to `Context`.
|
52
|
+
*
|
53
|
+
* @remarks
|
54
|
+
* This interface extends both `DataService` and `CudService`, combining read and write operations
|
55
|
+
* for entities. It is intended to be implemented by services that provide full CRUD functionality.
|
56
|
+
*/
|
10
57
|
export interface CrudService<IdType extends IdTypeFrom<EntityType>, EntityType extends Entity<unknown>, CreateInputType extends DeepPartial<EntityType>, UpdateInputType extends DeepPartial<EntityType>, ContextType extends Context = Context> extends DataService<IdType, EntityType, ContextType>, CudService<IdType, EntityType, CreateInputType, UpdateInputType, ContextType> {
|
11
58
|
}
|
12
59
|
//# sourceMappingURL=crud-service.interface.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"crud-service.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/services/crud-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"crud-service.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/services/crud-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,UAAU,CACnB,MAAM,SAAS,UAAU,CAAC,UAAU,CAAC,EACrC,UAAU,SAAS,MAAM,CAAC,OAAO,CAAC,EAClC,eAAe,SAAS,WAAW,CAAC,UAAU,CAAC,EAC/C,eAAe,SAAS,WAAW,CAAC,UAAU,CAAC,EAC/C,WAAW,SAAS,OAAO,GAAG,OAAO;IAGjC,MAAM,CACF,OAAO,EAAC,WAAW,EACnB,WAAW,EAAE,eAAe,GACzB,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3B,MAAM,CACF,OAAO,EAAC,WAAW,EACnB,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,eAAe,GACzB,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3B,MAAM,CACF,OAAO,EAAC,WAAW,EACnB,EAAE,EAAE,MAAM,GACP,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3B,UAAU,CACN,OAAO,EAAC,WAAW,EACnB,EAAE,EAAE,MAAM,GACP,OAAO,CAAC,UAAU,CAAC,CAAC;CAE9B;AAET;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,WAAW,CACpB,MAAM,SAAS,UAAU,CAAC,UAAU,CAAC,EACrC,UAAU,SAAS,MAAM,CAAC,OAAO,CAAC,EAClC,eAAe,SAAS,WAAW,CAAC,UAAU,CAAC,EAC/C,eAAe,SAAS,WAAW,CAAC,UAAU,CAAC,EAC/C,WAAW,SAAS,OAAO,GAAG,OAAO,CACnC,SAAQ,WAAW,CAAC,MAAM,EAAC,UAAU,EAAC,WAAW,CAAC,EACxC,UAAU,CAAC,MAAM,EAAC,UAAU,EAAC,eAAe,EAAC,eAAe,EAAC,WAAW,CAAC;CAGpF"}
|
@@ -1,6 +1,25 @@
|
|
1
1
|
import { BooleanType, NotNullableIf, If } from '../../types';
|
2
2
|
import { Context, IdTypeFrom, Entity, FindArgs, PaginationResult } from '../misc';
|
3
3
|
import { Where } from '../../types/find-args.type';
|
4
|
+
/**
|
5
|
+
* Generic interface for a data service that provides CRUD-like operations and transactional support.
|
6
|
+
*
|
7
|
+
* @typeParam IdType - The type of the entity's identifier.
|
8
|
+
* @typeParam EntityType - The type of the entity managed by the service.
|
9
|
+
* @typeParam ContextType - The type of the context object, defaults to `Context`.
|
10
|
+
*
|
11
|
+
* @remarks
|
12
|
+
* This interface abstracts common data access patterns, including retrieval, pagination,
|
13
|
+
* transactional execution, and auditing. It is designed to be implemented by concrete data
|
14
|
+
* service classes that interact with a data source.
|
15
|
+
*
|
16
|
+
* @method findAll - Retrieves all entities matching the given arguments, optionally with pagination.
|
17
|
+
* @method pagination - Retrieves pagination metadata for entities matching the given arguments.
|
18
|
+
* @method findOne - Retrieves a single entity by its identifier, optionally throwing if not found.
|
19
|
+
* @method findOneBy - Retrieves a single entity by a custom condition, optionally throwing if not found.
|
20
|
+
* @method runInTransaction - Executes a function within a transactional context.
|
21
|
+
* @method audit - Records an audit log entry for a specified action.
|
22
|
+
*/
|
4
23
|
export interface DataService<IdType extends IdTypeFrom<EntityType>, EntityType extends Entity<unknown>, ContextType extends Context = Context> {
|
5
24
|
findAll<TBool extends BooleanType = false>(context: ContextType, args?: FindArgs<EntityType>, withPagination?: TBool): Promise<If<TBool, {
|
6
25
|
data: EntityType[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-service.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/services/data-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAG,QAAQ,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;
|
1
|
+
{"version":3,"file":"data-service.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/services/data-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAG,QAAQ,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,WAAW,CAC1B,MAAM,SAAS,UAAU,CAAC,UAAU,CAAC,EACrC,UAAU,SAAS,MAAM,CAAC,OAAO,CAAC,EAClC,WAAW,SAAS,OAAO,GAAG,OAAO;IAGrC,OAAO,CAAC,KAAK,SAAS,WAAW,GAAG,KAAK,EACvC,OAAO,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,EAC3B,cAAc,CAAC,EAAC,KAAK,GACpB,OAAO,CAAE,EAAE,CAAC,KAAK,EAAC;QAAE,IAAI,EAAC,UAAU,EAAE,CAAC;QAAC,UAAU,EAAC,gBAAgB,CAAA;KAAE,EAAC,UAAU,EAAE,CAAC,CAAE,CAAC;IAExF,UAAU,CACR,OAAO,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE7B,OAAO,CAAC,KAAK,SAAS,WAAW,GAAG,KAAK,EACvC,OAAO,EAAE,WAAW,EACpB,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,KAAK,GACb,OAAO,CAAC,aAAa,CAAC,KAAK,EAAC,UAAU,CAAC,CAAC,CAAC;IAE5C,SAAS,CAAC,KAAK,SAAS,WAAW,GAAG,KAAK,EACzC,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,EACxB,MAAM,CAAC,EAAE,KAAK,GACb,OAAO,CAAC,aAAa,CAAC,KAAK,EAAC,UAAU,CAAC,CAAC,CAAC;IAE5C,gBAAgB,CAAC,UAAU,EACzB,OAAO,EAAE,WAAW,EACpB,EAAE,EAAC,CAAC,OAAO,EAAC,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,GAC/C,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtB,KAAK,CACH,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB"}
|
@@ -1,4 +1,22 @@
|
|
1
1
|
import { PipeTransform, ArgumentMetadata } from '@nestjs/common';
|
2
|
+
/**
|
3
|
+
* A NestJS pipe that transforms query parameters by attempting to parse string values as JSON.
|
4
|
+
* If parsing fails and the value is a numeric string, it converts it to a number.
|
5
|
+
* Otherwise, the original value is retained.
|
6
|
+
*
|
7
|
+
* @implements {PipeTransform}
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* // Given a query: ?filter={"name":"John"}&limit="10"
|
11
|
+
* // The pipe will transform:
|
12
|
+
* // { filter: '{"name":"John"}', limit: "10" }
|
13
|
+
* // into:
|
14
|
+
* // { filter: { name: "John" }, limit: 10 }
|
15
|
+
*
|
16
|
+
* @param value - The incoming value to be transformed, typically an object of query parameters.
|
17
|
+
* @param metadata - Metadata about the value being transformed.
|
18
|
+
* @returns The transformed object with parsed values where possible.
|
19
|
+
*/
|
2
20
|
export declare class QueryTransformPipe implements PipeTransform {
|
3
21
|
transform(value: any, metadata: ArgumentMetadata): any;
|
4
22
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query-transform.pipe.d.ts","sourceRoot":"","sources":["../../src/pipes/query-transform.pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
1
|
+
{"version":3,"file":"query-transform.pipe.d.ts","sourceRoot":"","sources":["../../src/pipes/query-transform.pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG7E;;;;;;;;;;;;;;;;;GAiBG;AACH,qBACa,kBAAmB,YAAW,aAAa;IAEtD,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,gBAAgB;CAmBjD"}
|
@@ -8,6 +8,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
9
9
|
exports.QueryTransformPipe = void 0;
|
10
10
|
const common_1 = require("@nestjs/common");
|
11
|
+
/**
|
12
|
+
* A NestJS pipe that transforms query parameters by attempting to parse string values as JSON.
|
13
|
+
* If parsing fails and the value is a numeric string, it converts it to a number.
|
14
|
+
* Otherwise, the original value is retained.
|
15
|
+
*
|
16
|
+
* @implements {PipeTransform}
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
* // Given a query: ?filter={"name":"John"}&limit="10"
|
20
|
+
* // The pipe will transform:
|
21
|
+
* // { filter: '{"name":"John"}', limit: "10" }
|
22
|
+
* // into:
|
23
|
+
* // { filter: { name: "John" }, limit: 10 }
|
24
|
+
*
|
25
|
+
* @param value - The incoming value to be transformed, typically an object of query parameters.
|
26
|
+
* @param metadata - Metadata about the value being transformed.
|
27
|
+
* @returns The transformed object with parsed values where possible.
|
28
|
+
*/
|
11
29
|
let QueryTransformPipe = class QueryTransformPipe {
|
12
30
|
transform(value, metadata) {
|
13
31
|
if (!value)
|
@@ -18,6 +36,7 @@ let QueryTransformPipe = class QueryTransformPipe {
|
|
18
36
|
transformed[key] = typeof val === 'string' ? JSON.parse(val) : val;
|
19
37
|
}
|
20
38
|
catch (e) {
|
39
|
+
// Handle numeric strings
|
21
40
|
if (typeof val === 'string' && !isNaN(Number(val))) {
|
22
41
|
transformed[key] = Number(val);
|
23
42
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query-transform.pipe.js","sourceRoot":"","sources":["../../src/pipes/query-transform.pipe.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA6E;
|
1
|
+
{"version":3,"file":"query-transform.pipe.js","sourceRoot":"","sources":["../../src/pipes/query-transform.pipe.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA6E;AAG7E;;;;;;;;;;;;;;;;;GAiBG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAE7B,SAAS,CAAC,KAAU,EAAE,QAA0B;QAC9C,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QAEzB,MAAM,WAAW,GAAG,EAAE,CAAC;QAEvB,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC;gBACH,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YACrE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,yBAAyB;gBAC3B,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;oBACjD,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACN,WAAW,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;gBACzB,CAAC;YACH,CAAC;QACL,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAA;AArBY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAqB9B"}
|
@@ -1,4 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* Represents a boolean type, restricted to `true` or `false`.
|
3
|
+
*/
|
1
4
|
export type BooleanType = true | false;
|
5
|
+
/**
|
6
|
+
* Conditionally makes a type nullable based on a boolean type.
|
7
|
+
*
|
8
|
+
* @typeParam TBool - A boolean type (`true` or `false`). Defaults to `false`.
|
9
|
+
* @typeParam TType - The type to conditionally make nullable. Defaults to `any`.
|
10
|
+
* @returns `TType` if `TBool` is `true`, otherwise `TType | null`.
|
11
|
+
*/
|
2
12
|
export type NotNullableIf<TBool extends BooleanType = false, TType = any> = TBool extends true ? TType : TType | null;
|
13
|
+
/**
|
14
|
+
* Conditional type that selects between two types based on a boolean type.
|
15
|
+
*
|
16
|
+
* @typeParam TBool - A boolean type (`true` or `false`). Defaults to `false`.
|
17
|
+
* @typeParam TType1 - The type to use if `TBool` is `true`. Defaults to `any`.
|
18
|
+
* @typeParam TType2 - The type to use if `TBool` is `false`. Defaults to `any`.
|
19
|
+
* @returns `TType1` if `TBool` is `true`, otherwise `TType2`.
|
20
|
+
*/
|
3
21
|
export type If<TBool extends BooleanType = false, TType1 = any, TType2 = any> = TBool extends true ? TType1 : TType2;
|
4
22
|
//# sourceMappingURL=boolean.type.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"boolean.type.d.ts","sourceRoot":"","sources":["../../src/types/boolean.type.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"boolean.type.d.ts","sourceRoot":"","sources":["../../src/types/boolean.type.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,KAAK,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,WAAW,GAAG,KAAK,EAAE,KAAK,GAAG,GAAG,IAAI,KAAK,SAAS,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;AAEtH;;;;;;;GAOG;AACH,MAAM,MAAM,EAAE,CAAC,KAAK,SAAS,WAAW,GAAG,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,KAAK,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC"}
|
@@ -1,3 +1,15 @@
|
|
1
1
|
export type Constructor = (new (...args: any[]) => any);
|
2
|
+
/**
|
3
|
+
* Represents a type that can be constructed with the `new` keyword.
|
4
|
+
*
|
5
|
+
* @typeParam Type - The type of the instance that will be created. Defaults to `object`.
|
6
|
+
*
|
7
|
+
* @example
|
8
|
+
* ```typescript
|
9
|
+
* class MyClass {}
|
10
|
+
* const ctor: Constructable<MyClass> = MyClass;
|
11
|
+
* const instance = new ctor();
|
12
|
+
* ```
|
13
|
+
*/
|
2
14
|
export type Constructable<Type = object> = new (...args: any[]) => Type;
|
3
15
|
//# sourceMappingURL=constructor.type.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constructor.type.d.ts","sourceRoot":"","sources":["../../src/types/constructor.type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"constructor.type.d.ts","sourceRoot":"","sources":["../../src/types/constructor.type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,CAAC,IAAI,GAAG,MAAM,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC"}
|
@@ -1,3 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Recursively makes all properties of a type optional, including nested objects, arrays, maps, and sets.
|
3
|
+
*
|
4
|
+
* - For objects, all properties become optional and are recursively made DeepPartial.
|
5
|
+
* - For arrays, the element type is recursively made DeepPartial.
|
6
|
+
* - For maps, both keys and values are recursively made DeepPartial.
|
7
|
+
* - For sets, the element type is recursively made DeepPartial.
|
8
|
+
* - For primitive types, the type itself is returned.
|
9
|
+
*
|
10
|
+
* @template T The type to make deeply partial.
|
11
|
+
*/
|
1
12
|
export type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
|
2
13
|
[K in keyof T]?: DeepPartial<T[K]>;
|
3
14
|
} : T);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deep-partial.type.d.ts","sourceRoot":"","sources":["../../src/types/deep-partial.type.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"deep-partial.type.d.ts","sourceRoot":"","sources":["../../src/types/deep-partial.type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG;KACrN,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACrC,GAAG,CAAC,CAAC,CAAC"}
|
@@ -1,12 +1,54 @@
|
|
1
|
+
import { OrderByTypes } from '../enums';
|
1
2
|
import { StringFilter, NumberFilter, DateFilter } from './../interfaces/misc/filters.interfaces';
|
3
|
+
/**
|
4
|
+
* Represents a flexible filter type for a given field type `T` in query operations.
|
5
|
+
*
|
6
|
+
* - For `string` fields, allows a string, an array of strings, or a `StringFilter` object.
|
7
|
+
* - For `number` fields, allows a number, an array of numbers, or a `NumberFilter` object.
|
8
|
+
* - For `Date` fields, allows a `Date`, an array of `Date`s, or a `DateFilter` object.
|
9
|
+
* - For `boolean` fields, allows a boolean value.
|
10
|
+
* - For all other types, recursively applies the `Where<T>` type.
|
11
|
+
*
|
12
|
+
* This utility type is typically used to define the shape of "where" filter arguments in query builders or ORM-like APIs.
|
13
|
+
*
|
14
|
+
* @template T - The type of the field to generate a filter for.
|
15
|
+
*/
|
2
16
|
type WhereField<T> = T extends string ? string | string[] | StringFilter : T extends number ? number | number[] | NumberFilter : T extends Date ? Date | Date[] | DateFilter : T extends boolean ? boolean : Where<T>;
|
17
|
+
/**
|
18
|
+
* Represents a flexible filter type for querying objects of type `T`.
|
19
|
+
*
|
20
|
+
* - Each property of `T` can be filtered using a corresponding `WhereField`.
|
21
|
+
* - Supports logical composition with `_and` and `_or` operators, allowing for nested and/or conditions.
|
22
|
+
*
|
23
|
+
* @template T The type of the object to filter.
|
24
|
+
* @property {WhereField<T[K]>} [K] Optional filter for each property of `T`.
|
25
|
+
* @property {Where<T> | Where<T>[]} [_and] Optional logical AND composition of filters.
|
26
|
+
* @property {Where<T> | Where<T>[]} [_or] Optional logical OR composition of filters.
|
27
|
+
*/
|
3
28
|
export type Where<T> = {
|
4
29
|
[K in keyof T]?: WhereField<T[K]>;
|
5
30
|
} & {
|
6
31
|
_and?: Where<T> | Where<T>[];
|
7
32
|
_or?: Where<T> | Where<T>[];
|
8
33
|
};
|
9
|
-
|
34
|
+
/**
|
35
|
+
* Infers the appropriate ordering type for a given field type `T`.
|
36
|
+
*
|
37
|
+
* - If `T` is a `string`, the type is `string`.
|
38
|
+
* - If `T` is a `number`, the type is `number`.
|
39
|
+
* - If `T` is a `Date`, the type is `Date`.
|
40
|
+
* - If `T` is a `boolean`, the type is `boolean`.
|
41
|
+
* - Otherwise, falls back to `OrderBy<T>`, allowing for nested ordering.
|
42
|
+
*
|
43
|
+
* @template T - The type of the field to determine the order-by type for.
|
44
|
+
*/
|
45
|
+
type OrderByField<T> = T extends string ? OrderByTypes : T extends number ? OrderByTypes : T extends Date ? OrderByTypes : T extends boolean ? OrderByTypes : OrderBy<T>;
|
46
|
+
/**
|
47
|
+
* Represents an object for specifying sorting order for each property of type `T`.
|
48
|
+
* Each key of `T` can be optionally assigned an `OrderByField` value to indicate the sort direction.
|
49
|
+
*
|
50
|
+
* @template T - The type whose properties can be used for ordering.
|
51
|
+
*/
|
10
52
|
export type OrderBy<T> = {
|
11
53
|
[K in keyof T]?: OrderByField<T[K]>;
|
12
54
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"find-args.type.d.ts","sourceRoot":"","sources":["../../src/types/find-args.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAA;
|
1
|
+
{"version":3,"file":"find-args.type.d.ts","sourceRoot":"","sources":["../../src/types/find-args.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAA;AAEhG;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,CAAC,CAAC,IACb,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,YAAY,GACnD,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,YAAY,GACnD,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,UAAU,GAC3C,CAAC,SAAS,OAAO,GAAG,OAAO,GAC3B,KAAK,CAAC,CAAC,CAAC,CAAC;AAEb;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;KAClB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACpC,GAAG;IACA,IAAI,CAAC,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAE;IAC7B,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,KAAK,YAAY,CAAC,CAAC,IACf,CAAC,SAAS,MAAM,GAAG,YAAY,GAC/B,CAAC,SAAS,MAAM,GAAG,YAAY,GAC/B,CAAC,SAAS,IAAI,GAAG,YAAY,GAC7B,CAAC,SAAS,OAAO,GAAG,YAAY,GAChC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEf;;;;;GAKG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;KACpB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACtC,CAAC"}
|
@@ -1,3 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* Applies an array of method decorators to a target method.
|
3
|
+
*
|
4
|
+
* @param decorators - An array of functions that return a `MethodDecorator`.
|
5
|
+
* If the array is falsy, no decorators are applied.
|
6
|
+
* @returns A composite decorator that applies all provided method decorators.
|
7
|
+
*/
|
1
8
|
export declare function applyMethodDecorators(decorators: (() => MethodDecorator)[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
9
|
+
/**
|
10
|
+
* Conditionally applies an array of method decorators based on a boolean value or a function returning a boolean.
|
11
|
+
*
|
12
|
+
* @param condition - A boolean or a function returning a boolean that determines whether the decorators should be applied.
|
13
|
+
* @param decorators - An array of functions that return method decorators to be applied if the condition is true.
|
14
|
+
* @returns The result of applying the decorators if the condition is true; otherwise, returns an empty decorator.
|
15
|
+
*/
|
16
|
+
export declare function applyMethodDecoratorsIf(condition: boolean | (() => boolean), decorators: (() => MethodDecorator)[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
17
|
+
/**
|
18
|
+
* Applies an array of class decorators to a target class.
|
19
|
+
*
|
20
|
+
* @param decorators - An array of functions that return a `ClassDecorator`.
|
21
|
+
* If the array is falsy, no decorators are applied.
|
22
|
+
* @returns A composite decorator that applies all provided class decorators.
|
23
|
+
*/
|
2
24
|
export declare function applyClassDecorators(decorators: (() => ClassDecorator)[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
25
|
+
/**
|
26
|
+
* Conditionally applies an array of class decorators based on a boolean value or a function returning a boolean.
|
27
|
+
*
|
28
|
+
* @param condition - A boolean or a function returning a boolean that determines whether the decorators should be applied.
|
29
|
+
* @param decorators - An array of functions, each returning a `ClassDecorator`, to be applied if the condition is true.
|
30
|
+
* @returns The result of applying the decorators if the condition is true; otherwise, returns the result of `applyDecorators()`.
|
31
|
+
*/
|
32
|
+
export declare function applyClassDecoratorsIf(condition: boolean | (() => boolean), decorators: (() => ClassDecorator)[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
3
33
|
//# sourceMappingURL=decorators.utils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"decorators.utils.d.ts","sourceRoot":"","sources":["../../src/utils/decorators.utils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"decorators.utils.d.ts","sourceRoot":"","sources":["../../src/utils/decorators.utils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,CAAC,MAAM,eAAe,CAAC,EAAE,+IAK1E;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,MAAM,eAAe,CAAC,EAAE,+IAOlH;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,CAAC,MAAM,cAAc,CAAC,EAAE,+IAKxE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,MAAM,cAAc,CAAC,EAAE,+IAOhH"}
|
@@ -1,16 +1,58 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.applyMethodDecorators = applyMethodDecorators;
|
4
|
+
exports.applyMethodDecoratorsIf = applyMethodDecoratorsIf;
|
4
5
|
exports.applyClassDecorators = applyClassDecorators;
|
6
|
+
exports.applyClassDecoratorsIf = applyClassDecoratorsIf;
|
5
7
|
const common_1 = require("@nestjs/common");
|
8
|
+
/**
|
9
|
+
* Applies an array of method decorators to a target method.
|
10
|
+
*
|
11
|
+
* @param decorators - An array of functions that return a `MethodDecorator`.
|
12
|
+
* If the array is falsy, no decorators are applied.
|
13
|
+
* @returns A composite decorator that applies all provided method decorators.
|
14
|
+
*/
|
6
15
|
function applyMethodDecorators(decorators) {
|
7
16
|
if (!decorators)
|
8
17
|
return (0, common_1.applyDecorators)();
|
9
18
|
return (0, common_1.applyDecorators)(...(decorators?.map((decorator) => decorator())));
|
10
19
|
}
|
20
|
+
/**
|
21
|
+
* Conditionally applies an array of method decorators based on a boolean value or a function returning a boolean.
|
22
|
+
*
|
23
|
+
* @param condition - A boolean or a function returning a boolean that determines whether the decorators should be applied.
|
24
|
+
* @param decorators - An array of functions that return method decorators to be applied if the condition is true.
|
25
|
+
* @returns The result of applying the decorators if the condition is true; otherwise, returns an empty decorator.
|
26
|
+
*/
|
27
|
+
function applyMethodDecoratorsIf(condition, decorators) {
|
28
|
+
condition = (typeof condition === 'function') ? condition() : condition;
|
29
|
+
if (!condition)
|
30
|
+
return (0, common_1.applyDecorators)();
|
31
|
+
return applyMethodDecorators(decorators);
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Applies an array of class decorators to a target class.
|
35
|
+
*
|
36
|
+
* @param decorators - An array of functions that return a `ClassDecorator`.
|
37
|
+
* If the array is falsy, no decorators are applied.
|
38
|
+
* @returns A composite decorator that applies all provided class decorators.
|
39
|
+
*/
|
11
40
|
function applyClassDecorators(decorators) {
|
12
41
|
if (!decorators)
|
13
42
|
return (0, common_1.applyDecorators)();
|
14
43
|
return (0, common_1.applyDecorators)(...(decorators?.map((decorator) => decorator())));
|
15
44
|
}
|
45
|
+
/**
|
46
|
+
* Conditionally applies an array of class decorators based on a boolean value or a function returning a boolean.
|
47
|
+
*
|
48
|
+
* @param condition - A boolean or a function returning a boolean that determines whether the decorators should be applied.
|
49
|
+
* @param decorators - An array of functions, each returning a `ClassDecorator`, to be applied if the condition is true.
|
50
|
+
* @returns The result of applying the decorators if the condition is true; otherwise, returns the result of `applyDecorators()`.
|
51
|
+
*/
|
52
|
+
function applyClassDecoratorsIf(condition, decorators) {
|
53
|
+
condition = (typeof condition === 'function') ? condition() : condition;
|
54
|
+
if (!condition)
|
55
|
+
return (0, common_1.applyDecorators)();
|
56
|
+
return applyClassDecorators(decorators);
|
57
|
+
}
|
16
58
|
//# sourceMappingURL=decorators.utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"decorators.utils.js","sourceRoot":"","sources":["../../src/utils/decorators.utils.ts"],"names":[],"mappings":";;AAQA,
|
1
|
+
{"version":3,"file":"decorators.utils.js","sourceRoot":"","sources":["../../src/utils/decorators.utils.ts"],"names":[],"mappings":";;AAQA,sDAKC;AASD,0DAOC;AASD,oDAKC;AASD,wDAOC;AA3DD,2CAAiD;AACjD;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,UAAqC;IACvE,IAAI,CAAC,UAAU;QACX,OAAO,IAAA,wBAAe,GAAE,CAAC;IAE7B,OAAO,IAAA,wBAAe,EAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,uBAAuB,CAAC,SAAoC,EAAE,UAAqC;IAC/G,SAAS,GAAG,CAAC,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAExE,IAAI,CAAC,SAAS;QACV,OAAO,IAAA,wBAAe,GAAE,CAAC;IAE7B,OAAO,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,UAAoC;IACrE,IAAI,CAAC,UAAU;QACX,OAAO,IAAA,wBAAe,GAAE,CAAC;IAE7B,OAAO,IAAA,wBAAe,EAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,SAAoC,EAAE,UAAoC;IAC7G,SAAS,GAAG,CAAC,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAExE,IAAI,CAAC,SAAS;QACV,OAAO,IAAA,wBAAe,GAAE,CAAC;IAE7B,OAAO,oBAAoB,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC"}
|
@@ -1,3 +1,12 @@
|
|
1
1
|
import { HttpStatus } from "@nestjs/common";
|
2
|
+
/**
|
3
|
+
* Returns a human-readable description for a given HTTP status code.
|
4
|
+
*
|
5
|
+
* If the description for the provided status code is not already cached,
|
6
|
+
* it will be generated, formatted, and stored for future use.
|
7
|
+
*
|
8
|
+
* @param status - The HTTP status code from the `HttpStatus` enum.
|
9
|
+
* @returns The formatted description of the HTTP status, or 'Unknown Status' if not found.
|
10
|
+
*/
|
2
11
|
export declare function getHttpStatusDescription(status: HttpStatus): string;
|
3
12
|
//# sourceMappingURL=http-status.utils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"http-status.utils.d.ts","sourceRoot":"","sources":["../../src/utils/http-status.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
1
|
+
{"version":3,"file":"http-status.utils.d.ts","sourceRoot":"","sources":["../../src/utils/http-status.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAW5C;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAOnE"}
|
@@ -9,6 +9,15 @@ function formatStatusDescription(status) {
|
|
9
9
|
.replace(/_/g, ' ')
|
10
10
|
.replace(/\b\w/g, l => l.toUpperCase());
|
11
11
|
}
|
12
|
+
/**
|
13
|
+
* Returns a human-readable description for a given HTTP status code.
|
14
|
+
*
|
15
|
+
* If the description for the provided status code is not already cached,
|
16
|
+
* it will be generated, formatted, and stored for future use.
|
17
|
+
*
|
18
|
+
* @param status - The HTTP status code from the `HttpStatus` enum.
|
19
|
+
* @returns The formatted description of the HTTP status, or 'Unknown Status' if not found.
|
20
|
+
*/
|
12
21
|
function getHttpStatusDescription(status) {
|
13
22
|
if (!httpStatusDescriptions.has(status)) {
|
14
23
|
const description = formatStatusDescription(status);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"http-status.utils.js","sourceRoot":"","sources":["../../src/utils/http-status.utils.ts"],"names":[],"mappings":";;AAoBA,4DAOC;AA3BD,2CAA4C;AAE5C,MAAM,sBAAsB,GAA4B,IAAI,GAAG,EAAsB,CAAC;AAEtF,SAAS,uBAAuB,CAAC,MAAkB;IAC/C,OAAO,mBAAU,CAAC,MAAM,CAAC;SACpB,WAAW,EAAE;SACb,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAChD,CAAC;
|
1
|
+
{"version":3,"file":"http-status.utils.js","sourceRoot":"","sources":["../../src/utils/http-status.utils.ts"],"names":[],"mappings":";;AAoBA,4DAOC;AA3BD,2CAA4C;AAE5C,MAAM,sBAAsB,GAA4B,IAAI,GAAG,EAAsB,CAAC;AAEtF,SAAS,uBAAuB,CAAC,MAAkB;IAC/C,OAAO,mBAAU,CAAC,MAAM,CAAC;SACpB,WAAW,EAAE;SACb,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,wBAAwB,CAAC,MAAkB;IACvD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;QACpD,sBAAsB,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,gBAAgB,CAAC;AAClE,CAAC"}
|