@invariant--labs/foundation 1.1.2 → 1.1.4

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.
Files changed (214) hide show
  1. package/dist/tsconfig.tsbuildinfo +1 -0
  2. package/package.json +108 -45
  3. package/.pnp.cjs +0 -22192
  4. package/.pnp.loader.mjs +0 -2126
  5. package/.yarnrc.yml +0 -1
  6. package/CHANGELOG.md +0 -527
  7. package/eslint.config.mjs +0 -52
  8. package/invariant.json +0 -22
  9. package/jest/jest.config.base.ts +0 -30
  10. package/jest/jest.spec.base.ts +0 -7
  11. package/jest.config.js +0 -49
  12. package/src/core/application/index.ts +0 -1
  13. package/src/core/application/persistence/index.ts +0 -3
  14. package/src/core/application/persistence/query-builder.ts +0 -2
  15. package/src/core/application/persistence/read-projection.ts +0 -2
  16. package/src/core/application/persistence/repository.ts +0 -23
  17. package/src/core/domain/entities/aggregate-root.ts +0 -34
  18. package/src/core/domain/entities/entity.spec.ts +0 -43
  19. package/src/core/domain/entities/entity.ts +0 -29
  20. package/src/core/domain/entities/identifier.spec.ts +0 -34
  21. package/src/core/domain/entities/identifier.ts +0 -16
  22. package/src/core/domain/entities/index.ts +0 -5
  23. package/src/core/domain/entities/projection.ts +0 -7
  24. package/src/core/domain/entities/unique-entity-id.ts +0 -9
  25. package/src/core/domain/events/domain-event.ts +0 -7
  26. package/src/core/domain/events/index.ts +0 -1
  27. package/src/core/domain/index.ts +0 -3
  28. package/src/core/domain/value-objects/index.ts +0 -2
  29. package/src/core/domain/value-objects/range.ts +0 -4
  30. package/src/core/domain/value-objects/value-object.spec.ts +0 -45
  31. package/src/core/domain/value-objects/value-object.ts +0 -17
  32. package/src/core/errors/command-failure.error.spec.ts +0 -30
  33. package/src/core/errors/command-failure.error.ts +0 -9
  34. package/src/core/errors/command-filter.error.ts +0 -3
  35. package/src/core/errors/detailed.error.ts +0 -25
  36. package/src/core/errors/domain.error.spec.ts +0 -27
  37. package/src/core/errors/domain.error.ts +0 -9
  38. package/src/core/errors/entity-not-found.error.spec.ts +0 -32
  39. package/src/core/errors/entity-not-found.error.ts +0 -9
  40. package/src/core/errors/fake-implementation.error.spec.ts +0 -27
  41. package/src/core/errors/fake-implementation.error.ts +0 -15
  42. package/src/core/errors/index.ts +0 -8
  43. package/src/core/errors/query-failure.error.ts +0 -8
  44. package/src/core/errors/too-many-results.error.ts +0 -3
  45. package/src/core/index.ts +0 -4
  46. package/src/core/infrastructure/config/config.provider.ts +0 -78
  47. package/src/core/infrastructure/config/config.service.ts +0 -25
  48. package/src/core/infrastructure/config/index.ts +0 -2
  49. package/src/core/infrastructure/messaging/fake/fake-messaging.service.ts +0 -17
  50. package/src/core/infrastructure/messaging/fake/fake-queue-manager.service.ts +0 -9
  51. package/src/core/infrastructure/messaging/fake/fake-queue-messaging.service.ts +0 -9
  52. package/src/core/infrastructure/messaging/fake/index.ts +0 -3
  53. package/src/core/infrastructure/messaging/index.ts +0 -6
  54. package/src/core/infrastructure/messaging/messaging.service.ts +0 -3
  55. package/src/core/infrastructure/messaging/queue-manager.service.ts +0 -6
  56. package/src/core/infrastructure/messaging/queue-messaging.service.ts +0 -3
  57. package/src/core/infrastructure/messaging/rabbitmq/index.ts +0 -2
  58. package/src/core/infrastructure/messaging/rabbitmq/rabbit-messaging.service.ts +0 -11
  59. package/src/core/infrastructure/messaging/rabbitmq/rabbit-queue-messaging.service.ts +0 -11
  60. package/src/core/infrastructure/messaging/types.ts +0 -28
  61. package/src/core/infrastructure/persistence/errors/index.ts +0 -2
  62. package/src/core/infrastructure/persistence/errors/model-to-entity-conversion.error.ts +0 -9
  63. package/src/core/infrastructure/persistence/errors/persistence.error.ts +0 -8
  64. package/src/core/infrastructure/persistence/in-memory/fake.repository.ts +0 -79
  65. package/src/core/infrastructure/persistence/in-memory/in-memory.query-builder.ts +0 -4
  66. package/src/core/infrastructure/persistence/in-memory/in-memory.repository.spec.ts +0 -50
  67. package/src/core/infrastructure/persistence/in-memory/in-memory.repository.ts +0 -81
  68. package/src/core/infrastructure/persistence/in-memory/index.ts +0 -3
  69. package/src/core/infrastructure/persistence/index.ts +0 -4
  70. package/src/core/infrastructure/persistence/read-side/in-memory.query-builder.ts +0 -4
  71. package/src/core/infrastructure/persistence/read-side/index.ts +0 -1
  72. package/src/core/infrastructure/persistence/read-side/knex/index.ts +0 -2
  73. package/src/core/infrastructure/persistence/read-side/knex/knex-types.definition.ts +0 -13
  74. package/src/core/infrastructure/persistence/read-side/knex/knex.query-builder.ts +0 -70
  75. package/src/core/infrastructure/persistence/read-side/knex-query-builder.ts +0 -70
  76. package/src/core/infrastructure/persistence/read-side/knex-types.definition.ts +0 -13
  77. package/src/core/infrastructure/persistence/write-side/aggregate-typeorm-repository.ts +0 -87
  78. package/src/core/infrastructure/persistence/write-side/entity-typeorm-repository.ts +0 -64
  79. package/src/core/infrastructure/persistence/write-side/in-memory.repository.ts +0 -82
  80. package/src/core/infrastructure/persistence/write-side/index.ts +0 -1
  81. package/src/core/infrastructure/persistence/write-side/model-attributes.ts +0 -4
  82. package/src/core/infrastructure/persistence/write-side/orm-embedded-mapper.ts +0 -11
  83. package/src/core/infrastructure/persistence/write-side/orm-mapper.ts +0 -11
  84. package/src/core/infrastructure/persistence/write-side/typeorm/aggregate-typeorm.repository.ts +0 -87
  85. package/src/core/infrastructure/persistence/write-side/typeorm/entity-typeorm.repository.ts +0 -64
  86. package/src/core/infrastructure/persistence/write-side/typeorm/index.ts +0 -5
  87. package/src/core/infrastructure/persistence/write-side/typeorm/model-attributes.ts +0 -4
  88. package/src/core/infrastructure/persistence/write-side/typeorm/orm-embedded.mapper.ts +0 -11
  89. package/src/core/infrastructure/persistence/write-side/typeorm/orm.mapper.ts +0 -11
  90. package/src/core/types/architecture-layer.ts +0 -52
  91. package/src/core/types/array-element.ts +0 -5
  92. package/src/core/types/index.ts +0 -2
  93. package/src/index.ts +0 -30
  94. package/src/modules/config/config.module.ts +0 -9
  95. package/src/modules/config/index.ts +0 -2
  96. package/src/modules/graphql/index.ts +0 -1
  97. package/src/modules/graphql/paginated-response.object-type.ts +0 -23
  98. package/src/modules/healthcheck/healthcheck-out.dto.ts +0 -43
  99. package/src/modules/healthcheck/index.ts +0 -1
  100. package/src/modules/knex/index.ts +0 -3
  101. package/src/modules/knex/knex-core.module.ts +0 -30
  102. package/src/modules/knex/knex.decorator.ts +0 -5
  103. package/src/modules/knex/knex.interface.ts +0 -12
  104. package/src/modules/knex/knex.module.ts +0 -14
  105. package/src/modules/knex/knex.token.ts +0 -2
  106. package/src/modules/logger/app-logger.ts +0 -28
  107. package/src/modules/logger/index.ts +0 -5
  108. package/src/modules/logger/log.ts +0 -26
  109. package/src/modules/logger/logger.module.ts +0 -47
  110. package/src/modules/logger/logger.service.ts +0 -131
  111. package/src/modules/logger/transports/console-color.transport.ts +0 -41
  112. package/src/modules/logger/transports/console-json.transport.ts +0 -23
  113. package/src/modules/logger/transports/console.transport.ts +0 -10
  114. package/src/modules/logger/transports/fake.transport.ts +0 -18
  115. package/src/modules/logger/transports/index.ts +0 -5
  116. package/src/modules/logger/transports/logger-transport.ts +0 -22
  117. package/src/modules/messaging/index.ts +0 -2
  118. package/src/modules/messaging/messaging.module.ts +0 -92
  119. package/src/modules/queue/default-queue-name.resolver.ts +0 -5
  120. package/src/modules/queue/index.ts +0 -3
  121. package/src/modules/queue/queue.module.ts +0 -73
  122. package/src/modules/queue/rabbit-queue-manager.service.ts +0 -67
  123. package/src/nestjs/errors/handlers/error-handler.ts +0 -38
  124. package/src/nestjs/errors/handlers/error-handler.type.ts +0 -23
  125. package/src/nestjs/errors/handlers/generic-error-handler.ts +0 -59
  126. package/src/nestjs/errors/handlers/handle-errors.decorator.ts +0 -43
  127. package/src/nestjs/errors/handlers/index.ts +0 -5
  128. package/src/nestjs/errors/handlers/validation-error-handler.ts +0 -46
  129. package/src/nestjs/errors/index.ts +0 -2
  130. package/src/nestjs/errors/parsers/axios-metadata.parser.ts +0 -21
  131. package/src/nestjs/errors/parsers/error-metadata.definition.ts +0 -1
  132. package/src/nestjs/errors/parsers/index.ts +0 -5
  133. package/src/nestjs/errors/parsers/knex-metadata.parser.ts +0 -18
  134. package/src/nestjs/errors/parsers/typeorm-metadata.parser.ts +0 -19
  135. package/src/nestjs/errors/parsers/workos-metadata.parser.ts +0 -17
  136. package/src/nestjs/http/decorators/index.ts +0 -1
  137. package/src/nestjs/http/decorators/log-app-ctx.decorator.ts +0 -32
  138. package/src/nestjs/http/dtos/date-range.dto.ts +0 -15
  139. package/src/nestjs/http/dtos/index.ts +0 -1
  140. package/src/nestjs/http/filters/all-exceptions.filter.ts +0 -92
  141. package/src/nestjs/http/filters/command-failure.filter.ts +0 -12
  142. package/src/nestjs/http/filters/index.ts +0 -4
  143. package/src/nestjs/http/filters/rpc-exceptions.filter.ts +0 -10
  144. package/src/nestjs/http/filters/too-many-results.filter.ts +0 -12
  145. package/src/nestjs/http/index.ts +0 -6
  146. package/src/nestjs/http/interceptors/index.ts +0 -2
  147. package/src/nestjs/http/interceptors/log-app-ctx.interceptor.ts +0 -109
  148. package/src/nestjs/http/interceptors/serialize-output.interceptor.ts +0 -19
  149. package/src/nestjs/http/middleware/http-logger.middleware.ts +0 -31
  150. package/src/nestjs/http/middleware/index.ts +0 -2
  151. package/src/nestjs/http/middleware/logger.middleware.ts +0 -21
  152. package/src/nestjs/http/swagger/index.ts +0 -1
  153. package/src/nestjs/http/swagger/swagger.ts +0 -44
  154. package/src/nestjs/index.ts +0 -2
  155. package/src/testing/command-bus.stub.ts +0 -33
  156. package/src/testing/event-bus.stub.ts +0 -56
  157. package/src/testing/event-publisher.stub.ts +0 -24
  158. package/src/testing/fake-logger.ts +0 -20
  159. package/src/testing/index.ts +0 -2
  160. package/src/testing/query-bus.stub.ts +0 -27
  161. package/src/testing/stub.spec.ts +0 -250
  162. package/src/testing/stub.ts +0 -170
  163. package/src/testing/stubs/command-bus.stub.ts +0 -33
  164. package/src/testing/stubs/event-bus.stub.ts +0 -56
  165. package/src/testing/stubs/event-publisher.stub.ts +0 -24
  166. package/src/testing/stubs/index.ts +0 -5
  167. package/src/testing/stubs/query-bus.stub.ts +0 -27
  168. package/src/testing/stubs/stub.ts +0 -170
  169. package/src/utils/array.spec.ts +0 -29
  170. package/src/utils/array.ts +0 -10
  171. package/src/utils/base64.spec.ts +0 -18
  172. package/src/utils/base64.ts +0 -6
  173. package/src/utils/collection.ts +0 -4
  174. package/src/utils/common.ts +0 -13
  175. package/src/utils/csv.ts +0 -49
  176. package/src/utils/date/date-range.ts +0 -4
  177. package/src/utils/date/date.spec.ts +0 -100
  178. package/src/utils/date/date.ts +0 -177
  179. package/src/utils/date/diff.spec.ts +0 -66
  180. package/src/utils/date/diffYear.spec.ts +0 -23
  181. package/src/utils/date/fillMissingRangeValues.spec.ts +0 -523
  182. package/src/utils/date/groubBy.spec.ts +0 -183
  183. package/src/utils/date/index.ts +0 -2
  184. package/src/utils/date/isSame.spec.ts +0 -111
  185. package/src/utils/file.spec.ts +0 -66
  186. package/src/utils/file.ts +0 -5
  187. package/src/utils/hash-key.ts +0 -23
  188. package/src/utils/index.ts +0 -14
  189. package/src/utils/invariant.ts +0 -3
  190. package/src/utils/iso-date.ts +0 -11
  191. package/src/utils/object.spec.ts +0 -18
  192. package/src/utils/object.ts +0 -6
  193. package/src/utils/paginated.ts +0 -36
  194. package/src/utils/string.spec.ts +0 -10
  195. package/src/utils/string.ts +0 -19
  196. package/src/utils/type.ts +0 -9
  197. package/src/utils/xml.ts +0 -6
  198. package/src/validation/ensure-array.decorator.ts +0 -5
  199. package/src/validation/index.ts +0 -7
  200. package/src/validation/is-iso-date.decorator.spec.ts +0 -29
  201. package/src/validation/is-iso-date.decorator.ts +0 -30
  202. package/src/validation/is-less-than-or-equal.decorator.spec.ts +0 -30
  203. package/src/validation/is-less-than-or-equal.decorator.ts +0 -52
  204. package/src/validation/is-less-than.decorator.spec.ts +0 -36
  205. package/src/validation/is-less-than.decorator.ts +0 -52
  206. package/src/validation/is-more-than-or-equal.decorator.spec.ts +0 -30
  207. package/src/validation/is-more-than-or-equal.decorator.ts +0 -52
  208. package/src/validation/is-more-than.decorator.spec.ts +0 -36
  209. package/src/validation/is-more-than.decorator.ts +0 -52
  210. package/src/validation/is-time-string.decorator.spec.ts +0 -35
  211. package/src/validation/is-time-string.decorator.ts +0 -29
  212. package/tsconfig.build.json +0 -6
  213. package/tsconfig.json +0 -34
  214. package/tsconfig.spec.json +0 -14
