@server/next 0.36.1 → 0.36.2

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 (3) hide show
  1. package/index.d.ts +33 -32
  2. package/index.js +3 -0
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -15,6 +15,38 @@ declare class UploadPipeline {
15
15
  }
16
16
  declare function upload(bucket?: Bucket | string | null): UploadPipeline;
17
17
 
18
+ type CookieOptions = string | string[] | Cookie | Cookie[] | null;
19
+ interface ResponseData {
20
+ headers: Headers;
21
+ status?: number;
22
+ }
23
+ declare class Reply$1 {
24
+ res: ResponseData;
25
+ constructor();
26
+ status(status: number): this;
27
+ type(type?: string): this;
28
+ download(name?: string): this;
29
+ headers(key: string | Record<string, string>, value?: string): this;
30
+ cache(value: CacheOption): this;
31
+ cookies(key: string | Record<string, CookieOptions>, value?: CookieOptions): this;
32
+ json(body: unknown): Response;
33
+ redirect(path: string): Response;
34
+ file(path: string): Promise<Response>;
35
+ send(body?: string | Buffer | ReadableStream | any): Response;
36
+ }
37
+ type Params<K extends keyof Reply$1> = Reply$1[K] extends (...args: infer A) => any ? A : never;
38
+ declare const status: (...args: Params<"status">) => Reply$1;
39
+ declare const headers: (...args: Params<"headers">) => Reply$1;
40
+ declare const type: (...args: Params<"type">) => Reply$1;
41
+ declare const cache: (...args: Params<"cache">) => Reply$1;
42
+ declare const download: (...args: Params<"download">) => Reply$1;
43
+ declare const cookies: (...args: Params<"cookies">) => Reply$1;
44
+ declare const send: (...args: Params<"send">) => Response;
45
+ declare const json: (...args: Params<"json">) => Response;
46
+ declare const file: (...args: Params<"file">) => Promise<Response>;
47
+ declare const redirect: (...args: Params<"redirect">) => Response;
48
+
49
+ type Reply = ReturnType<typeof status>;
18
50
  type Method = "get" | "post" | "put" | "patch" | "delete" | "head" | "options" | "socket";
19
51
  type ServerConfig<Session = {}, User = {}> = {
20
52
  Session?: Session;
@@ -266,7 +298,7 @@ type Context<Params extends Record<string, string | undefined> = Record<string,
266
298
  };
267
299
  app: Server;
268
300
  };
269
- type InlineReply = Response | {
301
+ type InlineReply = Response | Reply | {
270
302
  body: string;
271
303
  headers?: Headers;
272
304
  } | SerializableValue | JSX.Element | Buffer | ReadableStream;
@@ -337,37 +369,6 @@ declare class Router<O extends ServerConfig = object> {
337
369
  }
338
370
  declare function router(): Router;
339
371
 
340
- type CookieOptions = string | string[] | Cookie | Cookie[] | null;
341
- interface ResponseData {
342
- headers: Headers;
343
- status?: number;
344
- }
345
- declare class Reply {
346
- res: ResponseData;
347
- constructor();
348
- status(status: number): this;
349
- type(type?: string): this;
350
- download(name?: string): this;
351
- headers(key: string | Record<string, string>, value?: string): this;
352
- cache(value: CacheOption): this;
353
- cookies(key: string | Record<string, CookieOptions>, value?: CookieOptions): this;
354
- json(body: unknown): Response;
355
- redirect(path: string): Response;
356
- file(path: string): Promise<Response>;
357
- send(body?: string | Buffer | ReadableStream | any): Response;
358
- }
359
- type Params<K extends keyof Reply> = Reply[K] extends (...args: infer A) => any ? A : never;
360
- declare const status: (...args: Params<"status">) => Reply;
361
- declare const headers: (...args: Params<"headers">) => Reply;
362
- declare const type: (...args: Params<"type">) => Reply;
363
- declare const cache: (...args: Params<"cache">) => Reply;
364
- declare const download: (...args: Params<"download">) => Reply;
365
- declare const cookies: (...args: Params<"cookies">) => Reply;
366
- declare const send: (...args: Params<"send">) => Response;
367
- declare const json: (...args: Params<"json">) => Response;
368
- declare const file: (...args: Params<"file">) => Promise<Response>;
369
- declare const redirect: (...args: Params<"redirect">) => Response;
370
-
371
372
  declare class Server<O extends ServerConfig = {}> extends Router<O> {
372
373
  settings: Settings;
373
374
  platform: Platform;
package/index.js CHANGED
@@ -1836,6 +1836,9 @@ async function parseResponse(out, ctx) {
1836
1836
  if (typeof out === "function") {
1837
1837
  out = await out(ctx);
1838
1838
  }
1839
+ if (out && typeof out.send === "function" && out.res?.headers instanceof Headers) {
1840
+ out = out.send();
1841
+ }
1839
1842
  if (out instanceof Blob) {
1840
1843
  out = new Response(out, { headers: { "Content-Type": out.type } });
1841
1844
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.36.1",
3
+ "version": "0.36.2",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "github:franciscop/server-next",