Skip to content

Commit 51aad83

Browse files
committed
fix: scope.scope() replaces current scope instead of chaining
1 parent 0607a49 commit 51aad83

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

packages/devframe/src/client/scope.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ describe('client.scope()', () => {
5757
expect(scoped.scope(null)).toBe(rpc)
5858
})
5959

60+
it('replaces the scope instead of chaining when calling scope() on a scoped client', () => {
61+
const { rpc } = createMockClient()
62+
rpc.scope = (ns?: string | null) => (ns ? createScopedClientContext(rpc, ns) : rpc) as any
63+
const scope1 = rpc.scope('first')
64+
const scope2 = scope1.scope('second')
65+
expect(scope2.namespace).toBe('second')
66+
})
67+
6068
it('qualifies bare call/callEvent/callOptional method names', () => {
6169
const { rpc } = createMockClient()
6270
const scoped = createScopedClientContext(rpc, 'my-plugin')

packages/devframe/src/client/scope.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export interface DevframeScopedClientContext<NS extends string = string, Setting
8585
rpc: DevframeScopedClientRpc<NS>
8686
/** Persisted settings for this namespace (`global` + `project`). */
8787
settings: DevframeSettings<Settings>
88-
/** Derive another scope, or pass `null` / `''` to get the base client. */
88+
/**
89+
* Return a new scoped client, replacing the current scope. Pass `null`
90+
* or `''` to un-scope and get the base client.
91+
*/
8992
scope: DevframeRpcClient['scope']
9093
}
9194

packages/devframe/src/node/__tests__/scope.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ describe('ctx.scope()', () => {
4747
expect(scoped.scope(null)).toBe(ctx)
4848
})
4949

50+
it('replaces the scope instead of chaining when calling scope() on a scoped context', async () => {
51+
const { ctx } = await createCtx()
52+
const scope1 = ctx.scope('first')
53+
const scope2 = scope1.scope('second')
54+
expect(scope2.namespace).toBe('second')
55+
})
56+
5057
it('exposes the base context and read-only fields', async () => {
5158
const { ctx } = await createCtx()
5259
const scoped = ctx.scope('my-plugin')

packages/devframe/src/types/scope.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ export interface DevframeScopedNodeContext<NS extends string = string, Settings
208208
views: DevframeViewHost
209209
diagnostics: DevframeDiagnosticsHost
210210
agent: DevframeAgentHost
211-
/** Derive another scope, or pass `null` / `''` to get the base context. */
211+
/**
212+
* Return a new scoped context, replacing the current scope. Pass `null`
213+
* or `''` to un-scope and get the base context.
214+
*/
212215
scope: DevframeNodeContext['scope']
213216
}

0 commit comments

Comments
 (0)