@@ -1,52 +0,0 @@
1
- import {
2
- registerDecorator,
3
- ValidationArguments,
4
- ValidationOptions,
5
- ValidatorConstraint,
6
- ValidatorConstraintInterface,
7
- } from "class-validator";
8
-
9
- import { isValidISODate } from "../utils";
10
-
11
- export function IsMoreThanOrEqual(property: string, validationOptions?: ValidationOptions) {
12
- return function (object: object, propertyName: string) {
13
- registerDecorator({
14
- target: object.constructor,
15
- propertyName,
16
- constraints: [property],
17
- options: validationOptions,
18
- validator: IsMoreThanOrEqualConstraint,
19
- });
20
- };
21
- }
22
-
23
- @ValidatorConstraint({ name: "isMoreThanOrEqual" })
24
- class IsMoreThanOrEqualConstraint implements ValidatorConstraintInterface {
25
- validate(value: unknown, args: ValidationArguments) {
26
- const relatedPropertyName = args.constraints[0] as string;
27
- const relatedValue = (args.object as Record<string, unknown>)[relatedPropertyName];
28
-
29
- if (!relatedValue) {
30
- return true;
31
- }
32
-
33
- if (typeof value === "number" && typeof relatedValue === "number") {
34
- return value >= relatedValue;
35
- }
36
-
37
- if (value instanceof Date && relatedValue instanceof Date) {
38
- return +value >= +relatedValue;
39
- }
40
-
41
- if (typeof value === "string" && typeof relatedValue === "string" && isValidISODate(value) && isValidISODate(relatedValue)) {
42
- return +new Date(value) >= +new Date(relatedValue);
43
- }
44
-
45
- throw new Error("Unsupported comparison");
46
- }
47
-
48
- defaultMessage(args: ValidationArguments) {
49
- const relatedPropertyName = args.constraints[0] as string;
50
- return `${args.property} must be more than or equal ${relatedPropertyName}`;
51
- }
52
- }
@@ -1,36 +0,0 @@
1
- import { describe, it, expect } from "@jest/globals";
2
- import { validate } from "class-validator";
3
-
4
- import { IsMoreThan } from "./is-more-than.decorator";
5
-
6
- class Dto {
7
- min: number;
8
- @IsMoreThan("min")
9
- max: number;
10
- }
11
-
12
- describe("IsMoreThan", () => {
13
- it("should pass when value is greater", async () => {
14
- const dto = Object.assign(new Dto(), { min: 5, max: 10 });
15
- const errors = await validate(dto);
16
- expect(errors).toHaveLength(0);
17
- });
18
-
19
- it("should fail when value is equal", async () => {
20
- const dto = Object.assign(new Dto(), { min: 5, max: 5 });
21
- const errors = await validate(dto);
22
- expect(errors.length).toBeGreaterThan(0);
23
- });
24
-
25
- it("should fail when value is less", async () => {
26
- const dto = Object.assign(new Dto(), { min: 10, max: 5 });
27
- const errors = await validate(dto);
28
- expect(errors.length).toBeGreaterThan(0);
29
- });
30
-
31
- it("should pass when related value is falsy", async () => {
32
- const dto = Object.assign(new Dto(), { min: 0, max: 5 });
33
- const errors = await validate(dto);
34
- expect(errors).toHaveLength(0);
35
- });
36
- });
@@ -1,52 +0,0 @@
1
- import {
2
- registerDecorator,
3
- ValidationArguments,
4
- ValidationOptions,
5
- ValidatorConstraint,
6
- ValidatorConstraintInterface,
7
- } from "class-validator";
8
-
9
- import { isValidISODate } from "../utils";
10
-
11
- export function IsMoreThan(property: string, validationOptions?: ValidationOptions) {
12
- return function (object: object, propertyName: string) {
13
- registerDecorator({
14
- target: object.constructor,
15
- propertyName,
16
- constraints: [property],
17
- options: validationOptions,
18
- validator: IsMoreThanConstraint,
19
- });
20
- };
21
- }
22
-
23
- @ValidatorConstraint({ name: "isMoreThan" })
24
- class IsMoreThanConstraint implements ValidatorConstraintInterface {
25
- validate(value: unknown, args: ValidationArguments) {
26
- const relatedPropertyName = args.constraints[0] as string;
27
- const relatedValue = (args.object as Record<string, unknown>)[relatedPropertyName];
28
-
29
- if (!relatedValue) {
30
- return true;
31
- }
32
-
33
- if (typeof value === "number" && typeof relatedValue === "number") {
34
- return value > relatedValue;
35
- }
36
-
37
- if (value instanceof Date && relatedValue instanceof Date) {
38
- return +value > +relatedValue;
39
- }
40
-
41
- if (typeof value === "string" && typeof relatedValue === "string" && isValidISODate(value) && isValidISODate(relatedValue)) {
42
- return +new Date(value) > +new Date(relatedValue);
43
- }
44
-
45
- throw new Error("Unsupported comparison");
46
- }
47
-
48
- defaultMessage(args: ValidationArguments) {
49
- const relatedPropertyName = args.constraints[0] as string;
50
- return `${args.property} must be more than ${relatedPropertyName}`;
51
- }
52
- }
@@ -1,35 +0,0 @@
1
- import { describe, it, expect } from "@jest/globals";
2
- import { validate } from "class-validator";
3
-
4
- import { IsTimeString } from "./is-time-string.decorator";
5
-
6
- class Dto {
7
- @IsTimeString()
8
- time: unknown;
9
- }
10
-
11
- describe("IsTimeString", () => {
12
- it("should accept HH:mm:ss format", async () => {
13
- const dto = Object.assign(new Dto(), { time: "14:30:00" });
14
- const errors = await validate(dto);
15
- expect(errors).toHaveLength(0);
16
- });
17
-
18
- it("should accept compact HHmmss format", async () => {
19
- const dto = Object.assign(new Dto(), { time: "143000" });
20
- const errors = await validate(dto);
21
- expect(errors).toHaveLength(0);
22
- });
23
-
24
- it("should reject invalid time strings", async () => {
25
- const dto = Object.assign(new Dto(), { time: "25:00:00" });
26
- const errors = await validate(dto);
27
- expect(errors.length).toBeGreaterThan(0);
28
- });
29
-
30
- it("should reject non-string values", async () => {
31
- const dto = Object.assign(new Dto(), { time: 1430 });
32
- const errors = await validate(dto);
33
- expect(errors.length).toBeGreaterThan(0);
34
- });
35
- });
@@ -1,29 +0,0 @@
1
- import {
2
- registerDecorator,
3
- ValidationArguments,
4
- ValidationOptions,
5
- ValidatorConstraint,
6
- ValidatorConstraintInterface,
7
- } from "class-validator";
8
-
9
- export function IsTimeString(validationOptions?: ValidationOptions) {
10
- return function (object: object, propertyName: string) {
11
- registerDecorator({
12
- target: object.constructor,
13
- propertyName,
14
- options: validationOptions,
15
- validator: IsTimeStringConstraint,
16
- });
17
- };
18
- }
19
-
20
- @ValidatorConstraint({ name: "isTimeString" })
21
- class IsTimeStringConstraint implements ValidatorConstraintInterface {
22
- validate(value: unknown) {
23
- return typeof value === "string" && /^(([01]\d|2[0-3]):?[0-5]\d:?[0-5]\d+)$/.test(value);
24
- }
25
-
26
- defaultMessage(args: ValidationArguments) {
27
- return `${args.property} must be in HH:mm:ss format`;
28
- }
29
- }
@@ -1,6 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["."],
4
- "exclude": ["node_modules", "test", "dist", "jest.config.ts", "jest.setup.ts", "**/*spec.ts"]
5
- }
6
-
package/tsconfig.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "baseUrl": "./",
6
- "module": "CommonJS",
7
- "target": "ES2022",
8
- "moduleResolution": "node",
9
- "outDir": "./dist",
10
- "removeComments": true,
11
- "emitDecoratorMetadata": true,
12
- "experimentalDecorators": true,
13
- "allowSyntheticDefaultImports": true,
14
- "sourceMap": true,
15
- "incremental": true,
16
- "skipLibCheck": true,
17
- "skipDefaultLibCheck": true,
18
- "noImplicitAny": true,
19
- "strictBindCallApply": false,
20
- "forceConsistentCasingInFileNames": false,
21
- "noFallthroughCasesInSwitch": false,
22
- "esModuleInterop": true,
23
- "importHelpers": true,
24
- "resolveJsonModule": true,
25
- "strict": true,
26
- "strictNullChecks": true,
27
- "strictPropertyInitialization": false,
28
- "allowImportingTsExtensions": false,
29
- "paths": {
30
- "@invariant-labs/foundation": ["./src/index"]
31
- }
32
- },
33
- "exclude": ["node_modules"]
34
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "types": ["jest", "node"],
5
- "allowJs": true,
6
- "isolatedModules": true
7
- },
8
- "include": [
9
- "jest.config.ts",
10
- "**/*.spec.ts",
11
- "**/*.integration.ts",
12
- "**/*.e2e.ts"
13
- ]
14
- }