@solidjs/start 2.0.0-alpha.3 → 2.0.0-beta.1

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 (163) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.json +6 -5
  3. package/src/config/constants.ts +2 -2
  4. package/src/config/dev-server.ts +5 -1
  5. package/src/config/fs-routes/fs-watcher.ts +36 -40
  6. package/src/config/fs-routes/router.ts +27 -11
  7. package/src/config/fs-routes/tree-shake.ts +1 -48
  8. package/src/config/index.ts +12 -10
  9. package/src/config/lazy.ts +1 -0
  10. package/src/config/manifest.ts +8 -3
  11. package/src/directives/index.ts +1 -0
  12. package/src/directives/remove-unused-variables.ts +18 -3
  13. package/src/server/handler.ts +1 -1
  14. package/src/utils/debounce.ts +10 -0
  15. package/dist/client/StartClient.d.ts +0 -7
  16. package/dist/client/StartClient.jsx +0 -26
  17. package/dist/client/index.d.ts +0 -2
  18. package/dist/client/index.jsx +0 -2
  19. package/dist/client/mount.d.ts +0 -1
  20. package/dist/client/mount.js +0 -1
  21. package/dist/client/spa/index.d.ts +0 -4
  22. package/dist/client/spa/index.jsx +0 -5
  23. package/dist/config/constants.d.ts +0 -16
  24. package/dist/config/constants.js +0 -16
  25. package/dist/config/dev-server.d.ts +0 -2
  26. package/dist/config/dev-server.js +0 -126
  27. package/dist/config/env.d.ts +0 -19
  28. package/dist/config/env.js +0 -81
  29. package/dist/config/fs-router.d.ts +0 -37
  30. package/dist/config/fs-router.js +0 -141
  31. package/dist/config/fs-routes/fs-watcher.d.ts +0 -3
  32. package/dist/config/fs-routes/fs-watcher.js +0 -43
  33. package/dist/config/fs-routes/index.d.ts +0 -7
  34. package/dist/config/fs-routes/index.js +0 -107
  35. package/dist/config/fs-routes/router.d.ts +0 -37
  36. package/dist/config/fs-routes/router.js +0 -135
  37. package/dist/config/fs-routes/tree-shake.d.ts +0 -2
  38. package/dist/config/fs-routes/tree-shake.js +0 -348
  39. package/dist/config/index.d.ts +0 -25
  40. package/dist/config/index.js +0 -215
  41. package/dist/config/lazy.d.ts +0 -3
  42. package/dist/config/lazy.js +0 -112
  43. package/dist/config/manifest.d.ts +0 -3
  44. package/dist/config/manifest.js +0 -108
  45. package/dist/config/utils.d.ts +0 -4
  46. package/dist/config/utils.js +0 -6
  47. package/dist/config/vite-utils.d.ts +0 -21
  48. package/dist/config/vite-utils.js +0 -85
  49. package/dist/directives/bubble-function-declaration.d.ts +0 -3
  50. package/dist/directives/bubble-function-declaration.js +0 -23
  51. package/dist/directives/compile.d.ts +0 -9
  52. package/dist/directives/compile.js +0 -40
  53. package/dist/directives/generate-unique-name.d.ts +0 -3
  54. package/dist/directives/generate-unique-name.js +0 -16
  55. package/dist/directives/get-descriptive-name.d.ts +0 -2
  56. package/dist/directives/get-descriptive-name.js +0 -37
  57. package/dist/directives/get-import-identifier.d.ts +0 -4
  58. package/dist/directives/get-import-identifier.js +0 -19
  59. package/dist/directives/get-root-statement-path.d.ts +0 -2
  60. package/dist/directives/get-root-statement-path.js +0 -12
  61. package/dist/directives/index.d.ts +0 -14
  62. package/dist/directives/index.js +0 -169
  63. package/dist/directives/is-statement-top-level.d.ts +0 -3
  64. package/dist/directives/is-statement-top-level.js +0 -9
  65. package/dist/directives/paths.d.ts +0 -9
  66. package/dist/directives/paths.js +0 -36
  67. package/dist/directives/plugin.d.ts +0 -21
  68. package/dist/directives/plugin.js +0 -302
  69. package/dist/directives/remove-unused-variables.d.ts +0 -3
  70. package/dist/directives/remove-unused-variables.js +0 -53
  71. package/dist/directives/types.d.ts +0 -10
  72. package/dist/directives/types.js +0 -1
  73. package/dist/directives/xxhash32.d.ts +0 -6
  74. package/dist/directives/xxhash32.js +0 -193
  75. package/dist/fns/client.d.ts +0 -3
  76. package/dist/fns/client.js +0 -106
  77. package/dist/fns/handler.d.ts +0 -5
  78. package/dist/fns/handler.js +0 -269
  79. package/dist/fns/registration.d.ts +0 -2
  80. package/dist/fns/registration.js +0 -12
  81. package/dist/fns/serialization.d.ts +0 -6
  82. package/dist/fns/serialization.js +0 -208
  83. package/dist/fns/server.d.ts +0 -7
  84. package/dist/fns/server.js +0 -38
  85. package/dist/fns/shared.d.ts +0 -17
  86. package/dist/fns/shared.js +0 -105
  87. package/dist/http/index.d.ts +0 -81
  88. package/dist/http/index.js +0 -129
  89. package/dist/index.d.ts +0 -5
  90. package/dist/index.jsx +0 -6
  91. package/dist/middleware/index.d.ts +0 -38
  92. package/dist/middleware/index.js +0 -59
  93. package/dist/router.d.ts +0 -6
  94. package/dist/router.jsx +0 -29
  95. package/dist/server/StartServer.d.ts +0 -9
  96. package/dist/server/StartServer.jsx +0 -34
  97. package/dist/server/assets/PatchVirtualDevStyles.d.ts +0 -4
  98. package/dist/server/assets/PatchVirtualDevStyles.jsx +0 -28
  99. package/dist/server/assets/index.d.ts +0 -2
  100. package/dist/server/assets/index.js +0 -52
  101. package/dist/server/assets/render.d.ts +0 -19
  102. package/dist/server/assets/render.jsx +0 -14
  103. package/dist/server/collect-styles.d.ts +0 -3
  104. package/dist/server/collect-styles.js +0 -57
  105. package/dist/server/fetchEvent.d.ts +0 -7
  106. package/dist/server/fetchEvent.js +0 -26
  107. package/dist/server/handler.d.ts +0 -64
  108. package/dist/server/handler.js +0 -222
  109. package/dist/server/index.d.ts +0 -9
  110. package/dist/server/index.jsx +0 -14
  111. package/dist/server/manifest/client-manifest.d.ts +0 -9
  112. package/dist/server/manifest/client-manifest.js +0 -6
  113. package/dist/server/manifest/dev-client-manifest.d.ts +0 -4
  114. package/dist/server/manifest/dev-client-manifest.js +0 -24
  115. package/dist/server/manifest/dev-ssr-manifest.d.ts +0 -5
  116. package/dist/server/manifest/dev-ssr-manifest.js +0 -23
  117. package/dist/server/manifest/prod-client-manifest.d.ts +0 -5
  118. package/dist/server/manifest/prod-client-manifest.js +0 -26
  119. package/dist/server/manifest/prod-ssr-manifest.d.ts +0 -6
  120. package/dist/server/manifest/prod-ssr-manifest.js +0 -85
  121. package/dist/server/manifest/ssr-manifest.d.ts +0 -4
  122. package/dist/server/manifest/ssr-manifest.js +0 -6
  123. package/dist/server/routes.d.ts +0 -23
  124. package/dist/server/routes.js +0 -74
  125. package/dist/server/spa/StartServer.d.ts +0 -9
  126. package/dist/server/spa/StartServer.jsx +0 -25
  127. package/dist/server/spa/handler.d.ts +0 -36
  128. package/dist/server/spa/handler.js +0 -20
  129. package/dist/server/spa/index.d.ts +0 -4
  130. package/dist/server/spa/index.jsx +0 -5
  131. package/dist/server/types.d.ts +0 -75
  132. package/dist/server/types.js +0 -1
  133. package/dist/server/util.d.ts +0 -2
  134. package/dist/server/util.js +0 -8
  135. package/dist/shared/ErrorBoundary.d.ts +0 -3
  136. package/dist/shared/ErrorBoundary.jsx +0 -36
  137. package/dist/shared/GET.d.ts +0 -5
  138. package/dist/shared/GET.js +0 -8
  139. package/dist/shared/HttpHeader.d.ts +0 -10
  140. package/dist/shared/HttpHeader.jsx +0 -38
  141. package/dist/shared/HttpStatusCode.d.ts +0 -9
  142. package/dist/shared/HttpStatusCode.js +0 -18
  143. package/dist/shared/clientOnly.d.ts +0 -12
  144. package/dist/shared/clientOnly.js +0 -27
  145. package/dist/shared/dev-overlay/CodeView.d.ts +0 -7
  146. package/dist/shared/dev-overlay/CodeView.jsx +0 -62
  147. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +0 -9
  148. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +0 -226
  149. package/dist/shared/dev-overlay/createStackFrame.d.ts +0 -9
  150. package/dist/shared/dev-overlay/createStackFrame.js +0 -56
  151. package/dist/shared/dev-overlay/download.d.ts +0 -1
  152. package/dist/shared/dev-overlay/download.js +0 -6
  153. package/dist/shared/dev-overlay/get-source-map.d.ts +0 -2
  154. package/dist/shared/dev-overlay/get-source-map.js +0 -25
  155. package/dist/shared/dev-overlay/icons.d.ts +0 -28
  156. package/dist/shared/dev-overlay/icons.jsx +0 -150
  157. package/dist/shared/dev-overlay/index.d.ts +0 -5
  158. package/dist/shared/dev-overlay/index.jsx +0 -39
  159. package/dist/shared/dev-overlay/styles.css +0 -292
  160. package/dist/shared/lazy.d.ts +0 -3
  161. package/dist/shared/lazy.js +0 -42
  162. package/dist/shared/serverFunction.d.ts +0 -6
  163. package/dist/shared/serverFunction.js +0 -8
