Next release - #127
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
pumpit@11.0.0
Major Changes
72d5ed5:
PumpitErroris now the base class for every error the container throws and its constructor takes anErrorCodeinstead of aValidationError[]. Validation failures throwPumpitValidationError, a subclass that still carriesresult, but whose message now lists the unresolved keys instead of being the literal string"Validation".validateSafealways returns aValidationResultand no longer returnsundefined.Injection metadata is read once when a value is bound instead of on every resolve, so
registerInjections(or assigninginject/INJECT_KEY) must happen beforebindClassandbindFactory. Later changes are no longer picked up.Dependencies marked optional are no longer reported by
validateandvalidateSafe.resolvenow infers the return type when the key is a class or a typed token, where it previously widened tounknown.setParentacceptsundefinedto detach a parent, and throws when the parent would create a cycle.Resolving is substantially faster: bound values ~2.5x, cached singletons ~5x, and a small transient graph ~2.4x, mostly by dropping per resolve allocations and parsing injection metadata at bind time.
ae34601: Stricter type definitions, which can fail a build that previously compiled.
registerInjectionsnow takesInjectionDatainstead ofunknown[],PumpitError.resultisValidationError[]instead ofany, and theinjectproperty on a class or factory is type checked. The protectedaddmethod drops its second argument, which was always discarded.Also fixes
unbindandunbindAllthrowing aTypeErrorwhen aSINGLETONbinding resolved to a string or number, and exports the types that already appeared in public signatures but could not be imported:ClassConstructor,FactoryFn,WithInjectProp,ValidationError,ValidationResult,Injection,InjectionData,InjectionFn,InjectionOptions,InjectableandParsedInjectionData.Minor Changes
72d5ed5: Add typed tokens.
token<T>()creates aSymbolbind key that carries its type, soresolveinfers the result instead of being told, and bindings made under the token are type checked.resolvealso infers the instance type when a class is used as the key.Add
tryResolve, which returnsundefinedfor an unbound key instead of throwing. A missing required dependency of a bound key still throws.Add
getKeys, which lists the keys bound on the container, optionally including the parent chain.Add a
replacebind option, so a key can be rebound without unbinding it first. The previous binding is unbound, which disposes its cached singleton.Support
Symbol.disposeon resolved singletons, preferred over adisposemethod. The container itself is now disposable, sousing container = new PumpIt()unbinds everything on scope exit. Disposal ignores the lock, since throwing out of a disposal would mask whatever the enclosing block was doing.unbindAllstill refuses a locked container.Every error thrown by the container is now a
PumpitErrorcarrying a machine readablecode, exported asERROR_CODE.Patch Changes
72d5ed5: Fix bindings that resolve to
undefinedleaking an internal symbol. ASINGLETONorREQUESTbinding whose class or factory producedundefinedreturned that sentinel on the first resolve, and injected it into every dependent afterwards.Fix
validateandvalidateSafesilently giving up. Reaching a binding that an earlier binding already listed as a dependency aborted the whole check, sovalidatedid not throw andvalidateSafereturnedundefined. Missing dependencies are now reported regardless of bind order, and optional dependencies are no longer reported at all.Fix resolution that crosses into a parent container starting a fresh request. A
SINGLETONowned by a parent used to be resolved through a brand new context, which splitREQUESTscope into two instances within a singleresolvecall, ranpostConstructhooks before the outer graph finished building, and hid circular references behind a stack overflow.Fix
setParentaccepting a parent that creates a cycle in the hierarchy, which turned every lookup into infinite recursion.Fix
unbindAllsucceeding on a locked container when the container was empty.Circular reference errors now report the full resolution path with the bound class names, instead of stringifying an internal wrapper function.