@stone-js/service-container 0.1.3 → 0.8.1

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.
@@ -0,0 +1,48 @@
1
+ import { BindingValue, IContainer, IBinding } from '../declarations';
2
+ /**
3
+ * Abstract class representing a Binding.
4
+ *
5
+ * This abstract class serves as the base class for all types of bindings in the service container. It holds a value and provides an abstract method
6
+ * to resolve and return that value, allowing different subclasses to implement their own resolution logic. Bindings are used to manage dependencies
7
+ * and control how objects are instantiated within the container.
8
+ *
9
+ * @template V - The type of value that this binding holds.
10
+ * @author Mr. Stone <evensstone@gmail.com>
11
+ */
12
+ export declare abstract class Binding<V extends BindingValue> implements IBinding<V> {
13
+ /**
14
+ * The value held by the binding.
15
+ *
16
+ * This value is resolved at runtime, either directly or through a resolver function.
17
+ */
18
+ protected value?: V;
19
+ /**
20
+ * Whether the value has been resolved at least once.
21
+ *
22
+ * Tracked explicitly (not inferred from `value !== undefined`) so a binding whose resolved
23
+ * value is legitimately `undefined` is still considered resolved — preserving the singleton
24
+ * guarantee and avoiding repeated resolver side effects.
25
+ */
26
+ protected resolved: boolean;
27
+ /**
28
+ * Create a new instance of Binding.
29
+ *
30
+ * @param value - The value to be held by the binding.
31
+ */
32
+ constructor(value?: V);
33
+ /**
34
+ * Check if the value has been resolved.
35
+ *
36
+ * @returns A boolean indicating whether the value has been resolved.
37
+ */
38
+ protected isResolved(): boolean;
39
+ /**
40
+ * Resolve and return the value of the binding.
41
+ *
42
+ * This abstract method must be implemented by subclasses to provide specific resolution logic.
43
+ *
44
+ * @param container - The container to resolve dependencies from.
45
+ * @returns The resolved value of the binding.
46
+ */
47
+ abstract resolve(container: IContainer): V | undefined;
48
+ }
@@ -0,0 +1,24 @@
1
+ import { ResolverBinding } from './ResolverBinding';
2
+ import { BindingValue, IContainer } from '../declarations';
3
+ /**
4
+ * Class representing a Factory.
5
+ *
6
+ * The Factory class extends the ResolverBinding class, providing a mechanism to resolve a new instance each time the binding is resolved.
7
+ * This ensures that a fresh instance is created with each call to the `resolve` method.
8
+ *
9
+ * @template V - The type of value that this binding holds.
10
+ * @author Mr. Stone <evensstone@gmail.com>
11
+ */
12
+ export declare class Factory<V extends BindingValue> extends ResolverBinding<V> {
13
+ /**
14
+ * Resolve and return the value of the binding.
15
+ *
16
+ * Each time this method is called, a new value is resolved using the resolver function.
17
+ * This is intended for cases where a fresh instance is required for each resolution, such as factories or transient dependencies.
18
+ *
19
+ * @param container - The container to resolve dependencies from.
20
+ * @returns The resolved value of the binding.
21
+ * @throws ContainerError if the value cannot be resolved.
22
+ */
23
+ resolve(container: IContainer): V;
24
+ }
@@ -0,0 +1,20 @@
1
+ import { Binding } from './Binding';
2
+ import { BindingValue, IContainer } from '../declarations';
3
+ /**
4
+ * Class representing an Instance.
5
+ *
6
+ * This class extends the Binding class and directly holds an instance value.
7
+ * It provides a straightforward resolution mechanism that simply returns the stored value.
8
+ *
9
+ * @template V - The type of value that this binding holds.
10
+ * @author Mr. Stone <evensstone@gmail.com>
11
+ */
12
+ export declare class Instance<V extends BindingValue> extends Binding<V> {
13
+ /**
14
+ * Resolve and return the value of the binding.
15
+ *
16
+ * @param _container - Container to resolve dependencies (not used in this implementation).
17
+ * @returns The resolved value of the binding.
18
+ */
19
+ resolve(_container: IContainer): V | undefined;
20
+ }
@@ -0,0 +1,26 @@
1
+ import { Binding } from './Binding';
2
+ import { BindingValue, Resolver } from '../declarations';
3
+ /**
4
+ * Class representing a ResolverBinding.
5
+ *
6
+ * This class extends the Binding class, using a resolver function to lazily resolve the value when needed.
7
+ *
8
+ * @template V - The type of value that this binding holds.
9
+ * @author Mr. Stone <evensstone@gmail.com>
10
+ */
11
+ export declare abstract class ResolverBinding<V extends BindingValue> extends Binding<V> {
12
+ /**
13
+ * The resolver function used to provide the binding value.
14
+ *
15
+ * This function will be called when the value is needed, allowing for lazy instantiation
16
+ * and dependency resolution. It should return an instance of type `V`.
17
+ */
18
+ protected readonly resolver: Resolver<V>;
19
+ /**
20
+ * Create a new instance of ResolverBinding.
21
+ *
22
+ * @param resolver - The resolver function to provide the binding value.
23
+ * @throws ContainerError if the resolver is not a function.
24
+ */
25
+ constructor(resolver: Resolver<V>);
26
+ }
@@ -0,0 +1,24 @@
1
+ import { ResolverBinding } from './ResolverBinding';
2
+ import { BindingValue, IContainer } from '../declarations';
3
+ /**
4
+ * Class representing a Singleton.
5
+ *
6
+ * The Singleton class extends the ResolverBinding class, ensuring that the value is only resolved once.
7
+ * Subsequent calls to the `resolve` method will return the previously resolved value, making it behave as a singleton.
8
+ *
9
+ * @template V - The type of value that this binding holds.
10
+ * @author Mr. Stone <evensstone@gmail.com>
11
+ */
12
+ export declare class Singleton<V extends BindingValue> extends ResolverBinding<V> {
13
+ /**
14
+ * Resolve and return the value of the binding.
15
+ *
16
+ * If the value has already been resolved, return the cached value. Otherwise, use the resolver function
17
+ * to resolve the value, store it, and return it.
18
+ *
19
+ * @param container - The container to resolve dependencies from.
20
+ * @returns The resolved value of the binding.
21
+ * @throws ContainerError if the value cannot be resolved.
22
+ */
23
+ resolve(container: IContainer): V | undefined;
24
+ }
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@stone-js/service-container",
3
- "version": "0.1.3",
3
+ "version": "0.8.1",
4
4
  "description": "Javascript/Typescript IoC Service Container with proxy resolver and destructuring injection",
