@solidjs/web 2.0.0-beta.2 → 2.0.0-beta.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 (52) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +783 -223
  3. package/dist/dev.js +757 -217
  4. package/dist/server.cjs +742 -186
  5. package/dist/server.js +714 -183
  6. package/dist/web.cjs +772 -196
  7. package/dist/web.js +746 -190
  8. package/package.json +193 -38
  9. package/serialization/dist/serialization.cjs +83 -0
  10. package/serialization/dist/serialization.js +75 -0
  11. package/serialization/package.json +20 -0
  12. package/serialization/types/index.d.ts +139 -0
  13. package/serialization/types-cjs/index.d.cts +139 -0
  14. package/serialization/types-cjs/package.json +3 -0
  15. package/server-functions/dist/client.cjs +370 -0
  16. package/server-functions/dist/client.js +363 -0
  17. package/server-functions/dist/server.cjs +542 -0
  18. package/server-functions/dist/server.js +531 -0
  19. package/server-functions/package.json +30 -0
  20. package/storage/package.json +8 -3
  21. package/storage/types/index.d.ts +26 -0
  22. package/storage/types-cjs/index.d.cts +28 -0
  23. package/storage/types-cjs/package.json +3 -0
  24. package/types/client.d.ts +64 -21
  25. package/types/core.d.ts +3 -3
  26. package/types/index.d.ts +156 -24
  27. package/types/jsx-properties.d.ts +93 -0
  28. package/types/jsx.d.ts +4135 -1
  29. package/types/response.d.ts +93 -0
  30. package/types/serializer.d.ts +139 -0
  31. package/types/server-functions/client.d.ts +63 -0
  32. package/types/server-functions/server.d.ts +188 -0
  33. package/types/server-functions/shared.d.ts +171 -0
  34. package/types/server-mock.d.ts +89 -0
  35. package/types/server.d.ts +123 -28
  36. package/types-cjs/client.d.cts +131 -0
  37. package/types-cjs/core.d.cts +3 -0
  38. package/types-cjs/index.d.cts +178 -0
  39. package/types-cjs/jsx-properties.d.cts +93 -0
  40. package/types-cjs/jsx.d.cts +4135 -0
  41. package/types-cjs/package.json +3 -0
  42. package/types-cjs/response.d.cts +93 -0
  43. package/types-cjs/serializer.d.cts +139 -0
  44. package/types-cjs/server-functions/client.d.cts +63 -0
  45. package/types-cjs/server-functions/server.d.cts +188 -0
  46. package/types-cjs/server-functions/shared.d.cts +171 -0
  47. package/types-cjs/server-mock.d.cts +161 -0
  48. package/types-cjs/server.d.cts +251 -0
  49. package/storage/types/src/client.d.ts +0 -1
  50. package/storage/types/src/index.d.ts +0 -46
  51. package/storage/types/src/server-mock.d.ts +0 -72
  52. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,531 @@
