@djodjonx/neosyringe 0.1.0
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 +11 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/types.cjs +64 -0
- package/dist/types.d.cts +161 -0
- package/dist/types.d.mts +161 -0
- package/dist/types.mjs +59 -0
- package/package.json +31 -0
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_types = require('./types.cjs');
|
|
2
|
+
|
|
3
|
+
exports.declareContainerTokens = require_types.declareContainerTokens;
|
|
4
|
+
exports.defineBuilderConfig = require_types.defineBuilderConfig;
|
|
5
|
+
exports.definePartialConfig = require_types.definePartialConfig;
|
|
6
|
+
exports.useInterface = require_types.useInterface;
|
|
7
|
+
exports.useProperty = require_types.useProperty;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { BuilderConfig, Constructor, Container, Factory, Injection, InterfaceToken, Lifecycle, PartialConfig, PropertyToken, Provider, Token, declareContainerTokens, defineBuilderConfig, definePartialConfig, useInterface, useProperty } from "./types.cjs";
|
|
2
|
+
export { BuilderConfig, Constructor, Container, Factory, Injection, InterfaceToken, Lifecycle, PartialConfig, PropertyToken, Provider, Token, declareContainerTokens, defineBuilderConfig, definePartialConfig, useInterface, useProperty };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { BuilderConfig, Constructor, Container, Factory, Injection, InterfaceToken, Lifecycle, PartialConfig, PropertyToken, Provider, Token, declareContainerTokens, defineBuilderConfig, definePartialConfig, useInterface, useProperty } from "./types.mjs";
|
|
2
|
+
export { BuilderConfig, Constructor, Container, Factory, Injection, InterfaceToken, Lifecycle, PartialConfig, PropertyToken, Provider, Token, declareContainerTokens, defineBuilderConfig, definePartialConfig, useInterface, useProperty };
|
package/dist/index.mjs
ADDED
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/types.ts
|
|
3
|
+
/**
|
|
4
|
+
* Runtime helper to define a partial configuration.
|
|
5
|
+
*/
|
|
6
|
+
function definePartialConfig(config) {
|
|
7
|
+
return config;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Runtime helper to define the main builder configuration.
|
|
11
|
+
* This function is replaced at compile-time by the generated container.
|
|
12
|
+
*
|
|
13
|
+
* @throws {Error} If called at runtime without the build plugin.
|
|
14
|
+
*/
|
|
15
|
+
function defineBuilderConfig(_config) {
|
|
16
|
+
throw new Error("NeoSyringe: defineBuilderConfig() called at runtime. This library requires the compiler plugin to generate the container. Ensure the plugin is configured in your build system (Vite, Rollup, Webpack).");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Runtime helper to create an interface token.
|
|
20
|
+
* This function is replaced at compile-time by a unique ID.
|
|
21
|
+
*
|
|
22
|
+
* @throws {Error} If called at runtime without compilation.
|
|
23
|
+
*/
|
|
24
|
+
function useInterface() {
|
|
25
|
+
throw new Error("NeoSyringe: useInterface<T>() called at runtime. The build plugin is missing.");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a property token for injecting primitive values into class constructors.
|
|
29
|
+
* The token is bound to a specific class and parameter name for type-safety.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const apiUrl = useProperty<string>(ApiService, 'apiUrl');
|
|
34
|
+
*
|
|
35
|
+
* defineBuilderConfig({
|
|
36
|
+
* injections: [
|
|
37
|
+
* { token: apiUrl, provider: () => 'http://localhost' },
|
|
38
|
+
* { token: ApiService }
|
|
39
|
+
* ]
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @throws {Error} If called at runtime without compilation.
|
|
44
|
+
*/
|
|
45
|
+
function useProperty(targetClass, paramName) {
|
|
46
|
+
throw new Error(`NeoSyringe: useProperty(${targetClass.name}, '${paramName}') called at runtime. The build plugin is missing.`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Declares the tokens provided by a legacy container.
|
|
50
|
+
* This is a type-level helper; it returns the container instance as-is at runtime.
|
|
51
|
+
*
|
|
52
|
+
* @template T - A map of Token -> Type provided by the container.
|
|
53
|
+
* @param container - The legacy container instance.
|
|
54
|
+
*/
|
|
55
|
+
function declareContainerTokens(container) {
|
|
56
|
+
return container;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.declareContainerTokens = declareContainerTokens;
|
|
61
|
+
exports.defineBuilderConfig = defineBuilderConfig;
|
|
62
|
+
exports.definePartialConfig = definePartialConfig;
|
|
63
|
+
exports.useInterface = useInterface;
|
|
64
|
+
exports.useProperty = useProperty;
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Represents a generic class constructor.
|
|
4
|
+
* @template T - The type of the instance created by the constructor.
|
|
5
|
+
*/
|
|
6
|
+
type Constructor<T = any> = new (...args: any[]) => T;
|
|
7
|
+
/**
|
|
8
|
+
* Defines the lifecycle of a service.
|
|
9
|
+
* - `singleton`: One instance per container.
|
|
10
|
+
* - `transient`: A new instance every time it is resolved.
|
|
11
|
+
*/
|
|
12
|
+
type Lifecycle = 'singleton' | 'transient';
|
|
13
|
+
/**
|
|
14
|
+
* The dependency injection container interface.
|
|
15
|
+
* Provides access to the registered services.
|
|
16
|
+
*/
|
|
17
|
+
interface Container {
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a service by its token.
|
|
20
|
+
*
|
|
21
|
+
* @template T - The type of the service to resolve.
|
|
22
|
+
* @param token - The service token (class constructor, interface token, or property token).
|
|
23
|
+
* @returns The resolved service instance.
|
|
24
|
+
* @throws {Error} If the service is not found or not registered.
|
|
25
|
+
*/
|
|
26
|
+
resolve<T>(token: Token<T>): T;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A unique token for an interface, generated at compile-time.
|
|
30
|
+
*/
|
|
31
|
+
type InterfaceToken<T> = {
|
|
32
|
+
__brand: 'InterfaceToken';
|
|
33
|
+
__type: T;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A unique token for a primitive property bound to a specific class parameter.
|
|
37
|
+
* Used for injecting string, number, boolean, etc. into class constructors.
|
|
38
|
+
*/
|
|
39
|
+
type PropertyToken<T, C = unknown> = {
|
|
40
|
+
__brand: 'PropertyToken';
|
|
41
|
+
__type: T;
|
|
42
|
+
__class: C;
|
|
43
|
+
__name: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Represents a token that can be injected.
|
|
47
|
+
* Can be a Class Constructor, an Interface Token, or a Property Token.
|
|
48
|
+
*/
|
|
49
|
+
type Token<T = any> = Constructor<T> | InterfaceToken<T> | PropertyToken<T, any>;
|
|
50
|
+
/**
|
|
51
|
+
* A factory function that creates an instance.
|
|
52
|
+
* Receives the container to resolve dependencies.
|
|
53
|
+
*/
|
|
54
|
+
type Factory<T> = (container: Container) => T;
|
|
55
|
+
/**
|
|
56
|
+
* A provider can be a class constructor or a factory function.
|
|
57
|
+
*/
|
|
58
|
+
type Provider<T> = Constructor<T> | Factory<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Definition of a single injection.
|
|
61
|
+
*/
|
|
62
|
+
interface Injection<T = any> {
|
|
63
|
+
token: Token<T>;
|
|
64
|
+
provider?: Provider<T>;
|
|
65
|
+
/**
|
|
66
|
+
* If true, the provider is treated as a factory function.
|
|
67
|
+
* Required when provider is a function, not a class.
|
|
68
|
+
*/
|
|
69
|
+
useFactory?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Lifecycle of the service.
|
|
72
|
+
* - `singleton`: One instance per container (default).
|
|
73
|
+
* - `transient`: A new instance every time it is resolved.
|
|
74
|
+
*/
|
|
75
|
+
lifecycle?: Lifecycle;
|
|
76
|
+
/**
|
|
77
|
+
* If true, this injection is scoped to this container only.
|
|
78
|
+
* Allows overriding a token from a parent container without causing a duplicate error.
|
|
79
|
+
* The local instance will be used instead of delegating to the parent.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const parent = defineBuilderConfig({
|
|
84
|
+
* injections: [{ token: useInterface<ILogger>(), provider: ConsoleLogger }]
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* const child = defineBuilderConfig({
|
|
88
|
+
* useContainer: parent,
|
|
89
|
+
* injections: [
|
|
90
|
+
* // Override parent's ILogger with a local FileLogger
|
|
91
|
+
* { token: useInterface<ILogger>(), provider: FileLogger, scoped: true }
|
|
92
|
+
* ]
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
scoped?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Partial configuration that can be shared/extended.
|
|
100
|
+
*/
|
|
101
|
+
interface PartialConfig {
|
|
102
|
+
injections?: Injection[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Main configuration for a container builder.
|
|
106
|
+
*/
|
|
107
|
+
interface BuilderConfig extends PartialConfig {
|
|
108
|
+
name?: string;
|
|
109
|
+
extends?: PartialConfig[];
|
|
110
|
+
/**
|
|
111
|
+
* Parent container instance to bridge (NeoSyringe or legacy).
|
|
112
|
+
*/
|
|
113
|
+
useContainer?: any;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Runtime helper to define a partial configuration.
|
|
117
|
+
*/
|
|
118
|
+
declare function definePartialConfig(config: PartialConfig): PartialConfig;
|
|
119
|
+
/**
|
|
120
|
+
* Runtime helper to define the main builder configuration.
|
|
121
|
+
* This function is replaced at compile-time by the generated container.
|
|
122
|
+
*
|
|
123
|
+
* @throws {Error} If called at runtime without the build plugin.
|
|
124
|
+
*/
|
|
125
|
+
declare function defineBuilderConfig(_config: BuilderConfig): Container;
|
|
126
|
+
/**
|
|
127
|
+
* Runtime helper to create an interface token.
|
|
128
|
+
* This function is replaced at compile-time by a unique ID.
|
|
129
|
+
*
|
|
130
|
+
* @throws {Error} If called at runtime without compilation.
|
|
131
|
+
*/
|
|
132
|
+
declare function useInterface<T>(): InterfaceToken<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Creates a property token for injecting primitive values into class constructors.
|
|
135
|
+
* The token is bound to a specific class and parameter name for type-safety.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const apiUrl = useProperty<string>(ApiService, 'apiUrl');
|
|
140
|
+
*
|
|
141
|
+
* defineBuilderConfig({
|
|
142
|
+
* injections: [
|
|
143
|
+
* { token: apiUrl, provider: () => 'http://localhost' },
|
|
144
|
+
* { token: ApiService }
|
|
145
|
+
* ]
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @throws {Error} If called at runtime without compilation.
|
|
150
|
+
*/
|
|
151
|
+
declare function useProperty<T, C extends Constructor<any>>(targetClass: C, paramName: string): PropertyToken<T, InstanceType<C>>;
|
|
152
|
+
/**
|
|
153
|
+
* Declares the tokens provided by a legacy container.
|
|
154
|
+
* This is a type-level helper; it returns the container instance as-is at runtime.
|
|
155
|
+
*
|
|
156
|
+
* @template T - A map of Token -> Type provided by the container.
|
|
157
|
+
* @param container - The legacy container instance.
|
|
158
|
+
*/
|
|
159
|
+
declare function declareContainerTokens<T extends Record<string, any>>(container: any): T & { [K in keyof T]: T[K] };
|
|
160
|
+
//#endregion
|
|
161
|
+
export { BuilderConfig, Constructor, Container, Factory, Injection, InterfaceToken, Lifecycle, PartialConfig, PropertyToken, Provider, Token, declareContainerTokens, defineBuilderConfig, definePartialConfig, useInterface, useProperty };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Represents a generic class constructor.
|
|
4
|
+
* @template T - The type of the instance created by the constructor.
|
|
5
|
+
*/
|
|
6
|
+
type Constructor<T = any> = new (...args: any[]) => T;
|
|
7
|
+
/**
|
|
8
|
+
* Defines the lifecycle of a service.
|
|
9
|
+
* - `singleton`: One instance per container.
|
|
10
|
+
* - `transient`: A new instance every time it is resolved.
|
|
11
|
+
*/
|
|
12
|
+
type Lifecycle = 'singleton' | 'transient';
|
|
13
|
+
/**
|
|
14
|
+
* The dependency injection container interface.
|
|
15
|
+
* Provides access to the registered services.
|
|
16
|
+
*/
|
|
17
|
+
interface Container {
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a service by its token.
|
|
20
|
+
*
|
|
21
|
+
* @template T - The type of the service to resolve.
|
|
22
|
+
* @param token - The service token (class constructor, interface token, or property token).
|
|
23
|
+
* @returns The resolved service instance.
|
|
24
|
+
* @throws {Error} If the service is not found or not registered.
|
|
25
|
+
*/
|
|
26
|
+
resolve<T>(token: Token<T>): T;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A unique token for an interface, generated at compile-time.
|
|
30
|
+
*/
|
|
31
|
+
type InterfaceToken<T> = {
|
|
32
|
+
__brand: 'InterfaceToken';
|
|
33
|
+
__type: T;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A unique token for a primitive property bound to a specific class parameter.
|
|
37
|
+
* Used for injecting string, number, boolean, etc. into class constructors.
|
|
38
|
+
*/
|
|
39
|
+
type PropertyToken<T, C = unknown> = {
|
|
40
|
+
__brand: 'PropertyToken';
|
|
41
|
+
__type: T;
|
|
42
|
+
__class: C;
|
|
43
|
+
__name: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Represents a token that can be injected.
|
|
47
|
+
* Can be a Class Constructor, an Interface Token, or a Property Token.
|
|
48
|
+
*/
|
|
49
|
+
type Token<T = any> = Constructor<T> | InterfaceToken<T> | PropertyToken<T, any>;
|
|
50
|
+
/**
|
|
51
|
+
* A factory function that creates an instance.
|
|
52
|
+
* Receives the container to resolve dependencies.
|
|
53
|
+
*/
|
|
54
|
+
type Factory<T> = (container: Container) => T;
|
|
55
|
+
/**
|
|
56
|
+
* A provider can be a class constructor or a factory function.
|
|
57
|
+
*/
|
|
58
|
+
type Provider<T> = Constructor<T> | Factory<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Definition of a single injection.
|
|
61
|
+
*/
|
|
62
|
+
interface Injection<T = any> {
|
|
63
|
+
token: Token<T>;
|
|
64
|
+
provider?: Provider<T>;
|
|
65
|
+
/**
|
|
66
|
+
* If true, the provider is treated as a factory function.
|
|
67
|
+
* Required when provider is a function, not a class.
|
|
68
|
+
*/
|
|
69
|
+
useFactory?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Lifecycle of the service.
|
|
72
|
+
* - `singleton`: One instance per container (default).
|
|
73
|
+
* - `transient`: A new instance every time it is resolved.
|
|
74
|
+
*/
|
|
75
|
+
lifecycle?: Lifecycle;
|
|
76
|
+
/**
|
|
77
|
+
* If true, this injection is scoped to this container only.
|
|
78
|
+
* Allows overriding a token from a parent container without causing a duplicate error.
|
|
79
|
+
* The local instance will be used instead of delegating to the parent.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const parent = defineBuilderConfig({
|
|
84
|
+
* injections: [{ token: useInterface<ILogger>(), provider: ConsoleLogger }]
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* const child = defineBuilderConfig({
|
|
88
|
+
* useContainer: parent,
|
|
89
|
+
* injections: [
|
|
90
|
+
* // Override parent's ILogger with a local FileLogger
|
|
91
|
+
* { token: useInterface<ILogger>(), provider: FileLogger, scoped: true }
|
|
92
|
+
* ]
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
scoped?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Partial configuration that can be shared/extended.
|
|
100
|
+
*/
|
|
101
|
+
interface PartialConfig {
|
|
102
|
+
injections?: Injection[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Main configuration for a container builder.
|
|
106
|
+
*/
|
|
107
|
+
interface BuilderConfig extends PartialConfig {
|
|
108
|
+
name?: string;
|
|
109
|
+
extends?: PartialConfig[];
|
|
110
|
+
/**
|
|
111
|
+
* Parent container instance to bridge (NeoSyringe or legacy).
|
|
112
|
+
*/
|
|
113
|
+
useContainer?: any;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Runtime helper to define a partial configuration.
|
|
117
|
+
*/
|
|
118
|
+
declare function definePartialConfig(config: PartialConfig): PartialConfig;
|
|
119
|
+
/**
|
|
120
|
+
* Runtime helper to define the main builder configuration.
|
|
121
|
+
* This function is replaced at compile-time by the generated container.
|
|
122
|
+
*
|
|
123
|
+
* @throws {Error} If called at runtime without the build plugin.
|
|
124
|
+
*/
|
|
125
|
+
declare function defineBuilderConfig(_config: BuilderConfig): Container;
|
|
126
|
+
/**
|
|
127
|
+
* Runtime helper to create an interface token.
|
|
128
|
+
* This function is replaced at compile-time by a unique ID.
|
|
129
|
+
*
|
|
130
|
+
* @throws {Error} If called at runtime without compilation.
|
|
131
|
+
*/
|
|
132
|
+
declare function useInterface<T>(): InterfaceToken<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Creates a property token for injecting primitive values into class constructors.
|
|
135
|
+
* The token is bound to a specific class and parameter name for type-safety.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const apiUrl = useProperty<string>(ApiService, 'apiUrl');
|
|
140
|
+
*
|
|
141
|
+
* defineBuilderConfig({
|
|
142
|
+
* injections: [
|
|
143
|
+
* { token: apiUrl, provider: () => 'http://localhost' },
|
|
144
|
+
* { token: ApiService }
|
|
145
|
+
* ]
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @throws {Error} If called at runtime without compilation.
|
|
150
|
+
*/
|
|
151
|
+
declare function useProperty<T, C extends Constructor<any>>(targetClass: C, paramName: string): PropertyToken<T, InstanceType<C>>;
|
|
152
|
+
/**
|
|
153
|
+
* Declares the tokens provided by a legacy container.
|
|
154
|
+
* This is a type-level helper; it returns the container instance as-is at runtime.
|
|
155
|
+
*
|
|
156
|
+
* @template T - A map of Token -> Type provided by the container.
|
|
157
|
+
* @param container - The legacy container instance.
|
|
158
|
+
*/
|
|
159
|
+
declare function declareContainerTokens<T extends Record<string, any>>(container: any): T & { [K in keyof T]: T[K] };
|
|
160
|
+
//#endregion
|
|
161
|
+
export { BuilderConfig, Constructor, Container, Factory, Injection, InterfaceToken, Lifecycle, PartialConfig, PropertyToken, Provider, Token, declareContainerTokens, defineBuilderConfig, definePartialConfig, useInterface, useProperty };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime helper to define a partial configuration.
|
|
4
|
+
*/
|
|
5
|
+
function definePartialConfig(config) {
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Runtime helper to define the main builder configuration.
|
|
10
|
+
* This function is replaced at compile-time by the generated container.
|
|
11
|
+
*
|
|
12
|
+
* @throws {Error} If called at runtime without the build plugin.
|
|
13
|
+
*/
|
|
14
|
+
function defineBuilderConfig(_config) {
|
|
15
|
+
throw new Error("NeoSyringe: defineBuilderConfig() called at runtime. This library requires the compiler plugin to generate the container. Ensure the plugin is configured in your build system (Vite, Rollup, Webpack).");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runtime helper to create an interface token.
|
|
19
|
+
* This function is replaced at compile-time by a unique ID.
|
|
20
|
+
*
|
|
21
|
+
* @throws {Error} If called at runtime without compilation.
|
|
22
|
+
*/
|
|
23
|
+
function useInterface() {
|
|
24
|
+
throw new Error("NeoSyringe: useInterface<T>() called at runtime. The build plugin is missing.");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a property token for injecting primitive values into class constructors.
|
|
28
|
+
* The token is bound to a specific class and parameter name for type-safety.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const apiUrl = useProperty<string>(ApiService, 'apiUrl');
|
|
33
|
+
*
|
|
34
|
+
* defineBuilderConfig({
|
|
35
|
+
* injections: [
|
|
36
|
+
* { token: apiUrl, provider: () => 'http://localhost' },
|
|
37
|
+
* { token: ApiService }
|
|
38
|
+
* ]
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @throws {Error} If called at runtime without compilation.
|
|
43
|
+
*/
|
|
44
|
+
function useProperty(targetClass, paramName) {
|
|
45
|
+
throw new Error(`NeoSyringe: useProperty(${targetClass.name}, '${paramName}') called at runtime. The build plugin is missing.`);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Declares the tokens provided by a legacy container.
|
|
49
|
+
* This is a type-level helper; it returns the container instance as-is at runtime.
|
|
50
|
+
*
|
|
51
|
+
* @template T - A map of Token -> Type provided by the container.
|
|
52
|
+
* @param container - The legacy container instance.
|
|
53
|
+
*/
|
|
54
|
+
function declareContainerTokens(container) {
|
|
55
|
+
return container;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { declareContainerTokens, defineBuilderConfig, definePartialConfig, useInterface, useProperty };
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@djodjonx/neosyringe",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Runtime library for NeoSyringe DI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsdown": "0.20.0-beta.3",
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"vitest": "^4.0.17"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsdown",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
}
|
|
31
|
+
}
|