@bool-ts/core 1.9.0 → 1.9.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.
Files changed (42) hide show
  1. package/__test/_constants.ts +1 -0
  2. package/__test/container.ts +28 -0
  3. package/__test/controller.ts +1 -1
  4. package/__test/{module.ts → firstModule.ts} +4 -6
  5. package/__test/index.ts +2 -4
  6. package/__test/secondModule.ts +29 -0
  7. package/__test/tsconfig.json +1 -1
  8. package/__test/webSocket.ts +1 -1
  9. package/dist/decorators/arguments.d.ts +6 -1
  10. package/dist/decorators/container.d.ts +29 -0
  11. package/dist/decorators/http.d.ts +2 -0
  12. package/dist/decorators/index.d.ts +4 -2
  13. package/dist/decorators/module.d.ts +6 -2
  14. package/dist/decorators/webSocket.d.ts +2 -0
  15. package/dist/entities/httpRoute.d.ts +6 -0
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +5 -5
  18. package/dist/interfaces/context.d.ts +8 -2
  19. package/dist/interfaces/index.d.ts +1 -1
  20. package/dist/keys/index.d.ts +3 -0
  21. package/dist/producers/context.d.ts +13 -0
  22. package/dist/{hooks → producers}/factory.d.ts +5 -2
  23. package/dist/{hooks → producers}/injector.d.ts +7 -1
  24. package/package.json +3 -3
  25. package/src/decorators/arguments.ts +126 -77
  26. package/src/decorators/container.ts +94 -0
  27. package/src/decorators/controller.ts +1 -1
  28. package/src/decorators/http.ts +9 -2
  29. package/src/decorators/index.ts +4 -1
  30. package/src/decorators/module.ts +27 -4
  31. package/src/decorators/webSocket.ts +6 -2
  32. package/src/entities/httpRoute.ts +2 -0
  33. package/src/index.ts +1 -1
  34. package/src/interfaces/context.ts +9 -2
  35. package/src/interfaces/index.ts +1 -1
  36. package/src/keys/index.ts +3 -0
  37. package/src/producers/context.ts +63 -0
  38. package/src/producers/factory.ts +2013 -0
  39. package/src/{hooks → producers}/injector.ts +41 -6
  40. package/src/hooks/factory.ts +0 -1701
  41. /package/dist/{hooks → producers}/index.d.ts +0 -0
  42. /package/src/{hooks → producers}/index.ts +0 -0
package/src/keys/index.ts CHANGED
@@ -9,6 +9,7 @@ export const injectKey = Symbol("__bool:inject__");
9
9
  export const injectableKey = Symbol("__bool:injectable__");
10
10
  export const middlewareKey = Symbol("__bool:middleware__");
11
11
  export const moduleKey = Symbol("__bool:module__");
12
+ export const containerKey = Symbol("__bool:container__");
12
13
  export const zodSchemaKey = Symbol("__bool:zodSchema__");
13
14
  export const webSocketKey = Symbol("__bool:webSocket__");
14
15
  export const webSocketEventKey = Symbol("__bool:webSocket:event__");
@@ -31,3 +32,5 @@ export const responseHeadersArgsKey = Symbol("__bool:httpArguments:responseHeade
31
32
  export const contextArgsKey = Symbol("__bool:httpArguments:context__");
32
33
  export const routeModelArgsKey = Symbol("__bool:httpArguments:routeModel__");
33
34
  export const responseBodyArgsKey = Symbol("__bool:httpArguments:responseBody__");
35
+ export const responseStatusArgsKey = Symbol("__bool:httpArguments:responseStatus__");
36
+ export const responseStatusTextArgsKey = Symbol("__bool:httpArguments:responseStatusText__");
@@ -0,0 +1,63 @@
1
+ import type { IContext, TContextOptions } from "../interfaces";
2
+
3
+ export class Context implements IContext {
4
+ private readonly _staticMap = new Map<symbol, any>();
5
+ private readonly _dynamicMap = new Map<symbol, any>();
6
+
7
+ private _options?: TContextOptions = undefined;
8
+
9
+ constructor(...contexts: Array<Context>) {
10
+ contexts.forEach((context) => {
11
+ context.staticEntries.forEach(([key, value]) =>
12
+ this.set(key, value, { isStatic: true, isPassthrough: true })
13
+ );
14
+ context.dynamicEntries.forEach(([key, value]) =>
15
+ this.set(key, value, { isStatic: false })
16
+ );
17
+ });
18
+ }
19
+
20
+ get<T = unknown>(key: symbol, options?: TContextOptions) {
21
+ const temporaryOptions = options || this._options;
22
+
23
+ return !temporaryOptions?.isStatic
24
+ ? (this._dynamicMap.get(key) as T)
25
+ : (this._staticMap.get(key) as T);
26
+ }
27
+
28
+ has(key: symbol, options?: TContextOptions) {
29
+ const temporaryOptions = options || this._options;
30
+
31
+ return !temporaryOptions?.isStatic ? this._dynamicMap.has(key) : this._staticMap.has(key);
32
+ }
33
+
34
+ set(key: symbol, value: any, options?: TContextOptions) {
35
+ const temporaryOptions = options || this._options;
36
+
37
+ if (!temporaryOptions?.isStatic) {
38
+ this._dynamicMap.set(key, value);
39
+ } else {
40
+ if (!this._staticMap.has(key)) {
41
+ this._staticMap.set(key, value);
42
+ } else if (!temporaryOptions.isPassthrough) {
43
+ throw Error(`${String(key)} already exists in context static collection.`);
44
+ }
45
+ }
46
+
47
+ return this;
48
+ }
49
+
50
+ setOptions(options: TContextOptions) {
51
+ this._options = options;
52
+
53
+ return this;
54
+ }
55
+
56
+ get staticEntries() {
57
+ return [...this._staticMap.entries()];
58
+ }
59
+
60
+ get dynamicEntries() {
61
+ return [...this._dynamicMap.entries()];
62
+ }
63
+ }