1
+ import { sharedConfig } from 'solid-js';
2
+ import { fromCrossJSON, Feature, toCrossJSONStream } from 'seroval';
3
+ import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
4
+
5
+ const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
6
+ function isResponseEnvelope(value) {
7
+ return !!(value && typeof value === "object" && value[ENVELOPE]);
8
+ }
9
+
10
+ Feature.AggregateError | Feature.BigIntTypedArray;
11
+ const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
12
+ CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
13
+ FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin]);
14
+ function resolveSerializerPlugins(customPlugins) {
15
+ return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
16
+ }
17
+ const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
18
+ const JSON_CODEC_DEPTH_LIMIT = 64;
19
+ function resolveCodecOptions({
20
+ plugins,
21
+ disabledFeatures,
22
+ depthLimit
23
+ } = {}) {
24
+ return {
25
+ plugins: resolveSerializerPlugins(plugins),
26
+ disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
27
+ depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
28
+ };
29
+ }
30
+ function serializeJSON(value, {
31
+ onParse,
32
+ onDone,
33
+ onError,
34
+ ...codecOptions
35
+ }) {
36
+ return toCrossJSONStream(value, {
37
+ onParse,
38
+ onDone,
39
+ onError,
40
+ ...resolveCodecOptions(codecOptions)
41
+ });
42
+ }
43
+ function createJSONDeserializer(options) {
44
+ const refs = new Map();
45
+ const resolved = resolveCodecOptions(options);
46
+ return function deserializeJSONChunk(node) {
47
+ return fromCrossJSON(node, {
48
+ refs,
49
+ ...resolved
50
+ });
51
+ };
52
+ }
53
+
54
+ const RequestContext = Symbol.for("solid.RequestContext");
55
+ function getRequestEvent() {
56
+ return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
57
+ }
58
+
59
+ const codecConfig = {
60
+ codec: undefined
61
+ };
62
+ function configureServerFunctionsCodec(codec) {
63
+ codecConfig.codec = codec;
64
+ }
65
+ function getServerFunctionsCodec() {
66
+ return codecConfig.codec;
67
+ }
68
+ const FUNCTION_HEADER = "X-Server-Function-Id";
69
+ const INSTANCE_HEADER = "X-Server-Function-Instance";
70
+ const BODY_FORMAT_HEADER = "X-Server-Function-Format";
71
+ const FILE_FORM_KEY = "__server_function_file__";
72
+ const BodyFormat = {
73
+ Serialized: "0",
74
+ String: "1",
75
+ FormData: "2",
76
+ URLSearchParams: "3",
77
+ Blob: "4",
78
+ File: "5",
79
+ ArrayBuffer: "6",
80
+ Uint8Array: "7"
81
+ };
82
+ function getHeadersAndBody(body) {
83
+ switch (true) {
84
+ case typeof body === "string":
85
+ return {
86
+ headers: {
87
+ "Content-Type": "text/plain",
88
+ [BODY_FORMAT_HEADER]: BodyFormat.String
89
+ },
90
+ body
91
+ };
92
+ case body instanceof FormData:
93
+ return {
94
+ headers: {
95
+ [BODY_FORMAT_HEADER]: BodyFormat.FormData
96
+ },
97
+ body
98
+ };
99
+ case body instanceof URLSearchParams:
100
+ return {
101
+ headers: {
102
+ "Content-Type": "application/x-www-form-urlencoded",
103
+ [BODY_FORMAT_HEADER]: BodyFormat.URLSearchParams
104
+ },
105
+ body
106
+ };
107
+ case typeof File !== "undefined" && body instanceof File:
108
+ {
109
+ const formData = new FormData();
110
+ formData.append(FILE_FORM_KEY, body, body.name);
111
+ return {
112
+ headers: {
113
+ [BODY_FORMAT_HEADER]: BodyFormat.File
114
+ },
115
+ body: formData
116
+ };
117
+ }
118
+ case body instanceof Blob:
119
+ return {
120
+ headers: {
121
+ [BODY_FORMAT_HEADER]: BodyFormat.Blob
122
+ },
123
+ body
124
+ };
125
+ case body instanceof ArrayBuffer:
126
+ return {
127
+ headers: {
128
+ [BODY_FORMAT_HEADER]: BodyFormat.ArrayBuffer
129
+ },
130
+ body
131
+ };
132
+ case body instanceof Uint8Array:
133
+ return {
134
+ headers: {
135
+ [BODY_FORMAT_HEADER]: BodyFormat.Uint8Array
136
+ },
137
+ body: new Uint8Array(body)
138
+ };
139
+ default:
140
+ return undefined;
141
+ }
142
+ }
143
+ async function extractBody(source, codecOptions) {
144
+ const contentType = source.headers.get("content-type");
145
+ const format = source.headers.get(BODY_FORMAT_HEADER);
146
+ const clone = source.clone();
147
+ switch (true) {
148
+ case format === BodyFormat.Serialized:
149
+ return await deserializeStream(clone, codecOptions);
150
+ case format === BodyFormat.String:
151
+ return await clone.text();
152
+ case format === BodyFormat.File:
153
+ {
154
+ const formData = await clone.formData();
155
+ return formData.get(FILE_FORM_KEY);
156
+ }
157
+ case format === BodyFormat.FormData:
158
+ case contentType && contentType.startsWith("multipart/form-data"):
159
+ return await clone.formData();
160
+ case format === BodyFormat.URLSearchParams:
161
+ case contentType && contentType.startsWith("application/x-www-form-urlencoded"):
162
+ return new URLSearchParams(await clone.text());
163
+ case format === BodyFormat.Blob:
164
+ return await clone.blob();
165
+ case format === BodyFormat.ArrayBuffer:
166
+ return await clone.arrayBuffer();
167
+ case format === BodyFormat.Uint8Array:
168
+ return new Uint8Array(await clone.arrayBuffer());
169
+ }
170
+ return undefined;
171
+ }
172
+ function createChunk(data) {
173
+ const encodeData = new TextEncoder().encode(data);
174
+ const bytes = encodeData.length;
175
+ const baseHex = bytes.toString(16);
176
+ const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex;
177
+ const head = new TextEncoder().encode(`;0x${totalHex};`);
178
+ const chunk = new Uint8Array(12 + bytes);
179
+ chunk.set(head);
180
+ chunk.set(encodeData, 12);
181
+ return chunk;
182
+ }
183
+ class ChunkReader {
184
+ constructor(stream) {
185
+ this.reader = stream.getReader();
186
+ this.buffer = new Uint8Array(0);
187
+ this.done = false;
188
+ }
189
+ async readChunk() {
190
+ const chunk = await this.reader.read();
191
+ if (!chunk.done) {
192
+ const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
193
+ newBuffer.set(this.buffer);
194
+ newBuffer.set(chunk.value, this.buffer.length);
195
+ this.buffer = newBuffer;
196
+ } else {
197
+ this.done = true;
198
+ }
199
+ }
200
+ async next() {
201
+ if (this.buffer.length === 0) {
202
+ if (this.done) {
203
+ return {
204
+ done: true,
205
+ value: undefined
206
+ };
207
+ }
208
+ await this.readChunk();
209
+ return await this.next();
210
+ }
211
+ const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
212
+ const bytes = Number.parseInt(head, 16);
213
+ if (Number.isNaN(bytes)) {
214
+ throw new Error("Malformed server function stream.");
215
+ }
216
+ while (bytes > this.buffer.length - 12) {
217
+ if (this.done) {
218
+ throw new Error("Malformed server function stream.");
219
+ }
220
+ await this.readChunk();
221
+ }
222
+ const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
223
+ this.buffer = this.buffer.subarray(12 + bytes);
224
+ return {
225
+ done: false,
226
+ value: partial
227
+ };
228
+ }
229
+ async drain(interpret) {
230
+ while (true) {
231
+ const result = await this.next();
232
+ if (result.done) {
233
+ break;
234
+ }
235
+ interpret(result.value);
236
+ }
237
+ }
238
+ }
239
+ function serializeStream(value, codecOptions) {
240
+ return new ReadableStream({
241
+ start(controller) {
242
+ serializeJSON(value, {
243
+ ...codecOptions,
244
+ onParse(node) {
245
+ controller.enqueue(createChunk(JSON.stringify(node)));
246
+ },
247
+ onDone() {
248
+ controller.close();
249
+ },
250
+ onError(error) {
251
+ controller.error(error);
252
+ }
253
+ });
254
+ }
255
+ });
256
+ }
257
+ async function deserializeStream(source, codecOptions) {
258
+ if (!source.body) {
259
+ throw new Error("missing body");
260
+ }
261
+ const reader = new ChunkReader(source.body);
262
+ const result = await reader.next();
263
+ if (!result.done) {
264
+ const deserializeChunk = createJSONDeserializer(codecOptions);
265
+ function interpretChunk(chunk) {
266
+ return deserializeChunk(JSON.parse(chunk));
267
+ }
268
+ void reader.drain(interpretChunk);
269
+ return interpretChunk(result.value);
270
+ }
271
+ return undefined;
272
+ }
273
+ async function deserializeString(text, codecOptions) {
274
+ return await deserializeStream(new Response(text), codecOptions);
275
+ }
276
+ async function decodeResponse(response, codecOptions) {
277
+ if (!response.body) return undefined;
278
+ return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
279
+ }
280
+
281
+ const config = {
282
+ provideEvent: undefined,
283
+ endpoint: "/_server"
284
+ };
285
+ function configureServerFunctionsServer({
286
+ provideEvent,
287
+ endpoint,
288
+ codec
289
+ } = {}) {
290
+ if (provideEvent !== undefined) config.provideEvent = provideEvent;
291
+ if (endpoint !== undefined) config.endpoint = endpoint;
292
+ if (codec !== undefined) configureServerFunctionsCodec(codec);
293
+ }
294
+ function provideEvent(event, fn) {
295
+ if (config.provideEvent) return config.provideEvent(event, fn);
296
+ const ctx = globalThis[RequestContext];
297
+ if (ctx) return ctx.run(event, fn);
298
+ throw new Error("No request event provider. Configure one with configureServerFunctionsServer({ provideEvent }).");
299
+ }
300
+ const REGISTRATIONS = new Map();
301
+ function registerServerFunction(id, callback) {
302
+ REGISTRATIONS.set(id, callback);
303
+ return callback;
304
+ }
305
+ function getServerFunction(id) {
306
+ const fn = REGISTRATIONS.get(id);
307
+ if (fn) {
308
+ return fn;
309
+ }
310
+ throw new Error("invalid server function: " + id);
311
+ }
312
+ function registerServerReference(id, fn) {
313
+ registerServerFunction(id, fn);
314
+ return {
315
+ id,
316
+ fn
317
+ };
318
+ }
319
+ function createServerReference({
320
+ id,
321
+ fn
322
+ }) {
323
+ if (typeof fn !== "function") throw new Error("Export from a 'use server' module must be a function");
324
+ return new Proxy(fn, {
325
+ get(target, prop, receiver) {
326
+ if (prop === "url") {
327
+ return `${config.endpoint}?id=${encodeURIComponent(id)}`;
328
+ }
329
+ if (prop === "GET") return receiver;
330
+ return target[prop];
331
+ },
332
+ apply(target, thisArg, args) {
333
+ const ogEvt = getRequestEvent();
334
+ if (!ogEvt) throw new Error("Cannot call server function outside of a request");
335
+ const evt = {
336
+ ...ogEvt
337
+ };
338
+ evt.locals.serverFunctionMeta = {
339
+ id
340
+ };
341
+ evt.serverOnly = true;
342
+ return provideEvent(evt, () => {
343
+ return fn.apply(thisArg, args);
344
+ });
345
+ }
346
+ });
347
+ }
348
+ function getServerFunctionMeta() {
349
+ const event = getRequestEvent();
350
+ return event && event.locals.serverFunctionMeta;
351
+ }
352
+ function resolveFunctionId(request, url) {
353
+ const reference = request.headers.get(FUNCTION_HEADER);
354
+ if (reference) {
355
+ return reference.split("#")[0];
356
+ }
357
+ return url.searchParams.get("id");
358
+ }
359
+ async function parseArguments(request, url, instance, codec) {
360
+ const parsed = [];
361
+ if (!instance || request.method === "GET") {
362
+ const args = url.searchParams.get("args");
363
+ if (args) {
364
+ const result = args.startsWith(";0x") ? await deserializeString(args, codec) : JSON.parse(args);
365
+ for (const arg of result) {
366
+ parsed.push(arg);
367
+ }
368
+ }
369
+ }
370
+ if (request.method === "POST" && request.body !== null) {
371
+ const format = request.headers.get(BODY_FORMAT_HEADER);
372
+ const decoded = await extractBody(request.clone(), codec);
373
+ if (format === BodyFormat.Serialized) {
374
+ return decoded;
375
+ }
376
+ parsed.push(decoded);
377
+ }
378
+ return parsed;
379
+ }
380
+ function serializedResponse(value, headers, codec) {
381
+ headers.set(BODY_FORMAT_HEADER, BodyFormat.Serialized);
382
+ headers.set("Content-Type", "text/plain");
383
+ return new Response(serializeStream(value, codec), {
384
+ headers
385
+ });
386
+ }
387
+ function encodeResult(value, headers, status, codec) {
388
+ const direct = getHeadersAndBody(value);
389
+ if (direct) {
390
+ for (const [key, val] of Object.entries(direct.headers || {})) {
391
+ headers.set(key, val);
392
+ }
393
+ return new Response(direct.body, {
394
+ status,
395
+ headers
396
+ });
397
+ }
398
+ const response = serializedResponse(value, headers, codec);
399
+ return status === 200 ? response : new Response(response.body, {
400
+ status,
401
+ headers
402
+ });
403
+ }
404
+ async function handleServerFunctionRequest(request, options = {}) {
405
+ const codec = options.codec !== undefined ? options.codec : getServerFunctionsCodec();
406
+ const url = new URL(request.url);
407
+ const instance = request.headers.get(INSTANCE_HEADER);
408
+ const functionId = resolveFunctionId(request, url);
409
+ if (!functionId) {
410
+ return new Response(process.env.NODE_ENV === "development" ? "Server function not found" : null, {
411
+ status: 404
412
+ });
413
+ }
414
+ let serverFunction;
415
+ try {
416
+ serverFunction = getServerFunction(functionId);
417
+ } catch {
418
+ return new Response(process.env.NODE_ENV === "development" ? `Unknown server function: ${functionId}` : null, {
419
+ status: 404
420
+ });
421
+ }
422
+ const event = options.createEvent ? options.createEvent(request) : {
423
+ request,
424
+ locals: {}
425
+ };
426
+ const provide = options.provideEvent || provideEvent;
427
+ const parsed = await parseArguments(request, url, instance, codec);
428
+ const headers = new Headers();
429
+ try {
430
+ let result = await provide(event, async () => {
431
+ event.locals.serverFunctionMeta = {
432
+ id: functionId
433
+ };
434
+ return serverFunction(...parsed);
435
+ });
436
+ if (options.transformResult) {
437
+ result = await options.transformResult(event, result, {
438
+ instance,
439
+ request
440
+ });
441
+ }
442
+ let status = 200;
443
+ if (isResponseEnvelope(result)) {
444
+ const {
445
+ response,
446
+ value
447
+ } = result;
448
+ if (!instance && !options.handleNoJS && response && response.body) {
449
+ return response;
450
+ }
451
+ if (response && response.headers) {
452
+ response.headers.forEach((val, key) => headers.append(key, val));
453
+ }
454
+ if (response && response.status && (response.status < 300 || response.status >= 400)) {
455
+ status = response.status;
456
+ }
457
+ result = value;
458
+ } else if (result instanceof Response) {
459
+ if (result.headers && result.headers.has("X-Content-Raw")) return result;
460
+ if (instance) {
461
+ if (result.headers) {
462
+ result.headers.forEach((value, key) => headers.append(key, value));
463
+ }
464
+ if (result.status && (result.status < 300 || result.status >= 400)) {
465
+ status = result.status;
466
+ }
467
+ if (result.body == null) {
468
+ result = null;
469
+ }
470
+ }
471
+ }
472
+ if (!instance) {
473
+ if (options.handleNoJS) return options.handleNoJS(result, request, parsed);
474
+ if (result instanceof Response) return result;
475
+ return encodeResult(result, headers, 200, codec);
476
+ }
477
+ return encodeResult(result, headers, status, codec);
478
+ } catch (x) {
479
+ if (x instanceof Response || isResponseEnvelope(x)) {
480
+ if (options.transformResult) {
481
+ x = await options.transformResult(event, x, {
482
+ instance,
483
+ request,
484
+ thrown: true
485
+ });
486
+ }
487
+ let status = 200;
488
+ if (isResponseEnvelope(x)) {
489
+ const {
490
+ response,
491
+ value
492
+ } = x;
493
+ if (response && response.headers) {
494
+ response.headers.forEach((val, key) => headers.append(key, val));
495
+ }
496
+ if (response && response.status && (!instance || response.status < 300 || response.status >= 400)) {
497
+ status = response.status;
498
+ }
499
+ x = value;
500
+ } else if (x instanceof Response) {
501
+ if (x.headers) {
502
+ x.headers.forEach((value, key) => headers.append(key, value));
503
+ }
504
+ if (x.status && (!instance || x.status < 300 || x.status >= 400)) {
505
+ status = x.status;
506
+ }
507
+ if (x.body == null) {
508
+ x = null;
509
+ }
510
+ }
511
+ headers.set("X-Server-Function-Error", "true");
512
+ if (!instance) {
513
+ if (options.handleNoJS) return options.handleNoJS(x, request, parsed, true);
514
+ if (x instanceof Response) return x;
515
+ }
516
+ return encodeResult(x, headers, status, codec);
517
+ }
518
+ if (!instance) {
519
+ if (options.handleNoJS) return options.handleNoJS(x, request, parsed, true);
520
+ const message = x instanceof Error ? x.message : String(x);
521
+ return new Response(process.env.NODE_ENV === "development" ? message : null, {
522
+ status: 500
523
+ });
524
+ }
525
+ const error = x instanceof Error ? x.message : typeof x === "string" ? x : "true";
526
+ headers.set("X-Server-Function-Error", error.replace(/[\r\n]+/g, ""));
527
+ return encodeResult(x, headers, 200, codec);
528
+ }
529
+ }
530
+
531
+ export { FUNCTION_HEADER, INSTANCE_HEADER, configureServerFunctionsServer, createServerReference, decodeResponse, getServerFunction, getServerFunctionMeta, handleServerFunctionRequest, registerServerFunction, registerServerReference };
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@solidjs/web/server-functions",
3
+ "main": "./dist/server.cjs",
4
+ "module": "./dist/server.js",
5
+ "types": "../types/server-functions/server.d.ts",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "browser": {
11
+ "import": {
12
+ "types": "../types/server-functions/client.d.ts",
13
+ "default": "./dist/client.js"
14
+ },
15
+ "require": {
16
+ "types": "../types-cjs/server-functions/client.d.cts",
17
+ "default": "./dist/client.cjs"
18
+ }
19
+ },
20
+ "import": {
21
+ "types": "../types/server-functions/server.d.ts",
22
+ "default": "./dist/server.js"
23
+ },
24
+ "require": {
25
+ "types": "../types-cjs/server-functions/server.d.cts",
26
+ "default": "./dist/server.cjs"
27
+ }
28
+ }
29
+ }
30
+ }
@@ -7,9 +7,14 @@
7
7
  "sideEffects": false,
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./types/index.d.ts",
11
- "import": "./dist/storage.js",
12
- "require": "./dist/storage.cjs"
10
+ "import": {
11
+ "types": "./types/index.d.ts",
12
+ "default": "./dist/storage.js"
13
+ },
14
+ "require": {
15
+ "types": "./types-cjs/index.d.cts",
16
+ "default": "./dist/storage.cjs"
17
+ }
13
18
  }
