@stone-js/service-container 0.0.42 → 0.0.44

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
@@ -3,7 +3,7 @@
3
3
  [![npm](https://img.shields.io/npm/l/@stone-js/service-container)](https://opensource.org/licenses/Apache-2.0)
4
4
  [![npm](https://img.shields.io/npm/v/@stone-js/service-container)](https://www.npmjs.com/package/@stone-js/service-container)
5
5
  [![npm](https://img.shields.io/npm/dm/@stone-js/service-container)](https://www.npmjs.com/package/@stone-js/service-container)
6
- ![Maintenance](https://img.shields.io/maintenance/yes/2024)
6
+ ![Maintenance](https://img.shields.io/maintenance/yes/2025)
7
7
  [![Publish Package to npmjs](https://github.com/stonemjs/service-container/actions/workflows/release.yml/badge.svg)](https://github.com/stonemjs/service-container/actions/workflows/release.yml)
8
8
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
9
9
 
@@ -23,9 +23,7 @@ With the **Service Container**, you can easily register, resolve, and manage dep
23
23
 
24
24
  ## Installation
25
25
 
26
- To install the `Service container` utility, you need to add it to your project. Assuming it’s part of a package you manage.
27
-
28
- NPM:
26
+ The `Service Container` library is available from the [`npm registry`](https://www.npmjs.com/) and can be installed as follows:
29
27
 
30
28
  ```bash
31
29
  npm i @stone-js/service-container
@@ -43,7 +41,13 @@ PNPM:
43
41
  pnpm add @stone-js/service-container
44
42
  ```
45
43
 
46
- The `Container` module can only be imported via ESM import syntax:
44
+ > [!NOTE]
45
+ > This package is Pure ESM. If you are unfamiliar with what that means or how to handle it in your project,
46
+ > please refer to [`this guide on Pure ESM packages`](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
47
+
48
+ Make sure your project setup is compatible with ESM. This might involve updating your `package.json` or using certain bundler configurations.
49
+
50
+ The `Service Container` module can only be imported via ESM import syntax:
47
51
 
48
52
  ```typescript
49
53
  import { Container } from '@stone-js/service-container';
package/dist/index.d.ts CHANGED
@@ -113,12 +113,18 @@ declare class Container extends Proxiable {
113
113
  private readonly aliases;
114
114
  private readonly resolvingKeys;
115
115
  private readonly bindings;
116
+ /**
117
+ * Create a Container.
118
+ *
119
+ * @returns A new Container instance.
120
+ */
121
+ static create(): Container;
116
122
  /**
117
123
  * Create a container.
118
124
  *
119
125
  * Initializes the container with empty alias and binding maps.
120
126
  */
121
- constructor();
127
+ protected constructor();
122
128
  /**
123
129
  * Retrieve the value of the bindings property.
124
130
  *
@@ -155,15 +161,6 @@ declare class Container extends Proxiable {
155
161
  * @returns The binding key associated with the alias, or undefined if not found.
156
162
  */
157
163
  getAliasKey(alias: BindingKey): BindingKey | undefined;
158
- /**
159
- * Set class name as camelCase alias.
160
- *
161
- * Automatically assigns a camelCase alias to a given class based on its name or metadata.
162
- *
163
- * @param Class - The class to alias.
164
- * @returns The container instance.
165
- */
166
- asAlias(Class: Function): this;
167
164
  /**
168
165
  * Bind a single instance or value into the container under the provided key.
169
166
  *
@@ -221,7 +218,7 @@ declare class Container extends Proxiable {
221
218
  * @returns The resolved value.
222
219
  * @throws ContainerError if the key cannot be resolved.
223
220
  */
224
- make<V extends BindingValue>(key: BindingKey): V | undefined;
221
+ make<V extends BindingValue>(key: BindingKey): V;
225
222
  /**
226
223
  * Resolve a value from the container by its key, binding it if necessary.
227
224
  *
@@ -229,14 +226,14 @@ declare class Container extends Proxiable {
229
226
  * @param singleton - Whether to bind as a singleton if not already bound.
230
227
  * @returns The resolved value.
231
228
  */
232
- resolve<V extends BindingValue>(key: BindingKey, singleton?: boolean): V | undefined;
229
+ resolve<V extends BindingValue>(key: BindingKey, singleton?: boolean): V;
233
230
  /**
234
231
  * Resolve a value from the container by its key and return it in a factory function.
235
232
  *
236
233
  * @param key - The key to resolve.
237
234
  * @returns A factory function that returns the resolved value.
238
235
  */
239
- factory<V extends BindingValue>(key: BindingKey): () => V | undefined;
236
+ factory<V extends BindingValue>(key: BindingKey): () => V;
240
237
  /**
241
238
  * Check if a value is already bound in the container by its key.
242
239
  *
@@ -257,13 +254,6 @@ declare class Container extends Proxiable {
257
254
  * @returns The container instance.
258
255
  */
259
256
  clear(): this;
260
- /**
261
- * Register services with zero configuration.
262
- *
263
- * @param classes - Classes representing the services to be registered in the container.
264
- * @returns The container instance.
265
- */
266
- register(classes: Function | Function[]): this;
267
257
  /**
268
258
  * AutoBind value to the service container.
269
259
  *
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import { lowerFirst } from 'lodash-es';
2
-
3
1
  /**
4
2
  * Class representing a Proxiable.
5
3
  *
@@ -286,6 +284,14 @@ class Container extends Proxiable {
286
284
  aliases;
287
285
  resolvingKeys = new Set();
288
286
  bindings;
287
+ /**
288
+ * Create a Container.
289
+ *
290
+ * @returns A new Container instance.
291
+ */
292
+ static create() {
293
+ return new this();
294
+ }
289
295
  /**
290
296
  * Create a container.
291
297
  *
@@ -360,20 +366,6 @@ class Container extends Proxiable {
360
366
  getAliasKey(alias) {
361
367
  return this.aliases.get(alias);
362
368
  }
363
- /**
364
- * Set class name as camelCase alias.
365
- *
366
- * Automatically assigns a camelCase alias to a given class based on its name or metadata.
367
- *
368
- * @param Class - The class to alias.
369
- * @returns The container instance.
370
- */
371
- asAlias(Class) {
372
- if (typeof Class !== 'function' || !Object.prototype.hasOwnProperty.call(Class, 'prototype')) {
373
- return this;
374
- }
375
- return this.alias(Class, lowerFirst(Class.$$metadata$$?.name ?? Class.name));
376
- }
377
369
  /**
378
370
  * Bind a single instance or value into the container under the provided key.
379
371
  *
@@ -462,8 +454,9 @@ class Container extends Proxiable {
462
454
  }
463
455
  this.resolvingKeys.add(key);
464
456
  try {
465
- if (this.bindings.has(key)) {
466
- return this.bindings.get(key)?.resolve(this);
457
+ const binding = this.bindings.get(key);
458
+ if (binding !== undefined) {
459
+ return binding.resolve(this);
467
460
  }
468
461
  }
469
462
  finally {
@@ -523,24 +516,6 @@ class Container extends Proxiable {
523
516
  this.bindings.clear();
524
517
  return this;
525
518
  }
526
- /**
527
- * Register services with zero configuration.
528
- *
529
- * @param classes - Classes representing the services to be registered in the container.
530
- * @returns The container instance.
531
- */
532
- register(classes) {
533
- for (const Class of [].concat(classes)) {
534
- if (Class.$$metadata$$?.service !== undefined) {
535
- const { singleton = true, alias } = Class.$$metadata$$.service;
536
- this.autoBinding(Class, Class, singleton, alias ?? []);
537
- }
538
- else {
539
- throw new ContainerError(ContainerError.NOT_A_SERVICE_TYPE, Class);
540
- }
541
- }
542
- return this;
543
- }
544
519
  /**
545
520
  * AutoBind value to the service container.
546
521
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stone-js/service-container",
3
- "version": "0.0.42",
4
- "description": "Vanilla Javascript IoC Service Container with proposal decorator, proxy resolver and destructuring injection",
3
+ "version": "0.0.44",
4
+ "description": "Javascript/Typescript IoC Service Container with proxy resolver and destructuring injection",
5
5
  "author": "Mr. Stone <evensstone@gmail.com>",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -52,9 +52,6 @@
52
52
  "test:clover": "npm run test:cvg -- --coverage.reporter=clover",
53
53
  "prepare": "husky"
54
54
  },
55
- "dependencies": {
56
- "lodash-es": "^4.17.21"
57
- },
58
55
  "devDependencies": {
59
56
  "@commitlint/cli": "^19.5.0",
60
57
  "@commitlint/config-conventional": "^19.5.0",
@@ -62,7 +59,6 @@
62
59
  "@rollup/plugin-multi-entry": "^6.0.1",
63
60
  "@rollup/plugin-node-resolve": "^15.2.3",
64
61
  "@rollup/plugin-typescript": "^12.1.1",
65
- "@types/lodash-es": "^4.17.12",
66
62
  "@types/node": "^22.9.0",
67
63
  "@vitest/coverage-v8": "^2.1.4",
68
64
  "husky": "^9.1.6",