plutin 1.3.0 → 1.3.2
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/index.d.cts +286 -28
- package/dist/index.d.ts +286 -28
- package/dist/{index.js → index.mjs} +1 -1
- package/package.json +4 -3
- package/dist/base-controller-68008870.d.ts +0 -46
- package/dist/core/decorators/controller-http-decorator.cjs +0 -310
- package/dist/core/decorators/controller-http-decorator.cjs.map +0 -1
- package/dist/core/decorators/controller-http-decorator.d.cts +0 -13
- package/dist/core/decorators/controller-http-decorator.d.ts +0 -13
- package/dist/core/decorators/controller-http-decorator.js +0 -285
- package/dist/core/decorators/controller-http-decorator.js.map +0 -1
- package/dist/core/decorators/dependency-container.cjs +0 -95
- package/dist/core/decorators/dependency-container.cjs.map +0 -1
- package/dist/core/decorators/dependency-container.d.cts +0 -22
- package/dist/core/decorators/dependency-container.d.ts +0 -22
- package/dist/core/decorators/dependency-container.js +0 -71
- package/dist/core/decorators/dependency-container.js.map +0 -1
- package/dist/core/entities/aggregate-root.cjs +0 -99
- package/dist/core/entities/aggregate-root.cjs.map +0 -1
- package/dist/core/entities/aggregate-root.d.cts +0 -8
- package/dist/core/entities/aggregate-root.d.ts +0 -8
- package/dist/core/entities/aggregate-root.js +0 -74
- package/dist/core/entities/aggregate-root.js.map +0 -1
- package/dist/core/entities/common-dto.cjs +0 -19
- package/dist/core/entities/common-dto.cjs.map +0 -1
- package/dist/core/entities/common-dto.d.cts +0 -10
- package/dist/core/entities/common-dto.d.ts +0 -10
- package/dist/core/entities/common-dto.js +0 -1
- package/dist/core/entities/common-dto.js.map +0 -1
- package/dist/core/entities/domain-event.cjs +0 -19
- package/dist/core/entities/domain-event.cjs.map +0 -1
- package/dist/core/entities/domain-event.d.cts +0 -6
- package/dist/core/entities/domain-event.d.ts +0 -6
- package/dist/core/entities/domain-event.js +0 -1
- package/dist/core/entities/domain-event.js.map +0 -1
- package/dist/core/entities/entity.cjs +0 -92
- package/dist/core/entities/entity.cjs.map +0 -1
- package/dist/core/entities/entity.d.cts +0 -18
- package/dist/core/entities/entity.d.ts +0 -18
- package/dist/core/entities/entity.js +0 -67
- package/dist/core/entities/entity.js.map +0 -1
- package/dist/core/entities/optional.cjs +0 -19
- package/dist/core/entities/optional.cjs.map +0 -1
- package/dist/core/entities/optional.d.cts +0 -3
- package/dist/core/entities/optional.d.ts +0 -3
- package/dist/core/entities/optional.js +0 -1
- package/dist/core/entities/optional.js.map +0 -1
- package/dist/core/entities/replace.cjs +0 -19
- package/dist/core/entities/replace.cjs.map +0 -1
- package/dist/core/entities/replace.d.cts +0 -5
- package/dist/core/entities/replace.d.ts +0 -5
- package/dist/core/entities/replace.js +0 -1
- package/dist/core/entities/replace.js.map +0 -1
- package/dist/core/entities/unique-entity-id.cjs +0 -50
- package/dist/core/entities/unique-entity-id.cjs.map +0 -1
- package/dist/core/entities/unique-entity-id.d.cts +0 -9
- package/dist/core/entities/unique-entity-id.d.ts +0 -9
- package/dist/core/entities/unique-entity-id.js +0 -27
- package/dist/core/entities/unique-entity-id.js.map +0 -1
- package/dist/core/entities/value-object.cjs +0 -40
- package/dist/core/entities/value-object.cjs.map +0 -1
- package/dist/core/entities/value-object.d.cts +0 -6
- package/dist/core/entities/value-object.d.ts +0 -6
- package/dist/core/entities/value-object.js +0 -17
- package/dist/core/entities/value-object.js.map +0 -1
- package/dist/core/entities/watched-list.cjs +0 -121
- package/dist/core/entities/watched-list.cjs.map +0 -1
- package/dist/core/entities/watched-list.d.cts +0 -27
- package/dist/core/entities/watched-list.d.ts +0 -27
- package/dist/core/entities/watched-list.js +0 -98
- package/dist/core/entities/watched-list.js.map +0 -1
- package/dist/core/entities/watched-list.test.cjs +0 -186
- package/dist/core/entities/watched-list.test.cjs.map +0 -1
- package/dist/core/entities/watched-list.test.d.cts +0 -2
- package/dist/core/entities/watched-list.test.d.ts +0 -2
- package/dist/core/entities/watched-list.test.js +0 -185
- package/dist/core/entities/watched-list.test.js.map +0 -1
- package/dist/core/errors/api-common-error.cjs +0 -38
- package/dist/core/errors/api-common-error.cjs.map +0 -1
- package/dist/core/errors/api-common-error.d.cts +0 -28
- package/dist/core/errors/api-common-error.d.ts +0 -28
- package/dist/core/errors/api-common-error.js +0 -13
- package/dist/core/errors/api-common-error.js.map +0 -1
- package/dist/core/errors/application-error.cjs +0 -54
- package/dist/core/errors/application-error.cjs.map +0 -1
- package/dist/core/errors/application-error.d.cts +0 -8
- package/dist/core/errors/application-error.d.ts +0 -8
- package/dist/core/errors/application-error.js +0 -33
- package/dist/core/errors/application-error.js.map +0 -1
- package/dist/core/errors/conflict-error.cjs +0 -56
- package/dist/core/errors/conflict-error.cjs.map +0 -1
- package/dist/core/errors/conflict-error.d.cts +0 -13
- package/dist/core/errors/conflict-error.d.ts +0 -13
- package/dist/core/errors/conflict-error.js +0 -35
- package/dist/core/errors/conflict-error.js.map +0 -1
- package/dist/core/errors/domain-error.cjs +0 -54
- package/dist/core/errors/domain-error.cjs.map +0 -1
- package/dist/core/errors/domain-error.d.cts +0 -8
- package/dist/core/errors/domain-error.d.ts +0 -8
- package/dist/core/errors/domain-error.js +0 -33
- package/dist/core/errors/domain-error.js.map +0 -1
- package/dist/core/errors/http-client-error.cjs +0 -54
- package/dist/core/errors/http-client-error.cjs.map +0 -1
- package/dist/core/errors/http-client-error.d.cts +0 -8
- package/dist/core/errors/http-client-error.d.ts +0 -8
- package/dist/core/errors/http-client-error.js +0 -33
- package/dist/core/errors/http-client-error.js.map +0 -1
- package/dist/core/errors/infra-error.cjs +0 -54
- package/dist/core/errors/infra-error.cjs.map +0 -1
- package/dist/core/errors/infra-error.d.cts +0 -8
- package/dist/core/errors/infra-error.d.ts +0 -8
- package/dist/core/errors/infra-error.js +0 -33
- package/dist/core/errors/infra-error.js.map +0 -1
- package/dist/core/errors/validation-error.cjs +0 -55
- package/dist/core/errors/validation-error.cjs.map +0 -1
- package/dist/core/errors/validation-error.d.cts +0 -8
- package/dist/core/errors/validation-error.d.ts +0 -8
- package/dist/core/errors/validation-error.js +0 -34
- package/dist/core/errors/validation-error.js.map +0 -1
- package/dist/core/http/base-controller.cjs +0 -295
- package/dist/core/http/base-controller.cjs.map +0 -1
- package/dist/core/http/base-controller.d.cts +0 -1
- package/dist/core/http/base-controller.d.ts +0 -1
- package/dist/core/http/base-controller.js +0 -270
- package/dist/core/http/base-controller.js.map +0 -1
- package/dist/core/http/dto-response.cjs +0 -19
- package/dist/core/http/dto-response.cjs.map +0 -1
- package/dist/core/http/dto-response.d.cts +0 -10
- package/dist/core/http/dto-response.d.ts +0 -10
- package/dist/core/http/dto-response.js +0 -1
- package/dist/core/http/dto-response.js.map +0 -1
- package/dist/core/http/error-notifier.cjs +0 -19
- package/dist/core/http/error-notifier.cjs.map +0 -1
- package/dist/core/http/error-notifier.d.cts +0 -1
- package/dist/core/http/error-notifier.d.ts +0 -1
- package/dist/core/http/error-notifier.js +0 -1
- package/dist/core/http/error-notifier.js.map +0 -1
- package/dist/core/http/get-take-and-skip.cjs +0 -40
- package/dist/core/http/get-take-and-skip.cjs.map +0 -1
- package/dist/core/http/get-take-and-skip.d.cts +0 -6
- package/dist/core/http/get-take-and-skip.d.ts +0 -6
- package/dist/core/http/get-take-and-skip.js +0 -17
- package/dist/core/http/get-take-and-skip.js.map +0 -1
- package/dist/core/http/health-connections.cjs +0 -42
- package/dist/core/http/health-connections.cjs.map +0 -1
- package/dist/core/http/health-connections.d.cts +0 -16
- package/dist/core/http/health-connections.d.ts +0 -16
- package/dist/core/http/health-connections.js +0 -23
- package/dist/core/http/health-connections.js.map +0 -1
- package/dist/core/http/http.cjs +0 -19
- package/dist/core/http/http.cjs.map +0 -1
- package/dist/core/http/http.d.cts +0 -10
- package/dist/core/http/http.d.ts +0 -10
- package/dist/core/http/http.js +0 -1
- package/dist/core/http/http.js.map +0 -1
- package/dist/core/http/pagination.cjs +0 -19
- package/dist/core/http/pagination.cjs.map +0 -1
- package/dist/core/http/pagination.d.cts +0 -9
- package/dist/core/http/pagination.d.ts +0 -9
- package/dist/core/http/pagination.js +0 -1
- package/dist/core/http/pagination.js.map +0 -1
- package/dist/core/http/validator.cjs +0 -19
- package/dist/core/http/validator.cjs.map +0 -1
- package/dist/core/http/validator.d.cts +0 -11
- package/dist/core/http/validator.d.ts +0 -11
- package/dist/core/http/validator.js +0 -1
- package/dist/core/http/validator.js.map +0 -1
- package/dist/infra/adapters/http/express-adapter.cjs +0 -139
- package/dist/infra/adapters/http/express-adapter.cjs.map +0 -1
- package/dist/infra/adapters/http/express-adapter.d.cts +0 -15
- package/dist/infra/adapters/http/express-adapter.d.ts +0 -15
- package/dist/infra/adapters/http/express-adapter.js +0 -106
- package/dist/infra/adapters/http/express-adapter.js.map +0 -1
- package/dist/infra/adapters/http/fastify-adapter.cjs +0 -124
- package/dist/infra/adapters/http/fastify-adapter.cjs.map +0 -1
- package/dist/infra/adapters/http/fastify-adapter.d.cts +0 -14
- package/dist/infra/adapters/http/fastify-adapter.d.ts +0 -14
- package/dist/infra/adapters/http/fastify-adapter.js +0 -91
- package/dist/infra/adapters/http/fastify-adapter.js.map +0 -1
- package/dist/infra/adapters/http/response-error-code.cjs +0 -35
- package/dist/infra/adapters/http/response-error-code.cjs.map +0 -1
- package/dist/infra/adapters/http/response-error-code.d.cts +0 -6
- package/dist/infra/adapters/http/response-error-code.d.ts +0 -6
- package/dist/infra/adapters/http/response-error-code.js +0 -10
- package/dist/infra/adapters/http/response-error-code.js.map +0 -1
- package/dist/infra/adapters/http/validate-controller-metadata.cjs +0 -42
- package/dist/infra/adapters/http/validate-controller-metadata.cjs.map +0 -1
- package/dist/infra/adapters/http/validate-controller-metadata.d.cts +0 -11
- package/dist/infra/adapters/http/validate-controller-metadata.d.ts +0 -11
- package/dist/infra/adapters/http/validate-controller-metadata.js +0 -19
- package/dist/infra/adapters/http/validate-controller-metadata.js.map +0 -1
- package/dist/infra/adapters/notifications/discord.cjs +0 -90
- package/dist/infra/adapters/notifications/discord.cjs.map +0 -1
- package/dist/infra/adapters/notifications/discord.d.cts +0 -14
- package/dist/infra/adapters/notifications/discord.d.ts +0 -14
- package/dist/infra/adapters/notifications/discord.js +0 -65
- package/dist/infra/adapters/notifications/discord.js.map +0 -1
- package/dist/infra/adapters/notifications/in-memory.cjs +0 -44
- package/dist/infra/adapters/notifications/in-memory.cjs.map +0 -1
- package/dist/infra/adapters/notifications/in-memory.d.cts +0 -8
- package/dist/infra/adapters/notifications/in-memory.d.ts +0 -8
- package/dist/infra/adapters/notifications/in-memory.js +0 -21
- package/dist/infra/adapters/notifications/in-memory.js.map +0 -1
- package/dist/infra/adapters/notifications/notification-factory.cjs +0 -219
- package/dist/infra/adapters/notifications/notification-factory.cjs.map +0 -1
- package/dist/infra/adapters/notifications/notification-factory.d.cts +0 -18
- package/dist/infra/adapters/notifications/notification-factory.d.ts +0 -18
- package/dist/infra/adapters/notifications/notification-factory.js +0 -184
- package/dist/infra/adapters/notifications/notification-factory.js.map +0 -1
- package/dist/infra/adapters/notifications/sentry.cjs +0 -129
- package/dist/infra/adapters/notifications/sentry.cjs.map +0 -1
- package/dist/infra/adapters/notifications/sentry.d.cts +0 -13
- package/dist/infra/adapters/notifications/sentry.d.ts +0 -13
- package/dist/infra/adapters/notifications/sentry.js +0 -96
- package/dist/infra/adapters/notifications/sentry.js.map +0 -1
- package/dist/infra/adapters/validators/zod/index.cjs +0 -179
- package/dist/infra/adapters/validators/zod/index.cjs.map +0 -1
- package/dist/infra/adapters/validators/zod/index.d.cts +0 -19
- package/dist/infra/adapters/validators/zod/index.d.ts +0 -19
- package/dist/infra/adapters/validators/zod/index.js +0 -154
- package/dist/infra/adapters/validators/zod/index.js.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-map-error.cjs +0 -79
- package/dist/infra/adapters/validators/zod/zod-map-error.cjs.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-map-error.d.cts +0 -15
- package/dist/infra/adapters/validators/zod/zod-map-error.d.ts +0 -15
- package/dist/infra/adapters/validators/zod/zod-map-error.js +0 -60
- package/dist/infra/adapters/validators/zod/zod-map-error.js.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-validator.cjs +0 -178
- package/dist/infra/adapters/validators/zod/zod-validator.cjs.map +0 -1
- package/dist/infra/adapters/validators/zod/zod-validator.d.cts +0 -13
- package/dist/infra/adapters/validators/zod/zod-validator.d.ts +0 -13
- package/dist/infra/adapters/validators/zod/zod-validator.js +0 -153
- package/dist/infra/adapters/validators/zod/zod-validator.js.map +0 -1
- package/dist/infra/env/index.cjs +0 -467
- package/dist/infra/env/index.cjs.map +0 -1
- package/dist/infra/env/index.d.cts +0 -26
- package/dist/infra/env/index.d.ts +0 -26
- package/dist/infra/env/index.js +0 -452
- package/dist/infra/env/index.js.map +0 -1
- /package/dist/{index.js.map → index.mjs.map} +0 -0
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/core/decorators/dependency-container.ts
|
|
5
|
-
import "reflect-metadata";
|
|
6
|
-
var DependencyContainer = class {
|
|
7
|
-
static {
|
|
8
|
-
__name(this, "DependencyContainer");
|
|
9
|
-
}
|
|
10
|
-
static registry = /* @__PURE__ */ new Map();
|
|
11
|
-
static singletons = /* @__PURE__ */ new Map();
|
|
12
|
-
static register(token, myClass, options) {
|
|
13
|
-
this.registry.set(token, {
|
|
14
|
-
type: "class",
|
|
15
|
-
myClass,
|
|
16
|
-
singleton: options.singleton
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
static registerValue(token, value) {
|
|
20
|
-
this.registry.set(token, {
|
|
21
|
-
type: "value",
|
|
22
|
-
value
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
static resolve(target) {
|
|
26
|
-
const injectMetadata = Reflect.getOwnMetadata("inject:params", target) || {};
|
|
27
|
-
const paramCount = Object.keys(injectMetadata).length;
|
|
28
|
-
const params = Array.from({
|
|
29
|
-
length: paramCount
|
|
30
|
-
}, (_, index) => {
|
|
31
|
-
const token = injectMetadata[index];
|
|
32
|
-
if (!token) {
|
|
33
|
-
throw new Error(`Missing @Inject token for parameter index ${index} in ${target.name}`);
|
|
34
|
-
}
|
|
35
|
-
return this.resolveToken(token);
|
|
36
|
-
});
|
|
37
|
-
return new target(...params);
|
|
38
|
-
}
|
|
39
|
-
static resolveToken(token) {
|
|
40
|
-
const registration = this.registry.get(token);
|
|
41
|
-
if (!registration) {
|
|
42
|
-
throw new Error(`"${token}" not registered. Please register it in the container.`);
|
|
43
|
-
}
|
|
44
|
-
if (registration.type === "value") {
|
|
45
|
-
return registration.value;
|
|
46
|
-
}
|
|
47
|
-
const { myClass, singleton } = registration;
|
|
48
|
-
if (singleton) {
|
|
49
|
-
if (!this.singletons.has(token)) {
|
|
50
|
-
const instance = this.resolve(myClass);
|
|
51
|
-
this.singletons.set(token, instance);
|
|
52
|
-
}
|
|
53
|
-
return this.singletons.get(token);
|
|
54
|
-
}
|
|
55
|
-
return this.resolve(myClass);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// src/core/errors/api-common-error.ts
|
|
60
|
-
var ApiErrorEnum = /* @__PURE__ */ function(ApiErrorEnum2) {
|
|
61
|
-
ApiErrorEnum2["DOMAIN"] = "ERR001";
|
|
62
|
-
ApiErrorEnum2["APPLICATION"] = "ERR002";
|
|
63
|
-
ApiErrorEnum2["INFRA"] = "ERR003";
|
|
64
|
-
ApiErrorEnum2["HTTP_CLIENT"] = "ERR004";
|
|
65
|
-
ApiErrorEnum2["VALIDATOR"] = "ERR005";
|
|
66
|
-
return ApiErrorEnum2;
|
|
67
|
-
}({});
|
|
68
|
-
|
|
69
|
-
// src/core/errors/application-error.ts
|
|
70
|
-
var ApplicationError = class extends Error {
|
|
71
|
-
static {
|
|
72
|
-
__name(this, "ApplicationError");
|
|
73
|
-
}
|
|
74
|
-
props;
|
|
75
|
-
constructor(message) {
|
|
76
|
-
super(message);
|
|
77
|
-
this.props = {
|
|
78
|
-
code: 400,
|
|
79
|
-
errorCode: ApiErrorEnum.APPLICATION,
|
|
80
|
-
message,
|
|
81
|
-
occurredAt: /* @__PURE__ */ new Date()
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// src/core/errors/conflict-error.ts
|
|
87
|
-
var ConflictError = class extends Error {
|
|
88
|
-
static {
|
|
89
|
-
__name(this, "ConflictError");
|
|
90
|
-
}
|
|
91
|
-
props;
|
|
92
|
-
conflictProps;
|
|
93
|
-
constructor(conflictProps) {
|
|
94
|
-
super("Resource already exists.");
|
|
95
|
-
this.conflictProps = conflictProps;
|
|
96
|
-
this.props = {
|
|
97
|
-
code: 409,
|
|
98
|
-
errorCode: ApiErrorEnum.APPLICATION,
|
|
99
|
-
message: this.message,
|
|
100
|
-
occurredAt: /* @__PURE__ */ new Date()
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// src/core/errors/domain-error.ts
|
|
106
|
-
var DomainError = class extends Error {
|
|
107
|
-
static {
|
|
108
|
-
__name(this, "DomainError");
|
|
109
|
-
}
|
|
110
|
-
props;
|
|
111
|
-
constructor(message) {
|
|
112
|
-
super(message);
|
|
113
|
-
this.props = {
|
|
114
|
-
code: 400,
|
|
115
|
-
errorCode: ApiErrorEnum.DOMAIN,
|
|
116
|
-
message,
|
|
117
|
-
occurredAt: /* @__PURE__ */ new Date()
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// src/core/errors/infra-error.ts
|
|
123
|
-
var InfraError = class extends Error {
|
|
124
|
-
static {
|
|
125
|
-
__name(this, "InfraError");
|
|
126
|
-
}
|
|
127
|
-
props;
|
|
128
|
-
constructor(message) {
|
|
129
|
-
super(message);
|
|
130
|
-
this.props = {
|
|
131
|
-
code: 400,
|
|
132
|
-
errorCode: ApiErrorEnum.INFRA,
|
|
133
|
-
message,
|
|
134
|
-
occurredAt: /* @__PURE__ */ new Date()
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// src/core/errors/validation-error.ts
|
|
140
|
-
var ValidationError = class extends Error {
|
|
141
|
-
static {
|
|
142
|
-
__name(this, "ValidationError");
|
|
143
|
-
}
|
|
144
|
-
props;
|
|
145
|
-
constructor(errors) {
|
|
146
|
-
super("Validation Error");
|
|
147
|
-
this.props = {
|
|
148
|
-
code: 400,
|
|
149
|
-
errorCode: ApiErrorEnum.VALIDATOR,
|
|
150
|
-
message: "Validation Error",
|
|
151
|
-
occurredAt: /* @__PURE__ */ new Date(),
|
|
152
|
-
errors
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// src/core/http/base-controller.ts
|
|
158
|
-
import "reflect-metadata";
|
|
159
|
-
var BaseController = class {
|
|
160
|
-
static {
|
|
161
|
-
__name(this, "BaseController");
|
|
162
|
-
}
|
|
163
|
-
errorNotifier;
|
|
164
|
-
constructor() {
|
|
165
|
-
this.errorNotifier = DependencyContainer.resolveToken("IErrorNotifier");
|
|
166
|
-
}
|
|
167
|
-
success(dto) {
|
|
168
|
-
return {
|
|
169
|
-
code: 200,
|
|
170
|
-
data: {
|
|
171
|
-
data: dto
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
noContent() {
|
|
176
|
-
return {
|
|
177
|
-
code: 204,
|
|
178
|
-
data: void 0
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
created(dto) {
|
|
182
|
-
return {
|
|
183
|
-
code: 201,
|
|
184
|
-
data: dto ? {
|
|
185
|
-
data: dto
|
|
186
|
-
} : void 0
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
paginated(dto) {
|
|
190
|
-
return {
|
|
191
|
-
code: 200,
|
|
192
|
-
data: dto
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
buildContextError(request) {
|
|
196
|
-
return {
|
|
197
|
-
env: process.env.ENVIRONMENT,
|
|
198
|
-
request: {
|
|
199
|
-
body: request.body,
|
|
200
|
-
headers: request.headers,
|
|
201
|
-
params: request.params,
|
|
202
|
-
query: request.query
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
async failure(error, context) {
|
|
207
|
-
if (error instanceof ConflictError) {
|
|
208
|
-
return {
|
|
209
|
-
code: error.props.code,
|
|
210
|
-
data: {
|
|
211
|
-
message: error.message,
|
|
212
|
-
errorCode: error.props.errorCode,
|
|
213
|
-
occurredAt: error.props.occurredAt,
|
|
214
|
-
items: Array.isArray(error.conflictProps) ? error.conflictProps : [
|
|
215
|
-
error.conflictProps
|
|
216
|
-
]
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
if (error instanceof DomainError || error instanceof ApplicationError || error instanceof InfraError) {
|
|
221
|
-
return {
|
|
222
|
-
code: error.props.code,
|
|
223
|
-
data: {
|
|
224
|
-
message: error.message,
|
|
225
|
-
errorCode: error.props.errorCode,
|
|
226
|
-
occurredAt: error.props.occurredAt
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
if (error instanceof ValidationError) {
|
|
231
|
-
return {
|
|
232
|
-
code: error.props.code,
|
|
233
|
-
data: {
|
|
234
|
-
message: error.props.message,
|
|
235
|
-
errorCode: error.props.errorCode,
|
|
236
|
-
occurredAt: error.props.occurredAt,
|
|
237
|
-
errors: error.props.errors
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
if (process.env.SHOULD_NOTIFY_ERROR) {
|
|
242
|
-
await this.errorNotifier.notify(error, context);
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
code: 500,
|
|
246
|
-
data: {
|
|
247
|
-
code: 500,
|
|
248
|
-
message: "Server failed. Contact the administrator!"
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
async execute(request) {
|
|
253
|
-
const routeMetadata = Reflect.getMetadata("route", this.constructor);
|
|
254
|
-
if (!routeMetadata) {
|
|
255
|
-
throw new InfraError("Route metadata not found.");
|
|
256
|
-
}
|
|
257
|
-
const middlewares = routeMetadata.middlewares || [];
|
|
258
|
-
let processedRequest = request;
|
|
259
|
-
if (middlewares.length) {
|
|
260
|
-
for (const middleware of middlewares) {
|
|
261
|
-
processedRequest = await middleware(processedRequest);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return await this.handle(processedRequest);
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
// src/core/decorators/controller-http-decorator.ts
|
|
269
|
-
function Controller({ method, path, middlewares = [] }) {
|
|
270
|
-
return (target) => {
|
|
271
|
-
if (!(target.prototype instanceof BaseController)) {
|
|
272
|
-
throw new Error(`The class ${target.name} should extends abstract class BaseController`);
|
|
273
|
-
}
|
|
274
|
-
Reflect.defineMetadata("route", {
|
|
275
|
-
method,
|
|
276
|
-
path: `/api/${path}`,
|
|
277
|
-
middlewares
|
|
278
|
-
}, target);
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
__name(Controller, "Controller");
|
|
282
|
-
export {
|
|
283
|
-
Controller
|
|
284
|
-
};
|
|
285
|
-
//# sourceMappingURL=controller-http-decorator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/decorators/dependency-container.ts","../../../src/core/errors/api-common-error.ts","../../../src/core/errors/application-error.ts","../../../src/core/errors/conflict-error.ts","../../../src/core/errors/domain-error.ts","../../../src/core/errors/infra-error.ts","../../../src/core/errors/validation-error.ts","../../../src/core/http/base-controller.ts","../../../src/core/decorators/controller-http-decorator.ts"],"sourcesContent":["import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const paramCount = Object.keys(injectMetadata).length\n\n const params = Array.from({ length: paramCount }, (_, index) => {\n const token = injectMetadata[index]\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n","export type PropertiesError = {\n receivedValue?: any\n type: string\n message: string\n property: string | number | undefined\n propertyType?: string\n path?: string\n}\n\nexport type CommonError = {\n location: string\n propertyErrors?: PropertiesError[]\n}\n\nexport type ApiCommonError = {\n code: number\n occurredAt: Date\n message: string\n errorCode: string\n errors?: CommonError[]\n}\n\nexport enum ApiErrorEnum {\n DOMAIN = 'ERR001',\n APPLICATION = 'ERR002',\n INFRA = 'ERR003',\n HTTP_CLIENT = 'ERR004',\n VALIDATOR = 'ERR005',\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class ApplicationError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.APPLICATION,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\ntype ConflictProps = { id: string; [key: string]: unknown }\n\nexport default class ConflictError<T extends ConflictProps> extends Error {\n props: ApiCommonError\n conflictProps: T | T[]\n\n constructor(conflictProps: T | T[]) {\n super('Resource already exists.')\n this.conflictProps = conflictProps\n this.props = {\n code: 409,\n errorCode: ApiErrorEnum.APPLICATION,\n message: this.message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class DomainError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.DOMAIN,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import { type ApiCommonError, ApiErrorEnum } from './api-common-error'\n\nexport default class InfraError extends Error {\n props: ApiCommonError\n\n constructor(message: string) {\n super(message)\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.INFRA,\n message,\n occurredAt: new Date(),\n }\n }\n}\n","import {\n type ApiCommonError,\n ApiErrorEnum,\n type CommonError,\n} from './api-common-error'\n\nexport default class ValidationError extends Error {\n props: ApiCommonError\n\n constructor(errors: CommonError[]) {\n super('Validation Error')\n this.props = {\n code: 400,\n errorCode: ApiErrorEnum.VALIDATOR,\n message: 'Validation Error',\n occurredAt: new Date(),\n errors,\n }\n }\n}\n","import { DependencyContainer } from '../../core/decorators/dependency-container'\nimport ApplicationError from '../../core/errors/application-error'\nimport ConflictError from '../../core/errors/conflict-error'\nimport DomainError from '../../core/errors/domain-error'\nimport InfraError from '../../core/errors/infra-error'\nimport ValidationError from '../../core/errors/validation-error'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\n\nimport { IErrorNotifier } from './error-notifier'\n\nimport 'reflect-metadata'\n\ntype AnyObject = Record<string, any>\n\nexport type Request = {\n body: AnyObject\n params: AnyObject\n headers: AnyObject\n query: AnyObject\n}\n\nexport type Response = {\n code: number\n data: any\n}\n\nexport type ContextError = {\n env: string\n user?: {\n id?: string\n name?: string\n email?: string\n }\n request?: {\n method?: string\n requestId?: string\n url?: string\n headers?: any\n query?: any\n body?: any\n params?: any\n }\n}\n\nexport abstract class BaseController {\n protected readonly errorNotifier: IErrorNotifier\n\n abstract handle<T>(request: T | Request): Promise<Response>\n\n constructor() {\n this.errorNotifier = DependencyContainer.resolveToken('IErrorNotifier')\n }\n\n protected success<T>(dto?: T): Response {\n return {\n code: 200,\n data: { data: dto },\n }\n }\n\n protected noContent(): Response {\n return {\n code: 204,\n data: undefined,\n }\n }\n\n protected created<T>(dto?: T): Response {\n return {\n code: 201,\n data: dto ? { data: dto } : undefined,\n }\n }\n\n protected paginated<T>(dto?: T): Response {\n return {\n code: 200,\n data: dto,\n }\n }\n\n protected buildContextError(request: Request): ContextError {\n return {\n env: process.env.ENVIRONMENT as string,\n request: {\n body: request.body,\n headers: request.headers,\n params: request.params,\n query: request.query,\n },\n }\n }\n\n public async failure(error: Error, context: ContextError): Promise<Response> {\n if (error instanceof ConflictError) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n items: Array.isArray(error.conflictProps)\n ? error.conflictProps\n : [error.conflictProps],\n },\n }\n }\n\n if (\n error instanceof DomainError ||\n error instanceof ApplicationError ||\n error instanceof InfraError\n ) {\n return {\n code: error.props.code,\n data: {\n message: error.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n },\n }\n }\n\n if (error instanceof ValidationError) {\n return {\n code: error.props.code,\n data: {\n message: error.props.message,\n errorCode: error.props.errorCode,\n occurredAt: error.props.occurredAt,\n errors: error.props.errors,\n },\n }\n }\n\n if (process.env.SHOULD_NOTIFY_ERROR) {\n await this.errorNotifier.notify(error, context)\n }\n\n return {\n code: 500,\n data: {\n code: 500,\n message: 'Server failed. Contact the administrator!',\n },\n }\n }\n\n public async execute(request: Request): Promise<Response> {\n const routeMetadata = Reflect.getMetadata('route', this.constructor)\n\n if (!routeMetadata) {\n throw new InfraError('Route metadata not found.')\n }\n\n const middlewares: MiddlewareFunction[] = routeMetadata.middlewares || []\n\n let processedRequest = request\n\n if (middlewares.length) {\n for (const middleware of middlewares) {\n processedRequest = await middleware(processedRequest)\n }\n }\n\n return await this.handle(processedRequest)\n }\n}\n","import { BaseController } from '../../core/http/base-controller'\nimport { MiddlewareFunction } from '../../infra/adapters/validators/zod/zod-validator'\nimport type { MethodType } from '../http/http'\n\ntype Props = {\n method: MethodType\n path: string\n middlewares?: MiddlewareFunction[]\n}\n\nexport function Controller({\n method,\n path,\n middlewares = [],\n}: Props): ClassDecorator {\n return (target: any) => {\n if (!(target.prototype instanceof BaseController)) {\n throw new Error(\n `The class ${target.name} should extends abstract class BaseController`\n )\n }\n\n Reflect.defineMetadata(\n 'route',\n { method, path: `/api/${path}`, middlewares },\n target\n )\n }\n}\n"],"mappings":"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","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","injectMetadata","Reflect","getOwnMetadata","paramCount","Object","keys","length","params","Array","from","_","index","Error","name","resolveToken","registration","get","has","instance","ApiErrorEnum","ApplicationError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","APPLICATION","occurredAt","Date","ConflictError","Error","props","conflictProps","constructor","code","errorCode","ApiErrorEnum","APPLICATION","message","occurredAt","Date","DomainError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","DOMAIN","occurredAt","Date","InfraError","Error","props","constructor","message","code","errorCode","ApiErrorEnum","INFRA","occurredAt","Date","ValidationError","Error","props","constructor","errors","code","errorCode","ApiErrorEnum","VALIDATOR","message","occurredAt","Date","BaseController","errorNotifier","constructor","DependencyContainer","resolveToken","success","dto","code","data","noContent","undefined","created","paginated","buildContextError","request","env","process","ENVIRONMENT","body","headers","params","query","failure","error","context","ConflictError","props","message","errorCode","occurredAt","items","Array","isArray","conflictProps","DomainError","ApplicationError","InfraError","ValidationError","errors","SHOULD_NOTIFY_ERROR","notify","execute","routeMetadata","Reflect","getMetadata","middlewares","processedRequest","length","middleware","handle","Controller","method","path","middlewares","target","prototype","BaseController","Error","name","Reflect","defineMetadata"]}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/core/decorators/dependency-container.ts
|
|
22
|
-
var dependency_container_exports = {};
|
|
23
|
-
__export(dependency_container_exports, {
|
|
24
|
-
DependencyContainer: () => DependencyContainer,
|
|
25
|
-
Inject: () => Inject
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(dependency_container_exports);
|
|
28
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
29
|
-
var DependencyContainer = class {
|
|
30
|
-
static {
|
|
31
|
-
__name(this, "DependencyContainer");
|
|
32
|
-
}
|
|
33
|
-
static registry = /* @__PURE__ */ new Map();
|
|
34
|
-
static singletons = /* @__PURE__ */ new Map();
|
|
35
|
-
static register(token, myClass, options) {
|
|
36
|
-
this.registry.set(token, {
|
|
37
|
-
type: "class",
|
|
38
|
-
myClass,
|
|
39
|
-
singleton: options.singleton
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
static registerValue(token, value) {
|
|
43
|
-
this.registry.set(token, {
|
|
44
|
-
type: "value",
|
|
45
|
-
value
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
static resolve(target) {
|
|
49
|
-
const injectMetadata = Reflect.getOwnMetadata("inject:params", target) || {};
|
|
50
|
-
const paramCount = Object.keys(injectMetadata).length;
|
|
51
|
-
const params = Array.from({
|
|
52
|
-
length: paramCount
|
|
53
|
-
}, (_, index) => {
|
|
54
|
-
const token = injectMetadata[index];
|
|
55
|
-
if (!token) {
|
|
56
|
-
throw new Error(`Missing @Inject token for parameter index ${index} in ${target.name}`);
|
|
57
|
-
}
|
|
58
|
-
return this.resolveToken(token);
|
|
59
|
-
});
|
|
60
|
-
return new target(...params);
|
|
61
|
-
}
|
|
62
|
-
static resolveToken(token) {
|
|
63
|
-
const registration = this.registry.get(token);
|
|
64
|
-
if (!registration) {
|
|
65
|
-
throw new Error(`"${token}" not registered. Please register it in the container.`);
|
|
66
|
-
}
|
|
67
|
-
if (registration.type === "value") {
|
|
68
|
-
return registration.value;
|
|
69
|
-
}
|
|
70
|
-
const { myClass, singleton } = registration;
|
|
71
|
-
if (singleton) {
|
|
72
|
-
if (!this.singletons.has(token)) {
|
|
73
|
-
const instance = this.resolve(myClass);
|
|
74
|
-
this.singletons.set(token, instance);
|
|
75
|
-
}
|
|
76
|
-
return this.singletons.get(token);
|
|
77
|
-
}
|
|
78
|
-
return this.resolve(myClass);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
function Inject(token) {
|
|
82
|
-
return (target, _propertyKey, parameterIndex) => {
|
|
83
|
-
const constructor = typeof target === "function" ? target : target.constructor;
|
|
84
|
-
const existingInjectedParams = Reflect.getOwnMetadata("inject:params", constructor) || {};
|
|
85
|
-
existingInjectedParams[parameterIndex] = token;
|
|
86
|
-
Reflect.defineMetadata("inject:params", existingInjectedParams, constructor);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
__name(Inject, "Inject");
|
|
90
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
-
0 && (module.exports = {
|
|
92
|
-
DependencyContainer,
|
|
93
|
-
Inject
|
|
94
|
-
});
|
|
95
|
-
//# sourceMappingURL=dependency-container.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/decorators/dependency-container.ts"],"sourcesContent":["import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const paramCount = Object.keys(injectMetadata).length\n\n const params = Array.from({ length: paramCount }, (_, index) => {\n const token = injectMetadata[index]\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;8BAAO;AAQA,IAAMA,sBAAN,MAAMA;EARb,OAQaA;;;EACX,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,IAAIH,OAAO;MAAEI,MAAM;MAASG;IAAM,CAAA;EAClD;EAEA,OAAOC,QAAWC,QAAqB;AACrC,UAAMC,iBACJC,QAAQC,eAAe,iBAAiBH,MAAAA,KAAW,CAAC;AAEtD,UAAMI,aAAaC,OAAOC,KAAKL,cAAAA,EAAgBM;AAE/C,UAAMC,SAASC,MAAMC,KAAK;MAAEH,QAAQH;IAAW,GAAG,CAACO,GAAGC,UAAAA;AACpD,YAAMrB,QAAQU,eAAeW,KAAAA;AAC7B,UAAI,CAACrB,OAAO;AACV,cAAM,IAAIsB,MACR,6CAA6CD,KAAAA,OAAYZ,OAAOc,IAAI,EAAE;MAE1E;AACA,aAAO,KAAKC,aAAaxB,KAAAA;IAC3B,CAAA;AAEA,WAAO,IAAIS,OAAAA,GAAUQ,MAAAA;EACvB;EAEA,OAAOO,aAAaxB,OAAoB;AACtC,UAAMyB,eAAe,KAAK7B,SAAS8B,IAAI1B,KAAAA;AAEvC,QAAI,CAACyB,cAAc;AACjB,YAAM,IAAIH,MACR,IAAItB,KAAAA,wDAA6D;IAErE;AAEA,QAAIyB,aAAarB,SAAS,SAAS;AACjC,aAAOqB,aAAalB;IACtB;AAEA,UAAM,EAAEN,SAASI,UAAS,IAAKoB;AAE/B,QAAIpB,WAAW;AACb,UAAI,CAAC,KAAKP,WAAW6B,IAAI3B,KAAAA,GAAQ;AAC/B,cAAM4B,WAAW,KAAKpB,QAAQP,OAAAA;AAC9B,aAAKH,WAAWK,IAAIH,OAAO4B,QAAAA;MAC7B;AACA,aAAO,KAAK9B,WAAW4B,IAAI1B,KAAAA;IAC7B;AAEA,WAAO,KAAKQ,QAAQP,OAAAA;EACtB;AACF;AAEO,SAAS4B,OAAO7B,OAAa;AAClC,SAAO,CACLS,QACAqB,cACAC,mBAAAA;AAEA,UAAMC,cACJ,OAAOvB,WAAW,aAAaA,SAASA,OAAOuB;AAEjD,UAAMC,yBACJtB,QAAQC,eAAe,iBAAiBoB,WAAAA,KAAgB,CAAC;AAE3DC,2BAAuBF,cAAAA,IAAkB/B;AAEzCW,YAAQuB,eAAe,iBAAiBD,wBAAwBD,WAAAA;EAClE;AACF;AAhBgBH;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","injectMetadata","Reflect","getOwnMetadata","paramCount","Object","keys","length","params","Array","from","_","index","Error","name","resolveToken","registration","get","has","instance","Inject","_propertyKey","parameterIndex","constructor","existingInjectedParams","defineMetadata"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
type Class<T = any> = new (...args: any[]) => T;
|
|
2
|
-
type Registration = {
|
|
3
|
-
type: 'class';
|
|
4
|
-
myClass: Class;
|
|
5
|
-
singleton: boolean;
|
|
6
|
-
} | {
|
|
7
|
-
type: 'value';
|
|
8
|
-
value: any;
|
|
9
|
-
};
|
|
10
|
-
declare class DependencyContainer {
|
|
11
|
-
static registry: Map<string, Registration>;
|
|
12
|
-
static singletons: Map<string, any>;
|
|
13
|
-
static register<T>(token: string, myClass: Class<T>, options: {
|
|
14
|
-
singleton: boolean;
|
|
15
|
-
}): void;
|
|
16
|
-
static registerValue<T>(token: string, value: T): void;
|
|
17
|
-
static resolve<T>(target: Class<T>): T;
|
|
18
|
-
static resolveToken(token: string): any;
|
|
19
|
-
}
|
|
20
|
-
declare function Inject(token: string): ParameterDecorator;
|
|
21
|
-
|
|
22
|
-
export { DependencyContainer, Inject };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
type Class<T = any> = new (...args: any[]) => T;
|
|
2
|
-
type Registration = {
|
|
3
|
-
type: 'class';
|
|
4
|
-
myClass: Class;
|
|
5
|
-
singleton: boolean;
|
|
6
|
-
} | {
|
|
7
|
-
type: 'value';
|
|
8
|
-
value: any;
|
|
9
|
-
};
|
|
10
|
-
declare class DependencyContainer {
|
|
11
|
-
static registry: Map<string, Registration>;
|
|
12
|
-
static singletons: Map<string, any>;
|
|
13
|
-
static register<T>(token: string, myClass: Class<T>, options: {
|
|
14
|
-
singleton: boolean;
|
|
15
|
-
}): void;
|
|
16
|
-
static registerValue<T>(token: string, value: T): void;
|
|
17
|
-
static resolve<T>(target: Class<T>): T;
|
|
18
|
-
static resolveToken(token: string): any;
|
|
19
|
-
}
|
|
20
|
-
declare function Inject(token: string): ParameterDecorator;
|
|
21
|
-
|
|
22
|
-
export { DependencyContainer, Inject };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/core/decorators/dependency-container.ts
|
|
5
|
-
import "reflect-metadata";
|
|
6
|
-
var DependencyContainer = class {
|
|
7
|
-
static {
|
|
8
|
-
__name(this, "DependencyContainer");
|
|
9
|
-
}
|
|
10
|
-
static registry = /* @__PURE__ */ new Map();
|
|
11
|
-
static singletons = /* @__PURE__ */ new Map();
|
|
12
|
-
static register(token, myClass, options) {
|
|
13
|
-
this.registry.set(token, {
|
|
14
|
-
type: "class",
|
|
15
|
-
myClass,
|
|
16
|
-
singleton: options.singleton
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
static registerValue(token, value) {
|
|
20
|
-
this.registry.set(token, {
|
|
21
|
-
type: "value",
|
|
22
|
-
value
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
static resolve(target) {
|
|
26
|
-
const injectMetadata = Reflect.getOwnMetadata("inject:params", target) || {};
|
|
27
|
-
const paramCount = Object.keys(injectMetadata).length;
|
|
28
|
-
const params = Array.from({
|
|
29
|
-
length: paramCount
|
|
30
|
-
}, (_, index) => {
|
|
31
|
-
const token = injectMetadata[index];
|
|
32
|
-
if (!token) {
|
|
33
|
-
throw new Error(`Missing @Inject token for parameter index ${index} in ${target.name}`);
|
|
34
|
-
}
|
|
35
|
-
return this.resolveToken(token);
|
|
36
|
-
});
|
|
37
|
-
return new target(...params);
|
|
38
|
-
}
|
|
39
|
-
static resolveToken(token) {
|
|
40
|
-
const registration = this.registry.get(token);
|
|
41
|
-
if (!registration) {
|
|
42
|
-
throw new Error(`"${token}" not registered. Please register it in the container.`);
|
|
43
|
-
}
|
|
44
|
-
if (registration.type === "value") {
|
|
45
|
-
return registration.value;
|
|
46
|
-
}
|
|
47
|
-
const { myClass, singleton } = registration;
|
|
48
|
-
if (singleton) {
|
|
49
|
-
if (!this.singletons.has(token)) {
|
|
50
|
-
const instance = this.resolve(myClass);
|
|
51
|
-
this.singletons.set(token, instance);
|
|
52
|
-
}
|
|
53
|
-
return this.singletons.get(token);
|
|
54
|
-
}
|
|
55
|
-
return this.resolve(myClass);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
function Inject(token) {
|
|
59
|
-
return (target, _propertyKey, parameterIndex) => {
|
|
60
|
-
const constructor = typeof target === "function" ? target : target.constructor;
|
|
61
|
-
const existingInjectedParams = Reflect.getOwnMetadata("inject:params", constructor) || {};
|
|
62
|
-
existingInjectedParams[parameterIndex] = token;
|
|
63
|
-
Reflect.defineMetadata("inject:params", existingInjectedParams, constructor);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
__name(Inject, "Inject");
|
|
67
|
-
export {
|
|
68
|
-
DependencyContainer,
|
|
69
|
-
Inject
|
|
70
|
-
};
|
|
71
|
-
//# sourceMappingURL=dependency-container.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/decorators/dependency-container.ts"],"sourcesContent":["import 'reflect-metadata'\n\ntype Class<T = any> = new (...args: any[]) => T\n\ntype Registration =\n | { type: 'class'; myClass: Class; singleton: boolean }\n | { type: 'value'; value: any }\n\nexport class DependencyContainer {\n static registry = new Map<string, Registration>()\n static singletons = new Map<string, any>()\n\n static register<T>(\n token: string,\n myClass: Class<T>,\n options: { singleton: boolean }\n ) {\n this.registry.set(token, {\n type: 'class',\n myClass,\n singleton: options.singleton,\n })\n }\n\n static registerValue<T>(token: string, value: T) {\n this.registry.set(token, { type: 'value', value })\n }\n\n static resolve<T>(target: Class<T>): T {\n const injectMetadata: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', target) || {}\n\n const paramCount = Object.keys(injectMetadata).length\n\n const params = Array.from({ length: paramCount }, (_, index) => {\n const token = injectMetadata[index]\n if (!token) {\n throw new Error(\n `Missing @Inject token for parameter index ${index} in ${target.name}`\n )\n }\n return this.resolveToken(token)\n })\n\n return new target(...params)\n }\n\n static resolveToken(token: string): any {\n const registration = this.registry.get(token)\n\n if (!registration) {\n throw new Error(\n `\"${token}\" not registered. Please register it in the container.`\n )\n }\n\n if (registration.type === 'value') {\n return registration.value\n }\n\n const { myClass, singleton } = registration\n\n if (singleton) {\n if (!this.singletons.has(token)) {\n const instance = this.resolve(myClass)\n this.singletons.set(token, instance)\n }\n return this.singletons.get(token)\n }\n\n return this.resolve(myClass)\n }\n}\n\nexport function Inject(token: string): ParameterDecorator {\n return (\n target: object,\n _propertyKey: string | symbol | undefined,\n parameterIndex: number\n ): void => {\n const constructor =\n typeof target === 'function' ? target : target.constructor\n\n const existingInjectedParams: Record<number, string> =\n Reflect.getOwnMetadata('inject:params', constructor) || {}\n\n existingInjectedParams[parameterIndex] = token\n\n Reflect.defineMetadata('inject:params', existingInjectedParams, constructor)\n }\n}\n"],"mappings":";;;;AAAA,OAAO;AAQA,IAAMA,sBAAN,MAAMA;EARb,OAQaA;;;EACX,OAAOC,WAAW,oBAAIC,IAAAA;EACtB,OAAOC,aAAa,oBAAID,IAAAA;EAExB,OAAOE,SACLC,OACAC,SACAC,SACA;AACA,SAAKN,SAASO,IAAIH,OAAO;MACvBI,MAAM;MACNH;MACAI,WAAWH,QAAQG;IACrB,CAAA;EACF;EAEA,OAAOC,cAAiBN,OAAeO,OAAU;AAC/C,SAAKX,SAASO,IAAIH,OAAO;MAAEI,MAAM;MAASG;IAAM,CAAA;EAClD;EAEA,OAAOC,QAAWC,QAAqB;AACrC,UAAMC,iBACJC,QAAQC,eAAe,iBAAiBH,MAAAA,KAAW,CAAC;AAEtD,UAAMI,aAAaC,OAAOC,KAAKL,cAAAA,EAAgBM;AAE/C,UAAMC,SAASC,MAAMC,KAAK;MAAEH,QAAQH;IAAW,GAAG,CAACO,GAAGC,UAAAA;AACpD,YAAMrB,QAAQU,eAAeW,KAAAA;AAC7B,UAAI,CAACrB,OAAO;AACV,cAAM,IAAIsB,MACR,6CAA6CD,KAAAA,OAAYZ,OAAOc,IAAI,EAAE;MAE1E;AACA,aAAO,KAAKC,aAAaxB,KAAAA;IAC3B,CAAA;AAEA,WAAO,IAAIS,OAAAA,GAAUQ,MAAAA;EACvB;EAEA,OAAOO,aAAaxB,OAAoB;AACtC,UAAMyB,eAAe,KAAK7B,SAAS8B,IAAI1B,KAAAA;AAEvC,QAAI,CAACyB,cAAc;AACjB,YAAM,IAAIH,MACR,IAAItB,KAAAA,wDAA6D;IAErE;AAEA,QAAIyB,aAAarB,SAAS,SAAS;AACjC,aAAOqB,aAAalB;IACtB;AAEA,UAAM,EAAEN,SAASI,UAAS,IAAKoB;AAE/B,QAAIpB,WAAW;AACb,UAAI,CAAC,KAAKP,WAAW6B,IAAI3B,KAAAA,GAAQ;AAC/B,cAAM4B,WAAW,KAAKpB,QAAQP,OAAAA;AAC9B,aAAKH,WAAWK,IAAIH,OAAO4B,QAAAA;MAC7B;AACA,aAAO,KAAK9B,WAAW4B,IAAI1B,KAAAA;IAC7B;AAEA,WAAO,KAAKQ,QAAQP,OAAAA;EACtB;AACF;AAEO,SAAS4B,OAAO7B,OAAa;AAClC,SAAO,CACLS,QACAqB,cACAC,mBAAAA;AAEA,UAAMC,cACJ,OAAOvB,WAAW,aAAaA,SAASA,OAAOuB;AAEjD,UAAMC,yBACJtB,QAAQC,eAAe,iBAAiBoB,WAAAA,KAAgB,CAAC;AAE3DC,2BAAuBF,cAAAA,IAAkB/B;AAEzCW,YAAQuB,eAAe,iBAAiBD,wBAAwBD,WAAAA;EAClE;AACF;AAhBgBH;","names":["DependencyContainer","registry","Map","singletons","register","token","myClass","options","set","type","singleton","registerValue","value","resolve","target","injectMetadata","Reflect","getOwnMetadata","paramCount","Object","keys","length","params","Array","from","_","index","Error","name","resolveToken","registration","get","has","instance","Inject","_propertyKey","parameterIndex","constructor","existingInjectedParams","defineMetadata"]}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/core/entities/aggregate-root.ts
|
|
22
|
-
var aggregate_root_exports = {};
|
|
23
|
-
__export(aggregate_root_exports, {
|
|
24
|
-
AggregateRoot: () => AggregateRoot
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(aggregate_root_exports);
|
|
27
|
-
|
|
28
|
-
// src/core/entities/unique-entity-id.ts
|
|
29
|
-
var import_node_crypto = require("crypto");
|
|
30
|
-
var UniqueEntityId = class {
|
|
31
|
-
static {
|
|
32
|
-
__name(this, "UniqueEntityId");
|
|
33
|
-
}
|
|
34
|
-
value;
|
|
35
|
-
constructor(value) {
|
|
36
|
-
this.value = value ?? (0, import_node_crypto.randomUUID)();
|
|
37
|
-
}
|
|
38
|
-
toString() {
|
|
39
|
-
return this.value;
|
|
40
|
-
}
|
|
41
|
-
toValue() {
|
|
42
|
-
return this.value;
|
|
43
|
-
}
|
|
44
|
-
equals(id) {
|
|
45
|
-
return id.toValue() === this.toValue();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/core/entities/entity.ts
|
|
50
|
-
var Entity = class {
|
|
51
|
-
static {
|
|
52
|
-
__name(this, "Entity");
|
|
53
|
-
}
|
|
54
|
-
_id;
|
|
55
|
-
props;
|
|
56
|
-
get id() {
|
|
57
|
-
return this._id;
|
|
58
|
-
}
|
|
59
|
-
set id(id) {
|
|
60
|
-
this._id = id;
|
|
61
|
-
}
|
|
62
|
-
get createdAt() {
|
|
63
|
-
return this.props.createdAt;
|
|
64
|
-
}
|
|
65
|
-
set createdAt(date) {
|
|
66
|
-
this.props.createdAt = date;
|
|
67
|
-
}
|
|
68
|
-
get updatedAt() {
|
|
69
|
-
return this.props.updatedAt;
|
|
70
|
-
}
|
|
71
|
-
touch() {
|
|
72
|
-
this.props.updatedAt = /* @__PURE__ */ new Date();
|
|
73
|
-
}
|
|
74
|
-
constructor(props, id) {
|
|
75
|
-
this._id = id ?? new UniqueEntityId(id);
|
|
76
|
-
this.props = props;
|
|
77
|
-
}
|
|
78
|
-
equals(entity) {
|
|
79
|
-
if (entity === this) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
if (entity.id === this._id) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// src/core/entities/aggregate-root.ts
|
|
90
|
-
var AggregateRoot = class extends Entity {
|
|
91
|
-
static {
|
|
92
|
-
__name(this, "AggregateRoot");
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
-
0 && (module.exports = {
|
|
97
|
-
AggregateRoot
|
|
98
|
-
});
|
|
99
|
-
//# sourceMappingURL=aggregate-root.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/entities/aggregate-root.ts","../../../src/core/entities/unique-entity-id.ts","../../../src/core/entities/entity.ts"],"sourcesContent":["import { Entity } from './entity'\n\nexport abstract class AggregateRoot<Props> extends Entity<Props> {}\n","import { randomUUID } from 'node:crypto'\n\nexport class UniqueEntityId {\n private value: string\n\n constructor(value?: string) {\n this.value = value ?? randomUUID()\n }\n\n toString() {\n return this.value\n }\n\n toValue() {\n return this.value\n }\n\n public equals(id: UniqueEntityId) {\n return id.toValue() === this.toValue()\n }\n}\n","import { CommonDTO } from './common-dto'\nimport { UniqueEntityId } from './unique-entity-id'\n\ntype PropsWithCommonDTO<Props> = Props & CommonDTO\n\nexport abstract class Entity<Props> {\n private _id: UniqueEntityId\n protected props: PropsWithCommonDTO<Props>\n\n get id() {\n return this._id\n }\n\n set id(id: UniqueEntityId) {\n this._id = id\n }\n\n get createdAt() {\n return this.props.createdAt\n }\n\n set createdAt(date: Date) {\n this.props.createdAt = date\n }\n\n get updatedAt(): Date | undefined | null {\n return this.props.updatedAt\n }\n\n public touch() {\n this.props.updatedAt = new Date()\n }\n\n protected constructor(props: PropsWithCommonDTO<Props>, id?: UniqueEntityId) {\n this._id = id ?? new UniqueEntityId(id)\n this.props = props\n }\n\n public equals(entity: Entity<any>) {\n if (entity === this) {\n return true\n }\n\n if (entity.id === this._id) {\n return true\n }\n\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,yBAA2B;AAEpB,IAAMA,iBAAN,MAAMA;EAFb,OAEaA;;;EACHC;EAERC,YAAYD,OAAgB;AAC1B,SAAKA,QAAQA,aAASE,+BAAAA;EACxB;EAEAC,WAAW;AACT,WAAO,KAAKH;EACd;EAEAI,UAAU;AACR,WAAO,KAAKJ;EACd;EAEOK,OAAOC,IAAoB;AAChC,WAAOA,GAAGF,QAAO,MAAO,KAAKA,QAAO;EACtC;AACF;;;ACfO,IAAeG,SAAf,MAAeA;EAJtB,OAIsBA;;;EACZC;EACEC;EAEV,IAAIC,KAAK;AACP,WAAO,KAAKF;EACd;EAEA,IAAIE,GAAGA,IAAoB;AACzB,SAAKF,MAAME;EACb;EAEA,IAAIC,YAAY;AACd,WAAO,KAAKF,MAAME;EACpB;EAEA,IAAIA,UAAUC,MAAY;AACxB,SAAKH,MAAME,YAAYC;EACzB;EAEA,IAAIC,YAAqC;AACvC,WAAO,KAAKJ,MAAMI;EACpB;EAEOC,QAAQ;AACb,SAAKL,MAAMI,YAAY,oBAAIE,KAAAA;EAC7B;EAEA,YAAsBN,OAAkCC,IAAqB;AAC3E,SAAKF,MAAME,MAAM,IAAIM,eAAeN,EAAAA;AACpC,SAAKD,QAAQA;EACf;EAEOQ,OAAOC,QAAqB;AACjC,QAAIA,WAAW,MAAM;AACnB,aAAO;IACT;AAEA,QAAIA,OAAOR,OAAO,KAAKF,KAAK;AAC1B,aAAO;IACT;AAEA,WAAO;EACT;AACF;;;AF/CO,IAAeW,gBAAf,cAA4CC,OAAAA;EAFnD,OAEmDA;;;AAAe;","names":["UniqueEntityId","value","constructor","randomUUID","toString","toValue","equals","id","Entity","_id","props","id","createdAt","date","updatedAt","touch","Date","UniqueEntityId","equals","entity","AggregateRoot","Entity"]}
|