Skip to content

Commit 641cc7a

Browse files
fix(core): adapt getPeerSettings to async parseSchema after #1846 widen
Calls peerSchema['~standard'].validate directly (sync path); falls back to raw blob with a warning if the schema's validation is async, since getPeerSettings() is a synchronous read of already-received capabilities.
1 parent 6dc66eb commit 641cc7a

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

packages/core/src/shared/extensionHandle.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { SdkError, SdkErrorCode } from '../errors/sdkErrors.js';
22
import type { JSONObject, Result } from '../types/types.js';
33
import type { AnySchema, SchemaOutput } from '../util/schema.js';
4-
import { parseSchema } from '../util/schema.js';
54
import type { BaseContext, NotificationOptions, RequestOptions } from './protocol.js';
65

76
/**
@@ -86,14 +85,20 @@ export class ExtensionHandle<Local extends JSONObject, Peer = JSONObject, Contex
8685
if (this._peerSchema === undefined) {
8786
return raw as Peer;
8887
}
89-
const parsed = parseSchema(this._peerSchema, raw);
90-
if (!parsed.success) {
88+
const result = this._peerSchema['~standard'].validate(raw);
89+
if (result instanceof Promise) {
9190
console.warn(
92-
`[ExtensionHandle] Peer's capabilities.extensions["${this.id}"] failed schema validation: ${parsed.error.message}`
91+
`[ExtensionHandle] peerSchema for extension "${this.id}" has async validation; getPeerSettings() returns the raw (unvalidated) blob.`
92+
);
93+
return raw as Peer;
94+
}
95+
if (result.issues && result.issues.length > 0) {
96+
console.warn(
97+
`[ExtensionHandle] Peer's capabilities.extensions["${this.id}"] failed schema validation: ${result.issues.map(i => i.message).join(', ')}`
9398
);
9499
return undefined;
95100
}
96-
return parsed.data as Peer;
101+
return (result as { value: Peer }).value;
97102
}
98103

99104
/**

0 commit comments

Comments
 (0)