Skip to content

Commit a75a4c8

Browse files
committed
refactor: rename
1 parent 7aa26b7 commit a75a4c8

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

packages/devframe/src/rpc/collector.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ export class RpcFunctionsCollectorBase<
3939
}) as LocalFunctions
4040
}
4141

42-
register(fn: RpcFunctionDefinition<string, any, any, any, any, any, SetupContext>, force = false): void {
43-
if (this.definitions.has(fn.name) && !force) {
44-
throw diagnostics.DF0021({ name: fn.name })
42+
register(fnDef: RpcFunctionDefinition<string, any, any, any, any, any, SetupContext>, force = false): void {
43+
if (this.definitions.has(fnDef.name) && !force) {
44+
throw diagnostics.DF0021({ name: fnDef.name })
4545
}
46-
fn = normalizeAgentJsonSerializable(fn)
47-
this.definitions.set(fn.name, fn)
48-
this._onChanged.forEach(cb => cb(fn.name))
46+
ensureAgentJsonSerializable(fnDef)
47+
this.definitions.set(fnDef.name, fnDef)
48+
this._onChanged.forEach(cb => cb(fnDef.name))
4949
}
5050

5151
update(fn: RpcFunctionDefinition<string, any, any, any, any, any, SetupContext>, force = false): void {
5252
if (!this.definitions.has(fn.name) && !force) {
5353
throw diagnostics.DF0022({ name: fn.name })
5454
}
55-
fn = normalizeAgentJsonSerializable(fn)
55+
ensureAgentJsonSerializable(fn)
5656
this.definitions.set(fn.name, fn)
5757
this._onChanged.forEach(cb => cb(fn.name))
5858
}
@@ -94,12 +94,18 @@ export class RpcFunctionsCollectorBase<
9494
}
9595
}
9696

97-
function normalizeAgentJsonSerializable<T extends RpcFunctionDefinition<string, any, any, any, any, any, any>>(
98-
fn: T,
99-
): T {
100-
if (fn.agent && fn.jsonSerializable === false)
101-
throw diagnostics.DF0019({ name: fn.name })
102-
if (fn.agent && fn.jsonSerializable === undefined)
103-
return { ...fn, jsonSerializable: true }
104-
return fn
97+
/**
98+
* Prevents registering an agent function that is explicitly marked as
99+
* non-serializable, and ensures that agent functions are marked as
100+
* serializable by default.
101+
*
102+
* @internal
103+
*/
104+
function ensureAgentJsonSerializable(
105+
fnDef: RpcFunctionDefinition<string, any, any, any, any, any, any>,
106+
): void {
107+
if (fnDef.agent && fnDef.jsonSerializable === false)
108+
throw diagnostics.DF0019({ name: fnDef.name })
109+
if (fnDef.agent && !fnDef.jsonSerializable)
110+
fnDef.jsonSerializable = true
105111
}

0 commit comments

Comments
 (0)