class-resolver 4.0.1 → 4.0.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/README.md CHANGED
@@ -643,15 +643,19 @@ Version 2.0.0 introduces generic type support for better type safety. This chang
643
643
  ## Contributing
644
644
 
645
645
  ```bash
646
- $ npm install
646
+ $ pnpm install
647
647
  $ git checkout -b YOUR_TOPIC_BRANCH
648
- $ npm test
649
- $ npm run build
648
+ $ pnpm run lint
649
+ $ pnpm run typecheck
650
+ $ pnpm test
651
+ $ pnpm run build
650
652
  $ git add ./
651
- $ git commit -m "YOUR UPDATE DESCRIPTION"
653
+ $ git commit -m "feat: YOUR UPDATE DESCRIPTION"
652
654
  $ git push YOUR_ORIGIN YOUR_TOPIC_BRANCH
653
655
  ```
654
656
 
657
+ Commit messages must follow [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `chore:`, ...). Releases are automated: merging to `main` runs semantic-release on CircleCI, which picks the next version from the commits, pushes the `v*` tag, publishes to npm and creates the GitHub Release. Do not bump `version` in `package.json` by hand.
658
+
655
659
  ## License
656
660
 
657
661
  MIT
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Interface for async resolver targets
3
+ * Handle method returns a Promise
4
+ */
5
+ declare interface AsyncResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> extends SupportsType<TType> {
6
+ /**
7
+ * Handles the request asynchronously
8
+ * @param args Arguments needed for processing
9
+ * @returns Promise with processing result
10
+ */
11
+ handle(...args: TArgs): Promise<TReturn>;
12
+ }
13
+
14
+ /**
15
+ * Interface for prioritized handlers
16
+ * Higher priority values are executed first
17
+ */
18
+ declare interface HasPriority {
19
+ /**
20
+ * Priority for this handler (higher values execute first)
21
+ * Default is 0 if not specified
22
+ */
23
+ priority?: number;
24
+ }
25
+
26
+ declare namespace interfaces {
27
+ export interface ResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> {
28
+ supports(type: TType): boolean;
29
+ handle(...args: TArgs): TReturn;
30
+ }
31
+ export interface PrioritizedResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> extends ResolveTarget<TArgs, TReturn, TType> {
32
+ priority?: number;
33
+ }
34
+ export interface AsyncResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> {
35
+ supports(type: TType): boolean;
36
+ handle(...args: TArgs): Promise<TReturn>;
37
+ }
38
+ export interface PrioritizedAsyncResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> extends AsyncResolveTarget<TArgs, TReturn, TType> {
39
+ priority?: number;
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Interface for async resolver targets with priority support
45
+ * Higher priority values are executed first
46
+ */
47
+ declare interface PrioritizedAsyncResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> extends AsyncResolveTarget<TArgs, TReturn, TType>, HasPriority {
48
+ }
49
+
50
+ /**
51
+ * Interface for resolver targets with priority support
52
+ * Higher priority values are executed first
53
+ */
54
+ declare interface PrioritizedResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> extends ResolveTarget<TArgs, TReturn, TType>, HasPriority {
55
+ }
56
+
57
+ /**
58
+ * Resolver class implementing the Chain of Responsibility pattern
59
+ * Resolves handlers for specific types
60
+ */
61
+ declare class Resolver<TBase extends ResolveTarget<any[], any, any> = ResolveTarget<any[], any, any>, TType = string> {
62
+ /**
63
+ * Array of registered resolver targets
64
+ * @private
65
+ */
66
+ private updaters;
67
+ /**
68
+ * Fallback handler function
69
+ * @private
70
+ */
71
+ private fallbackHandler?;
72
+ /**
73
+ * Initializes the resolver
74
+ * @param args Initial resolver targets
75
+ */
76
+ constructor(...args: TBase[]);
77
+ /**
78
+ * Processes an array of arguments
79
+ * @param args Array of resolver targets
80
+ * @returns Processed array
81
+ * @private
82
+ */
83
+ private getArgs;
84
+ /**
85
+ * Sets resolver targets
86
+ * @param updaters Array of resolver targets
87
+ */
88
+ set(updaters: TBase[]): void;
89
+ /**
90
+ * Sets resolver targets (variadic version)
91
+ * @param args Resolver targets
92
+ */
93
+ setUpdaters(...args: TBase[]): void;
94
+ /**
95
+ * Adds a resolver target
96
+ * @param updater Resolver target to add
97
+ */
98
+ addUpdater(updater: TBase): this;
99
+ /**
100
+ * Sets a fallback handler for unsupported types
101
+ * @param handler Fallback handler function
102
+ * @returns This resolver instance for method chaining
103
+ */
104
+ setFallbackHandler(handler: (...args: Parameters<TBase['handle']>) => ReturnType<TBase['handle']>): this;
105
+ /**
106
+ * Gets the priority of a handler
107
+ * @param handler The handler to get priority for
108
+ * @returns Priority value (0 if not defined)
109
+ * @private
110
+ */
111
+ private getPriority;
112
+ /**
113
+ * Sorts handlers by priority (highest first), maintaining registration order for equal priorities
114
+ * @param handlers Array of handlers to sort
115
+ * @returns Sorted array of handlers
116
+ * @private
117
+ */
118
+ private sortByPriority;
119
+ /**
120
+ * Resolves a resolver target for the specified type
121
+ * @param type Type to resolve
122
+ * @returns Resolved resolver target
123
+ * @throws {Error} When no resolver targets are registered
124
+ * @throws {Error} When no resolver target supporting the specified type is found and no fallback is set
125
+ */
126
+ resolve(type: TType): TBase;
127
+ /**
128
+ * Resolves all resolver targets for the specified type
129
+ * @param type Type to resolve
130
+ * @returns Array of all matching resolver targets sorted by priority (highest first).
131
+ * Returns an empty array if no handlers match and no fallback is set.
132
+ * Note: Unlike resolve(), this method does not throw when no handlers match.
133
+ * @throws {Error} When no resolver targets are registered
134
+ */
135
+ resolveAll(type: TType): TBase[];
136
+ /**
137
+ * Executes all matching handlers for the specified type
138
+ * @param type Type to resolve
139
+ * @param args Arguments to pass to the handlers
140
+ * @returns Array of results from all matching handlers
141
+ * @throws {Error} When no resolver targets are registered
142
+ */
143
+ handleAll(type: TType, ...args: Parameters<TBase['handle']>): ReturnType<TBase['handle']>[];
144
+ /**
145
+ * Executes all matching async handlers in parallel for the specified type
146
+ * @param type Type to resolve
147
+ * @param args Arguments to pass to the handlers
148
+ * @returns Promise that resolves to array of results from all matching handlers
149
+ * @throws {Error} When no resolver targets are registered
150
+ */
151
+ handleAllAsync(type: TType, ...args: Parameters<TBase['handle']>): Promise<Awaited<ReturnType<TBase['handle']>>[]>;
152
+ /**
153
+ * Executes all matching async handlers sequentially for the specified type
154
+ * Stops on first error
155
+ * @param type Type to resolve
156
+ * @param args Arguments to pass to the handlers
157
+ * @returns Promise that resolves to array of results from all matching handlers
158
+ * @throws {Error} When no resolver targets are registered
159
+ * @throws {Error} When any handler throws an error
160
+ */
161
+ handleAllSequential(type: TType, ...args: Parameters<TBase['handle']>): Promise<Awaited<ReturnType<TBase['handle']>>[]>;
162
+ }
163
+
164
+
165
+ /**
166
+ * Interface that classes which are targets for the resolver should implement
167
+ */
168
+ declare interface ResolveTarget<TArgs extends any[] = any[], TReturn = any, TType = string> extends SupportsType<TType> {
169
+ /**
170
+ * Handles the request
171
+ * @param args Arguments needed for processing
172
+ * @returns Processing result
173
+ */
174
+ handle(...args: TArgs): TReturn;
175
+ }
176
+
177
+ /**
178
+ * Base interface for type matching
179
+ * Extracted to reduce code duplication across sync and async targets
180
+ */
181
+ declare interface SupportsType<TType = string> {
182
+ /**
183
+ * Determines whether the specified type is supported
184
+ * @param type The type to check for support
185
+ * @returns true if supported, false otherwise
186
+ */
187
+ supports(type: TType): boolean;
188
+ }
189
+
190
+ declare namespace Resolver {
191
+ export { AsyncResolveTarget, HasPriority, interfaces, PrioritizedAsyncResolveTarget, PrioritizedResolveTarget, ResolveTarget, SupportsType };
192
+ }
193
+
194
+ export = Resolver;
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "class-resolver",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Simple class resolver.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
8
- "types": "dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
10
  "import": {
12
- "types": "./dist/index.d.ts",
11
+ "types": "./dist/index.d.mts",
13
12
  "default": "./dist/index.mjs"
14
13
  },
15
14
  "require": {
16
- "types": "./dist/index.d.ts",
15
+ "types": "./dist/index.d.cts",
17
16
  "default": "./dist/index.cjs"
18
17
  }
19
18
  }
@@ -22,7 +21,7 @@
22
21
  "dist"
23
22
  ],
