@stone-js/service-container 0.0.42 → 0.0.43

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
@@ -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
  *
@@ -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
  *
@@ -523,24 +515,6 @@ class Container extends Proxiable {
523
515
  this.bindings.clear();
524
516
  return this;
525
517
  }
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
518
  /**
545
519
  * AutoBind value to the service container.
546
520
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stone-js/service-container",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "description": "Vanilla Javascript IoC Service Container with proposal decorator, proxy resolver and destructuring injection",
5
5
  "author": "Mr. Stone <evensstone@gmail.com>",
6
6
  "license": "Apache-2.0",
@@ -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",