@@ -1,208 +0,0 @@
1
- import { crossSerializeStream, deserialize, Feature, fromCrossJSON, getCrossReferenceHeader, toCrossJSONStream, } from "seroval";
2
- import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLPlugin, URLSearchParamsPlugin, } from "seroval-plugins/web";
3
- // TODO(Alexis): if we can, allow providing an option to extend these.
4
- const DEFAULT_PLUGINS = [
5
- AbortSignalPlugin,
6
- CustomEventPlugin,
7
- DOMExceptionPlugin,
8
- EventPlugin,
9
- FormDataPlugin,
10
- HeadersPlugin,
11
- ReadableStreamPlugin,
12
- RequestPlugin,
13
- ResponsePlugin,
14
- URLSearchParamsPlugin,
15
- URLPlugin,
16
- ];
17
- const MAX_SERIALIZATION_DEPTH_LIMIT = 64;
18
- const DISABLED_FEATURES = Feature.RegExp;
19
- /**
20
- * Alexis:
21
- *
22
- * A "chunk" is a piece of data emitted by the streaming serializer.
23
- * Each chunk is represented by a 32-bit value (encoded in hexadecimal),
24
- * followed by the encoded string (8-bit representation). This format
25
- * is important so we know how much of the chunk being streamed we
26
- * are expecting before parsing the entire string data.
27
- *
28
- * This is sort of a bootleg "multipart/form-data" except it's bad at
29
- * handling File/Blob LOL
30
- *
31
- * The format is as follows:
32
- * ;0xFFFFFFFF;<string data>
33
- */
34
- function createChunk(data) {
35
- const encodeData = new TextEncoder().encode(data);
36
- const bytes = encodeData.length;
37
- const baseHex = bytes.toString(16);
38
- const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex; // 32-bit
39
- const head = new TextEncoder().encode(`;0x${totalHex};`);
40
- const chunk = new Uint8Array(12 + bytes);
41
- chunk.set(head);
42
- chunk.set(encodeData, 12);
43
- return chunk;
44
- }
45
- export function serializeToJSStream(id, value) {
46
- return new ReadableStream({
47
- start(controller) {
48
- crossSerializeStream(value, {
49
- scopeId: id,
50
- plugins: DEFAULT_PLUGINS,
51
- onSerialize(data, initial) {
52
- controller.enqueue(createChunk(initial ? `(${getCrossReferenceHeader(id)},${data})` : data));
53
- },
54
- onDone() {
55
- controller.close();
56
- },
57
- onError(error) {
58
- controller.error(error);
59
- },
60
- });
61
- },
62
- });
63
- }
64
- export function serializeToJSONStream(value) {
65
- return new ReadableStream({
66
- start(controller) {
67
- toCrossJSONStream(value, {
68
- disabledFeatures: DISABLED_FEATURES,
69
- depthLimit: MAX_SERIALIZATION_DEPTH_LIMIT,
70
- plugins: DEFAULT_PLUGINS,
71
- onParse(node) {
72
- controller.enqueue(createChunk(JSON.stringify(node)));
73
- },
74
- onDone() {
75
- controller.close();
76
- },
77
- onError(error) {
78
- controller.error(error);
79
- },
80
- });
81
- },
82
- });
83
- }
84
- class SerovalChunkReader {
85
- reader;
86
- buffer;
87
- done;
88
- constructor(stream) {
89
- this.reader = stream.getReader();
90
- this.buffer = new Uint8Array(0);
91
- this.done = false;
92
- }
93
- async readChunk() {
94
- // if there's no chunk, read again
95
- const chunk = await this.reader.read();
96
- if (!chunk.done) {
97
- // repopulate the buffer
98
- const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
99
- newBuffer.set(this.buffer);
100
- newBuffer.set(chunk.value, this.buffer.length);
101
- this.buffer = newBuffer;
102
- }
103
- else {
104
- this.done = true;
105
- }
106
- }
107
- async next() {
108
- // Check if the buffer is empty
109
- if (this.buffer.length === 0) {
110
- // if we are already done...
111
- if (this.done) {
112
- return {
113
- done: true,
114
- value: undefined,
115
- };
116
- }
117
- // Otherwise, read a new chunk
118
- await this.readChunk();
119
- return await this.next();
120
- }
121
- // Read the "byte header"
122
- // The byte header tells us how big the expected data is
123
- // so we know how much data we should wait before we
124
- // deserialize the data
125
- const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
126
- const bytes = Number.parseInt(head, 16); // ;0x00000000;
127
- if (Number.isNaN(bytes)) {
128
- throw new Error("Malformed server function stream.");
129
- }
130
- // Check if the buffer has enough bytes to be parsed
131
- while (bytes > this.buffer.length - 12) {
132
- // If it's not enough, and the reader is done
133
- // then the chunk is invalid.
134
- if (this.done) {
135
- throw new Error("Malformed server function stream.");
136
- }
137
- // Otherwise, we read more chunks
138
- await this.readChunk();
139
- }
140
- // Extract the exact chunk as defined by the byte header
141
- const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
142
- // The rest goes to the buffer
143
- this.buffer = this.buffer.subarray(12 + bytes);
144
- // Deserialize the chunk
145
- return {
146
- done: false,
147
- value: partial,
148
- };
149
- }
150
- async drain(interpret) {
151
- while (true) {
152
- const result = await this.next();
153
- if (result.done) {
154
- break;
155
- }
156
- else {
157
- interpret(result.value);
158
- }
159
- }
160
- }
161
- }
162
- export async function serializeToJSONString(value) {
163
- const response = new Response(serializeToJSONStream(value));
164
- return await response.text();
165
- }
166
- export async function deserializeFromJSONString(json) {
167
- const blob = new Response(json);
168
- return await deserializeJSONStream(blob);
169
- }
170
- export async function deserializeJSONStream(response) {
171
- if (!response.body) {
172
- throw new Error("missing body");
173
- }
174
- const reader = new SerovalChunkReader(response.body);
175
- const result = await reader.next();
176
- if (!result.done) {
177
- const refs = new Map();
178
- function interpretChunk(chunk) {
179
- const value = fromCrossJSON(JSON.parse(chunk), {
180
- refs,
181
- disabledFeatures: DISABLED_FEATURES,
182
- depthLimit: MAX_SERIALIZATION_DEPTH_LIMIT,
183
- plugins: DEFAULT_PLUGINS,
184
- });
185
- return value;
186
- }
187
- void reader.drain(interpretChunk);
188
- return interpretChunk(result.value);
189
- }
190
- return undefined;
191
- }
192
- export async function deserializeJSStream(id, response) {
193
- if (!response.body) {
194
- throw new Error("missing body");
195
- }
196
- const reader = new SerovalChunkReader(response.body);
197
- const result = await reader.next();
198
- if (!result.done) {
199
- reader.drain(deserialize).then(() => {
200
- // @ts-ignore
201
- delete $R[id];
202
- }, () => {
203
- // no-op
204
- });
205
- return deserialize(result.value);
206
- }
207
- return undefined;
208
- }
@@ -1,7 +0,0 @@
1
- interface Registration<T extends any[], R> {
2
- id: string;
3
- fn: (...args: T) => Promise<R>;
4
- }
5
- export declare function createServerReference<T extends any[], R>(id: string, fn: (...args: T) => Promise<R>): Registration<T, R>;
6
- export declare function cloneServerReference<T extends any[], R>({ id, fn }: Registration<T, R>): (...args: T) => Promise<R>;
7
- export {};
@@ -1,38 +0,0 @@
1
- import { getRequestEvent } from "solid-js/web";
2
- import { provideRequestEvent } from "solid-js/web/storage";
3
- import { registerServerFunction } from "./registration.js";
4
- export function createServerReference(id, fn) {
5
- const registration = { id, fn };
6
- registerServerFunction(id, fn);
7
- return registration;
8
- }
9
- export function cloneServerReference({ id, fn }) {
10
- if (typeof fn !== "function")
11
- throw new Error("Export from a 'use server' module must be a function");
12
- let baseURL = import.meta.env.BASE_URL ?? "/";
13
- if (!baseURL.endsWith("/"))
14
- baseURL += "/";
15
- return new Proxy(fn, {
16
- get(target, prop, receiver) {
17
- if (prop === "url") {
18
- return `${baseURL}_server?id=${encodeURIComponent(id)}`;
19
- }
20
- if (prop === "GET")
21
- return receiver;
22
- return target[prop];
23
- },
24
- apply(target, thisArg, args) {
25
- const ogEvt = getRequestEvent();
26
- if (!ogEvt)
27
- throw new Error("Cannot call server function outside of a request");
28
- const evt = { ...ogEvt };
29
- evt.locals.serverFunctionMeta = {
30
- id,
31
- };
32
- evt.serverOnly = true;
33
- return provideRequestEvent(evt, () => {
34
- return fn.apply(thisArg, args);
35
- });
36
- },
37
- });
38
- }
@@ -1,17 +0,0 @@
1
- export declare const BODY_FORMAT_KEY = "X-Start-Type";
2
- export declare const BODY_FORMAL_FILE = "__START__";
3
- export declare const enum BodyFormat {
4
- Seroval = "0",
5
- String = "1",
6
- FormData = "2",
7
- URLSearchParams = "3",
8
- Blob = "4",
9
- File = "5",
10
- ArrayBuffer = "6",
11
- Uint8Array = "7"
12
- }
13
- export declare function getHeadersAndBody(body: any): {
14
- headers?: HeadersInit;
15
- body: BodyInit;
16
- } | undefined;
17
- export declare function extractBody(instance: string, client: boolean, source: Request | Response): Promise<unknown>;
@@ -1,105 +0,0 @@
1
- import { deserializeJSONStream, deserializeJSStream } from "./serialization.js";
2
- export const BODY_FORMAT_KEY = "X-Start-Type";
3
- export const BODY_FORMAL_FILE = "__START__";
4
- export var BodyFormat;
5
- (function (BodyFormat) {
6
- BodyFormat["Seroval"] = "0";
7
- BodyFormat["String"] = "1";
8
- BodyFormat["FormData"] = "2";
9
- BodyFormat["URLSearchParams"] = "3";
10
- BodyFormat["Blob"] = "4";
11
- BodyFormat["File"] = "5";
12
- BodyFormat["ArrayBuffer"] = "6";
13
- BodyFormat["Uint8Array"] = "7";
14
- })(BodyFormat || (BodyFormat = {}));
15
- export function getHeadersAndBody(body) {
16
- switch (true) {
17
- case typeof body === "string":
18
- return {
19
- headers: {
20
- "Content-Type": "text/plain",
21
- [BODY_FORMAT_KEY]: BodyFormat.String,
22
- },
23
- body,
24
- };
25
- case body instanceof FormData:
26
- return {
27
- headers: {
28
- [BODY_FORMAT_KEY]: BodyFormat.FormData,
29
- },
30
- body,
31
- };
32
- case body instanceof URLSearchParams:
33
- return {
34
- headers: {
35
- "Content-Type": "application/x-www-form-urlencoded",
36
- [BODY_FORMAT_KEY]: BodyFormat.URLSearchParams,
37
- },
38
- body,
39
- };
40
- case body instanceof File: {
41
- const formData = new FormData();
42
- formData.append(BODY_FORMAL_FILE, body, body.name);
43
- return {
44
- headers: {
45
- [BODY_FORMAT_KEY]: BodyFormat.File,
46
- },
47
- body: formData,
48
- };
49
- }
50
- case body instanceof Blob:
51
- return {
52
- headers: {
53
- [BODY_FORMAT_KEY]: BodyFormat.Blob,
54
- },
55
- body,
56
- };
57
- case body instanceof ArrayBuffer:
58
- return {
59
- headers: {
60
- [BODY_FORMAT_KEY]: BodyFormat.ArrayBuffer,
61
- },
62
- body,
63
- };
64
- case body instanceof Uint8Array:
65
- return {
66
- headers: {
67
- [BODY_FORMAT_KEY]: BodyFormat.Uint8Array,
68
- },
69
- body: new Uint8Array(body),
70
- };
71
- default:
72
- return undefined;
73
- }
74
- }
75
- export async function extractBody(instance, client, source) {
76
- const contentType = source.headers.get("content-type");
77
- const startType = source.headers.get(BODY_FORMAT_KEY);
78
- const clone = source.clone();
79
- switch (true) {
80
- case startType === BodyFormat.Seroval:
81
- if (client && import.meta.env.SEROVAL_MODE === "js") {
82
- return await deserializeJSStream(instance, clone);
83
- }
84
- return await deserializeJSONStream(clone);
85
- case startType === BodyFormat.String:
86
- return await clone.text();
87
- case startType === BodyFormat.File: {
88
- const formData = await clone.formData();
89
- return formData.get(BODY_FORMAL_FILE);
90
- }
91
- case startType === BodyFormat.FormData:
92
- case contentType?.startsWith("multipart/form-data"):
93
- return await clone.formData();
94
- case startType === BodyFormat.URLSearchParams:
95
- case contentType?.startsWith("application/x-www-form-urlencoded"):
96
- return new URLSearchParams(await clone.text());
97
- case startType === BodyFormat.Blob:
98
- return await clone.blob();
99
- case startType === BodyFormat.ArrayBuffer:
100
- return await clone.arrayBuffer();
101
- case startType === BodyFormat.Uint8Array:
102
- return new Uint8Array(await clone.arrayBuffer());
103
- }
104
- return undefined;
105
- }
@@ -1,81 +0,0 @@
1
- import type { H3Event, HTTPEvent, InferEventInput } from "h3";
2
- import * as h3 from "h3";
3
- declare function _setContext(event: H3Event, key: string, value: any): void;
4
- declare function _getContext(event: H3Event, key: string): unknown;
5
- export declare function getWebRequest(): Request;
6
- export declare const HTTPEventSymbol: unique symbol;
7
- export declare function isEvent(obj: any): obj is h3.H3Event | {
8
- [HTTPEventSymbol]: h3.H3Event;
9
- };
10
- type Tail<T> = T extends [any, ...infer U] ? U : never;
11
- type PrependOverload<TOriginal extends (...args: Array<any>) => any, TOverload extends (...args: Array<any>) => any> = TOverload & TOriginal;
12
- type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<TFn, (...args: Parameters<TFn> extends [h3.HTTPEvent<any> | h3.H3Event<any>, ...infer TArgs] ? TArgs : Parameters<TFn>) => ReturnType<TFn>>;
13
- type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
14
- export declare const readBody: PrependOverload<typeof h3.readBody, WrappedReadBody>;
15
- type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
16
- export declare const getQuery: PrependOverload<typeof h3.getQuery, WrappedGetQuery>;
17
- export declare const isMethod: WrapFunction<typeof h3.isMethod>;
18
- export declare const isPreflightRequest: WrapFunction<typeof h3.isPreflightRequest>;
19
- type WrappedGetValidatedQuery = <T extends HTTPEvent, TEventInput = InferEventInput<"query", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>;
20
- export declare const getValidatedQuery: PrependOverload<typeof h3.getValidatedQuery, WrappedGetValidatedQuery>;
21
- export declare const getRouterParams: WrapFunction<typeof h3.getRouterParams>;
22
- export declare const getRouterParam: WrapFunction<typeof h3.getRouterParam>;
23
- type WrappedGetValidatedRouterParams = <T extends HTTPEvent, TEventInput = InferEventInput<"routerParams", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>;
24
- export declare const getValidatedRouterParams: PrependOverload<typeof h3.getValidatedRouterParams, WrappedGetValidatedRouterParams>;
25
- export declare const assertMethod: WrapFunction<typeof h3.assertMethod>;
26
- export declare const getRequestHeaders: WrapFunction<typeof h3.getRequestHeaders>;
27
- export declare const getRequestHeader: WrapFunction<typeof h3.getRequestHeader>;
28
- export declare const getRequestURL: WrapFunction<typeof h3.getRequestURL>;
29
- export declare const getRequestHost: WrapFunction<typeof h3.getRequestHost>;
30
- export declare const getRequestProtocol: WrapFunction<typeof h3.getRequestProtocol>;
31
- export declare const getRequestIP: WrapFunction<typeof h3.getRequestIP>;
32
- export declare const setResponseStatus: (code?: number, text?: string) => void;
33
- export declare const getResponseStatus: () => number | undefined;
34
- export declare const getResponseStatusText: () => string | undefined;
35
- export declare const getResponseHeaders: () => {
36
- [k: string]: string;
37
- };
38
- export declare const getResponseHeader: (name: string) => string | null;
39
- export declare const setResponseHeaders: (values: Record<string, string>) => void;
40
- export declare const setResponseHeader: (name: string, value: string | string[]) => void;
41
- export declare const appendResponseHeaders: (values: Record<string, string>) => void;
42
- export declare const appendResponseHeader: (name: string, value: string | string[]) => void;
43
- export declare const defaultContentType: (type: string) => void;
44
- export declare const proxyRequest: WrapFunction<typeof h3.proxyRequest>;
45
- export declare const fetchWithEvent: WrapFunction<typeof h3.fetchWithEvent>;
46
- export declare const getProxyRequestHeaders: WrapFunction<typeof h3.getProxyRequestHeaders>;
47
- export declare const parseCookies: WrapFunction<typeof h3.parseCookies>;
48
- export declare const getCookie: WrapFunction<typeof h3.getCookie>;
49
- export declare const setCookie: WrapFunction<typeof h3.setCookie>;
50
- export declare const deleteCookie: WrapFunction<typeof h3.deleteCookie>;
51
- type SessionDataT = Record<string, any>;
52
- type WrappedUseSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.useSession<T>>>) => ReturnType<typeof h3.useSession<T>>;
53
- export declare const useSession: WrappedUseSession;
54
- type WrappedGetSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.getSession<T>>>) => ReturnType<typeof h3.getSession<T>>;
55
- export declare const getSession: WrappedGetSession;
56
- type WrappedUpdateSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.updateSession<T>>>) => ReturnType<typeof h3.updateSession<T>>;
57
- export declare const updateSession: WrappedUpdateSession;
58
- type WrappedSealSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.sealSession<T>>>) => ReturnType<typeof h3.sealSession<T>>;
59
- export declare const sealSession: WrappedSealSession;
60
- export declare const unsealSession: WrapFunction<typeof h3.unsealSession>;
61
- export declare const clearSession: WrapFunction<typeof h3.clearSession>;
62
- export declare const handleCacheHeaders: WrapFunction<typeof h3.handleCacheHeaders>;
63
- export declare const handleCors: WrapFunction<typeof h3.handleCors>;
64
- export declare const appendCorsHeaders: WrapFunction<typeof h3.appendCorsHeaders>;
65
- export declare const appendCorsPreflightHeaders: WrapFunction<typeof h3.appendCorsPreflightHeaders>;
66
- export declare const appendHeader: (name: string, value: string | string[]) => void;
67
- export declare const appendHeaders: (values: Record<string, string>) => void;
68
- export declare const setHeader: (name: string, value: string | string[]) => void;
69
- export declare const setHeaders: (values: Record<string, string>) => void;
70
- export declare const getHeader: WrapFunction<typeof h3.getRequestHeader>;
71
- export declare const getHeaders: WrapFunction<typeof h3.getRequestHeaders>;
72
- export declare const getRequestFingerprint: WrapFunction<typeof h3.getRequestFingerprint>;
73
- export declare const getRequestWebStream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
74
- export declare const readFormData: () => Promise<FormData>;
75
- type WrappedReadValidatedBody = <T extends HTTPEvent, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readValidatedBody<T, H3Event, TEventInput>>;
76
- export declare const readValidatedBody: PrependOverload<typeof h3.readValidatedBody, WrappedReadValidatedBody>;
77
- export declare const getContext: WrapFunction<typeof _getContext>;
78
- export declare const setContext: WrapFunction<typeof _setContext>;
79
- export declare const removeResponseHeader: (name: string) => void;
80
- export declare const clearResponseHeaders: (headerNames?: string[]) => void;
81
- export {};
@@ -1,129 +0,0 @@
1
- import * as h3 from "h3";
2
- import { getRequestEvent } from "solid-js/web";
3
- function _setContext(event, key, value) {
4
- event.context[key] = value;
5
- }
6
- function _getContext(event, key) {
7
- return event.context[key];
8
- }
9
- function getEvent() {
10
- return getRequestEvent().nativeEvent;
11
- }
12
- export function getWebRequest() {
13
- return getEvent().req;
14
- }
15
- export const HTTPEventSymbol = Symbol("$HTTPEvent");
16
- export function isEvent(obj) {
17
- return (typeof obj === "object" &&
18
- (obj instanceof h3.H3Event ||
19
- obj?.[HTTPEventSymbol] instanceof h3.H3Event ||
20
- obj?.__is_event__ === true));
21
- // Implement logic to check if obj is an H3Event
22
- }
23
- function createWrapperFunction(h3Function) {
24
- return ((...args) => {
25
- const event = args[0];
26
- if (!isEvent(event)) {
27
- args.unshift(getEvent());
28
- }
29
- else {
30
- args[0] =
31
- event instanceof h3.H3Event || event.__is_event__ ? event : event[HTTPEventSymbol];
32
- }
33
- return h3Function(...args);
34
- });
35
- }
36
- export const readBody = createWrapperFunction(h3.readBody);
37
- export const getQuery = createWrapperFunction(h3.getQuery);
38
- export const isMethod = createWrapperFunction(h3.isMethod);
39
- export const isPreflightRequest = createWrapperFunction(h3.isPreflightRequest);
40
- export const getValidatedQuery = createWrapperFunction(h3.getValidatedQuery);
41
- export const getRouterParams = createWrapperFunction(h3.getRouterParams);
42
- export const getRouterParam = createWrapperFunction(h3.getRouterParam);
43
- export const getValidatedRouterParams = createWrapperFunction(h3.getValidatedRouterParams);
44
- export const assertMethod = createWrapperFunction(h3.assertMethod);
45
- export const getRequestHeaders = createWrapperFunction(h3.getRequestHeaders);
46
- export const getRequestHeader = createWrapperFunction(h3.getRequestHeader);
47
- export const getRequestURL = createWrapperFunction(h3.getRequestURL);
48
- export const getRequestHost = createWrapperFunction(h3.getRequestHost);
49
- export const getRequestProtocol = createWrapperFunction(h3.getRequestProtocol);
50
- export const getRequestIP = createWrapperFunction(h3.getRequestIP);
51
- export const setResponseStatus = (code, text) => {
52
- const e = getEvent();
53
- if (e.res.status !== undefined)
54
- e.res.status = code;
55
- if (e.res.statusText !== undefined)
56
- e.res.statusText = text;
57
- };
58
- export const getResponseStatus = () => getEvent().res.status;
59
- export const getResponseStatusText = () => getEvent().res.statusText;
60
- export const getResponseHeaders = () => Object.fromEntries(getEvent().res.headers.entries());
61
- export const getResponseHeader = (name) => getEvent().res.headers.get(name);
62
- export const setResponseHeaders = (values) => {
63
- const headers = getEvent().res.headers;
64
- for (const [name, value] of Object.entries(values)) {
65
- headers.set(name, value);
66
- }
67
- };
68
- export const setResponseHeader = (name, value) => {
69
- const headers = getEvent().res.headers;
70
- (Array.isArray(value) ? value : [value]).forEach(value => {
71
- headers.set(name, value);
72
- });
73
- };
74
- export const appendResponseHeaders = (values) => {
75
- const headers = getEvent().res.headers;
76
- for (const [name, value] of Object.entries(values)) {
77
- headers.append(name, value);
78
- }
79
- };
80
- export const appendResponseHeader = (name, value) => {
81
- const headers = getEvent().res.headers;
82
- (Array.isArray(value) ? value : [value]).forEach(value => {
83
- headers.append(name, value);
84
- });
85
- };
86
- export const defaultContentType = (type) => getEvent().res.headers.set("content-type", type);
87
- export const proxyRequest = createWrapperFunction(h3.proxyRequest);
88
- export const fetchWithEvent = createWrapperFunction(h3.fetchWithEvent);
89
- export const getProxyRequestHeaders = createWrapperFunction(h3.getProxyRequestHeaders);
90
- export const parseCookies = createWrapperFunction(h3.parseCookies);
91
- export const getCookie = createWrapperFunction(h3.getCookie);
92
- export const setCookie = createWrapperFunction(h3.setCookie);
93
- export const deleteCookie = createWrapperFunction(h3.deleteCookie);
94
- export const useSession = createWrapperFunction(h3.useSession);
95
- export const getSession = createWrapperFunction(h3.getSession);
96
- export const updateSession = createWrapperFunction(h3.updateSession);
97
- export const sealSession = createWrapperFunction(h3.sealSession);
98
- export const unsealSession = createWrapperFunction(h3.unsealSession);
99
- export const clearSession = createWrapperFunction(h3.clearSession);
100
- export const handleCacheHeaders = createWrapperFunction(h3.handleCacheHeaders);
101
- export const handleCors = createWrapperFunction(h3.handleCors);
102
- export const appendCorsHeaders = createWrapperFunction(h3.appendCorsHeaders);
103
- export const appendCorsPreflightHeaders = createWrapperFunction(h3.appendCorsPreflightHeaders);
104
- export const appendHeader = appendResponseHeader;
105
- export const appendHeaders = appendResponseHeaders;
106
- export const setHeader = setResponseHeader;
107
- export const setHeaders = setResponseHeaders;
108
- export const getHeader = getRequestHeader;
109
- export const getHeaders = getRequestHeaders;
110
- export const getRequestFingerprint = createWrapperFunction(h3.getRequestFingerprint);
111
- export const getRequestWebStream = () => getEvent().req.body;
112
- export const readFormData = () => getEvent().req.formData();
113
- export const readValidatedBody = createWrapperFunction(h3.readValidatedBody);
114
- export const getContext = createWrapperFunction(_getContext);
115
- export const setContext = createWrapperFunction(_setContext);
116
- export const removeResponseHeader = (name) => getEvent().res.headers.delete(name);
117
- export const clearResponseHeaders = (headerNames) => {
118
- const headers = getEvent().res.headers;
119
- if (headerNames && headerNames.length > 0) {
120
- for (const name of headerNames) {
121
- headers.delete(name);
122
- }
123
- }
124
- else {
125
- for (const name of headers.keys()) {
126
- headers.delete(name);
127
- }
128
- }
129
- };
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { default as clientOnly } from "./shared/clientOnly.ts";
2
- export { GET } from "./shared/GET.ts";
3
- export { HttpHeader } from "./shared/HttpHeader.tsx";
4
- export { HttpStatusCode } from "./shared/HttpStatusCode.ts";
5
- export { getServerFunctionMeta } from "./shared/serverFunction.ts";
package/dist/index.jsx DELETED
@@ -1,6 +0,0 @@
1
- // @refresh skip
2
- export { default as clientOnly } from "./shared/clientOnly.js";
3
- export { GET } from "./shared/GET.js";
4
- export { HttpHeader } from "./shared/HttpHeader.jsx";
5
- export { HttpStatusCode } from "./shared/HttpStatusCode.js";
6
- export { getServerFunctionMeta } from "./shared/serverFunction.js";
@@ -1,38 +0,0 @@
1
- import type { Middleware } from "h3";
2
- import type { FetchEvent } from "../server/types.ts";
3
- /** Function responsible for receiving an observable [operation]{@link Operation} and returning a [result]{@link OperationResult}. */
4
- export type MiddlewareFn = (event: FetchEvent) => Promise<unknown> | unknown;
5
- /** This composes an array of Exchanges into a single ExchangeIO function */
6
- export type RequestMiddleware = (event: FetchEvent) => Response | Promise<Response> | void | Promise<void> | Promise<void | Response>;
7
- type EventHandlerResponse<T = any> = T | Promise<T>;
8
- type ResponseMiddlewareResponseParam = {
9
- body?: Awaited<EventHandlerResponse>;
10
- };
11
- export type ResponseMiddleware = (event: FetchEvent, response: ResponseMiddlewareResponseParam) => Response | Promise<Response> | void | Promise<void>;
12
- /**
13
- * Creates middleware for handling requests and responses.
14
- *
15
- * @see https://docs.solidjs.com/solid-start/reference/server/create-middleware
16
- /**
17
- * Creates request/response middlewares via H3.
18
- *
19
- * Accepts an array of H3 {@link Middleware}
20
- *
21
- * @tip To run your middleware before response, `await next()` in your function block.
22
- *@example
23
- * const middleware = createMiddleware([
24
- * async (event, next) => {
25
- * const resp = await next();
26
- * if (resp instanceof Response) return resp;
27
- * return new Response("Not found", { status: 404 });
28
- * },
29
- * ]);
30
- *
31
- */
32
- export declare function createMiddleware(args: {
33
- /** @deprecated Use H3 `Middleware` */
34
- onRequest?: RequestMiddleware | RequestMiddleware[] | undefined;
35
- /** @deprecated Use H3 `Middleware` */
36
- onBeforeResponse?: ResponseMiddleware | ResponseMiddleware[] | undefined;
37
- } | Middleware[]): Middleware[];
38
- export {};