fragment-ts 1.0.23 → 1.0.24

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 (49) hide show
  1. package/dist/cli/commands/init.command.js +1 -1
  2. package/dist/core/decorators/application.decorator.d.ts +1 -6
  3. package/dist/core/decorators/application.decorator.d.ts.map +1 -1
  4. package/dist/core/decorators/application.decorator.js +2 -7
  5. package/dist/core/decorators/application.decorator.js.map +1 -1
  6. package/dist/core/decorators/auto-configuration.decorator.d.ts.map +1 -1
  7. package/dist/core/decorators/auto-configuration.decorator.js +5 -4
  8. package/dist/core/decorators/auto-configuration.decorator.js.map +1 -1
  9. package/dist/core/decorators/conditional.decorators.d.ts +0 -4
  10. package/dist/core/decorators/conditional.decorators.d.ts.map +1 -1
  11. package/dist/core/decorators/conditional.decorators.js +0 -32
  12. package/dist/core/decorators/conditional.decorators.js.map +1 -1
  13. package/dist/core/decorators/controller.decorator.d.ts.map +1 -1
  14. package/dist/core/decorators/controller.decorator.js +2 -1
  15. package/dist/core/decorators/controller.decorator.js.map +1 -1
  16. package/dist/core/decorators/http.decorators.d.ts +0 -1
  17. package/dist/core/decorators/http.decorators.d.ts.map +1 -1
  18. package/dist/core/decorators/http.decorators.js +10 -10
  19. package/dist/core/decorators/http.decorators.js.map +1 -1
  20. package/dist/core/decorators/injectable.decorator.d.ts +0 -3
  21. package/dist/core/decorators/injectable.decorator.d.ts.map +1 -1
  22. package/dist/core/decorators/injectable.decorator.js +5 -12
  23. package/dist/core/decorators/injectable.decorator.js.map +1 -1
  24. package/dist/core/decorators/injection.decorators.d.ts +37 -2
  25. package/dist/core/decorators/injection.decorators.d.ts.map +1 -1
  26. package/dist/core/decorators/injection.decorators.js +75 -43
  27. package/dist/core/decorators/injection.decorators.js.map +1 -1
  28. package/dist/core/decorators/repository.decorator.d.ts.map +1 -1
  29. package/dist/core/decorators/repository.decorator.js +5 -4
  30. package/dist/core/decorators/repository.decorator.js.map +1 -1
  31. package/dist/core/decorators/service.decorator.d.ts.map +1 -1
  32. package/dist/core/decorators/service.decorator.js +5 -4
  33. package/dist/core/decorators/service.decorator.js.map +1 -1
  34. package/dist/core/metadata/metadata-storage.d.ts +20 -9
  35. package/dist/core/metadata/metadata-storage.d.ts.map +1 -1
  36. package/dist/core/metadata/metadata-storage.js +10 -58
  37. package/dist/core/metadata/metadata-storage.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/cli/commands/init.command.ts +1 -1
  40. package/src/core/decorators/application.decorator.ts +3 -13
  41. package/src/core/decorators/auto-configuration.decorator.ts +10 -8
  42. package/src/core/decorators/conditional.decorators.ts +1 -37
  43. package/src/core/decorators/controller.decorator.ts +3 -1
  44. package/src/core/decorators/http.decorators.ts +32 -11
  45. package/src/core/decorators/injectable.decorator.ts +8 -15
  46. package/src/core/decorators/injection.decorators.ts +103 -50
  47. package/src/core/decorators/repository.decorator.ts +10 -8
  48. package/src/core/decorators/service.decorator.ts +10 -8
  49. package/src/core/metadata/metadata-storage.ts +43 -75
@@ -1,15 +1,17 @@
1
- import { Injectable } from "./injectable.decorator";
2
- import { METADATA_KEYS } from "../metadata/metadata-keys";
3
- import { MetadataStorage } from "../metadata/metadata-storage";
1
+ import { Injectable } from './injectable.decorator';
2
+ import { METADATA_KEYS } from '../metadata/metadata-keys';
3
+ import { MetadataStorage } from '../metadata/metadata-storage';
4
4
 