24
23
  "scripts": {
25
- "build": "vite build",
24
+ "build": "vite build && node scripts/emit-cts-types.js",
26
25
  "verify-build": "node scripts/verify-build.js",
27
26
  "test": "vitest run",
28
27
  "test:watch": "vitest",
@@ -31,6 +30,7 @@
31
30
  "lint": "biome check .",
32
31
  "lint:fix": "biome check --write .",
33
32
  "format": "biome format --write .",
33
+ "typecheck": "tsc --noEmit",
34
34
  "prepublishOnly": "npm run build",
35
35
  "release": "np"
36
36
  },
@@ -44,23 +44,28 @@
44
44
  "devDependencies": {
45
45
  "@biomejs/biome": "^1.9.4",
46
46
  "@types/node": "^22.0.0",
47
- "@vitest/coverage-v8": "^4.0.16",
48
- "@vitest/ui": "^4.0.16",
47
+ "@vitest/coverage-v8": "^4.1.12",
48
+ "@vitest/ui": "^4.1.12",
49
49
  "esbuild": "^0.27.2",
50
50
  "np": "^10.2.0",
51
51
  "typescript": "^5.7.2",
52
52
  "vite": "^7.2.2",
53
53
  "vite-plugin-dts": "^4.3.0",
54
- "vitest": "^4.0.16"
54
+ "vitest": "^4.1.12"
55
55
  },
56
56
  "repository": {
57
57
  "type": "git",
58
58
  "url": "https://github.com/hideokamoto/class-resolver.git"
59
59
  },
60
+ "homepage": "https://github.com/hideokamoto/class-resolver#readme",
61
+ "bugs": {
62
+ "url": "https://github.com/hideokamoto/class-resolver/issues"
63
+ },
60
64
  "engines": {
61
65
  "node": ">=14.0.0"
62
66
  },
63
67
  "np": {
64
68
  "yarn": false
65
- }
69
+ },
70
+ "packageManager": "pnpm@10.34.9"
66
71
  }
File without changes