@navios/di 0.5.1 → 0.6.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/CHANGELOG.md +146 -0
- package/README.md +196 -219
- package/docs/README.md +69 -11
- package/docs/api-reference.md +281 -117
- package/docs/container.md +220 -56
- package/docs/examples/request-scope-example.mts +2 -2
- package/docs/factory.md +3 -8
- package/docs/getting-started.md +37 -8
- package/docs/migration.md +318 -37
- package/docs/request-contexts.md +263 -175
- package/docs/scopes.md +79 -42
- package/lib/browser/index.d.mts +1577 -0
- package/lib/browser/index.d.mts.map +1 -0
- package/lib/browser/index.mjs +3012 -0
- package/lib/browser/index.mjs.map +1 -0
- package/lib/index-S_qX2VLI.d.mts +1211 -0
- package/lib/index-S_qX2VLI.d.mts.map +1 -0
- package/lib/index-fKPuT65j.d.cts +1206 -0
- package/lib/index-fKPuT65j.d.cts.map +1 -0
- package/lib/index.cjs +389 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +376 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +371 -78
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +325 -63
- package/lib/index.mjs.map +1 -1
- package/lib/testing/index.cjs +9 -0
- package/lib/testing/index.d.cts +2 -0
- package/lib/testing/index.d.mts +2 -2
- package/lib/testing/index.mjs +2 -72
- package/lib/testing-BMGmmxH7.cjs +2895 -0
- package/lib/testing-BMGmmxH7.cjs.map +1 -0
- package/lib/testing-DCXz8AJD.mjs +2655 -0
- package/lib/testing-DCXz8AJD.mjs.map +1 -0
- package/package.json +23 -1
- package/project.json +2 -2
- package/src/__tests__/async-local-storage.browser.spec.mts +240 -0
- package/src/__tests__/async-local-storage.spec.mts +333 -0
- package/src/__tests__/container.spec.mts +30 -25
- package/src/__tests__/e2e.browser.spec.mts +790 -0
- package/src/__tests__/e2e.spec.mts +1222 -0
- package/src/__tests__/errors.spec.mts +6 -6
- package/src/__tests__/factory.spec.mts +1 -1
- package/src/__tests__/get-injectors.spec.mts +1 -1
- package/src/__tests__/injectable.spec.mts +1 -1
- package/src/__tests__/injection-token.spec.mts +1 -1
- package/src/__tests__/library-findings.spec.mts +563 -0
- package/src/__tests__/registry.spec.mts +2 -2
- package/src/__tests__/request-scope.spec.mts +266 -274
- package/src/__tests__/service-instantiator.spec.mts +18 -17
- package/src/__tests__/service-locator-event-bus.spec.mts +9 -9
- package/src/__tests__/service-locator-manager.spec.mts +15 -15
- package/src/__tests__/service-locator.spec.mts +167 -244
- package/src/__tests__/unified-api.spec.mts +27 -27
- package/src/__type-tests__/factory.spec-d.mts +2 -2
- package/src/__type-tests__/inject.spec-d.mts +2 -2
- package/src/__type-tests__/injectable.spec-d.mts +1 -1
- package/src/browser.mts +16 -0
- package/src/container/container.mts +319 -0
- package/src/container/index.mts +2 -0
- package/src/container/scoped-container.mts +350 -0
- package/src/decorators/factory.decorator.mts +4 -4
- package/src/decorators/injectable.decorator.mts +5 -5
- package/src/errors/di-error.mts +13 -7
- package/src/errors/index.mts +0 -8
- package/src/index.mts +156 -15
- package/src/interfaces/container.interface.mts +82 -0
- package/src/interfaces/factory.interface.mts +2 -2
- package/src/interfaces/index.mts +1 -0
- package/src/internal/context/async-local-storage.mts +120 -0
- package/src/internal/context/factory-context.mts +18 -0
- package/src/internal/context/index.mts +3 -0
- package/src/{request-context-holder.mts → internal/context/request-context.mts} +40 -27
- package/src/internal/context/resolution-context.mts +63 -0
- package/src/internal/context/sync-local-storage.mts +51 -0
- package/src/internal/core/index.mts +5 -0
- package/src/internal/core/instance-resolver.mts +641 -0
- package/src/{service-instantiator.mts → internal/core/instantiator.mts} +31 -27
- package/src/internal/core/invalidator.mts +437 -0
- package/src/internal/core/service-locator.mts +202 -0
- package/src/{token-processor.mts → internal/core/token-processor.mts} +79 -60
- package/src/{base-instance-holder-manager.mts → internal/holder/base-holder-manager.mts} +91 -21
- package/src/internal/holder/holder-manager.mts +85 -0
- package/src/internal/holder/holder-storage.interface.mts +116 -0
- package/src/internal/holder/index.mts +6 -0
- package/src/internal/holder/instance-holder.mts +109 -0
- package/src/internal/holder/request-storage.mts +134 -0
- package/src/internal/holder/singleton-storage.mts +105 -0
- package/src/internal/index.mts +4 -0
- package/src/internal/lifecycle/circular-detector.mts +77 -0
- package/src/internal/lifecycle/index.mts +2 -0
- package/src/{service-locator-event-bus.mts → internal/lifecycle/lifecycle-event-bus.mts} +11 -4
- package/src/testing/__tests__/test-container.spec.mts +2 -2
- package/src/testing/test-container.mts +4 -4
- package/src/token/index.mts +2 -0
- package/src/{injection-token.mts → token/injection-token.mts} +1 -1
- package/src/{registry.mts → token/registry.mts} +1 -1
- package/src/utils/get-injectable-token.mts +1 -1
- package/src/utils/get-injectors.mts +32 -15
- package/src/utils/types.mts +1 -1
- package/tsdown.config.mts +67 -0
- package/lib/_tsup-dts-rollup.d.mts +0 -1283
- package/lib/_tsup-dts-rollup.d.ts +0 -1283
- package/lib/chunk-2M576LCC.mjs +0 -2043
- package/lib/chunk-2M576LCC.mjs.map +0 -1
- package/lib/index.d.ts +0 -78
- package/lib/index.js +0 -2127
- package/lib/index.js.map +0 -1
- package/lib/testing/index.d.ts +0 -2
- package/lib/testing/index.js +0 -2060
- package/lib/testing/index.js.map +0 -1
- package/lib/testing/index.mjs.map +0 -1
- package/src/container.mts +0 -227
- package/src/factory-context.mts +0 -8
- package/src/instance-resolver.mts +0 -559
- package/src/request-context-manager.mts +0 -149
- package/src/service-invalidator.mts +0 -429
- package/src/service-locator-instance-holder.mts +0 -70
- package/src/service-locator-manager.mts +0 -85
- package/src/service-locator.mts +0 -246
- package/tsup.config.mts +0 -12
- /package/src/{injector.mts → injectors.mts} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.6.0] - 2025-12-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Circular Dependency Detection**: Automatic detection of circular dependencies with clear error messages
|
|
13
|
+
- Detects cycles when using `inject()` and throws descriptive errors
|
|
14
|
+
- Shows the full cycle path: `ServiceA -> ServiceB -> ServiceA`
|
|
15
|
+
- Use `asyncInject()` to break circular dependencies
|
|
16
|
+
- **Browser Support**: Full browser environment support
|
|
17
|
+
- Dedicated browser entry point via `package.json` exports
|
|
18
|
+
- Automatically uses `SyncLocalStorage` instead of `AsyncLocalStorage` in browsers
|
|
19
|
+
- Works seamlessly with bundlers (webpack, vite, etc.)
|
|
20
|
+
- **Cross-Storage Invalidation**: Proper invalidation of singletons that depend on request-scoped services
|
|
21
|
+
- Singletons are automatically invalidated when their request-scoped dependencies are cleaned up
|
|
22
|
+
- Prevents memory leaks and stale references
|
|
23
|
+
- **Resolution Context**: Uses `AsyncLocalStorage` to track resolution across async boundaries
|
|
24
|
+
- Enables proper circular dependency detection in async scenarios
|
|
25
|
+
- Maintains context across async operations
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **Type Renames**: Many internal types have been renamed for cleaner naming
|
|
30
|
+
- Old names are still available as deprecated aliases for backward compatibility
|
|
31
|
+
- See migration guide for complete list of renamed types
|
|
32
|
+
- New names: `InstanceHolder`, `InstanceStatus`, `HolderManager`, `LifecycleEventBus`, etc.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- Circular dependencies now throw clear errors instead of hanging indefinitely
|
|
37
|
+
- Request-scoped services properly invalidate dependent singletons
|
|
38
|
+
- Browser compatibility issues resolved
|
|
39
|
+
|
|
40
|
+
## [0.4.0] - 2025
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- **ScopedContainer**: New request context management API
|
|
45
|
+
- Eliminates race conditions in concurrent request handling
|
|
46
|
+
- Each request gets its own isolated container
|
|
47
|
+
- Proper cleanup with `endRequest()` method
|
|
48
|
+
- **IContainer Interface**: Common interface for `Container` and `ScopedContainer`
|
|
49
|
+
- Enables polymorphic usage of containers
|
|
50
|
+
- Consistent API across container types
|
|
51
|
+
- **Active Request Tracking**: Methods to track active requests
|
|
52
|
+
- `hasActiveRequest(requestId: string): boolean`
|
|
53
|
+
- `getActiveRequestIds(): ReadonlySet<string>`
|
|
54
|
+
- **Request-Scoped Error Protection**: Clear error when attempting to resolve request-scoped services from `Container`
|
|
55
|
+
- Helpful error message guides users to use `ScopedContainer`
|
|
56
|
+
|
|
57
|
+
### Changed
|
|
58
|
+
|
|
59
|
+
- **BREAKING**: `Container.beginRequest()` now returns `ScopedContainer` instead of `RequestContextHolder`
|
|
60
|
+
- **BREAKING**: Removed `Container.setCurrentRequestContext(requestId)`
|
|
61
|
+
- **BREAKING**: Removed `Container.getCurrentRequestContext()`
|
|
62
|
+
- **BREAKING**: Removed `Container.endRequest(requestId)` - use `ScopedContainer.endRequest()` instead
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- Race condition in concurrent request handling
|
|
67
|
+
- Old API could cause request contexts to be mixed when multiple requests processed concurrently
|
|
68
|
+
- New `ScopedContainer` API eliminates this issue completely
|
|
69
|
+
|
|
70
|
+
### Migration
|
|
71
|
+
|
|
72
|
+
- See [Migration Guide](./docs/migration.md) for detailed migration steps
|
|
73
|
+
- Old request context API is no longer available
|
|
74
|
+
- Update middleware code to use `ScopedContainer` pattern
|
|
75
|
+
|
|
76
|
+
## [0.3.0] - 2024-XX-XX
|
|
77
|
+
|
|
78
|
+
### Added
|
|
79
|
+
|
|
80
|
+
- **Request Context Management**: Initial request-scoped service support
|
|
81
|
+
- `Container.beginRequest(requestId, metadata?, priority?)` - returns `RequestContextHolder`
|
|
82
|
+
- `Container.endRequest(requestId)` - cleanup request context
|
|
83
|
+
- `Container.setCurrentRequestContext(requestId)` - set active context
|
|
84
|
+
- `Container.getCurrentRequestContext()` - get current context
|
|
85
|
+
- **RequestContextHolder Interface**: Interface for managing request contexts
|
|
86
|
+
- Enhanced error messages for injection failures
|
|
87
|
+
- Improved TypeScript type definitions
|
|
88
|
+
|
|
89
|
+
### Changed
|
|
90
|
+
|
|
91
|
+
- Enhanced container API with request context methods
|
|
92
|
+
- Better error messages throughout the library
|
|
93
|
+
|
|
94
|
+
## [0.2.0] - 2024-XX-XX
|
|
95
|
+
|
|
96
|
+
### Added
|
|
97
|
+
|
|
98
|
+
- **Basic Dependency Injection**: Core DI functionality
|
|
99
|
+
- `@Injectable()` decorator for service registration
|
|
100
|
+
- `@Factory()` decorator for factory pattern
|
|
101
|
+
- `Container` class for dependency management
|
|
102
|
+
- **Injection Tokens**: Token-based dependency resolution
|
|
103
|
+
- `InjectionToken.create()` for creating tokens
|
|
104
|
+
- `InjectionToken.bound()` for pre-bound values
|
|
105
|
+
- `InjectionToken.factory()` for factory-based resolution
|
|
106
|
+
- Zod schema validation support
|
|
107
|
+
- **Service Lifecycle Hooks**:
|
|
108
|
+
- `OnServiceInit` interface for initialization
|
|
109
|
+
- `OnServiceDestroy` interface for cleanup
|
|
110
|
+
- **Service Scopes**:
|
|
111
|
+
- `InjectableScope.Singleton` - single instance per container
|
|
112
|
+
- `InjectableScope.Transient` - new instance each time
|
|
113
|
+
- `InjectableScope.Request` - instance per request context
|
|
114
|
+
- **Injection Methods**:
|
|
115
|
+
- `inject()` - synchronous injection
|
|
116
|
+
- `asyncInject()` - asynchronous injection
|
|
117
|
+
- `optional()` - optional injection
|
|
118
|
+
- **Registry**: Service registration system
|
|
119
|
+
- `Registry` class for managing service registrations
|
|
120
|
+
- `globalRegistry` for default registrations
|
|
121
|
+
|
|
122
|
+
## [0.1.0] - 2024-XX-XX
|
|
123
|
+
|
|
124
|
+
### Added
|
|
125
|
+
|
|
126
|
+
- Initial release
|
|
127
|
+
- Basic dependency injection functionality
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Types of Changes
|
|
132
|
+
|
|
133
|
+
- **Added** for new features
|
|
134
|
+
- **Changed** for changes in existing functionality
|
|
135
|
+
- **Deprecated** for soon-to-be removed features
|
|
136
|
+
- **Removed** for now removed features
|
|
137
|
+
- **Fixed** for any bug fixes
|
|
138
|
+
- **Security** for vulnerability fixes
|
|
139
|
+
|
|
140
|
+
[Unreleased]: https://github.com/Arilas/navios/compare/v0.6.0...HEAD
|
|
141
|
+
[0.6.0]: https://github.com/Arilas/navios/compare/v0.5.0...v0.6.0
|
|
142
|
+
[0.5.0]: https://github.com/Arilas/navios/compare/v0.4.0...v0.5.0
|
|
143
|
+
[0.4.0]: https://github.com/Arilas/navios/compare/v0.3.0...v0.4.0
|
|
144
|
+
[0.3.0]: https://github.com/Arilas/navios/compare/v0.2.0...v0.3.0
|
|
145
|
+
[0.2.0]: https://github.com/Arilas/navios/compare/v0.1.0...v0.2.0
|
|
146
|
+
[0.1.0]: https://github.com/Arilas/navios/releases/tag/v0.1.0
|