14
19
  }
15
20
  }
@@ -1,2 +1,28 @@
1
1
  import type { RequestEvent } from "@solidjs/web";
2
+ /**
3
+ * Establishes the request-event scope for a server request: everything
4
+ * `cb` runs (across `await`s, via AsyncLocalStorage) sees `init` from
5
+ * `getRequestEvent()`. Call it at the top of the server's request handling,
6
+ * wrapping SSR and server-function dispatch; the server-functions runtime
7
+ * also picks the scope up automatically as its default event provider.
8
+ *
9
+ * Lives on its own subpath because it imports `node:async_hooks` — keep it
10
+ * out of environments without that module.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { provideRequestEvent } from "@solidjs/web/storage";
15
+ *
16
+ * async function handler(request: Request) {
17
+ * return provideRequestEvent({ request, locals: {} }, () =>
18
+ * renderToStringAsync(() => <App />)
19
+ * );
20
+ * }
21
+ * ```
22
+ *
23
+ * @param init the event for this request — frameworks pass their richer
24
+ * event shapes
25
+ * @param cb runs synchronously; its return value is passed through
26
+ * @throws on the client, where there is no request to scope
27
+ */
2
28
  export declare function provideRequestEvent<T extends RequestEvent, U>(init: T, cb: () => U): U;
@@ -0,0 +1,28 @@
1
+ import type { RequestEvent } from "@solidjs/web";
2
+ /**
3
+ * Establishes the request-event scope for a server request: everything
4
+ * `cb` runs (across `await`s, via AsyncLocalStorage) sees `init` from
5
+ * `getRequestEvent()`. Call it at the top of the server's request handling,
6
+ * wrapping SSR and server-function dispatch; the server-functions runtime
7
+ * also picks the scope up automatically as its default event provider.
8
+ *
9
+ * Lives on its own subpath because it imports `node:async_hooks` — keep it
10
+ * out of environments without that module.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { provideRequestEvent } from "@solidjs/web/storage";
15
+ *
16
+ * async function handler(request: Request) {
17
+ * return provideRequestEvent({ request, locals: {} }, () =>
18
+ * renderToStringAsync(() => <App />)
19
+ * );
20
+ * }
21
+ * ```
22
+ *
23
+ * @param init the event for this request — frameworks pass their richer
24
+ * event shapes
25
+ * @param cb runs synchronously; its return value is passed through
26
+ * @throws on the client, where there is no request to scope
27
+ */
28
+ export declare function provideRequestEvent<T extends RequestEvent, U>(init: T, cb: () => U): U;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }