Criada a API do site
This commit is contained in:
21
node_modules/vite-dev-rpc/LICENSE
generated
vendored
Normal file
21
node_modules/vite-dev-rpc/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
25
node_modules/vite-dev-rpc/README.md
generated
vendored
Normal file
25
node_modules/vite-dev-rpc/README.md
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# vite-dev-rpc
|
||||
|
||||
[](https://www.npmjs.com/package/vite-dev-rpc)
|
||||
|
||||
Remote procedure call for client-server communication in Vite plugins.
|
||||
|
||||
> Requires Vite ^2.9.0-beta.9
|
||||
|
||||
Based on
|
||||
|
||||
- [`birpc`](https://github.com/antfu/birpc) - Message-based two-way remote procedure call.
|
||||
- [`vite-hot-client`](https://github.com/antfu/vite-hot-client) - Get `import.meta.hot` at runtime.
|
||||
- [`import.meta.hot.send` API in Vite 2.9](https://github.com/vitejs/vite/pull/7437) - Server-client communication support.
|
||||
|
||||
## Sponsors
|
||||
|
||||
<p align="center">
|
||||
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
||||
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
|
||||
62
node_modules/vite-dev-rpc/dist/index.cjs
generated
vendored
Normal file
62
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
node_modules/vite-dev-rpc/dist/index.d.cts
generated
vendored
Normal file
9
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
node_modules/vite-dev-rpc/dist/index.d.mts
generated
vendored
Normal file
9
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
node_modules/vite-dev-rpc/dist/index.d.ts
generated
vendored
Normal file
9
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
node_modules/vite-dev-rpc/dist/index.mjs
generated
vendored
Normal file
59
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 };
|
||||
72
node_modules/vite-dev-rpc/package.json
generated
vendored
Normal file
72
node_modules/vite-dev-rpc/package.json
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "vite-dev-rpc",
|
||||
"type": "module",
|
||||
"version": "1.1.0",
|
||||
"description": "Remote procedure call for client-server communication in Vite plugins",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
||||
"license": "MIT",
|
||||
"funding": "https://github.com/sponsors/antfu",
|
||||
"homepage": "https://github.com/antfu/vite-dev-rpc#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/antfu/vite-dev-rpc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/antfu/vite-dev-rpc/issues"
|
||||
},
|
||||
"keywords": [],
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"./dist/*",
|
||||
"./dist/index.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"vite": "^2.9.0 || ^3.0.0-0 || ^4.0.0-0 || ^5.0.0-0 || ^6.0.1 || ^7.0.0-0"
|
||||
},
|
||||
"dependencies": {
|
||||
"birpc": "^2.4.0",
|
||||
"vite-hot-client": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^4.16.1",
|
||||
"@antfu/ni": "^25.0.0",
|
||||
"@babel/types": "^7.27.7",
|
||||
"@types/node": "^24.0.7",
|
||||
"bumpp": "^10.2.0",
|
||||
"eslint": "^9.30.0",
|
||||
"esno": "^4.8.0",
|
||||
"pnpm": "^10.12.4",
|
||||
"rimraf": "^6.0.1",
|
||||
"typescript": "^5.8.3",
|
||||
"unbuild": "^3.5.0",
|
||||
"vite": "^7.0.0",
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && unbuild",
|
||||
"dev": "unbuild --stub",
|
||||
"lint": "eslint .",
|
||||
"play": "nr dev && vite playground",
|
||||
"release": "bumpp && pnpm publish",
|
||||
"start": "esno src/index.ts",
|
||||
"test": "vitest",
|
||||
"typecheck": "tsc --noEmit"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user