-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(tegg): isolate per-app state for concurrent multi-app via TeggScope #5986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9bbad5f
feat(tegg): isolate per-app state for concurrent multi-app via TeggScope
killagu 8777fb5
docs(tegg): document TeggScope multi-app isolation constraints
killagu 0814a0b
perf(tegg): converge per-app scope wrapping and speed up the hot path
killagu f5cfc0b
Merge branch 'next' into feat/tegg-multiapp-isolation
killagu babd8e1
fix(tegg): drop unused @eggjs/tegg-types dep from aop/eventbus plugins
killagu 70e71d1
fix(tegg): resolve single-app state outside an explicit scope
killagu 30caefb
refactor(tegg): address review feedback on TeggScope facades
killagu 87cc089
test(tegg): cover TeggScope scope/fallback/escape behavior
killagu 061f23d
refactor(tegg): simplify multi-app scoping boilerplate
killagu acd2558
fix(tegg): close multi-app scope-isolation gaps found in review
killagu e8d0f03
fix(tegg): revert destructured lifecycle-util exports (isolatedDeclar…
killagu 35f5d0b
fix(tegg): scope teggConfig configNames in the per-app TeggScope bag
killagu b87a2b8
test(tegg): cover concurrent multi-app boot under vitest parallel
killagu e582e5b
fix(tegg): correct standalone preload loader + scope Runner proto lookup
killagu 3923892
fix(tegg): close remaining per-app scope/teardown gaps
killagu 45482bd
test(tegg): tighten multi-app fixtures
killagu 84d4762
docs(tegg): match lifecycle-util guidance to the shipped facade
killagu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import type { LifecycleContext, LifecycleObject } from '@eggjs/tegg-types'; | ||
| import { TeggScope, type TeggScopeBag } from '@eggjs/tegg-types'; | ||
|
|
||
| import { LifecycleUtil } from './LifycycleUtil.ts'; | ||
|
|
||
| /** | ||
| * Get-or-create the concrete per-app {@link LifecycleUtil} stored at `slot` in a | ||
| * specific bag. Used to **pin** a lifecycle util to a known app's bag | ||
| * (`app._teggScopeBag`) without depending on the active async scope — e.g. the | ||
| * `app.xxxLifecycleUtil` facades, so plugins can register hooks during boot | ||
| * WITHOUT wrapping every call in `TeggScope.run(...)`. | ||
| */ | ||
| export function lifecycleUtilFromBag<T extends LifecycleContext, R extends LifecycleObject<T>>( | ||
| bag: TeggScopeBag, | ||
| slot: symbol, | ||
| ): LifecycleUtil<T, R> { | ||
| let util = bag.get(slot) as LifecycleUtil<T, R> | undefined; | ||
| if (!util) { | ||
| util = new LifecycleUtil<T, R>(); | ||
| bag.set(slot, util); | ||
| } | ||
| return util; | ||
| } | ||
|
|
||
| /** | ||
| * Create a per-app {@link LifecycleUtil} facade backed by {@link TeggScope}. | ||
| * | ||
| * The returned object has the same shape/type as a `LifecycleUtil`, but every | ||
| * method resolves the per-app instance from the active {@link TeggScope} bag (the | ||
| * SAME instance {@link lifecycleUtilFromBag} returns for that bag). This lets | ||
| * module-level lifecycle-util singletons (e.g. `EggPrototypeLifecycleUtil`) | ||
| * become per-app WITHOUT changing any call site, so hooks fired deep in | ||
| * metadata/runtime (where there is no `app` reference) hit the current app's util. | ||
| * | ||
| * It is an explicit delegating object (NOT a Proxy) — each call is one slot | ||
| * resolve + a direct method call, with no per-access trap or bound-function | ||
| * allocation. | ||
| */ | ||
| export function createScopedLifecycleUtil<T extends LifecycleContext, R extends LifecycleObject<T>>( | ||
| slot: symbol, | ||
| desc: string, | ||
| ): LifecycleUtil<T, R> { | ||
| const get = (): LifecycleUtil<T, R> => TeggScope.resolve(slot, () => new LifecycleUtil<T, R>(), desc); | ||
| const facade: Pick< | ||
| LifecycleUtil<T, R>, | ||
| | 'registerLifecycle' | ||
| | 'deleteLifecycle' | ||
| | 'getLifecycleList' | ||
| | 'registerObjectLifecycle' | ||
| | 'deleteObjectLifecycle' | ||
| | 'clearObjectLifecycle' | ||
| | 'getObjectLifecycleList' | ||
| | 'objectPreCreate' | ||
| | 'objectPostCreate' | ||
| | 'objectPreDestroy' | ||
| | 'getLifecycleHook' | ||
| > = { | ||
| registerLifecycle: (lifecycle) => get().registerLifecycle(lifecycle), | ||
| deleteLifecycle: (lifecycle) => get().deleteLifecycle(lifecycle), | ||
| getLifecycleList: () => get().getLifecycleList(), | ||
| registerObjectLifecycle: (obj, lifecycle) => get().registerObjectLifecycle(obj, lifecycle), | ||
| deleteObjectLifecycle: (obj, lifecycle) => get().deleteObjectLifecycle(obj, lifecycle), | ||
| clearObjectLifecycle: (obj) => get().clearObjectLifecycle(obj), | ||
| getObjectLifecycleList: (obj) => get().getObjectLifecycleList(obj), | ||
| objectPreCreate: (ctx, obj) => get().objectPreCreate(ctx, obj), | ||
| objectPostCreate: (ctx, obj) => get().objectPostCreate(ctx, obj), | ||
| objectPreDestroy: (ctx, obj) => get().objectPreDestroy(ctx, obj), | ||
| getLifecycleHook: (hookName, proto) => get().getLifecycleHook(hookName, proto), | ||
| }; | ||
| return facade as LifecycleUtil<T, R>; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| export * from '@eggjs/tegg-types/lifecycle'; | ||
|
|
||
| export * from './LifycycleUtil.ts'; | ||
| export * from './ScopedLifecycleUtil.ts'; | ||
| export * from './IdenticalObject.ts'; | ||
| export * from './decorator/index.ts'; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.