devframe 0.9.17 → 0.9.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/in-page-channel/index.mjs +26 -16
- package/package.json +1 -1
|
@@ -186,6 +186,12 @@ function createLocalFunctionRegistry(codec) {
|
|
|
186
186
|
register(definition) {
|
|
187
187
|
definitions.set(channelMethod(definition.type, definition.name), definition);
|
|
188
188
|
},
|
|
189
|
+
registerInternal(method, handler) {
|
|
190
|
+
definitions.set(method, {
|
|
191
|
+
name: method,
|
|
192
|
+
handler
|
|
193
|
+
});
|
|
194
|
+
},
|
|
189
195
|
on(name, listener) {
|
|
190
196
|
const key = channelMethod("event", name);
|
|
191
197
|
let registered = listeners.get(key);
|
|
@@ -202,12 +208,7 @@ function createLocalFunctionRegistry(codec) {
|
|
|
202
208
|
resolve(name) {
|
|
203
209
|
const definition = definitions.get(name);
|
|
204
210
|
const registered = listeners.get(name);
|
|
205
|
-
if (!definition && !registered?.size)
|
|
206
|
-
if (name.startsWith(FUNCTION_METHOD_PREFIX)) return () => {
|
|
207
|
-
throw diagnostics.DF0077({ name: name.slice(FUNCTION_METHOD_PREFIX.length) });
|
|
208
|
-
};
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
+
if (!definition && !registered?.size) return void 0;
|
|
211
212
|
return async (...rawArgs) => {
|
|
212
213
|
const args = codec.deserialize ? rawArgs.map(codec.deserialize) : rawArgs;
|
|
213
214
|
if (definition?.jsonSerializable) assertJsonSerializable(args, "its arguments", definition.name);
|
|
@@ -221,6 +222,21 @@ function createLocalFunctionRegistry(codec) {
|
|
|
221
222
|
}
|
|
222
223
|
};
|
|
223
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Consult each registry in order and, only once none owns the name, fall back
|
|
227
|
+
* to the coded "not registered" error for a `function:` call (events stay
|
|
228
|
+
* silent). The fallback lives here, after every registry, so chaining a
|
|
229
|
+
* state registry ahead of the user registry never masks a real handler.
|
|
230
|
+
*/
|
|
231
|
+
function resolveLocalHandler(name, registries) {
|
|
232
|
+
for (const registry of registries) {
|
|
233
|
+
const handler = registry(name);
|
|
234
|
+
if (handler) return handler;
|
|
235
|
+
}
|
|
236
|
+
if (name.startsWith(FUNCTION_METHOD_PREFIX)) return () => {
|
|
237
|
+
throw diagnostics.DF0077({ name: name.slice(FUNCTION_METHOD_PREFIX.length) });
|
|
238
|
+
};
|
|
239
|
+
}
|
|
224
240
|
function wrapPostError(error) {
|
|
225
241
|
if (error instanceof DOMException && error.name === "DataCloneError") return new InPageChannelError("not-cloneable", `a payload could not be structured-cloned across the in-page channel: ${error.message}. Strip non-cloneable values (functions, DOM nodes, framework reactivity proxies) before sending: declare the function \`jsonSerializable: true\` for a precise error, or provide a \`serialize\` hook.`, { cause: error });
|
|
226
242
|
return error;
|
|
@@ -539,12 +555,9 @@ function createPageScriptChannel(options) {
|
|
|
539
555
|
}
|
|
540
556
|
});
|
|
541
557
|
const stateRegistry = createLocalFunctionRegistry(codec);
|
|
542
|
-
for (const [
|
|
543
|
-
name,
|
|
544
|
-
handler
|
|
545
|
-
});
|
|
558
|
+
for (const [method, handler] of Object.entries(internal.internalHandlers)) stateRegistry.registerInternal(method, handler);
|
|
546
559
|
internal.attached = attachChannelPort(port, {
|
|
547
|
-
resolveLocal: (fnName) => stateRegistry.resolve
|
|
560
|
+
resolveLocal: (fnName) => resolveLocalHandler(fnName, [stateRegistry.resolve, registry.resolve]),
|
|
548
561
|
onControl: (kind) => {
|
|
549
562
|
if (kind === "ping") internal.attached.postControl("pong");
|
|
550
563
|
},
|
|
@@ -697,10 +710,7 @@ function connectPanelChannel(options) {
|
|
|
697
710
|
call: (method, args) => enqueueCall(method, serializeArgs(codec, args))
|
|
698
711
|
});
|
|
699
712
|
const stateRegistry = createLocalFunctionRegistry(codec);
|
|
700
|
-
for (const [
|
|
701
|
-
name,
|
|
702
|
-
handler
|
|
703
|
-
});
|
|
713
|
+
for (const [method, handler] of Object.entries(stateHost.handlers)) stateRegistry.registerInternal(method, handler);
|
|
704
714
|
function sendEventNow(method, args) {
|
|
705
715
|
attached?.rpc.$callRaw({
|
|
706
716
|
method,
|
|
@@ -746,7 +756,7 @@ function connectPanelChannel(options) {
|
|
|
746
756
|
reason: "the panel adopted a newer port"
|
|
747
757
|
});
|
|
748
758
|
attached = attachChannelPort(port, {
|
|
749
|
-
resolveLocal: (fnName) => stateRegistry.resolve
|
|
759
|
+
resolveLocal: (fnName) => resolveLocalHandler(fnName, [stateRegistry.resolve, registry.resolve]),
|
|
750
760
|
onControl: (kind) => {
|
|
751
761
|
if (kind === "ping") attached?.postControl("pong");
|
|
752
762
|
},
|
package/package.json
CHANGED