New Project
All checks were successful
BeijingMediaOfficialWebsite-ZhaoJian/BeijingMediaOfficialWebsite-ZhaoJian/pipeline/head This commit looks good
All checks were successful
BeijingMediaOfficialWebsite-ZhaoJian/BeijingMediaOfficialWebsite-ZhaoJian/pipeline/head This commit looks good
This commit is contained in:
62
web/node_modules/vite-dev-rpc/dist/index.cjs
generated
vendored
Normal file
62
web/node_modules/vite-dev-rpc/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
const birpc = require('birpc');
|
||||
|
||||
function createRPCServer(name, ws, functions, options = {}) {
|
||||
const event = `${name}:rpc`;
|
||||
const group = birpc.createBirpcGroup(
|
||||
functions,
|
||||
() => birpc.cachedMap(
|
||||
Array.from(ws?.clients || []),
|
||||
(channel) => {
|
||||
if (channel.socket.readyState === channel.socket.CLOSED)
|
||||
return void 0;
|
||||
return {
|
||||
on: (fn) => {
|
||||
function handler(data, source) {
|
||||
if (!source.socket)
|
||||
throw new Error("source.socket is undefined");
|
||||
if (channel.socket === source.socket)
|
||||
fn(data, source);
|
||||
}
|
||||
ws.on(event, handler);
|
||||
channel.socket.on("close", () => {
|
||||
ws.off(event, handler);
|
||||
});
|
||||
},
|
||||
post: (data) => {
|
||||
channel.send(event, data);
|
||||
}
|
||||
};
|
||||
}
|
||||
).filter((c) => !!c),
|
||||
options
|
||||
);
|
||||
ws.on("connection", () => {
|
||||
group.updateChannels();
|
||||
});
|
||||
return group.broadcast;
|
||||
}
|
||||
function createRPCClient(name, hot, functions = {}, options = {}) {
|
||||
const event = `${name}:rpc`;
|
||||
const promise = Promise.resolve(hot).then((r) => {
|
||||
if (!r)
|
||||
console.warn("[vite-hot-client] Received undefined hot context, RPC calls are ignored");
|
||||
return r;
|
||||
});
|
||||
return birpc.createBirpc(
|
||||
functions,
|
||||
{
|
||||
...options,
|
||||
on: async (fn) => {
|
||||
(await promise)?.on(event, fn);
|
||||
},
|
||||
post: async (data) => {
|
||||
(await promise)?.send(event, data);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports.createRPCClient = createRPCClient;
|
||||
exports.createRPCServer = createRPCServer;
|
||||
9
web/node_modules/vite-dev-rpc/dist/index.d.cts
generated
vendored
Normal file
9
web/node_modules/vite-dev-rpc/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as birpc from 'birpc';
|
||||
import { EventOptions, BirpcOptions } from 'birpc';
|
||||
import { WebSocketServer } from 'vite';
|
||||
import { ViteHotContext } from 'vite-hot-client';
|
||||
|
||||
declare function createRPCServer<ClientFunction extends object, ServerFunctions extends object>(name: string, ws: WebSocketServer, functions: ServerFunctions, options?: EventOptions<ClientFunction>): birpc.BirpcGroupReturn<ClientFunction>;
|
||||
declare function createRPCClient<ServerFunctions extends object, ClientFunctions extends object>(name: string, hot: ViteHotContext | undefined | Promise<ViteHotContext | undefined>, functions?: ClientFunctions, options?: Omit<BirpcOptions<ServerFunctions>, 'on' | 'post'>): birpc.BirpcReturn<ServerFunctions, ClientFunctions>;
|
||||
|
||||
export { createRPCClient, createRPCServer };
|
||||
9
web/node_modules/vite-dev-rpc/dist/index.d.mts
generated
vendored
Normal file
9
web/node_modules/vite-dev-rpc/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as birpc from 'birpc';
|
||||
import { EventOptions, BirpcOptions } from 'birpc';
|
||||
import { WebSocketServer } from 'vite';
|
||||
import { ViteHotContext } from 'vite-hot-client';
|
||||
|
||||
declare function createRPCServer<ClientFunction extends object, ServerFunctions extends object>(name: string, ws: WebSocketServer, functions: ServerFunctions, options?: EventOptions<ClientFunction>): birpc.BirpcGroupReturn<ClientFunction>;
|
||||
declare function createRPCClient<ServerFunctions extends object, ClientFunctions extends object>(name: string, hot: ViteHotContext | undefined | Promise<ViteHotContext | undefined>, functions?: ClientFunctions, options?: Omit<BirpcOptions<ServerFunctions>, 'on' | 'post'>): birpc.BirpcReturn<ServerFunctions, ClientFunctions>;
|
||||
|
||||
export { createRPCClient, createRPCServer };
|
||||
9
web/node_modules/vite-dev-rpc/dist/index.d.ts
generated
vendored
Normal file
9
web/node_modules/vite-dev-rpc/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as birpc from 'birpc';
|
||||
import { EventOptions, BirpcOptions } from 'birpc';
|
||||
import { WebSocketServer } from 'vite';
|
||||
import { ViteHotContext } from 'vite-hot-client';
|
||||
|
||||
declare function createRPCServer<ClientFunction extends object, ServerFunctions extends object>(name: string, ws: WebSocketServer, functions: ServerFunctions, options?: EventOptions<ClientFunction>): birpc.BirpcGroupReturn<ClientFunction>;
|
||||
declare function createRPCClient<ServerFunctions extends object, ClientFunctions extends object>(name: string, hot: ViteHotContext | undefined | Promise<ViteHotContext | undefined>, functions?: ClientFunctions, options?: Omit<BirpcOptions<ServerFunctions>, 'on' | 'post'>): birpc.BirpcReturn<ServerFunctions, ClientFunctions>;
|
||||
|
||||
export { createRPCClient, createRPCServer };
|
||||
59
web/node_modules/vite-dev-rpc/dist/index.mjs
generated
vendored
Normal file
59
web/node_modules/vite-dev-rpc/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import { createBirpcGroup, cachedMap, createBirpc } from 'birpc';
|
||||
|
||||
function createRPCServer(name, ws, functions, options = {}) {
|
||||
const event = `${name}:rpc`;
|
||||
const group = createBirpcGroup(
|
||||
functions,
|
||||
() => cachedMap(
|
||||
Array.from(ws?.clients || []),
|
||||
(channel) => {
|
||||
if (channel.socket.readyState === channel.socket.CLOSED)
|
||||
return void 0;
|
||||
return {
|
||||
on: (fn) => {
|
||||
function handler(data, source) {
|
||||
if (!source.socket)
|
||||
throw new Error("source.socket is undefined");
|
||||
if (channel.socket === source.socket)
|
||||
fn(data, source);
|
||||
}
|
||||
ws.on(event, handler);
|
||||
channel.socket.on("close", () => {
|
||||
ws.off(event, handler);
|
||||
});
|
||||
},
|
||||
post: (data) => {
|
||||
channel.send(event, data);
|
||||
}
|
||||
};
|
||||
}
|
||||
).filter((c) => !!c),
|
||||
options
|
||||
);
|
||||
ws.on("connection", () => {
|
||||
group.updateChannels();
|
||||
});
|
||||
return group.broadcast;
|
||||
}
|
||||
function createRPCClient(name, hot, functions = {}, options = {}) {
|
||||
const event = `${name}:rpc`;
|
||||
const promise = Promise.resolve(hot).then((r) => {
|
||||
if (!r)
|
||||
console.warn("[vite-hot-client] Received undefined hot context, RPC calls are ignored");
|
||||
return r;
|
||||
});
|
||||
return createBirpc(
|
||||
functions,
|
||||
{
|
||||
...options,
|
||||
on: async (fn) => {
|
||||
(await promise)?.on(event, fn);
|
||||
},
|
||||
post: async (data) => {
|
||||
(await promise)?.send(event, data);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export { createRPCClient, createRPCServer };
|
||||
Reference in New Issue
Block a user