@fluojs/react 0.1.0
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/LICENSE +21 -0
- package/README.ko.md +715 -0
- package/README.md +729 -0
- package/dist/client/errors.d.ts +12 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +19 -0
- package/dist/client/hooks.d.ts +38 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +56 -0
- package/dist/client/link.d.ts +13 -0
- package/dist/client/link.d.ts.map +1 -0
- package/dist/client/link.js +39 -0
- package/dist/client/provider.d.ts +12 -0
- package/dist/client/provider.d.ts.map +1 -0
- package/dist/client/provider.js +54 -0
- package/dist/client/search-params.d.ts +17 -0
- package/dist/client/search-params.d.ts.map +1 -0
- package/dist/client/search-params.js +39 -0
- package/dist/client/snapshot.d.ts +15 -0
- package/dist/client/snapshot.d.ts.map +1 -0
- package/dist/client/snapshot.js +57 -0
- package/dist/client/store.d.ts +26 -0
- package/dist/client/store.d.ts.map +1 -0
- package/dist/client/store.js +138 -0
- package/dist/client/types.d.ts +63 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +1 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +5 -0
- package/dist/decorators.d.ts +80 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +194 -0
- package/dist/experimental/rsc-diagnostics.d.ts +13 -0
- package/dist/experimental/rsc-diagnostics.d.ts.map +1 -0
- package/dist/experimental/rsc-diagnostics.js +58 -0
- package/dist/experimental/rsc-flight-response.d.ts +15 -0
- package/dist/experimental/rsc-flight-response.d.ts.map +1 -0
- package/dist/experimental/rsc-flight-response.js +76 -0
- package/dist/experimental/rsc-manifest.d.ts +13 -0
- package/dist/experimental/rsc-manifest.d.ts.map +1 -0
- package/dist/experimental/rsc-manifest.js +88 -0
- package/dist/experimental/rsc-types.d.ts +118 -0
- package/dist/experimental/rsc-types.d.ts.map +1 -0
- package/dist/experimental/rsc-types.js +50 -0
- package/dist/experimental/rsc.d.ts +11 -0
- package/dist/experimental/rsc.d.ts.map +1 -0
- package/dist/experimental/rsc.js +8 -0
- package/dist/experimental/server-functions-client.d.ts +14 -0
- package/dist/experimental/server-functions-client.d.ts.map +1 -0
- package/dist/experimental/server-functions-client.js +120 -0
- package/dist/experimental/server-functions-configuration.d.ts +17 -0
- package/dist/experimental/server-functions-configuration.d.ts.map +1 -0
- package/dist/experimental/server-functions-configuration.js +68 -0
- package/dist/experimental/server-functions-errors.d.ts +19 -0
- package/dist/experimental/server-functions-errors.d.ts.map +1 -0
- package/dist/experimental/server-functions-errors.js +22 -0
- package/dist/experimental/server-functions-reference.d.ts +22 -0
- package/dist/experimental/server-functions-reference.d.ts.map +1 -0
- package/dist/experimental/server-functions-reference.js +76 -0
- package/dist/experimental/server-functions-serialization.d.ts +37 -0
- package/dist/experimental/server-functions-serialization.d.ts.map +1 -0
- package/dist/experimental/server-functions-serialization.js +158 -0
- package/dist/experimental/server-functions-server.d.ts +14 -0
- package/dist/experimental/server-functions-server.d.ts.map +1 -0
- package/dist/experimental/server-functions-server.js +176 -0
- package/dist/experimental/server-functions-types.d.ts +86 -0
- package/dist/experimental/server-functions-types.d.ts.map +1 -0
- package/dist/experimental/server-functions-types.js +35 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/module.d.ts +40 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +58 -0
- package/dist/render-stream.d.ts +27 -0
- package/dist/render-stream.d.ts.map +1 -0
- package/dist/render-stream.js +135 -0
- package/dist/render.d.ts +50 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +201 -0
- package/dist/server-entry.d.ts +87 -0
- package/dist/server-entry.d.ts.map +1 -0
- package/dist/server-entry.js +126 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/vite/asset-utils.d.ts +57 -0
- package/dist/vite/asset-utils.d.ts.map +1 -0
- package/dist/vite/asset-utils.js +184 -0
- package/dist/vite/create-asset-manifest.d.ts +9 -0
- package/dist/vite/create-asset-manifest.d.ts.map +1 -0
- package/dist/vite/create-asset-manifest.js +127 -0
- package/dist/vite/diagnostics.d.ts +27 -0
- package/dist/vite/diagnostics.d.ts.map +1 -0
- package/dist/vite/diagnostics.js +47 -0
- package/dist/vite/parse-manifest.d.ts +18 -0
- package/dist/vite/parse-manifest.d.ts.map +1 -0
- package/dist/vite/parse-manifest.js +168 -0
- package/dist/vite/types.d.ts +187 -0
- package/dist/vite/types.d.ts.map +1 -0
- package/dist/vite/types.js +59 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** Exact React, React DOM, and Flight renderer version supported by the experimental RSC contract. */
|
|
2
|
+
export declare const REACT_RSC_SUPPORTED_VERSION = "19.2.6";
|
|
3
|
+
/** HTTP content type written for experimental React Flight payload responses. */
|
|
4
|
+
export declare const REACT_RSC_FLIGHT_CONTENT_TYPE = "text/x-component; charset=utf-8";
|
|
5
|
+
/** Stable diagnostic codes emitted by the experimental RSC compatibility and manifest checks. */
|
|
6
|
+
export declare const REACT_RSC_DIAGNOSTIC_CODES: {
|
|
7
|
+
readonly emptyClientReferenceManifest: "react-rsc-empty-client-reference-manifest";
|
|
8
|
+
readonly emptyServerClientModuleMap: "react-rsc-empty-server-client-module-map";
|
|
9
|
+
readonly missingClientReferenceManifest: "react-rsc-missing-client-reference-manifest";
|
|
10
|
+
readonly missingServerClientModuleMap: "react-rsc-missing-server-client-module-map";
|
|
11
|
+
readonly unknownClientReference: "react-rsc-unknown-client-reference";
|
|
12
|
+
readonly unsupportedFlightRendererVersion: "react-rsc-unsupported-flight-renderer-version";
|
|
13
|
+
readonly unsupportedReactDomVersion: "react-rsc-unsupported-react-dom-version";
|
|
14
|
+
readonly unsupportedReactVersion: "react-rsc-unsupported-react-version";
|
|
15
|
+
readonly unsupportedRuntime: "react-rsc-unsupported-runtime";
|
|
16
|
+
};
|
|
17
|
+
/** Machine-readable diagnostic code produced by the experimental RSC contract. */
|
|
18
|
+
export type ReactRscDiagnosticCode = (typeof REACT_RSC_DIAGNOSTIC_CODES)[keyof typeof REACT_RSC_DIAGNOSTIC_CODES];
|
|
19
|
+
/** Actionable compatibility or build diagnostic produced instead of an expected configuration throw. */
|
|
20
|
+
export type ReactRscDiagnostic = {
|
|
21
|
+
/** Stable machine-readable diagnostic code. */
|
|
22
|
+
readonly code: ReactRscDiagnosticCode;
|
|
23
|
+
/** Human-readable explanation of the unsupported condition. */
|
|
24
|
+
readonly message: string;
|
|
25
|
+
/** Build manifest path associated with the diagnostic, when applicable. */
|
|
26
|
+
readonly path?: string;
|
|
27
|
+
};
|
|
28
|
+
/** Runtime capabilities required by the experimental Flight response transport. */
|
|
29
|
+
export type ReactRscRuntimeCapabilities = {
|
|
30
|
+
/** Application-facing runtime name included in unsupported-runtime diagnostics. */
|
|
31
|
+
readonly name: string;
|
|
32
|
+
/** Whether the runtime provides Web `ReadableStream` support. */
|
|
33
|
+
readonly webStreams: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** Build-adapter capabilities required to connect RSC module graphs explicitly. */
|
|
36
|
+
export type ReactRscBuildCapabilities = {
|
|
37
|
+
/** Whether the build adapter produced a client-reference manifest. */
|
|
38
|
+
readonly clientReferenceManifest: boolean;
|
|
39
|
+
/** Application-facing build adapter name included in diagnostics. */
|
|
40
|
+
readonly name: string;
|
|
41
|
+
/** Whether the build adapter produced an explicit server-to-client module map. */
|
|
42
|
+
readonly serverClientModuleMap: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** Environment inputs checked before an application enables the experimental RSC path. */
|
|
45
|
+
export type ReactRscEnvironmentOptions = {
|
|
46
|
+
/** Explicit build-adapter capabilities. */
|
|
47
|
+
readonly build: ReactRscBuildCapabilities;
|
|
48
|
+
/** Installed Flight renderer version, such as `react-server-dom-webpack`. */
|
|
49
|
+
readonly flightRendererVersion: string;
|
|
50
|
+
/** Installed `react-dom` version. */
|
|
51
|
+
readonly reactDomVersion: string;
|
|
52
|
+
/** Installed `react` version. */
|
|
53
|
+
readonly reactVersion: string;
|
|
54
|
+
/** Explicit runtime capabilities. */
|
|
55
|
+
readonly runtime: ReactRscRuntimeCapabilities;
|
|
56
|
+
};
|
|
57
|
+
/** Result of inspecting one experimental RSC runtime and build environment. */
|
|
58
|
+
export type ReactRscSupportResult = {
|
|
59
|
+
readonly diagnostics: readonly [];
|
|
60
|
+
readonly ok: true;
|
|
61
|
+
} | {
|
|
62
|
+
readonly diagnostics: readonly ReactRscDiagnostic[];
|
|
63
|
+
readonly ok: false;
|
|
64
|
+
};
|
|
65
|
+
/** Bundler-produced metadata for one client module export referenced by a Flight payload. */
|
|
66
|
+
export type ReactRscClientReference = {
|
|
67
|
+
/** Whether the referenced module is loaded asynchronously. */
|
|
68
|
+
readonly async?: boolean;
|
|
69
|
+
/** Build chunks required to load the client reference. */
|
|
70
|
+
readonly chunks: readonly string[];
|
|
71
|
+
/** Bundler-specific module id consumed by the application-owned Flight renderer. */
|
|
72
|
+
readonly id: string;
|
|
73
|
+
/** Export name consumed from the referenced client module. */
|
|
74
|
+
readonly name: string;
|
|
75
|
+
};
|
|
76
|
+
/** Client-reference metadata keyed by an application-owned stable reference id. */
|
|
77
|
+
export type ReactRscClientReferenceManifest = Readonly<Record<string, ReactRscClientReference>>;
|
|
78
|
+
/** Server module exports mapped to keys in the client-reference manifest. */
|
|
79
|
+
export type ReactRscServerClientModuleMap = Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
80
|
+
/** Build output accepted by `createReactRscManifest(...)`. */
|
|
81
|
+
export type ReactRscManifestInput = {
|
|
82
|
+
/** Client references produced by the application build adapter. */
|
|
83
|
+
readonly clientReferences: ReactRscClientReferenceManifest;
|
|
84
|
+
/** Server module exports mapped to client-reference keys. */
|
|
85
|
+
readonly serverClientModuleMap: ReactRscServerClientModuleMap;
|
|
86
|
+
};
|
|
87
|
+
/** Defensive RSC module graph snapshot passed to an application-owned Flight renderer. */
|
|
88
|
+
export type ReactRscManifest = ReactRscManifestInput;
|
|
89
|
+
/** Result of validating and snapshotting an experimental RSC manifest. */
|
|
90
|
+
export type ReactRscManifestResult = {
|
|
91
|
+
readonly diagnostics: readonly [];
|
|
92
|
+
readonly manifest: ReactRscManifest;
|
|
93
|
+
readonly ok: true;
|
|
94
|
+
} | {
|
|
95
|
+
readonly diagnostics: readonly ReactRscDiagnostic[];
|
|
96
|
+
readonly ok: false;
|
|
97
|
+
};
|
|
98
|
+
/** Encoded React Flight payload accepted by the experimental HTTP response helper. */
|
|
99
|
+
export type ReactFlightPayload = string | Uint8Array | ReadableStream<Uint8Array>;
|
|
100
|
+
/** Additional HTTP headers applied to an experimental Flight response. */
|
|
101
|
+
export type ReactFlightResponseHeaders = Readonly<Record<string, string | readonly string[]>>;
|
|
102
|
+
/** Options applied after ordinary fluo route success metadata for a Flight response. */
|
|
103
|
+
export type ReactFlightResponseOptions = {
|
|
104
|
+
/** Additional response headers; the Flight `Content-Type` remains fixed. */
|
|
105
|
+
readonly headers?: ReactFlightResponseHeaders;
|
|
106
|
+
/** HTTP status overriding ordinary route success metadata. */
|
|
107
|
+
readonly status?: number;
|
|
108
|
+
};
|
|
109
|
+
/** Response entry returned from an ordinary fluo HTTP handler to emit an encoded Flight payload. */
|
|
110
|
+
export type ReactFlightResponse = {
|
|
111
|
+
/** Additional response headers applied before the payload commits. */
|
|
112
|
+
readonly headers: ReactFlightResponseHeaders;
|
|
113
|
+
/** Encoded Flight payload or one-shot Flight stream. */
|
|
114
|
+
readonly payload: ReactFlightPayload;
|
|
115
|
+
/** Optional status overriding ordinary route success metadata. */
|
|
116
|
+
readonly status?: number;
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=rsc-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rsc-types.d.ts","sourceRoot":"","sources":["../../src/experimental/rsc-types.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,eAAO,MAAM,2BAA2B,WAAW,CAAC;AAEpD,iFAAiF;AACjF,eAAO,MAAM,6BAA6B,oCAAoC,CAAC;AAE/E,iGAAiG;AACjG,eAAO,MAAM,0BAA0B;;;;;;;;;;CAU7B,CAAC;AAEX,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,GAChC,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,OAAO,0BAA0B,CAAC,CAAC;AAE/E,wGAAwG;AACxG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,2BAA2B,GAAG;IACxC,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,yBAAyB,GAAG;IACtC,sEAAsE;IACtE,QAAQ,CAAC,uBAAuB,EAAE,OAAO,CAAC;IAC1C,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kFAAkF;IAClF,QAAQ,CAAC,qBAAqB,EAAE,OAAO,CAAC;CACzC,CAAC;AAEF,0FAA0F;AAC1F,MAAM,MAAM,0BAA0B,GAAG;IACvC,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,yBAAyB,CAAC;IAC1C,6EAA6E;IAC7E,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,qCAAqC;IACrC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,iCAAiC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,2BAA2B,CAAC;CAC/C,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAC7B;IAAE,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,WAAW,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhF,6FAA6F;AAC7F,MAAM,MAAM,uBAAuB,GAAG;IACpC,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,oFAAoF;IACpF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC;AAEhG,6EAA6E;AAC7E,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvG,8DAA8D;AAC9D,MAAM,MAAM,qBAAqB,GAAG;IAClC,mEAAmE;IACnE,QAAQ,CAAC,gBAAgB,EAAE,+BAA+B,CAAC;IAC3D,6DAA6D;IAC7D,QAAQ,CAAC,qBAAqB,EAAE,6BAA6B,CAAC;CAC/D,CAAC;AAEF,0FAA0F;AAC1F,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAErD,0EAA0E;AAC1E,MAAM,MAAM,sBAAsB,GAC9B;IAAE,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GAC7F;IAAE,QAAQ,CAAC,WAAW,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhF,sFAAsF;AACtF,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AAElF,0EAA0E;AAC1E,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;AAE9F,wFAAwF;AACxF,MAAM,MAAM,0BAA0B,GAAG;IACvC,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE,0BAA0B,CAAC;IAC9C,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,oGAAoG;AACpG,MAAM,MAAM,mBAAmB,GAAG;IAChC,sEAAsE;IACtE,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAC;IAC7C,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,kEAAkE;IAClE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Exact React, React DOM, and Flight renderer version supported by the experimental RSC contract. */
|
|
2
|
+
export const REACT_RSC_SUPPORTED_VERSION = '19.2.6';
|
|
3
|
+
|
|
4
|
+
/** HTTP content type written for experimental React Flight payload responses. */
|
|
5
|
+
export const REACT_RSC_FLIGHT_CONTENT_TYPE = 'text/x-component; charset=utf-8';
|
|
6
|
+
|
|
7
|
+
/** Stable diagnostic codes emitted by the experimental RSC compatibility and manifest checks. */
|
|
8
|
+
export const REACT_RSC_DIAGNOSTIC_CODES = {
|
|
9
|
+
emptyClientReferenceManifest: 'react-rsc-empty-client-reference-manifest',
|
|
10
|
+
emptyServerClientModuleMap: 'react-rsc-empty-server-client-module-map',
|
|
11
|
+
missingClientReferenceManifest: 'react-rsc-missing-client-reference-manifest',
|
|
12
|
+
missingServerClientModuleMap: 'react-rsc-missing-server-client-module-map',
|
|
13
|
+
unknownClientReference: 'react-rsc-unknown-client-reference',
|
|
14
|
+
unsupportedFlightRendererVersion: 'react-rsc-unsupported-flight-renderer-version',
|
|
15
|
+
unsupportedReactDomVersion: 'react-rsc-unsupported-react-dom-version',
|
|
16
|
+
unsupportedReactVersion: 'react-rsc-unsupported-react-version',
|
|
17
|
+
unsupportedRuntime: 'react-rsc-unsupported-runtime'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Machine-readable diagnostic code produced by the experimental RSC contract. */
|
|
21
|
+
|
|
22
|
+
/** Actionable compatibility or build diagnostic produced instead of an expected configuration throw. */
|
|
23
|
+
|
|
24
|
+
/** Runtime capabilities required by the experimental Flight response transport. */
|
|
25
|
+
|
|
26
|
+
/** Build-adapter capabilities required to connect RSC module graphs explicitly. */
|
|
27
|
+
|
|
28
|
+
/** Environment inputs checked before an application enables the experimental RSC path. */
|
|
29
|
+
|
|
30
|
+
/** Result of inspecting one experimental RSC runtime and build environment. */
|
|
31
|
+
|
|
32
|
+
/** Bundler-produced metadata for one client module export referenced by a Flight payload. */
|
|
33
|
+
|
|
34
|
+
/** Client-reference metadata keyed by an application-owned stable reference id. */
|
|
35
|
+
|
|
36
|
+
/** Server module exports mapped to keys in the client-reference manifest. */
|
|
37
|
+
|
|
38
|
+
/** Build output accepted by `createReactRscManifest(...)`. */
|
|
39
|
+
|
|
40
|
+
/** Defensive RSC module graph snapshot passed to an application-owned Flight renderer. */
|
|
41
|
+
|
|
42
|
+
/** Result of validating and snapshotting an experimental RSC manifest. */
|
|
43
|
+
|
|
44
|
+
/** Encoded React Flight payload accepted by the experimental HTTP response helper. */
|
|
45
|
+
|
|
46
|
+
/** Additional HTTP headers applied to an experimental Flight response. */
|
|
47
|
+
|
|
48
|
+
/** Options applied after ordinary fluo route success metadata for a Flight response. */
|
|
49
|
+
|
|
50
|
+
/** Response entry returned from an ordinary fluo HTTP handler to emit an encoded Flight payload. */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { inspectReactRscEnvironment } from './rsc-diagnostics.js';
|
|
2
|
+
export { createReactFlightResponse } from './rsc-flight-response.js';
|
|
3
|
+
export { createReactRscManifest } from './rsc-manifest.js';
|
|
4
|
+
export type { ReactFlightPayload, ReactFlightResponse, ReactFlightResponseHeaders, ReactFlightResponseOptions, ReactRscBuildCapabilities, ReactRscClientReference, ReactRscClientReferenceManifest, ReactRscDiagnostic, ReactRscDiagnosticCode, ReactRscEnvironmentOptions, ReactRscManifest, ReactRscManifestInput, ReactRscManifestResult, ReactRscRuntimeCapabilities, ReactRscServerClientModuleMap, ReactRscSupportResult, } from './rsc-types.js';
|
|
5
|
+
export { REACT_RSC_DIAGNOSTIC_CODES, REACT_RSC_FLIGHT_CONTENT_TYPE, REACT_RSC_SUPPORTED_VERSION, } from './rsc-types.js';
|
|
6
|
+
export { createReactServerFunctionClient } from './server-functions-client.js';
|
|
7
|
+
export { ReactServerFunctionClientError, ReactServerFunctionConfigurationError, } from './server-functions-errors.js';
|
|
8
|
+
export { createReactServerFunctionRegistry } from './server-functions-server.js';
|
|
9
|
+
export type { ReactServerFunctionClient, ReactServerFunctionClientOptions, ReactServerFunctionErrorCode, ReactServerFunctionFetch, ReactServerFunctionHandler, ReactServerFunctionReference, ReactServerFunctionRegistry, ReactServerFunctionRegistryOptions, ReactServerFunctionResponse, ReactServerFunctionValue, } from './server-functions-types.js';
|
|
10
|
+
export { REACT_SERVER_FUNCTION_ERROR_CODES, REACT_SERVER_FUNCTION_REQUEST_HEADER, } from './server-functions-types.js';
|
|
11
|
+
//# sourceMappingURL=rsc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../src/experimental/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,uBAAuB,EACvB,+BAA+B,EAC/B,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,GACtC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iCAAiC,EAAE,MAAM,8BAA8B,CAAC;AACjF,YAAY,EACV,yBAAyB,EACzB,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,kCAAkC,EAClC,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,iCAAiC,EACjC,oCAAoC,GACrC,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { inspectReactRscEnvironment } from './rsc-diagnostics.js';
|
|
2
|
+
export { createReactFlightResponse } from './rsc-flight-response.js';
|
|
3
|
+
export { createReactRscManifest } from './rsc-manifest.js';
|
|
4
|
+
export { REACT_RSC_DIAGNOSTIC_CODES, REACT_RSC_FLIGHT_CONTENT_TYPE, REACT_RSC_SUPPORTED_VERSION } from './rsc-types.js';
|
|
5
|
+
export { createReactServerFunctionClient } from './server-functions-client.js';
|
|
6
|
+
export { ReactServerFunctionClientError, ReactServerFunctionConfigurationError } from './server-functions-errors.js';
|
|
7
|
+
export { createReactServerFunctionRegistry } from './server-functions-server.js';
|
|
8
|
+
export { REACT_SERVER_FUNCTION_ERROR_CODES, REACT_SERVER_FUNCTION_REQUEST_HEADER } from './server-functions-types.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactServerFunctionClient, type ReactServerFunctionClientOptions } from './server-functions-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a client callable that posts signed Server Function invocations to one explicit endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The callable sends `Content-Type: application/json`, the non-simple request marker, and
|
|
7
|
+
* `credentials: 'same-origin'`. Browsers still own the `Origin` header; the matching server
|
|
8
|
+
* registry rejects missing or unapproved origins.
|
|
9
|
+
*
|
|
10
|
+
* @param options Explicit endpoint, signed reference, fetch transport, and response limits.
|
|
11
|
+
* @returns An async callable accepting only the documented JSON-compatible value subset.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createReactServerFunctionClient(options: ReactServerFunctionClientOptions): ReactServerFunctionClient;
|
|
14
|
+
//# sourceMappingURL=server-functions-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-functions-client.d.ts","sourceRoot":"","sources":["../../src/experimental/server-functions-client.ts"],"names":[],"mappings":"AAQA,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,gCAAgC,EACtC,MAAM,6BAA6B,CAAC;AAmErC;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,gCAAgC,GACxC,yBAAyB,CAkE3B"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ReactServerFunctionClientError, ReactServerFunctionConfigurationError } from './server-functions-errors.js';
|
|
2
|
+
import { parseReactServerFunctionArguments, parseReactServerFunctionValue } from './server-functions-serialization.js';
|
|
3
|
+
import { REACT_SERVER_FUNCTION_ERROR_CODES, REACT_SERVER_FUNCTION_REQUEST_HEADER } from './server-functions-types.js';
|
|
4
|
+
const DEFAULT_MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
5
|
+
const DEFAULT_MAX_SERIALIZATION_DEPTH = 32;
|
|
6
|
+
function parsePositiveInteger(value, fallback, name) {
|
|
7
|
+
const parsed = value ?? fallback;
|
|
8
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
9
|
+
throw new ReactServerFunctionConfigurationError(`${name} must be a positive safe integer.`);
|
|
10
|
+
}
|
|
11
|
+
return parsed;
|
|
12
|
+
}
|
|
13
|
+
function parseJson(text, status) {
|
|
14
|
+
try {
|
|
15
|
+
const parsed = JSON.parse(text);
|
|
16
|
+
return parsed;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error instanceof SyntaxError) {
|
|
19
|
+
throw new ReactServerFunctionClientError('Server Function response was not valid JSON.', status, text);
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function isResponseRecord(value) {
|
|
25
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
async function readBoundedResponseText(response, maxResponseBytes) {
|
|
28
|
+
const reader = response.body?.getReader();
|
|
29
|
+
if (reader === undefined) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
const decoder = new TextDecoder();
|
|
33
|
+
let byteLength = 0;
|
|
34
|
+
let text = '';
|
|
35
|
+
try {
|
|
36
|
+
while (true) {
|
|
37
|
+
const chunk = await reader.read();
|
|
38
|
+
if (chunk.done) {
|
|
39
|
+
return text + decoder.decode();
|
|
40
|
+
}
|
|
41
|
+
byteLength += chunk.value.byteLength;
|
|
42
|
+
if (byteLength > maxResponseBytes) {
|
|
43
|
+
await Promise.allSettled([reader.cancel()]);
|
|
44
|
+
throw new ReactServerFunctionClientError('Server Function response exceeds the configured byte limit.', response.status);
|
|
45
|
+
}
|
|
46
|
+
text += decoder.decode(chunk.value, {
|
|
47
|
+
stream: true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error instanceof ReactServerFunctionClientError) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
throw new ReactServerFunctionClientError('Server Function response body could not be read.', response.status);
|
|
55
|
+
} finally {
|
|
56
|
+
reader.releaseLock();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates a client callable that posts signed Server Function invocations to one explicit endpoint.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* The callable sends `Content-Type: application/json`, the non-simple request marker, and
|
|
65
|
+
* `credentials: 'same-origin'`. Browsers still own the `Origin` header; the matching server
|
|
66
|
+
* registry rejects missing or unapproved origins.
|
|
67
|
+
*
|
|
68
|
+
* @param options Explicit endpoint, signed reference, fetch transport, and response limits.
|
|
69
|
+
* @returns An async callable accepting only the documented JSON-compatible value subset.
|
|
70
|
+
*/
|
|
71
|
+
export function createReactServerFunctionClient(options) {
|
|
72
|
+
if (options.endpoint.trim().length === 0) {
|
|
73
|
+
throw new ReactServerFunctionConfigurationError('Server Function client endpoints must not be empty.');
|
|
74
|
+
}
|
|
75
|
+
if (options.reference.value.length === 0) {
|
|
76
|
+
throw new ReactServerFunctionConfigurationError('Server Function client references must not be empty.');
|
|
77
|
+
}
|
|
78
|
+
const maxResponseBytes = parsePositiveInteger(options.maxResponseBytes, DEFAULT_MAX_RESPONSE_BYTES, 'maxResponseBytes');
|
|
79
|
+
const maxSerializationDepth = parsePositiveInteger(options.maxSerializationDepth, DEFAULT_MAX_SERIALIZATION_DEPTH, 'maxSerializationDepth');
|
|
80
|
+
if (maxSerializationDepth > 128) {
|
|
81
|
+
throw new ReactServerFunctionConfigurationError('maxSerializationDepth must not exceed 128.');
|
|
82
|
+
}
|
|
83
|
+
return async (...args) => {
|
|
84
|
+
const parsedArgs = parseReactServerFunctionArguments(args, maxSerializationDepth);
|
|
85
|
+
if (!parsedArgs.ok) {
|
|
86
|
+
throw new ReactServerFunctionClientError(`${REACT_SERVER_FUNCTION_ERROR_CODES.argumentSerializationFailed}: ${parsedArgs.path} ${parsedArgs.reason}`, 0);
|
|
87
|
+
}
|
|
88
|
+
let response;
|
|
89
|
+
try {
|
|
90
|
+
response = await options.fetch(options.endpoint, {
|
|
91
|
+
body: JSON.stringify({
|
|
92
|
+
action: options.reference.value,
|
|
93
|
+
args: parsedArgs.value
|
|
94
|
+
}),
|
|
95
|
+
credentials: 'same-origin',
|
|
96
|
+
headers: {
|
|
97
|
+
Accept: 'application/json',
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
[REACT_SERVER_FUNCTION_REQUEST_HEADER]: '1'
|
|
100
|
+
},
|
|
101
|
+
method: 'POST'
|
|
102
|
+
});
|
|
103
|
+
} catch {
|
|
104
|
+
throw new ReactServerFunctionClientError('Server Function request failed before receiving an HTTP response.', 0);
|
|
105
|
+
}
|
|
106
|
+
const responseText = await readBoundedResponseText(response, maxResponseBytes);
|
|
107
|
+
const responseBody = parseJson(responseText, response.status);
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new ReactServerFunctionClientError('Server Function request failed.', response.status, responseBody);
|
|
110
|
+
}
|
|
111
|
+
if (!isResponseRecord(responseBody) || !Object.hasOwn(responseBody, 'result')) {
|
|
112
|
+
throw new ReactServerFunctionClientError('Server Function response is missing a result.', response.status, responseBody);
|
|
113
|
+
}
|
|
114
|
+
const result = parseReactServerFunctionValue(responseBody.result, maxSerializationDepth);
|
|
115
|
+
if (!result.ok) {
|
|
116
|
+
throw new ReactServerFunctionClientError(`Server Function response is not safely serializable: ${result.path} ${result.reason}`, response.status, responseBody);
|
|
117
|
+
}
|
|
118
|
+
return result.value;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactServerFunctionHandler, ReactServerFunctionRegistryOptions } from './server-functions-types.js';
|
|
2
|
+
/** Validated immutable configuration consumed by the Server Function request boundary. */
|
|
3
|
+
export type ReactServerFunctionRegistryConfiguration = {
|
|
4
|
+
readonly actions: Readonly<Record<string, ReactServerFunctionHandler>>;
|
|
5
|
+
readonly allowedOrigins: ReadonlySet<string>;
|
|
6
|
+
readonly maxBodyBytes: number;
|
|
7
|
+
readonly maxResultBytes: number;
|
|
8
|
+
readonly maxSerializationDepth: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Parses and snapshots caller-owned registry options before references or requests are handled.
|
|
12
|
+
*
|
|
13
|
+
* @param options Untrusted registry configuration supplied at the application boundary.
|
|
14
|
+
* @returns Validated actions, origins, and transport limits.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createReactServerFunctionRegistryConfiguration(options: ReactServerFunctionRegistryOptions): ReactServerFunctionRegistryConfiguration;
|
|
17
|
+
//# sourceMappingURL=server-functions-configuration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-functions-configuration.d.ts","sourceRoot":"","sources":["../../src/experimental/server-functions-configuration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,0BAA0B,EAC1B,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AAMrC,0FAA0F;AAC1F,MAAM,MAAM,wCAAwC,GAAG;IACrD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC;IACvE,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;CACxC,CAAC;AAoCF;;;;;GAKG;AACH,wBAAgB,8CAA8C,CAC5D,OAAO,EAAE,kCAAkC,GAC1C,wCAAwC,CA+B1C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ReactServerFunctionConfigurationError } from './server-functions-errors.js';
|
|
2
|
+
import { isReactServerFunctionActionId } from './server-functions-reference.js';
|
|
3
|
+
const DEFAULT_MAX_BODY_BYTES = 64 * 1024;
|
|
4
|
+
const DEFAULT_MAX_RESULT_BYTES = 1024 * 1024;
|
|
5
|
+
const DEFAULT_MAX_SERIALIZATION_DEPTH = 32;
|
|
6
|
+
|
|
7
|
+
/** Validated immutable configuration consumed by the Server Function request boundary. */
|
|
8
|
+
|
|
9
|
+
function configurationError(message) {
|
|
10
|
+
throw new ReactServerFunctionConfigurationError(message);
|
|
11
|
+
}
|
|
12
|
+
function parsePositiveInteger(value, fallback, name) {
|
|
13
|
+
const parsed = value ?? fallback;
|
|
14
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : configurationError(`${name} must be a positive safe integer.`);
|
|
15
|
+
}
|
|
16
|
+
function parseSerializationDepth(value) {
|
|
17
|
+
const parsed = parsePositiveInteger(value, DEFAULT_MAX_SERIALIZATION_DEPTH, 'maxSerializationDepth');
|
|
18
|
+
return parsed <= 128 ? parsed : configurationError('maxSerializationDepth must not exceed 128.');
|
|
19
|
+
}
|
|
20
|
+
function normalizeOrigin(origin) {
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = new URL(origin);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (error instanceof TypeError) {
|
|
26
|
+
return configurationError(`Server Function allowed origin "${origin}" is not a valid URL origin.`);
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:' || parsed.origin !== origin) {
|
|
31
|
+
return configurationError(`Server Function allowed origin "${origin}" must be an exact HTTP(S) origin.`);
|
|
32
|
+
}
|
|
33
|
+
return parsed.origin;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Parses and snapshots caller-owned registry options before references or requests are handled.
|
|
38
|
+
*
|
|
39
|
+
* @param options Untrusted registry configuration supplied at the application boundary.
|
|
40
|
+
* @returns Validated actions, origins, and transport limits.
|
|
41
|
+
*/
|
|
42
|
+
export function createReactServerFunctionRegistryConfiguration(options) {
|
|
43
|
+
const actions = {};
|
|
44
|
+
Object.setPrototypeOf(actions, null);
|
|
45
|
+
for (const [actionId, handler] of Object.entries(options.actions)) {
|
|
46
|
+
if (!isReactServerFunctionActionId(actionId)) {
|
|
47
|
+
return configurationError(`Server Function action id "${actionId}" must match [A-Za-z0-9_-] and contain 1 to 128 characters.`);
|
|
48
|
+
}
|
|
49
|
+
if (typeof handler !== 'function') {
|
|
50
|
+
return configurationError(`Server Function action "${actionId}" must map to a handler function.`);
|
|
51
|
+
}
|
|
52
|
+
actions[actionId] = handler;
|
|
53
|
+
}
|
|
54
|
+
if (Object.keys(actions).length === 0) {
|
|
55
|
+
return configurationError('Server Function registries must contain at least one action.');
|
|
56
|
+
}
|
|
57
|
+
const origins = new Set(options.allowedOrigins.map(normalizeOrigin));
|
|
58
|
+
if (origins.size === 0) {
|
|
59
|
+
return configurationError('Server Function registries must allow at least one exact HTTP(S) origin.');
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
actions: Object.freeze(actions),
|
|
63
|
+
allowedOrigins: origins,
|
|
64
|
+
maxBodyBytes: parsePositiveInteger(options.maxBodyBytes, DEFAULT_MAX_BODY_BYTES, 'maxBodyBytes'),
|
|
65
|
+
maxResultBytes: parsePositiveInteger(options.maxResultBytes, DEFAULT_MAX_RESULT_BYTES, 'maxResultBytes'),
|
|
66
|
+
maxSerializationDepth: parseSerializationDepth(options.maxSerializationDepth)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Configuration failure detected before an experimental Server Function registry is used. */
|
|
2
|
+
export declare class ReactServerFunctionConfigurationError extends Error {
|
|
3
|
+
readonly name = "ReactServerFunctionConfigurationError";
|
|
4
|
+
}
|
|
5
|
+
/** Client-side HTTP or serialization failure from an experimental Server Function call. */
|
|
6
|
+
export declare class ReactServerFunctionClientError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly responseBody?: unknown | undefined;
|
|
9
|
+
readonly name = "ReactServerFunctionClientError";
|
|
10
|
+
/**
|
|
11
|
+
* Creates a typed client error without converting a failed response into an action result.
|
|
12
|
+
*
|
|
13
|
+
* @param message Human-readable transport failure.
|
|
14
|
+
* @param status HTTP status, or zero when no valid HTTP response was available.
|
|
15
|
+
* @param responseBody Parsed response body when one was available.
|
|
16
|
+
*/
|
|
17
|
+
constructor(message: string, status: number, responseBody?: unknown | undefined);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=server-functions-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-functions-errors.d.ts","sourceRoot":"","sources":["../../src/experimental/server-functions-errors.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,qBAAa,qCAAsC,SAAQ,KAAK;IAC9D,QAAQ,CAAC,IAAI,2CAA2C;CACzD;AAED,2FAA2F;AAC3F,qBAAa,8BAA+B,SAAQ,KAAK;IAYrD,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO;IAZjC,QAAQ,CAAC,IAAI,oCAAoC;IAEjD;;;;;;OAMG;gBAED,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,OAAO,YAAA;CAIlC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Configuration failure detected before an experimental Server Function registry is used. */
|
|
2
|
+
export class ReactServerFunctionConfigurationError extends Error {
|
|
3
|
+
name = 'ReactServerFunctionConfigurationError';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Client-side HTTP or serialization failure from an experimental Server Function call. */
|
|
7
|
+
export class ReactServerFunctionClientError extends Error {
|
|
8
|
+
name = 'ReactServerFunctionClientError';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a typed client error without converting a failed response into an action result.
|
|
12
|
+
*
|
|
13
|
+
* @param message Human-readable transport failure.
|
|
14
|
+
* @param status HTTP status, or zero when no valid HTTP response was available.
|
|
15
|
+
* @param responseBody Parsed response body when one was available.
|
|
16
|
+
*/
|
|
17
|
+
constructor(message, status, responseBody) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.responseBody = responseBody;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactServerFunctionReference } from './server-functions-types.js';
|
|
2
|
+
type ReferenceSigner = {
|
|
3
|
+
readonly createReference: (actionId: string) => Promise<ReactServerFunctionReference>;
|
|
4
|
+
readonly verifyReference: (reference: string) => Promise<string | undefined>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns whether an action id is stable and safe to embed in the versioned reference format.
|
|
8
|
+
*
|
|
9
|
+
* @param value Candidate action id.
|
|
10
|
+
* @returns Whether the id matches the bounded reference grammar.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isReactServerFunctionActionId(value: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Creates the HMAC-SHA-256 action reference signer used by one registry.
|
|
15
|
+
*
|
|
16
|
+
* @param crypto Explicit runtime Web Crypto provider.
|
|
17
|
+
* @param secret Application-owned secret snapshot.
|
|
18
|
+
* @returns Reference issue and verification operations.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createReactServerFunctionReferenceSigner(crypto: Pick<Crypto, 'subtle'>, secret: Uint8Array): ReferenceSigner;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=server-functions-reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-functions-reference.d.ts","sourceRoot":"","sources":["../../src/experimental/server-functions-reference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAMhF,KAAK,eAAe,GAAG;IACrB,QAAQ,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACtF,QAAQ,CAAC,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC9E,CAAC;AAyBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,wCAAwC,CACtD,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EAC9B,MAAM,EAAE,UAAU,GACjB,eAAe,CA4CjB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ReactServerFunctionConfigurationError } from './server-functions-errors.js';
|
|
2
|
+
const actionIdPattern = /^[A-Za-z0-9_-]{1,128}$/;
|
|
3
|
+
const referencePattern = /^v1:([A-Za-z0-9_-]{1,128}):([a-f0-9]{64})$/;
|
|
4
|
+
const signaturePrefix = 'fluo.react.server-function.v1:';
|
|
5
|
+
function toHex(value) {
|
|
6
|
+
let result = '';
|
|
7
|
+
for (const byte of new Uint8Array(value)) {
|
|
8
|
+
result += byte.toString(16).padStart(2, '0');
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
function fromHex(value) {
|
|
13
|
+
if (value.length % 2 !== 0) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const result = new Uint8Array(value.length / 2);
|
|
17
|
+
for (let index = 0; index < value.length; index += 2) {
|
|
18
|
+
const byte = Number.parseInt(value.slice(index, index + 2), 16);
|
|
19
|
+
if (!Number.isInteger(byte)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
result[index / 2] = byte;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether an action id is stable and safe to embed in the versioned reference format.
|
|
29
|
+
*
|
|
30
|
+
* @param value Candidate action id.
|
|
31
|
+
* @returns Whether the id matches the bounded reference grammar.
|
|
32
|
+
*/
|
|
33
|
+
export function isReactServerFunctionActionId(value) {
|
|
34
|
+
return actionIdPattern.test(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates the HMAC-SHA-256 action reference signer used by one registry.
|
|
39
|
+
*
|
|
40
|
+
* @param crypto Explicit runtime Web Crypto provider.
|
|
41
|
+
* @param secret Application-owned secret snapshot.
|
|
42
|
+
* @returns Reference issue and verification operations.
|
|
43
|
+
*/
|
|
44
|
+
export function createReactServerFunctionReferenceSigner(crypto, secret) {
|
|
45
|
+
if (secret.byteLength < 32) {
|
|
46
|
+
throw new ReactServerFunctionConfigurationError('Server Function HMAC secrets must contain at least 32 bytes.');
|
|
47
|
+
}
|
|
48
|
+
const encoder = new TextEncoder();
|
|
49
|
+
const secretSnapshot = new Uint8Array(secret);
|
|
50
|
+
const key = crypto.subtle.importKey('raw', secretSnapshot, {
|
|
51
|
+
hash: 'SHA-256',
|
|
52
|
+
name: 'HMAC'
|
|
53
|
+
}, false, ['sign', 'verify']);
|
|
54
|
+
return {
|
|
55
|
+
async createReference(actionId) {
|
|
56
|
+
const signature = await crypto.subtle.sign('HMAC', await key, encoder.encode(`${signaturePrefix}${actionId}`));
|
|
57
|
+
return Object.freeze({
|
|
58
|
+
value: `v1:${actionId}:${toHex(signature)}`
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
async verifyReference(reference) {
|
|
62
|
+
const match = referencePattern.exec(reference);
|
|
63
|
+
const actionId = match?.[1];
|
|
64
|
+
const signatureHex = match?.[2];
|
|
65
|
+
if (actionId === undefined || signatureHex === undefined) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const signature = fromHex(signatureHex);
|
|
69
|
+
if (signature === undefined) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const valid = await crypto.subtle.verify('HMAC', await key, signature, encoder.encode(`${signaturePrefix}${actionId}`));
|
|
73
|
+
return valid ? actionId : undefined;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReactServerFunctionValue } from './server-functions-types.js';
|
|
2
|
+
type SerializationFailure = {
|
|
3
|
+
readonly ok: false;
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly reason: string;
|
|
6
|
+
};
|
|
7
|
+
type SerializationSuccess<T> = {
|
|
8
|
+
readonly ok: true;
|
|
9
|
+
readonly value: T;
|
|
10
|
+
};
|
|
11
|
+
/** Result of parsing an untrusted value into the Server Function serialization subset. */
|
|
12
|
+
export type ReactServerFunctionSerializationResult<T> = SerializationSuccess<T> | SerializationFailure;
|
|
13
|
+
/**
|
|
14
|
+
* Parses an untrusted argument list into an immutable JSON-compatible snapshot.
|
|
15
|
+
*
|
|
16
|
+
* @param value Unknown request argument value.
|
|
17
|
+
* @param maxDepth Maximum supported nesting depth.
|
|
18
|
+
* @returns A parsed argument list or a deterministic path and reason.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseReactServerFunctionArguments(value: unknown, maxDepth: number): ReactServerFunctionSerializationResult<readonly ReactServerFunctionValue[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Parses one untrusted action result into an immutable JSON-compatible snapshot.
|
|
23
|
+
*
|
|
24
|
+
* @param value Unknown action result.
|
|
25
|
+
* @param maxDepth Maximum supported nesting depth.
|
|
26
|
+
* @returns A parsed result or a deterministic path and reason.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseReactServerFunctionValue(value: unknown, maxDepth: number): ReactServerFunctionSerializationResult<ReactServerFunctionValue>;
|
|
29
|
+
/**
|
|
30
|
+
* Measures the UTF-8 JSON representation of an already parsed Server Function value.
|
|
31
|
+
*
|
|
32
|
+
* @param value JSON-compatible value produced by this module.
|
|
33
|
+
* @returns Encoded byte length.
|
|
34
|
+
*/
|
|
35
|
+
export declare function measureReactServerFunctionValue(value: ReactServerFunctionValue): number;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=server-functions-serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-functions-serialization.d.ts","sourceRoot":"","sources":["../../src/experimental/server-functions-serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAI5E,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,oBAAoB,CAAC,CAAC,IAAI;IAC7B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB,CAAC;AAEF,0FAA0F;AAC1F,MAAM,MAAM,sCAAsC,CAAC,CAAC,IAChD,oBAAoB,CAAC,CAAC,CAAC,GACvB,oBAAoB,CAAC;AA+GzB;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,GACf,sCAAsC,CAAC,SAAS,wBAAwB,EAAE,CAAC,CAgB7E;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,GACf,sCAAsC,CAAC,wBAAwB,CAAC,CAOlE;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,wBAAwB,GAAG,MAAM,CAGvF"}
|