@alanszp/typeorm 4.0.5 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseEntityWithoutId.js +2 -2
- package/dist/BaseEntityWithoutId.js.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/BaseEntityWithoutId.ts +1 -1
- package/src/index.ts +0 -3
- package/dist/BaseModel.d.ts +0 -6
- package/dist/BaseModel.js +0 -31
- package/dist/BaseModel.js.map +0 -1
- package/dist/ModelValidationError.d.ts +0 -16
- package/dist/ModelValidationError.js +0 -40
- package/dist/ModelValidationError.js.map +0 -1
- package/dist/entityOrValidationError.d.ts +0 -1
- package/dist/entityOrValidationError.js +0 -17
- package/dist/entityOrValidationError.js.map +0 -1
- package/src/BaseModel.ts +0 -17
- package/src/ModelValidationError.ts +0 -53
- package/src/entityOrValidationError.ts +0 -16
|
@@ -18,14 +18,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.BaseEntityWithoutId = void 0;
|
|
19
19
|
const class_validator_1 = require("class-validator");
|
|
20
20
|
const typeorm_1 = require("typeorm");
|
|
21
|
-
const
|
|
21
|
+
const validations_1 = require("@alanszp/validations");
|
|
22
22
|
class BaseEntityWithoutId extends typeorm_1.BaseEntity {
|
|
23
23
|
// TODO: This model is shared between baseEntity and baseModel. Do a mixin.
|
|
24
24
|
validate() {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
const validationResult = yield (0, class_validator_1.validate)(this);
|
|
27
27
|
if (validationResult.length > 0) {
|
|
28
|
-
return Promise.reject(new
|
|
28
|
+
return Promise.reject(new validations_1.ModelValidationError(validationResult));
|
|
29
29
|
}
|
|
30
30
|
return Promise.resolve();
|
|
31
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseEntityWithoutId.js","sourceRoot":"","sources":["../src/BaseEntityWithoutId.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,qDAA2C;AAC3C,qCAIiB;AACjB,
|
|
1
|
+
{"version":3,"file":"BaseEntityWithoutId.js","sourceRoot":"","sources":["../src/BaseEntityWithoutId.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,qDAA2C;AAC3C,qCAIiB;AACjB,sDAA4D;AAE5D,MAAsB,mBAAoB,SAAQ,oBAAiB;IACjE,2EAA2E;IAG9D,QAAQ;;YACnB,MAAM,gBAAgB,GAAG,MAAM,IAAA,0BAAQ,EAAC,IAAI,CAAC,CAAC;YAE9C,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC/B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,kCAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC;aACnE;YACD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;KAAA;IAIM,MAAM;QACX,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;IACpC,CAAC;CACF;AAdC;IAFC,IAAA,sBAAY,GAAE;IACd,IAAA,sBAAY,GAAE;mDAQd;AAXH,kDAkBC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,4 @@ __exportStar(require("./TypeormLogger"), exports);
|
|
|
14
14
|
__exportStar(require("./BaseEntity"), exports);
|
|
15
15
|
__exportStar(require("./BaseEntityUuid"), exports);
|
|
16
16
|
__exportStar(require("./BaseEntityWithoutId"), exports);
|
|
17
|
-
__exportStar(require("./BaseModel"), exports);
|
|
18
|
-
__exportStar(require("./ModelValidationError"), exports);
|
|
19
|
-
__exportStar(require("./entityOrValidationError"), exports);
|
|
20
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,+CAA6B;AAC7B,mDAAiC;AACjC,wDAAsC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,+CAA6B;AAC7B,mDAAiC;AACjC,wDAAsC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/typeorm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Alan's typeorm utils.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"yalc-publish": "yarn run yalc publish"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@alanszp/logger": "^
|
|
22
|
+
"@alanszp/logger": "^6.0.0",
|
|
23
23
|
"@types/node": "^15.12.3",
|
|
24
24
|
"class-validator": "^0.13.1",
|
|
25
25
|
"ts-node": "^10.0.0",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"typeorm": "^0.2.34"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@alanszp/errors": "^
|
|
36
|
+
"@alanszp/errors": "^6.0.0",
|
|
37
|
+
"@alanszp/validations": "^6.0.0"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "75b34d763277366fdf93146cd1d20084ff469273"
|
|
39
40
|
}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
BeforeInsert,
|
|
5
5
|
BeforeUpdate,
|
|
6
6
|
} from "typeorm";
|
|
7
|
-
import { ModelValidationError } from "
|
|
7
|
+
import { ModelValidationError } from "@alanszp/validations";
|
|
8
8
|
|
|
9
9
|
export abstract class BaseEntityWithoutId extends TypeOrmBaseEntity {
|
|
10
10
|
// TODO: This model is shared between baseEntity and baseModel. Do a mixin.
|
package/src/index.ts
CHANGED
package/dist/BaseModel.d.ts
DELETED
package/dist/BaseModel.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.BaseModel = void 0;
|
|
13
|
-
const class_validator_1 = require("class-validator");
|
|
14
|
-
const ModelValidationError_1 = require("./ModelValidationError");
|
|
15
|
-
/**
|
|
16
|
-
* BaseModel represents a va
|
|
17
|
-
*/
|
|
18
|
-
class BaseModel {
|
|
19
|
-
// TODO: This model is shared between baseEntity and baseModel. Do a mixin.
|
|
20
|
-
validate() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const validationResult = yield (0, class_validator_1.validate)(this);
|
|
23
|
-
if (validationResult.length > 0) {
|
|
24
|
-
return Promise.reject(new ModelValidationError_1.ModelValidationError(validationResult));
|
|
25
|
-
}
|
|
26
|
-
return Promise.resolve();
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.BaseModel = BaseModel;
|
|
31
|
-
//# sourceMappingURL=BaseModel.js.map
|
package/dist/BaseModel.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseModel.js","sourceRoot":"","sources":["../src/BaseModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA2C;AAC3C,iEAA8D;AAE9D;;GAEG;AACH,MAAsB,SAAS;IAC7B,2EAA2E;IAC9D,QAAQ;;YACnB,MAAM,gBAAgB,GAAG,MAAM,IAAA,0BAAQ,EAAC,IAAI,CAAC,CAAC;YAE9C,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC/B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,2CAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC;aACnE;YACD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;KAAA;CACF;AAVD,8BAUC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ValidationError } from "class-validator";
|
|
2
|
-
import { BaseError, RenderableError, RenderableContext } from "@alanszp/errors";
|
|
3
|
-
export interface ValidationObject {
|
|
4
|
-
property: string;
|
|
5
|
-
constraints: {
|
|
6
|
-
[type: string]: string;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export declare class ModelValidationError extends BaseError implements RenderableError {
|
|
10
|
-
errors: ValidationError[];
|
|
11
|
-
constructor(errors: ValidationError[]);
|
|
12
|
-
static from(objects: ValidationObject | ValidationObject[]): ModelValidationError;
|
|
13
|
-
renderMessage(): string;
|
|
14
|
-
code(): string;
|
|
15
|
-
context(): RenderableContext;
|
|
16
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelValidationError = void 0;
|
|
4
|
-
const class_validator_1 = require("class-validator");
|
|
5
|
-
const lodash_1 = require("lodash");
|
|
6
|
-
const errors_1 = require("@alanszp/errors");
|
|
7
|
-
class ModelValidationError extends errors_1.BaseError {
|
|
8
|
-
constructor(errors) {
|
|
9
|
-
super("Model Validation Error");
|
|
10
|
-
this.errors = errors;
|
|
11
|
-
}
|
|
12
|
-
static from(objects) {
|
|
13
|
-
const arrayObjects = (0, lodash_1.isArray)(objects) ? objects : [objects];
|
|
14
|
-
const validationErrors = arrayObjects.map((o) => {
|
|
15
|
-
const validationError = new class_validator_1.ValidationError();
|
|
16
|
-
validationError.property = o.property;
|
|
17
|
-
validationError.children = [];
|
|
18
|
-
validationError.constraints = o.constraints;
|
|
19
|
-
return validationError;
|
|
20
|
-
});
|
|
21
|
-
return new ModelValidationError(validationErrors);
|
|
22
|
-
}
|
|
23
|
-
renderMessage() {
|
|
24
|
-
return "Model validation error";
|
|
25
|
-
}
|
|
26
|
-
code() {
|
|
27
|
-
return "model_validation_error";
|
|
28
|
-
}
|
|
29
|
-
context() {
|
|
30
|
-
return {
|
|
31
|
-
errors: this.errors.map((e) => ({
|
|
32
|
-
property: e.property,
|
|
33
|
-
errors: e.constraints,
|
|
34
|
-
children: e.children,
|
|
35
|
-
})),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.ModelValidationError = ModelValidationError;
|
|
40
|
-
//# sourceMappingURL=ModelValidationError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ModelValidationError.js","sourceRoot":"","sources":["../src/ModelValidationError.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,mCAAiC;AACjC,4CAAgF;AAOhF,MAAa,oBAAqB,SAAQ,kBAAS;IAGjD,YAAY,MAAyB;QACnC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,MAAM,CAAC,IAAI,CAChB,OAA8C;QAE9C,MAAM,YAAY,GAAG,IAAA,gBAAO,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAE5D,MAAM,gBAAgB,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC9C,MAAM,eAAe,GAAG,IAAI,iCAAe,EAAE,CAAC;YAE9C,eAAe,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;YACtC,eAAe,CAAC,QAAQ,GAAG,EAAE,CAAC;YAC9B,eAAe,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;YAE5C,OAAO,eAAe,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IACpD,CAAC;IAEM,aAAa;QAClB,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAEM,IAAI;QACT,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAEM,OAAO;QACZ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,MAAM,EAAE,CAAC,CAAC,WAAW;gBACrB,QAAQ,EAAE,CAAC,CAAC,QAAQ;aACrB,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC;CACF;AA3CD,oDA2CC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function entityOrValidationError<T>(entity: T | undefined, property: string): T;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.entityOrValidationError = void 0;
|
|
4
|
-
const ModelValidationError_1 = require("./ModelValidationError");
|
|
5
|
-
function entityOrValidationError(entity, property) {
|
|
6
|
-
if (!entity) {
|
|
7
|
-
throw ModelValidationError_1.ModelValidationError.from({
|
|
8
|
-
property,
|
|
9
|
-
constraints: {
|
|
10
|
-
mustBePresent: `${property} is not present`,
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return entity;
|
|
15
|
-
}
|
|
16
|
-
exports.entityOrValidationError = entityOrValidationError;
|
|
17
|
-
//# sourceMappingURL=entityOrValidationError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entityOrValidationError.js","sourceRoot":"","sources":["../src/entityOrValidationError.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAE9D,SAAgB,uBAAuB,CACrC,MAAqB,EACrB,QAAgB;IAEhB,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,2CAAoB,CAAC,IAAI,CAAC;YAC9B,QAAQ;YACR,WAAW,EAAE;gBACX,aAAa,EAAE,GAAG,QAAQ,iBAAiB;aAC5C;SACF,CAAC,CAAC;KACJ;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,0DAaC"}
|
package/src/BaseModel.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { validate } from "class-validator";
|
|
2
|
-
import { ModelValidationError } from "./ModelValidationError";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* BaseModel represents a va
|
|
6
|
-
*/
|
|
7
|
-
export abstract class BaseModel {
|
|
8
|
-
// TODO: This model is shared between baseEntity and baseModel. Do a mixin.
|
|
9
|
-
public async validate(): Promise<void> {
|
|
10
|
-
const validationResult = await validate(this);
|
|
11
|
-
|
|
12
|
-
if (validationResult.length > 0) {
|
|
13
|
-
return Promise.reject(new ModelValidationError(validationResult));
|
|
14
|
-
}
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ValidationError } from "class-validator";
|
|
2
|
-
import { isArray } from "lodash";
|
|
3
|
-
import { BaseError, RenderableError, RenderableContext } from "@alanszp/errors";
|
|
4
|
-
|
|
5
|
-
export interface ValidationObject {
|
|
6
|
-
property: string;
|
|
7
|
-
constraints: { [type: string]: string };
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class ModelValidationError extends BaseError implements RenderableError {
|
|
11
|
-
public errors: ValidationError[];
|
|
12
|
-
|
|
13
|
-
constructor(errors: ValidationError[]) {
|
|
14
|
-
super("Model Validation Error");
|
|
15
|
-
this.errors = errors;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public static from(
|
|
19
|
-
objects: ValidationObject | ValidationObject[]
|
|
20
|
-
): ModelValidationError {
|
|
21
|
-
const arrayObjects = isArray(objects) ? objects : [objects];
|
|
22
|
-
|
|
23
|
-
const validationErrors = arrayObjects.map((o) => {
|
|
24
|
-
const validationError = new ValidationError();
|
|
25
|
-
|
|
26
|
-
validationError.property = o.property;
|
|
27
|
-
validationError.children = [];
|
|
28
|
-
validationError.constraints = o.constraints;
|
|
29
|
-
|
|
30
|
-
return validationError;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return new ModelValidationError(validationErrors);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public renderMessage(): string {
|
|
37
|
-
return "Model validation error";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public code(): string {
|
|
41
|
-
return "model_validation_error";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public context(): RenderableContext {
|
|
45
|
-
return {
|
|
46
|
-
errors: this.errors.map((e) => ({
|
|
47
|
-
property: e.property,
|
|
48
|
-
errors: e.constraints,
|
|
49
|
-
children: e.children,
|
|
50
|
-
})),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ModelValidationError } from "./ModelValidationError";
|
|
2
|
-
|
|
3
|
-
export function entityOrValidationError<T>(
|
|
4
|
-
entity: T | undefined,
|
|
5
|
-
property: string
|
|
6
|
-
): T {
|
|
7
|
-
if (!entity) {
|
|
8
|
-
throw ModelValidationError.from({
|
|
9
|
-
property,
|
|
10
|
-
constraints: {
|
|
11
|
-
mustBePresent: `${property} is not present`,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return entity;
|
|
16
|
-
}
|