@vitejs/plugin-rsc 0.5.19 → 0.5.20

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.
Files changed (41) hide show
  1. package/dist/browser.d.ts +2 -2
  2. package/dist/{chunk-Dj_d7TT4.js → chunk-f2BShn47.js} +1 -1
  3. package/dist/{cjs-D2v1gYgq.js → cjs-v2jRTNln.js} +1 -61
  4. package/dist/core/browser.d.ts +5 -1
  5. package/dist/core/browser.js +1 -1
  6. package/dist/core/plugin.js +25 -1
  7. package/dist/core/rsc.d.ts +1 -1
  8. package/dist/core/rsc.js +84 -1
  9. package/dist/core/ssr.d.ts +1 -1
  10. package/dist/core/ssr.js +1 -1
  11. package/dist/import-environment-B994HXEc.d.ts +11 -0
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.js +4 -4
  14. package/dist/{picocolors-BRyoHAlU.js → picocolors-B0A1T24z.js} +1 -1
  15. package/dist/plugin.d.ts +179 -3
  16. package/dist/plugin.js +1461 -4
  17. package/dist/plugins/cjs.js +62 -1
  18. package/dist/react/browser.d.ts +2 -2
  19. package/dist/react/rsc.js +1 -1
  20. package/dist/rsc.d.ts +3 -2
  21. package/dist/rsc.js +2 -2
  22. package/dist/ssr.d.ts +3 -2
  23. package/dist/ssr.js +1 -1
  24. package/dist/transforms/index.d.ts +1 -1
  25. package/dist/transforms/index.js +1 -1
  26. package/dist/utils/encryption-runtime.js +1 -2
  27. package/dist/utils/rpc.js +89 -1
  28. package/dist/validate-import-DJumtHRw.js +498 -0
  29. package/package.json +7 -7
  30. package/dist/browser-s-WcB8A7.d.ts +0 -6
  31. package/dist/plugin-BGmSmdwL.js +0 -27
  32. package/dist/plugin-K7i9F4Fd.d.ts +0 -187
  33. package/dist/plugin-Xwi_Uxiv.js +0 -1947
  34. package/dist/rpc-EIuXyQpO.js +0 -91
  35. package/dist/rsc-Bhp6O2qz.js +0 -86
  36. /package/dist/{encryption-utils-DdqSKS_O.js → encryption-utils-Bk5eKdu6.js} +0 -0
  37. /package/dist/{index-now_lP2V.d.ts → index-BIbdRBfk.d.ts} +0 -0
  38. /package/dist/{index-CLmWsR1c.d.ts → server-action-B2zS9t-J.d.ts} +0 -0
  39. /package/dist/{transforms-B2EJTNXG.js → server-action-JkEy-6yW.js} +0 -0
  40. /package/dist/{shared-rtJPs0Yj.js → shared-Dhw3vs8e.js} +0 -0
  41. /package/dist/{shared-CGK4coF3.js → shared-d80_k_tn.js} +0 -0