5
5
  "author": "Mr. Stone <evensstone@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+ssh://git@github.com/stone-foundation/stone-js-service-container.git"
9
+ "url": "git+https://github.com/stone-foundation/stone-js-framework.git",
10
+ "directory": "stone-js-service-container"
10
11
  },
11
12
  "homepage": "https://stonejs.dev",
12
13
  "bugs": {
13
- "url": "https://github.com/stone-foundation/stone-js-service-container/issues"
14
+ "url": "https://github.com/stone-foundation/stone-js-framework/issues"
14
15
  },
15
16
  "keywords": [
16
17
  "DI",
@@ -38,20 +39,6 @@
38
39
  "engines": {
39
40
  "node": ">=18.17.0"
40
41
  },
41
- "scripts": {
42
- "lint": "ts-standard src",
43
- "lint:fix": "ts-standard --fix src tests",
44
- "predoc": "rimraf docs",
45
- "doc": "typedoc",
46
- "prebuild": "rimraf dist && npm run doc",
47
- "build": "rollup -c",
48
- "test": "vitest run",
49
- "test:cvg": "npm run test -- --coverage",
50
- "test:text": "npm run test:cvg -- --coverage.reporter=text",
51
- "test:html": "npm run test:cvg -- --coverage.reporter=html",
52
- "test:clover": "npm run test:cvg -- --coverage.reporter=clover",
53
- "prepare": "husky"
54
- },
55
42
  "devDependencies": {
56
43
  "@commitlint/cli": "^19.8.1",
57
44
  "@commitlint/config-conventional": "^19.8.1",
@@ -64,8 +51,6 @@
64
51
  "husky": "^9.1.7",
65
52
  "rimraf": "^6.0.1",
66
53
  "rollup": "^4.44.1",
67
- "rollup-plugin-delete": "^3.0.1",
68
- "rollup-plugin-dts": "^6.2.1",
69
54
  "rollup-plugin-node-externals": "^8.0.1",
70
55
  "ts-standard": "^12.0.2",
71
56
  "tslib": "^2.8.1",
@@ -82,5 +67,19 @@
82
67
  "describe",
83
68
  "beforeEach"
84
69
  ]
70
+ },
71
+ "sideEffects": false,
72
+ "scripts": {
73
+ "lint": "ts-standard src",
74
+ "lint:fix": "ts-standard --fix src tests",
75
+ "predoc": "rimraf docs",
76
+ "doc": "typedoc",
77
+ "clean": "rimraf dist",
78
+ "build": "rollup -c",
79
+ "test": "vitest run",
80
+ "test:cvg": "npm run test -- --coverage",
81
+ "test:text": "npm run test:cvg -- --coverage.reporter=text",
82
+ "test:html": "npm run test:cvg -- --coverage.reporter=html",
83
+ "test:clover": "npm run test:cvg -- --coverage.reporter=clover"
85
84
  }
86
- }
85
+ }