@dereekb/model 4.0.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/CHANGELOG.md +47 -0
- package/README.md +6 -0
- package/package.json +17 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/index.js +5 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/transform/index.d.ts +5 -0
- package/src/lib/transform/index.js +9 -0
- package/src/lib/transform/index.js.map +1 -0
- package/src/lib/transform/transform.d.ts +62 -0
- package/src/lib/transform/transform.function.d.ts +15 -0
- package/src/lib/transform/transform.function.js +28 -0
- package/src/lib/transform/transform.function.js.map +1 -0
- package/src/lib/transform/transform.js +71 -0
- package/src/lib/transform/transform.js.map +1 -0
- package/src/lib/transform/transform.result.d.ts +8 -0
- package/src/lib/transform/transform.result.js +17 -0
- package/src/lib/transform/transform.result.js.map +1 -0
- package/src/lib/transform/type.annotation.d.ts +5 -0
- package/src/lib/transform/type.annotation.js +17 -0
- package/src/lib/transform/type.annotation.js.map +1 -0
- package/src/lib/transform/type.d.ts +6 -0
- package/src/lib/transform/type.js +44 -0
- package/src/lib/transform/type.js.map +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
## [4.0.1](https://github.com/dereekb/dbx-components/compare/v4.0.0-dev...v4.0.1) (2022-05-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# [4.0.0](https://github.com/dereekb/dbx-components/compare/v3.0.0...v4.0.0) (2022-05-14)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# [3.0.0](https://github.com/dereekb/dbx-components/compare/v2.1.0...v3.0.0) (2022-05-13)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* added transformAndValidateObject ([1f66094](https://github.com/dereekb/dbx-components/commit/1f6609413b85ae1a2b851a70bc2190ff66c7b467))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [2.1.0](https://github.com/dereekb/dbx-components/compare/v2.0.0...v2.1.0) (2022-03-17)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# [2.0.0](https://github.com/dereekb/dbx-components/compare/v1.2.0...v2.0.0) (2022-03-13)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [1.2.0](https://github.com/dereekb/dbx-components/compare/v1.1.0...v1.2.0) (2022-03-04)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# [1.1.0](https://github.com/dereekb/dbx-components/compare/v1.0.0...v1.1.0) (2022-03-02)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# 1.0.0 (2022-02-23)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# 0.1.0 (2022-01-29)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Features
|
|
46
|
+
|
|
47
|
+
* pageLoadingState ([1a5851d](https://github.com/dereekb/dbx-components/commit/1a5851d689b980fff9db3bd592e465e22d54c612))
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dereekb/model",
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"typings": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"@dereekb/util": "4.0.1",
|
|
10
|
+
"make-error": "^1.3.0",
|
|
11
|
+
"extra-set": "^2.2.11",
|
|
12
|
+
"change-case": "^4.1.2",
|
|
13
|
+
"class-transformer": "^0.5.1",
|
|
14
|
+
"class-validator": "^0.13.2",
|
|
15
|
+
"tslib": "^2.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/model/src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './transform';
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/model/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./type"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./type.annotation"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./transform"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./transform.function"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./transform.result"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/model/src/lib/transform/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,4DAAkC;AAClC,sDAA4B;AAC5B,+DAAqC;AACrC,6DAAmC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ClassType } from "@dereekb/util";
|
|
2
|
+
import { ClassTransformOptions } from "class-transformer";
|
|
3
|
+
import { ValidationError, ValidationOptions } from "class-validator";
|
|
4
|
+
export interface TransformAndValidateObjectOutput<T, O> {
|
|
5
|
+
object: T;
|
|
6
|
+
result: O;
|
|
7
|
+
}
|
|
8
|
+
export declare type TransformAndValidateObjectFunction<T, O, I extends object = object, C = any> = (input: I, context?: C) => Promise<TransformAndValidateObjectOutput<T, O>>;
|
|
9
|
+
export declare type TransformAndValidateObjectHandleValidate<O = any> = (validationErrors: ValidationError[]) => Promise<O>;
|
|
10
|
+
/**
|
|
11
|
+
* transformAndValidateObject() configuration that also provides error handling.
|
|
12
|
+
*/
|
|
13
|
+
export interface TransformAndValidateObject<T extends object, O, C = any> {
|
|
14
|
+
readonly classType: ClassType<T>;
|
|
15
|
+
readonly fn: (parsed: T) => Promise<O>;
|
|
16
|
+
readonly handleValidationError: TransformAndValidateObjectHandleValidate<O>;
|
|
17
|
+
readonly optionsForContext?: TransformAndValidateObjectResultContextOptionsFunction<C>;
|
|
18
|
+
}
|
|
19
|
+
export declare function transformAndValidateObject<T extends object, O, I extends object = object, C = any>(config: TransformAndValidateObject<T, O, C>): TransformAndValidateObjectFunction<T, O, I, C>;
|
|
20
|
+
/**
|
|
21
|
+
* Configuration for the transformAndValidateObject function from transformAndValidateObjectFactory().
|
|
22
|
+
*/
|
|
23
|
+
export interface TransformAndValidateObjectFactoryDefaults<C> {
|
|
24
|
+
readonly handleValidationError: TransformAndValidateObjectHandleValidate<any>;
|
|
25
|
+
readonly optionsForContext?: TransformAndValidateObjectResultContextOptionsFunction<C>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Factory for generating TransformAndValidateObjectFunction functions.
|
|
29
|
+
*/
|
|
30
|
+
export declare type TransformAndValidateObjectFactory<C = any> = <T extends object, O, I extends object = object>(classType: ClassType<T>, fn: (parsed: T) => Promise<O>, handleValidationError?: TransformAndValidateObjectHandleValidate<O>) => TransformAndValidateObjectFunction<T, O, I, C>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new TransformAndValidateObjectFactory.
|
|
33
|
+
*
|
|
34
|
+
* @param defaults
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare function transformAndValidateObjectFactory<C = any>(defaults: TransformAndValidateObjectFactoryDefaults<C>): TransformAndValidateObjectFactory<C>;
|
|
38
|
+
export declare type TransformAndValidateObjectResultFunction<T, O, I extends object = object, C = any> = (input: I, context?: C) => Promise<TransformAndValidateObjectResultOutput<T, O>>;
|
|
39
|
+
export interface TransformAndValidateObjectResultTransformContextOptions {
|
|
40
|
+
transform?: ClassTransformOptions;
|
|
41
|
+
validate?: ValidationOptions;
|
|
42
|
+
}
|
|
43
|
+
export declare type TransformAndValidateObjectResultContextOptionsFunction<C> = (context?: C) => TransformAndValidateObjectResultTransformContextOptions;
|
|
44
|
+
export declare type TransformAndValidateObjectResultOutput<T, O> = TransformAndValidateObjectSuccessResultOutput<T, O> | TransformAndValidateObjectErrorResultOutput<T>;
|
|
45
|
+
export interface TransformAndValidateObjectSuccessResultOutput<T, O> {
|
|
46
|
+
readonly success: true;
|
|
47
|
+
readonly object: T;
|
|
48
|
+
readonly result: O;
|
|
49
|
+
}
|
|
50
|
+
export interface TransformAndValidateObjectErrorResultOutput<T> {
|
|
51
|
+
readonly success: false;
|
|
52
|
+
readonly object: T;
|
|
53
|
+
readonly validationErrors: ValidationError[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Factory function that wraps the input class type and handler function to first transform the input object to a the given class, and then validate it.
|
|
57
|
+
*
|
|
58
|
+
* @param classType
|
|
59
|
+
* @param fn
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export declare function transformAndValidateObjectResult<T extends object, O, I extends object = object, C = any>(classType: ClassType<T>, fn: (parsed: T) => Promise<O>, inputOptionsForContext?: TransformAndValidateObjectResultContextOptionsFunction<C>): TransformAndValidateObjectResultFunction<T, O, I, C>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClassType } from "@dereekb/util";
|
|
2
|
+
import { TransformAndValidateObjectFactory, TransformAndValidateObjectFactoryDefaults, TransformAndValidateObjectHandleValidate, TransformAndValidateObjectOutput } from "./transform";
|
|
3
|
+
import { TransformAndValidateResultFunction } from "./transform.result";
|
|
4
|
+
/**
|
|
5
|
+
* A TransformAndValidate result for a function with the parsed object attached as "params".
|
|
6
|
+
*/
|
|
7
|
+
export declare type TransformAndValidateFunctionResult<T extends object, O extends Function> = O & {
|
|
8
|
+
params: T;
|
|
9
|
+
};
|
|
10
|
+
export declare type TransformAndValidateFunctionResultFunction<T extends object, O extends Function, I extends object = object, C = any> = TransformAndValidateResultFunction<TransformAndValidateFunctionResult<T, O>, I, C>;
|
|
11
|
+
export declare type TransformAndValidateFunctionResultFactory<C = any> = <T extends object, O extends Function, I extends object = object>(classType: ClassType<T>, fn: (parsed: T) => Promise<O>, handleValidationError?: TransformAndValidateObjectHandleValidate<O>) => TransformAndValidateFunctionResultFunction<T, O, I, C>;
|
|
12
|
+
export declare function transformAndValidateFunctionResultFactory<C = any>(defaults: TransformAndValidateObjectFactoryDefaults<C>): TransformAndValidateFunctionResultFactory<C>;
|
|
13
|
+
export declare function toTransformAndValidateFunctionResultFactory<C = any>(transformAndValidateObjectFactory: TransformAndValidateObjectFactory<C>): TransformAndValidateFunctionResultFactory<C>;
|
|
14
|
+
export declare function toTransformAndValidateFunctionResult<T extends object, O extends Function>(objectOutput: Promise<TransformAndValidateObjectOutput<T, O>>): Promise<TransformAndValidateFunctionResult<T, O>>;
|
|
15
|
+
export declare function toTransformAndValidateFunctionResult<T extends object, O extends Function>(objectOutput: TransformAndValidateObjectOutput<T, O>): TransformAndValidateFunctionResult<T, O>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toTransformAndValidateFunctionResult = exports.toTransformAndValidateFunctionResultFactory = exports.transformAndValidateFunctionResultFactory = void 0;
|
|
4
|
+
const util_1 = require("@dereekb/util");
|
|
5
|
+
const transform_1 = require("./transform");
|
|
6
|
+
function transformAndValidateFunctionResultFactory(defaults) {
|
|
7
|
+
return toTransformAndValidateFunctionResultFactory((0, transform_1.transformAndValidateObjectFactory)(defaults));
|
|
8
|
+
}
|
|
9
|
+
exports.transformAndValidateFunctionResultFactory = transformAndValidateFunctionResultFactory;
|
|
10
|
+
function toTransformAndValidateFunctionResultFactory(transformAndValidateObjectFactory) {
|
|
11
|
+
return (classType, fn, handleValidationError) => {
|
|
12
|
+
const transformAndValidateObjectFn = transformAndValidateObjectFactory(classType, fn, handleValidationError);
|
|
13
|
+
return (input, context) => {
|
|
14
|
+
return toTransformAndValidateFunctionResult(transformAndValidateObjectFn(input, context));
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.toTransformAndValidateFunctionResultFactory = toTransformAndValidateFunctionResultFactory;
|
|
19
|
+
function toTransformAndValidateFunctionResult(objectOutput) {
|
|
20
|
+
return (0, util_1.mapPromiseOrValue)(objectOutput, (x) => {
|
|
21
|
+
const { object, result } = x;
|
|
22
|
+
const fnResult = result;
|
|
23
|
+
fnResult.params = object;
|
|
24
|
+
return fnResult;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.toTransformAndValidateFunctionResult = toTransformAndValidateFunctionResult;
|
|
28
|
+
//# sourceMappingURL=transform.function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.function.js","sourceRoot":"","sources":["../../../../../../packages/model/src/lib/transform/transform.function.ts"],"names":[],"mappings":";;;AAAA,wCAA6E;AAC7E,2CAA0N;AAY1N,SAAgB,yCAAyC,CAAU,QAAsD;IACvH,OAAO,2CAA2C,CAAC,IAAA,6CAAiC,EAAC,QAAQ,CAAC,CAAC,CAAC;AAClG,CAAC;AAFD,8FAEC;AAED,SAAgB,2CAA2C,CAAU,iCAAuE;IAC1I,OAAO,CAAkE,SAAuB,EAAE,EAA6B,EAAE,qBAAqE,EAAE,EAAE;QACxM,MAAM,4BAA4B,GAAG,iCAAiC,CAAU,SAAS,EAAE,EAAE,EAAE,qBAAqB,CAAC,CAAC;QAEtH,OAAO,CAAC,KAAQ,EAAE,OAAW,EAAE,EAAE;YAC/B,OAAO,oCAAoC,CAAC,4BAA4B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;QAC5F,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AARD,kGAQC;AAID,SAAgB,oCAAoC,CAAuC,YAAoE;IAC7J,OAAO,IAAA,wBAAiB,EAAC,YAAY,EAAE,CAAC,CAAyC,EAAE,EAAE;QACnF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAkD,CAAC;QACpE,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,oFAOC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformAndValidateObjectResult = exports.transformAndValidateObjectFactory = exports.transformAndValidateObject = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const class_validator_1 = require("class-validator");
|
|
7
|
+
;
|
|
8
|
+
function transformAndValidateObject(config) {
|
|
9
|
+
const transformToResult = transformAndValidateObjectResult(config.classType, config.fn, config.optionsForContext);
|
|
10
|
+
const { handleValidationError } = config;
|
|
11
|
+
return (input, context) => transformToResult(input, context).then((x) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
let object = x.object;
|
|
13
|
+
let result;
|
|
14
|
+
if (x.success) {
|
|
15
|
+
result = x.result;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
result = yield handleValidationError(x.validationErrors);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
object,
|
|
22
|
+
result
|
|
23
|
+
};
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
exports.transformAndValidateObject = transformAndValidateObject;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new TransformAndValidateObjectFactory.
|
|
29
|
+
*
|
|
30
|
+
* @param defaults
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
function transformAndValidateObjectFactory(defaults) {
|
|
34
|
+
const { handleValidationError: defaultHandleValidationError, optionsForContext } = defaults;
|
|
35
|
+
return (classType, fn, handleValidationError) => {
|
|
36
|
+
const config = {
|
|
37
|
+
classType,
|
|
38
|
+
fn,
|
|
39
|
+
handleValidationError: handleValidationError !== null && handleValidationError !== void 0 ? handleValidationError : defaultHandleValidationError,
|
|
40
|
+
optionsForContext
|
|
41
|
+
};
|
|
42
|
+
return transformAndValidateObject(config);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.transformAndValidateObjectFactory = transformAndValidateObjectFactory;
|
|
46
|
+
/**
|
|
47
|
+
* Factory function that wraps the input class type and handler function to first transform the input object to a the given class, and then validate it.
|
|
48
|
+
*
|
|
49
|
+
* @param classType
|
|
50
|
+
* @param fn
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
function transformAndValidateObjectResult(classType, fn, inputOptionsForContext) {
|
|
54
|
+
const optionsForContext = inputOptionsForContext !== null && inputOptionsForContext !== void 0 ? inputOptionsForContext : (() => ({}));
|
|
55
|
+
return (input, context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const { transform: transformOptions, validate: validateOptions } = optionsForContext(context);
|
|
57
|
+
const object = (0, class_transformer_1.plainToClass)(classType, input, Object.assign(Object.assign({}, transformOptions), {
|
|
58
|
+
// Note: Each variable on the target class must be marked with the @Expose() annotation.
|
|
59
|
+
excludeExtraneousValues: true }));
|
|
60
|
+
const validationErrors = yield (0, class_validator_1.validate)(object, validateOptions);
|
|
61
|
+
if (validationErrors.length) {
|
|
62
|
+
return { object, validationErrors, success: false };
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const result = yield fn(object);
|
|
66
|
+
return { object, result, success: true };
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.transformAndValidateObjectResult = transformAndValidateObjectResult;
|
|
71
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../../../../packages/model/src/lib/transform/transform.ts"],"names":[],"mappings":";;;;AACA,yDAAwE;AACxE,qDAA+E;AAM9E,CAAC;AAeF,SAAgB,0BAA0B,CAA0D,MAA2C;IAC7I,MAAM,iBAAiB,GAAG,gCAAgC,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAClH,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;IAEzC,OAAO,CAAC,KAAQ,EAAE,OAAW,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAO,CAAC,EAAE,EAAE;QACnF,IAAI,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QACtB,IAAI,MAAS,CAAC;QAEd,IAAI,CAAC,CAAC,OAAO,EAAE;YACb,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;SACnB;aAAM;YACL,MAAM,GAAG,MAAM,qBAAqB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;SAC1D;QAED,OAAO;YACL,MAAM;YACN,MAAM;SACP,CAAC;IACJ,CAAC,CAAA,CAAC,CAAC;AACL,CAAC;AAnBD,gEAmBC;AAgBD;;;;;GAKG;AACH,SAAgB,iCAAiC,CAAU,QAAsD;IAC/G,MAAM,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE5F,OAAO,CAAiD,SAAuB,EAAE,EAA6B,EAAE,qBAAqE,EAAE,EAAE;QACvL,MAAM,MAAM,GAAwC;YAClD,SAAS;YACT,EAAE;YACF,qBAAqB,EAAE,qBAAqB,aAArB,qBAAqB,cAArB,qBAAqB,GAAI,4BAA4B;YAC5E,iBAAiB;SAClB,CAAC;QAEF,OAAO,0BAA0B,CAAa,MAAM,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC;AAbD,8EAaC;AAyBD;;;;;;GAMG;AACH,SAAgB,gCAAgC,CAA0D,SAAuB,EAAE,EAA6B,EAAE,sBAAkF;IAClP,MAAM,iBAAiB,GAA8D,sBAAsB,aAAtB,sBAAsB,cAAtB,sBAAsB,GAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5H,OAAO,CAAO,KAAQ,EAAE,OAAW,EAAE,EAAE;QACrC,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAE9F,MAAM,MAAM,GAAM,IAAA,gCAAY,EAAC,SAAS,EAAE,KAAK,kCAC1C,gBAAgB;YACnB,wFAAwF;YACxF,uBAAuB,EAAE,IAAI,IAC7B,CAAC;QAEH,MAAM,gBAAgB,GAAsB,MAAM,IAAA,0BAAQ,EAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QAEpF,IAAI,gBAAgB,CAAC,MAAM,EAAE;YAC3B,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;SACrD;aAAM;YACL,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;YAChC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;SAC1C;IACH,CAAC,CAAA,CAAC;AACJ,CAAC;AApBD,4EAoBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ClassType } from "@dereekb/util";
|
|
2
|
+
import { TransformAndValidateObjectFactoryDefaults, TransformAndValidateObjectHandleValidate } from "./transform";
|
|
3
|
+
/**
|
|
4
|
+
* A TransformAndValidate function that returns only the result.
|
|
5
|
+
*/
|
|
6
|
+
export declare type TransformAndValidateResultFunction<O, I extends object = object, C = any> = (input: I, context?: C) => Promise<O>;
|
|
7
|
+
export declare type TransformAndValidateResultFactory<C = any> = <T extends object, O, I extends object = object>(classType: ClassType<T>, fn: (parsed: T) => Promise<O>, handleValidationError?: TransformAndValidateObjectHandleValidate<O>) => TransformAndValidateResultFunction<O, I, C>;
|
|
8
|
+
export declare function transformAndValidateResultFactory<C = any>(defaults: TransformAndValidateObjectFactoryDefaults<C>): TransformAndValidateResultFactory<C>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformAndValidateResultFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const transform_1 = require("./transform");
|
|
6
|
+
function transformAndValidateResultFactory(defaults) {
|
|
7
|
+
const factory = (0, transform_1.transformAndValidateObjectFactory)(defaults);
|
|
8
|
+
return (classType, fn, handleValidationError) => {
|
|
9
|
+
const transformAndValidateObjectFn = factory(classType, fn, handleValidationError);
|
|
10
|
+
return (input, context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
const { result } = yield transformAndValidateObjectFn(input, context);
|
|
12
|
+
return result;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.transformAndValidateResultFactory = transformAndValidateResultFactory;
|
|
17
|
+
//# sourceMappingURL=transform.result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.result.js","sourceRoot":"","sources":["../../../../../../packages/model/src/lib/transform/transform.result.ts"],"names":[],"mappings":";;;;AACA,2CAAqJ;AASrJ,SAAgB,iCAAiC,CAAU,QAAsD;IAC/G,MAAM,OAAO,GAAG,IAAA,6CAAiC,EAAC,QAAQ,CAAC,CAAC;IAE5D,OAAO,CAAiD,SAAuB,EAAE,EAA6B,EAAE,qBAAqE,EAAE,EAAE;QACvL,MAAM,4BAA4B,GAAG,OAAO,CAAU,SAAS,EAAE,EAAE,EAAE,qBAAqB,CAAC,CAAC;QAE5F,OAAO,CAAO,KAAQ,EAAE,OAAW,EAAE,EAAE;YACrC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,4BAA4B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACtE,OAAO,MAAM,CAAC;QAChB,CAAC,CAAA,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAXD,8EAWC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MapStringFn } from "@dereekb/util";
|
|
2
|
+
export declare function TransformCommaSeparatedValueToArray<T>(mapFn: MapStringFn<T>): PropertyDecorator;
|
|
3
|
+
export declare const TransformCommaSeparatedStringValueToArray: () => PropertyDecorator;
|
|
4
|
+
export declare const TransformCommaSeparatedNumberValueToArray: () => PropertyDecorator;
|
|
5
|
+
export declare const TransformStringValueToBoolean: () => PropertyDecorator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransformStringValueToBoolean = exports.TransformCommaSeparatedNumberValueToArray = exports.TransformCommaSeparatedStringValueToArray = exports.TransformCommaSeparatedValueToArray = void 0;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
const type_1 = require("./type");
|
|
6
|
+
// MARK: Transform Annotations
|
|
7
|
+
function TransformCommaSeparatedValueToArray(mapFn) {
|
|
8
|
+
return (0, class_transformer_1.Transform)((0, type_1.transformCommaSeparatedValueToArray)(mapFn));
|
|
9
|
+
}
|
|
10
|
+
exports.TransformCommaSeparatedValueToArray = TransformCommaSeparatedValueToArray;
|
|
11
|
+
const TransformCommaSeparatedStringValueToArray = () => (0, class_transformer_1.Transform)(type_1.transformCommaSeparatedStringValueToArray);
|
|
12
|
+
exports.TransformCommaSeparatedStringValueToArray = TransformCommaSeparatedStringValueToArray;
|
|
13
|
+
const TransformCommaSeparatedNumberValueToArray = () => (0, class_transformer_1.Transform)(type_1.transformCommaSeparatedNumberValueToArray);
|
|
14
|
+
exports.TransformCommaSeparatedNumberValueToArray = TransformCommaSeparatedNumberValueToArray;
|
|
15
|
+
const TransformStringValueToBoolean = () => (0, class_transformer_1.Transform)((0, type_1.transformStringToBoolean)());
|
|
16
|
+
exports.TransformStringValueToBoolean = TransformStringValueToBoolean;
|
|
17
|
+
//# sourceMappingURL=type.annotation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.annotation.js","sourceRoot":"","sources":["../../../../../../packages/model/src/lib/transform/type.annotation.ts"],"names":[],"mappings":";;;AACA,yDAA8C;AAC9C,iCAA6K;AAE7K,8BAA8B;AAC9B,SAAgB,mCAAmC,CAAI,KAAqB;IAC1E,OAAO,IAAA,6BAAS,EAAC,IAAA,0CAAmC,EAAC,KAAK,CAAC,CAAC,CAAC;AAC/D,CAAC;AAFD,kFAEC;AAEM,MAAM,yCAAyC,GAAG,GAAG,EAAE,CAAC,IAAA,6BAAS,EAAC,gDAAyC,CAAC,CAAC;AAAvG,QAAA,yCAAyC,6CAA8D;AAC7G,MAAM,yCAAyC,GAAG,GAAG,EAAE,CAAC,IAAA,6BAAS,EAAC,gDAAyC,CAAC,CAAC;AAAvG,QAAA,yCAAyC,6CAA8D;AAE7G,MAAM,6BAA6B,GAAG,GAAG,EAAE,CAAC,IAAA,6BAAS,EAAC,IAAA,+BAAwB,GAAE,CAAC,CAAC;AAA5E,QAAA,6BAA6B,iCAA+C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MapStringFn, Maybe } from "@dereekb/util";
|
|
2
|
+
import { TransformFnParams } from "class-transformer";
|
|
3
|
+
export declare function transformStringToBoolean(defaultValue?: boolean | undefined): (params: TransformFnParams) => Maybe<boolean>;
|
|
4
|
+
export declare function transformCommaSeparatedValueToArray<T>(mapFn: MapStringFn<T>): (params: TransformFnParams) => Maybe<T[]>;
|
|
5
|
+
export declare const transformCommaSeparatedNumberValueToArray: (params: TransformFnParams) => Maybe<number[]>;
|
|
6
|
+
export declare const transformCommaSeparatedStringValueToArray: (params: TransformFnParams) => Maybe<string[]>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformCommaSeparatedStringValueToArray = exports.transformCommaSeparatedNumberValueToArray = exports.transformCommaSeparatedValueToArray = exports.transformStringToBoolean = void 0;
|
|
4
|
+
const util_1 = require("@dereekb/util");
|
|
5
|
+
// MARK: String
|
|
6
|
+
function transformStringToBoolean(defaultValue) {
|
|
7
|
+
return (params) => {
|
|
8
|
+
if (params.value) {
|
|
9
|
+
switch (params.value.toLowerCase()) {
|
|
10
|
+
case 't':
|
|
11
|
+
case 'true':
|
|
12
|
+
return true;
|
|
13
|
+
case 'f':
|
|
14
|
+
case 'false':
|
|
15
|
+
return false;
|
|
16
|
+
default:
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return defaultValue;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.transformStringToBoolean = transformStringToBoolean;
|
|
26
|
+
// MARK: Comma Separated Values
|
|
27
|
+
function transformCommaSeparatedValueToArray(mapFn) {
|
|
28
|
+
return (params) => {
|
|
29
|
+
let result;
|
|
30
|
+
if (params.value) {
|
|
31
|
+
if (Array.isArray(params.value)) {
|
|
32
|
+
result = params.value;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
result = (0, util_1.splitCommaSeparatedString)(params.value, mapFn);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.transformCommaSeparatedValueToArray = transformCommaSeparatedValueToArray;
|
|
42
|
+
exports.transformCommaSeparatedNumberValueToArray = transformCommaSeparatedValueToArray((x) => Number(x));
|
|
43
|
+
exports.transformCommaSeparatedStringValueToArray = transformCommaSeparatedValueToArray((x) => x);
|
|
44
|
+
//# sourceMappingURL=type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../../../../packages/model/src/lib/transform/type.ts"],"names":[],"mappings":";;;AAAA,wCAA8E;AAG9E,eAAe;AACf,SAAgB,wBAAwB,CAAC,YAAkC;IACzE,OAAO,CAAC,MAAyB,EAAE,EAAE;QACnC,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,QAAQ,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE;gBAClC,KAAK,GAAG,CAAC;gBACT,KAAK,MAAM;oBACT,OAAO,IAAI,CAAC;gBACd,KAAK,GAAG,CAAC;gBACT,KAAK,OAAO;oBACV,OAAO,KAAK,CAAC;gBACf;oBACE,OAAO,YAAY,CAAC;aACvB;SACF;aAAM;YACL,OAAO,YAAY,CAAC;SACrB;IACH,CAAC,CAAA;AACH,CAAC;AAjBD,4DAiBC;AAED,+BAA+B;AAC/B,SAAgB,mCAAmC,CAAI,KAAqB;IAC1E,OAAO,CAAC,MAAyB,EAAE,EAAE;QACnC,IAAI,MAAkB,CAAC;QAEvB,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;gBAC/B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;aACvB;iBAAM;gBACL,MAAM,GAAG,IAAA,gCAAyB,EAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;aACzD;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAA;AACH,CAAC;AAdD,kFAcC;AAEY,QAAA,yCAAyC,GAAG,mCAAmC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAClG,QAAA,yCAAyC,GAAG,mCAAmC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC"}
|