@@ -1,91 +0,0 @@
1
- import { decode, encode } from "turbo-stream";
2
-
3
- //#region src/utils/rpc.ts
4
- const decodePlugins = [(type, ...rest) => {
5
- switch (type) {
6
- case "Request": {
7
- const [method, url, headers, body] = rest;
8
- return { value: new Request(url, {
9
- body,
10
- headers,
11
- method,
12
- duplex: body ? "half" : void 0
13
- }) };
14
- }
15
- case "Response": {
16
- const [status, statusText, headers, body] = rest;
17
- return { value: new Response(body, {
18
- headers,
19
- status,
20
- statusText
21
- }) };
22
- }
23
- }
24
- return false;
25
- }];
26
- const encodePlugins = [(obj) => {
27
- if (obj instanceof Request) return [
28
- "Request",
29
- obj.method,
30
- obj.url,
31
- Array.from(obj.headers),
32
- obj.body
33
- ];
34
- if (obj instanceof Response) return [
35
- "Response",
36
- obj.status,
37
- obj.statusText,
38
- Array.from(obj.headers),
39
- obj.body
40
- ];
41
- return false;
42
- }];
43
- function createRpcServer(handlers) {
44
- return async (request) => {
45
- if (!request.body) throw new Error(`loadModuleDevProxy error: missing request body`);
46
- const reqPayload = await decode(request.body.pipeThrough(new TextDecoderStream()), { plugins: decodePlugins });
47
- const handler = handlers[reqPayload.method];
48
- if (!handler) throw new Error(`loadModuleDevProxy error: unknown method ${reqPayload.method}`);
49
- const resPayload = {
50
- ok: true,
51
- data: void 0
52
- };
53
- try {
54
- resPayload.data = await handler(...reqPayload.args);
55
- } catch (e) {
56
- resPayload.ok = false;
57
- resPayload.data = e;
58
- }
59
- return new Response(encode(resPayload, {
60
- plugins: encodePlugins,
61
- redactErrors: false
62
- }));
63
- };
64
- }
65
- function createRpcClient(options) {
66
- async function callRpc(method, args) {
67
- const body = encode({
68
- method,
69
- args
70
- }, {
71
- plugins: encodePlugins,
72
- redactErrors: false
73
- }).pipeThrough(new TextEncoderStream());
74
- const res = await fetch(options.endpoint, {
75
- method: "POST",
76
- body,
77
- duplex: "half"
78
- });
79
- if (!res.ok || !res.body) throw new Error(`loadModuleDevProxy error: ${res.status} ${res.statusText}`);
80
- const resPayload = await decode(res.body.pipeThrough(new TextDecoderStream()), { plugins: decodePlugins });
81
- if (!resPayload.ok) throw resPayload.data;
82
- return resPayload.data;
83
- }
84
- return new Proxy({}, { get(_target, p, _receiver) {
85
- if (typeof p !== "string" || p === "then") return;
86
- return (...args) => callRpc(p, args);
87
- } });
88
- }
89
-
90
- //#endregion
91
- export { createRpcServer as n, createRpcClient as t };
@@ -1,86 +0,0 @@
1
- import { i as tinyassert, n as memoize } from "./dist-yW9-EeG1.js";
2
- import { a as setInternalRequire, i as removeReferenceCacheTag, n as SERVER_REFERENCE_PREFIX, r as createReferenceCacheTag, t as SERVER_DECODE_CLIENT_PREFIX } from "./shared-rtJPs0Yj.js";
3
- import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
4
-
5
- //#region src/core/rsc.ts
6
- let init = false;
7
- let requireModule;
8
- function setRequireModule(options) {
9
- if (init) return;
10
- init = true;
11
- requireModule = (id) => {
12
- return options.load(removeReferenceCacheTag(id));
13
- };
14
- globalThis.__vite_rsc_server_require__ = memoize(async (id) => {
15
- if (id.startsWith(SERVER_DECODE_CLIENT_PREFIX)) {
16
- id = id.slice(SERVER_DECODE_CLIENT_PREFIX.length);
17
- id = removeReferenceCacheTag(id);
18
- const target = {};
19
- const getOrCreateClientReference = (name) => {
20
- return target[name] ??= ReactServer.registerClientReference(() => {
21
- throw new Error(`Unexpectedly client reference export '${name}' is called on server`);
22
- }, id, name);
23
- };
24
- return new Proxy(target, { getOwnPropertyDescriptor(_target, name) {
25
- if (typeof name !== "string" || name === "then") return Reflect.getOwnPropertyDescriptor(target, name);
26
- getOrCreateClientReference(name);
27
- return Reflect.getOwnPropertyDescriptor(target, name);
28
- } });
29
- }
30
- return requireModule(id);
31
- });
32
- setInternalRequire();
33
- }
34
- async function loadServerAction(id) {
35
- const [file, name] = id.split("#");
36
- return (await requireModule(file))[name];
37
- }
38
- function createServerManifest() {
39
- const cacheTag = import.meta.env.DEV ? createReferenceCacheTag() : "";
40
- return new Proxy({}, { get(_target, $$id, _receiver) {
41
- tinyassert(typeof $$id === "string");
42
- let [id, name] = $$id.split("#");
43
- tinyassert(id);
44
- tinyassert(name);
45
- return {
46
- id: SERVER_REFERENCE_PREFIX + id + cacheTag,
47
- name,
48
- chunks: [],
49
- async: true
50
- };
51
- } });
52
- }
53
- function createServerDecodeClientManifest() {
54
- return new Proxy({}, { get(_target, id) {
55
- return new Proxy({}, { get(_target, name) {
56
- return {
57
- id: SERVER_REFERENCE_PREFIX + SERVER_DECODE_CLIENT_PREFIX + id,
58
- name,
59
- chunks: [],
60
- async: true
61
- };
62
- } });
63
- } });
64
- }
65
- function createClientManifest(options) {
66
- const cacheTag = import.meta.env.DEV ? createReferenceCacheTag() : "";
67
- return new Proxy({}, { get(_target, $$id, _receiver) {
68
- tinyassert(typeof $$id === "string");
69
- let [id, name] = $$id.split("#");
70
- tinyassert(id);
71
- tinyassert(name);
72
- options?.onClientReference?.({
73
- id,
74
- name
75
- });
76
- return {
77
- id: id + cacheTag,
78
- name,
79
- chunks: [],
80
- async: true
81
- };
82
- } });
83
- }
84
-
85
- //#endregion
86
- export { setRequireModule as a, loadServerAction as i, createServerDecodeClientManifest as n, createServerManifest as r, createClientManifest as t };
File without changes
File without changes