@driveup/schema 0.1.4 → 0.1.5
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/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -17,5 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./activity.helper"), exports);
|
|
18
18
|
__exportStar(require("./json-metrics.transform"), exports);
|
|
19
19
|
__exportStar(require("./numeric.transform"), exports);
|
|
20
|
-
__exportStar(require("./trackable
|
|
20
|
+
__exportStar(require("./trackable"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,2DAAyC;AACzC,sDAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,2DAAyC;AACzC,sDAAoC;AACpC,8CAA4B"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Activity, Language } from '@driveup/common';
|
|
2
|
+
import { BaseEntity } from 'typeorm';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base entity with comprehensive audit tracking properties.
|
|
5
|
+
* Provides automatic tracking of creation, updates, and soft deletion with user attribution.
|
|
6
|
+
* All entities requiring an audit trail should extend this class.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The model type that the entity converts to
|
|
9
|
+
* @extends BaseEntity
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Entity('users')
|
|
14
|
+
* export class UserEntity extends TrackableEntity<User> {
|
|
15
|
+
* // entity properties
|
|
16
|
+
*
|
|
17
|
+
* toModel() {
|
|
18
|
+
* return new User({ id: this.id, ... });
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* async getActivities() {
|
|
22
|
+
* return [];
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare abstract class TrackableEntity<T = any> extends BaseEntity {
|
|
28
|
+
/**
|
|
29
|
+
* Primary key - auto-generated sequential ID
|
|
30
|
+
*/
|
|
31
|
+
id: number;
|
|
32
|
+
/**
|
|
33
|
+
* ID of the user who created this entity
|
|
34
|
+
*/
|
|
35
|
+
createdBy: number;
|
|
36
|
+
/**
|
|
37
|
+
* Timestamp when the entity was created
|
|
38
|
+
* Automatically set by TypeORM
|
|
39
|
+
*/
|
|
40
|
+
createdOn: Date;
|
|
41
|
+
/**
|
|
42
|
+
* ID of the user who last updated this entity
|
|
43
|
+
*/
|
|
44
|
+
updatedBy: number;
|
|
45
|
+
/**
|
|
46
|
+
* Timestamp when the entity was last updated
|
|
47
|
+
* Automatically updated by TypeORM
|
|
48
|
+
*/
|
|
49
|
+
updatedOn: Date;
|
|
50
|
+
/**
|
|
51
|
+
* ID of the user who soft-deleted this entity
|
|
52
|
+
*/
|
|
53
|
+
deletedBy: number;
|
|
54
|
+
/**
|
|
55
|
+
* Timestamp when the entity was soft-deleted
|
|
56
|
+
* When set, the entity is excluded from normal queries
|
|
57
|
+
*/
|
|
58
|
+
deletedOn: Date;
|
|
59
|
+
/**
|
|
60
|
+
* Converts the entity to its corresponding model instance.
|
|
61
|
+
* Must be implemented by child classes to define transformation logic.
|
|
62
|
+
*
|
|
63
|
+
* @param lang - Optional language for localized content
|
|
64
|
+
* @returns Model instance or Promise resolving to model instance
|
|
65
|
+
*/
|
|
66
|
+
abstract toModel(lang?: Language): T | Promise<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Converts the entity to a summary representation.
|
|
69
|
+
* Must be implemented by child classes to define summary transformation logic.
|
|
70
|
+
*
|
|
71
|
+
* @param lang - Optional language for localized content
|
|
72
|
+
* @returns Summary model instance or Promise resolving to summary model instance
|
|
73
|
+
*/
|
|
74
|
+
abstract toSummary(lang?: Language): T | Promise<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves all activity records associated with this entity.
|
|
77
|
+
* Must be implemented by child classes to return their specific activity relations.
|
|
78
|
+
*
|
|
79
|
+
* @returns Promise resolving to array of Activity objects
|
|
80
|
+
*/
|
|
81
|
+
abstract getActivities(): Promise<Activity[]>;
|
|
82
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TrackableEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
/**
|
|
15
|
+
* Abstract base entity with comprehensive audit tracking properties.
|
|
16
|
+
* Provides automatic tracking of creation, updates, and soft deletion with user attribution.
|
|
17
|
+
* All entities requiring an audit trail should extend this class.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The model type that the entity converts to
|
|
20
|
+
* @extends BaseEntity
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* @Entity('users')
|
|
25
|
+
* export class UserEntity extends TrackableEntity<User> {
|
|
26
|
+
* // entity properties
|
|
27
|
+
*
|
|
28
|
+
* toModel() {
|
|
29
|
+
* return new User({ id: this.id, ... });
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* async getActivities() {
|
|
33
|
+
* return [];
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
class TrackableEntity extends typeorm_1.BaseEntity {
|
|
39
|
+
}
|
|
40
|
+
exports.TrackableEntity = TrackableEntity;
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
43
|
+
__metadata("design:type", Number)
|
|
44
|
+
], TrackableEntity.prototype, "id", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typeorm_1.Column)({ nullable: true, default: null }),
|
|
47
|
+
__metadata("design:type", Number)
|
|
48
|
+
], TrackableEntity.prototype, "createdBy", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, typeorm_1.CreateDateColumn)({ nullable: true, default: null }),
|
|
51
|
+
__metadata("design:type", Date)
|
|
52
|
+
], TrackableEntity.prototype, "createdOn", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typeorm_1.Column)({ nullable: true, default: null }),
|
|
55
|
+
__metadata("design:type", Number)
|
|
56
|
+
], TrackableEntity.prototype, "updatedBy", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, typeorm_1.UpdateDateColumn)({ nullable: true, default: null }),
|
|
59
|
+
__metadata("design:type", Date)
|
|
60
|
+
], TrackableEntity.prototype, "updatedOn", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.Column)({ nullable: true, default: null }),
|
|
63
|
+
__metadata("design:type", Number)
|
|
64
|
+
], TrackableEntity.prototype, "deletedBy", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, typeorm_1.DeleteDateColumn)({ nullable: true, default: null }),
|
|
67
|
+
__metadata("design:type", Date)
|
|
68
|
+
], TrackableEntity.prototype, "deletedOn", void 0);
|
|
69
|
+
//# sourceMappingURL=trackable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trackable.js","sourceRoot":"","sources":["../../src/utils/trackable.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAA2H;AAE3H;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAsB,eAAuB,SAAQ,oBAAU;CAyE9D;AAzED,0CAyEC;AAnEA;IADC,IAAA,gCAAsB,GAAE;;2CACd;AAMX;IADC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;kDACxB;AAOlB;IADC,IAAA,0BAAgB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8BACzC,IAAI;kDAAC;AAMhB;IADC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;kDACxB;AAOlB;IADC,IAAA,0BAAgB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8BACzC,IAAI;kDAAC;AAMhB;IADC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;kDACxB;AAOlB;IADC,IAAA,0BAAgB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8BACzC,IAAI;kDAAC"}
|