5
5
  export function Service(): ClassDecorator {
6
6
  return (target: any) => {
7
- Injectable("singleton")(target);
7
+ Injectable('singleton')(target);
8
8
  Reflect.defineMetadata(METADATA_KEYS.SERVICE, true, target);
9
- MetadataStorage.getInstance().addClass({
9
+
10
+ const storage = MetadataStorage.getInstance();
11
+ storage.addClass({
10
12
  target,
11
- type: "service",
12
- scope: "singleton",
13
+ type: 'service',
14
+ scope: 'singleton'
13
15
  });
14
16
  };
15
- }
17
+ }
@@ -1,21 +1,39 @@
1
- import {
2
- ClassMetadata,
3
- MethodMetadata,
4
- ParamMetadata,
5
- } from "../types/decoration.types";
6
-
7
- /**
8
- * Central storage for all metadata: classes, methods, parameters
9
- */
1
+ import { METADATA_KEYS } from "./metadata-keys";
2
+
3
+ export interface ClassMetadata {
4
+ target: any;
5
+ type:
6
+ | "injectable"
7
+ | "service"
8
+ | "controller"
9
+ | "repository"
10
+ | "auto-configuration";
11
+ scope?: "singleton" | "request" | "transient";
12
+ path?: string;
13
+ }
14
+
15
+ export interface MethodMetadata {
16
+ target: any;
17
+ propertyKey: string;
18
+ method: string;
19
+ path: string;
20
+ paramMetadata: ParamMetadata[];
21
+ }
22
+
23
+ export interface ParamMetadata {
24
+ target: any;
25
+ propertyKey: string;
26
+ index: number;
27
+ type: "body" | "param" | "query" | "header" | "req" | "res";
28
+ paramName?: string;
29
+ }
30
+
10
31
  export class MetadataStorage {
11
32
  private static instance: MetadataStorage;
12
-
13
- // Maps for storing metadata
14
- private classes: Map<Function, ClassMetadata> = new Map();
33
+ private classes: Map<any, ClassMetadata> = new Map();
15
34
  private methods: Map<string, MethodMetadata> = new Map();
16
35
  private params: Map<string, ParamMetadata[]> = new Map();
17
36
 
18
- // Singleton instance
19
37
  static getInstance(): MetadataStorage {
20
38
  if (!MetadataStorage.instance) {
21
39
  MetadataStorage.instance = new MetadataStorage();
@@ -23,16 +41,11 @@ export class MetadataStorage {
23
41
  return MetadataStorage.instance;
24
42
  }
25
43
 
26
- // ----- Classes -----
27
44
  addClass(metadata: ClassMetadata): void {
28
- if (!metadata?.target) return;
29
- if (!this.classes.has(metadata.target)) {
30
- this.classes.set(metadata.target, metadata);
31
- }
45
+ this.classes.set(metadata.target, metadata);
32
46
  }
33
47
 
34
48
  getClass(target: any): ClassMetadata | undefined {
35
- if (!target) return undefined;
36
49
  return this.classes.get(target);
37
50
  }
38
51
 
@@ -40,35 +53,20 @@ export class MetadataStorage {
40
53
  return Array.from(this.classes.values());
41
54
  }
42
55
 
43
- hasClass(target: any): boolean {
44
- return !!target && this.classes.has(target);
45
- }
46
-
47
- // ----- Methods -----
48
- private getMethodKey(target: Function, propertyKey: string): string {
49
- return `${target.name}_${propertyKey}`;
50
- }
51
-
52
56
  addMethod(metadata: MethodMetadata): void {
53
- if (!metadata?.target || !metadata.propertyKey) return;
54
-
55
- const targetForKey = metadata.target.prototype || metadata.target;
56
- const key = this.getMethodKey(metadata.target, metadata.propertyKey);
57
+ const key = `${metadata.target.name}.${metadata.propertyKey}`;
57
58
 
58
- // Attach existing params for this method
59
59
  const existingParams = this.getParams(
60
- targetForKey,
60
+ metadata.target,
61
61
  metadata.propertyKey,
62
- ).sort((a, b) => a.index - b.index);
63
-
64
- metadata.paramMetadata = existingParams;
62
+ );
63
+ metadata.paramMetadata = existingParams.sort((a, b) => a.index - b.index);
65
64
 
66
65
  this.methods.set(key, metadata);
67
66
  }
68
67
 
69
68
  getMethod(target: any, propertyKey: string): MethodMetadata | undefined {
70
- if (!target || !propertyKey) return undefined;
71
- const key = this.getMethodKey(target.constructor || target, propertyKey);
69
+ const key = `${target.name}.${propertyKey}`;
72
70
  return this.methods.get(key);
73
71
  }
74
72
 
@@ -76,48 +74,18 @@ export class MetadataStorage {
76
74
  return Array.from(this.methods.values());
77
75
  }
78
76
 
79
- hasMethod(target: any, propertyKey: string): boolean {
80
- if (!target || !propertyKey) return false;
81
- const key = this.getMethodKey(target.constructor || target, propertyKey);
82
- return this.methods.has(key);
83
- }
84
-
85
- // ----- Params -----
86
- private getParamKey(target: any, propertyKey: string): string {
87
- return `${target.constructor.name}_${propertyKey}`;
88
- }
89
-
90
77
  addParam(metadata: ParamMetadata): void {
91
- if (!metadata?.target || !metadata.propertyKey) return;
92
-
93
- const key = this.getParamKey(metadata.target, metadata.propertyKey);
78
+ const key = `${metadata.target.constructor.name}.${metadata.propertyKey}`;
94
79
  const existing = this.params.get(key) || [];
95
-
96
- // Deduplicate by propertyKey + index
97
- if (
98
- !existing.some(
99
- (p) =>
100
- p.index === metadata.index && p.propertyKey === metadata.propertyKey,
101
- )
102
- ) {
103
- existing.push(metadata);
104
- }
105
-
80
+ existing.push(metadata);
106
81
  this.params.set(key, existing);
107
82
  }
108
83
 
109
84
  getParams(target: any, propertyKey: string): ParamMetadata[] {
110
- if (!target || !propertyKey) return [];
111
- const key = this.getParamKey(target, propertyKey);
112
- return this.params.get(key) || [];
113
- }
85
+ const targetName = target.name || target.constructor?.name;
86
+ if (!targetName) return [];
114
87
 
115
- hasParam(target: any, propertyKey: string, index?: number): boolean {
116
- if (!target || !propertyKey) return false;
117
- const key = this.getParamKey(target, propertyKey);
118
- const existing = this.params.get(key) || [];
119
- return index !== undefined
120
- ? existing.some((p) => p.index === index)
121
- : existing.length > 0;
88
+ const key = `${targetName}.${propertyKey}`;
89
+ return this.params.get(key) || [];
122
90
  }
123
91
  }