@muhgholy/next-drive 4.23.32 → 4.23.33

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.
@@ -3,10 +3,75 @@
3
3
  var chunkWUG4ATLH_cjs = require('../chunk-WUG4ATLH.cjs');
4
4
  require('../chunk-HQTC3554.cjs');
5
5
  var chunkHWNIRA6Y_cjs = require('../chunk-HWNIRA6Y.cjs');
6
+ var stream = require('stream');
6
7
 
7
- // src/server/hono.ts
8
- var driveAPIHandlerHono = chunkWUG4ATLH_cjs.driveAPIHandler;
9
- var driveConfigurationHono = chunkHWNIRA6Y_cjs.driveConfiguration;
8
+ var HONO_CONTEXT = /* @__PURE__ */ Symbol("honoContext");
9
+ var buildNodeRequest = (c) => {
10
+ const raw = c.req.raw;
11
+ const url = new URL(raw.url);
12
+ const query = {};
13
+ for (const key of url.searchParams.keys()) {
14
+ if (key in query) continue;
15
+ const values = url.searchParams.getAll(key);
16
+ query[key] = values.length > 1 ? values : values[0];
17
+ }
18
+ const headers = {};
19
+ raw.headers.forEach((value, key) => {
20
+ headers[key] = value;
21
+ });
22
+ const stream$1 = raw.body ? stream.Readable.fromWeb(raw.body) : new stream.Readable({ read() {
23
+ this.push(null);
24
+ } });
25
+ return Object.assign(stream$1, { method: raw.method, url: url.pathname + url.search, headers, query, [HONO_CONTEXT]: c });
26
+ };
27
+ var buildNodeResponse = () => {
28
+ const state = { statusCode: 200, headers: new Headers(), body: null, ended: false };
29
+ const res = {
30
+ get statusCode() {
31
+ return state.statusCode;
32
+ },
33
+ set statusCode(code) {
34
+ state.statusCode = code;
35
+ },
36
+ status(code) {
37
+ state.statusCode = code;
38
+ return res;
39
+ },
40
+ setHeader(name, value) {
41
+ state.headers.set(name, Array.isArray(value) ? value.join(", ") : String(value));
42
+ return res;
43
+ },
44
+ json(payload) {
45
+ if (!state.headers.has("content-type")) state.headers.set("content-type", "application/json; charset=utf-8");
46
+ state.body = JSON.stringify(payload);
47
+ state.ended = true;
48
+ },
49
+ send(payload) {
50
+ state.body = payload ?? null;
51
+ state.ended = true;
52
+ },
53
+ end(payload) {
54
+ if (payload !== void 0) state.body = payload;
55
+ state.ended = true;
56
+ }
57
+ };
58
+ return { res, toResponse: () => new Response(state.ended ? state.body : null, { status: state.statusCode, headers: state.headers }) };
59
+ };
60
+ var driveAPIHandlerHono = async (c) => {
61
+ const req = buildNodeRequest(c);
62
+ const { res, toResponse } = buildNodeResponse();
63
+ await chunkWUG4ATLH_cjs.driveAPIHandler(req, res);
64
+ return toResponse();
65
+ };
66
+ var driveConfigurationHono = (config) => {
67
+ const userInformation = config.information;
68
+ const information = userInformation ? async (input) => {
69
+ if (input.method === "KEY") return userInformation(input);
70
+ const honoContext = input.req[HONO_CONTEXT];
71
+ return userInformation({ method: "REQUEST", req: honoContext });
72
+ } : void 0;
73
+ return chunkHWNIRA6Y_cjs.driveConfiguration({ ...config, information });
74
+ };
10
75
 
11
76
  Object.defineProperty(exports, "driveFileSchemaZod", {
12
77
  enumerable: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server/hono.ts"],"names":["driveAPIHandler","driveConfiguration"],"mappings":";;;;;;;AASO,IAAM,mBAAA,GAAsBA;AAI5B,IAAM,sBAAA,GAAyBC","file":"hono.cjs","sourcesContent":["// ** Hono Adapter for next-drive\n// ** Provides Hono-compatible types for the drive API handler and configuration\nimport type { Context } from 'hono';\nimport type { TDriveConfigurationHono } from '@/types/server/hono';\n\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\n\n// ** Hono API Handler\n// ** Type-cast wrapper that allows Hono Context to be used with the core handler\nexport const driveAPIHandlerHono = driveAPIHandler as unknown as (c: Context) => Promise<void>;\n\n// ** Hono Configuration\n// ** Type-cast wrapper that accepts Hono Context in the information callback\nexport const driveConfigurationHono = driveConfiguration as unknown as (config: TDriveConfigurationHono) => Promise<TDriveConfigurationHono>;\n\n// ** Re-export utilities that work with any framework\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\nexport { getDriveConfig } from '@/server/config';\n\n// ** Re-export types\nexport type { TDriveConfigurationHono, TDriveConfigInformation } from '@/types/server/hono';\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\n"]}
1
+ {"version":3,"sources":["../../src/server/hono.ts"],"names":["stream","Readable","driveAPIHandler","driveConfiguration"],"mappings":";;;;;;;AAgBA,IAAM,YAAA,0BAAsB,aAAa,CAAA;AAQzC,IAAM,gBAAA,GAAmB,CAAC,CAAA,KAAwC;AAC9D,EAAA,MAAM,GAAA,GAAM,EAAE,GAAA,CAAI,GAAA;AAClB,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA;AAE3B,EAAA,MAAM,QAA2C,EAAC;AAClD,EAAA,KAAA,MAAW,GAAA,IAAO,GAAA,CAAI,YAAA,CAAa,IAAA,EAAK,EAAG;AACvC,IAAA,IAAI,OAAO,KAAA,EAAO;AAClB,IAAA,MAAM,MAAA,GAAS,GAAA,CAAI,YAAA,CAAa,MAAA,CAAO,GAAG,CAAA;AAC1C,IAAA,KAAA,CAAM,GAAG,CAAA,GAAI,MAAA,CAAO,SAAS,CAAA,GAAI,MAAA,GAAS,OAAO,CAAC,CAAA;AAAA,EACtD;AAEA,EAAA,MAAM,UAAkC,EAAC;AACzC,EAAA,GAAA,CAAI,OAAA,CAAQ,OAAA,CAAQ,CAAC,KAAA,EAAO,GAAA,KAAQ;AAAE,IAAA,OAAA,CAAQ,GAAG,CAAA,GAAI,KAAA;AAAA,EAAO,CAAC,CAAA;AAE7D,EAAA,MAAMA,QAAA,GAAS,GAAA,CAAI,IAAA,GACZC,eAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,IAAsD,CAAA,GAC5E,IAAIA,eAAA,CAAS,EAAE,IAAA,GAAO;AAAE,IAAA,IAAA,CAAK,KAAK,IAAI,CAAA;AAAA,EAAG,GAAG,CA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ACA,MAAA;AAEN,EAAA,OAAOC,oCAAA,CAAmB,EAAE,GAAG,MAAA,EAAQ,aAAoE,CAAA;AAC/G","file":"hono.cjs","sourcesContent":["// ** Hono Adapter for next-drive\n// ** Hono's `Context` is fetch-based (web `Request`/`Response`), while the core handler is written\n// ** against the Node `(req, res)` style (`NextApiRequest`/`NextApiResponse`) shared with the Next.js\n// ** and Express adapters. This bridges the two: builds a Node-shaped request/response from the\n// ** `Context`, runs it through the core handler, and returns a web `Response` for Hono to send.\nimport { Readable } from 'stream';\nimport type { Context } from 'hono';\nimport type { NextApiRequest, NextApiResponse } from 'next';\nimport type { TDriveConfigurationHono, TDriveConfigInformation } from '@/types/server/hono';\nimport type { TDriveInformationInput } from '@/types/server/config';\n\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\n\n// ** Marker used to stash the original Hono `Context` on the synthetic Node-style request built below,\n// ** so `driveConfigurationHono`'s `information` callback can hand the user back a real `Context`\n// ** (matching `TDriveConfigurationHono`'s declared type) instead of the internal Node-shaped stand-in.\nconst HONO_CONTEXT = Symbol('honoContext');\ntype TNodeRequestWithContext = NextApiRequest & { [HONO_CONTEXT]?: Context };\n\n// ** Builds a Node-`NextApiRequest`-shaped object - a real `Readable` instance carrying `.method`,\n// ** `.url`, `.headers` and `.query` - from a Hono `Context`'s underlying web `Request`. Being a real\n// ** `Readable` (rather than a plain object) matters for `?action=upload`: `handleUpload`\n// ** (src/server/tus.ts) calls `Readable.toWeb(req)` on whatever is passed as `req`, which requires an\n// ** actual stream instance.\nconst buildNodeRequest = (c: Context): TNodeRequestWithContext => {\n const raw = c.req.raw;\n const url = new URL(raw.url);\n\n const query: Record<string, string | string[]> = {};\n for (const key of url.searchParams.keys()) {\n if (key in query) continue;\n const values = url.searchParams.getAll(key);\n query[key] = values.length > 1 ? values : values[0];\n }\n\n const headers: Record<string, string> = {};\n raw.headers.forEach((value, key) => { headers[key] = value; });\n\n const stream = raw.body\n ? (Readable.fromWeb(raw.body as unknown as import('stream/web').ReadableStream) as unknown as Readable)\n : new Readable({ read() { this.push(null); } });\n\n return Object.assign(stream, { method: raw.method, url: url.pathname + url.search, headers, query, [HONO_CONTEXT]: c }) as unknown as TNodeRequestWithContext;\n};\n\n// ** Minimal Node-`ServerResponse`-shaped object that buffers status/headers/body (everything the core\n// ** handler, `applyCorsHeaders` and `handleUpload` call: `.status().json()`, `.setHeader()`, `.send()`,\n// ** `.end()`, and direct `.statusCode =` assignment) so it can be translated into a web `Response`.\nconst buildNodeResponse = (): { res: NextApiResponse; toResponse: () => Response } => {\n const state: { statusCode: number; headers: Headers; body: BodyInit | null; ended: boolean } = { statusCode: 200, headers: new Headers(), body: null, ended: false };\n\n const res = {\n get statusCode() { return state.statusCode; },\n set statusCode(code: number) { state.statusCode = code; },\n status(code: number) { state.statusCode = code; return res; },\n setHeader(name: string, value: string | number | readonly string[]) {\n state.headers.set(name, Array.isArray(value) ? value.join(', ') : String(value));\n return res;\n },\n json(payload: unknown) {\n if (!state.headers.has('content-type')) state.headers.set('content-type', 'application/json; charset=utf-8');\n state.body = JSON.stringify(payload);\n state.ended = true;\n },\n send(payload: unknown) {\n state.body = (payload ?? null) as BodyInit | null;\n state.ended = true;\n },\n end(payload?: unknown) {\n if (payload !== undefined) state.body = payload as BodyInit;\n state.ended = true;\n },\n };\n\n return { res: res as unknown as NextApiResponse, toResponse: () => new Response(state.ended ? state.body : null, { status: state.statusCode, headers: state.headers }) };\n};\n\n// ** Hono API Handler\n// ** Bridges a Hono `Context` into the core Node-style handler and returns a web `Response` - wire it\n// ** up as e.g. `app.all('/api/drive', (c) => driveAPIHandlerHono(c))`.\nexport const driveAPIHandlerHono = async (c: Context): Promise<Response> => {\n const req = buildNodeRequest(c);\n const { res, toResponse } = buildNodeResponse();\n await driveAPIHandler(req, res);\n return toResponse();\n};\n\n// ** Hono Configuration\n// ** Wraps the user's `information` callback so it receives the original Hono `Context` (matching\n// ** `TDriveConfigurationHono`'s declared type) instead of the internal Node-shaped request built above.\nexport const driveConfigurationHono = (config: TDriveConfigurationHono): Promise<TDriveConfigurationHono> => {\n const userInformation = config.information;\n\n const information = userInformation\n ? async (input: TDriveInformationInput): Promise<TDriveConfigInformation> => {\n if (input.method === 'KEY') return userInformation(input);\n const honoContext = (input.req as TNodeRequestWithContext)[HONO_CONTEXT] as Context;\n return userInformation({ method: 'REQUEST', req: honoContext });\n }\n : undefined;\n\n return driveConfiguration({ ...config, information } as unknown as Parameters<typeof driveConfiguration>[0]) as unknown as Promise<TDriveConfigurationHono>;\n};\n\n// ** Re-export utilities that work with any framework\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\nexport { getDriveConfig } from '@/server/config';\n\n// ** Re-export types\nexport type { TDriveConfigurationHono, TDriveConfigInformation } from '@/types/server/hono';\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { Context } from 'hono';
2
2
  import type { TDriveConfigurationHono } from '../types/server/hono';
3
- export declare const driveAPIHandlerHono: (c: Context) => Promise<void>;
3
+ export declare const driveAPIHandlerHono: (c: Context) => Promise<Response>;
4
4
  export declare const driveConfigurationHono: (config: TDriveConfigurationHono) => Promise<TDriveConfigurationHono>;
5
5
  export { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '../server/controllers/drive';
6
6
  export { driveFileSchemaZod } from '../server/zod/schemas';
@@ -1 +1 @@
1
- {"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../src/server/hono.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAMnE,eAAO,MAAM,mBAAmB,EAAiC,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAI/F,eAAO,MAAM,sBAAsB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
  import { driveConfiguration } from '../chunk-IWV6G7HQ.js';
5
5
  export { driveDelete, driveFilePath, driveGetUrl, driveList, driveReadFile, driveUpload, getDriveConfig } from '../chunk-IWV6G7HQ.js';
6
+ import { Readable } from 'stream';
6
7
 
7
- // src/server/hono.ts
8
- var driveAPIHandlerHono = driveAPIHandler;
9
- var driveConfigurationHono = driveConfiguration;
8
+ var HONO_CONTEXT = /* @__PURE__ */ Symbol("honoContext");
9
+ var buildNodeRequest = (c) => {
10
+ const raw = c.req.raw;
11
+ const url = new URL(raw.url);
12
+ const query = {};
13
+ for (const key of url.searchParams.keys()) {
14
+ if (key in query) continue;
15
+ const values = url.searchParams.getAll(key);
16
+ query[key] = values.length > 1 ? values : values[0];
17
+ }
18
+ const headers = {};
19
+ raw.headers.forEach((value, key) => {
20
+ headers[key] = value;
21
+ });
22
+ const stream = raw.body ? Readable.fromWeb(raw.body) : new Readable({ read() {
23
+ this.push(null);
24
+ } });
25
+ return Object.assign(stream, { method: raw.method, url: url.pathname + url.search, headers, query, [HONO_CONTEXT]: c });
26
+ };
27
+ var buildNodeResponse = () => {
28
+ const state = { statusCode: 200, headers: new Headers(), body: null, ended: false };
29
+ const res = {
30
+ get statusCode() {
31
+ return state.statusCode;
32
+ },
33
+ set statusCode(code) {
34
+ state.statusCode = code;
35
+ },
36
+ status(code) {
37
+ state.statusCode = code;
38
+ return res;
39
+ },
40
+ setHeader(name, value) {
41
+ state.headers.set(name, Array.isArray(value) ? value.join(", ") : String(value));
42
+ return res;
43
+ },
44
+ json(payload) {
45
+ if (!state.headers.has("content-type")) state.headers.set("content-type", "application/json; charset=utf-8");
46
+ state.body = JSON.stringify(payload);
47
+ state.ended = true;
48
+ },
49
+ send(payload) {
50
+ state.body = payload ?? null;
51
+ state.ended = true;
52
+ },
53
+ end(payload) {
54
+ if (payload !== void 0) state.body = payload;
55
+ state.ended = true;
56
+ }
57
+ };
58
+ return { res, toResponse: () => new Response(state.ended ? state.body : null, { status: state.statusCode, headers: state.headers }) };
59
+ };
60
+ var driveAPIHandlerHono = async (c) => {
61
+ const req = buildNodeRequest(c);
62
+ const { res, toResponse } = buildNodeResponse();
63
+ await driveAPIHandler(req, res);
64
+ return toResponse();
65
+ };
66
+ var driveConfigurationHono = (config) => {
67
+ const userInformation = config.information;
68
+ const information = userInformation ? async (input) => {
69
+ if (input.method === "KEY") return userInformation(input);
70
+ const honoContext = input.req[HONO_CONTEXT];
71
+ return userInformation({ method: "REQUEST", req: honoContext });
72
+ } : void 0;
73
+ return driveConfiguration({ ...config, information });
74
+ };
10
75
 
11
76
  export { driveAPIHandlerHono, driveConfigurationHono };
12
77
  //# sourceMappingURL=hono.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server/hono.ts"],"names":[],"mappings":";;;;;;;AASO,IAAM,mBAAA,GAAsB;AAI5B,IAAM,sBAAA,GAAyB","file":"hono.js","sourcesContent":["// ** Hono Adapter for next-drive\n// ** Provides Hono-compatible types for the drive API handler and configuration\nimport type { Context } from 'hono';\nimport type { TDriveConfigurationHono } from '@/types/server/hono';\n\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\n\n// ** Hono API Handler\n// ** Type-cast wrapper that allows Hono Context to be used with the core handler\nexport const driveAPIHandlerHono = driveAPIHandler as unknown as (c: Context) => Promise<void>;\n\n// ** Hono Configuration\n// ** Type-cast wrapper that accepts Hono Context in the information callback\nexport const driveConfigurationHono = driveConfiguration as unknown as (config: TDriveConfigurationHono) => Promise<TDriveConfigurationHono>;\n\n// ** Re-export utilities that work with any framework\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\nexport { getDriveConfig } from '@/server/config';\n\n// ** Re-export types\nexport type { TDriveConfigurationHono, TDriveConfigInformation } from '@/types/server/hono';\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\n"]}
1
+ {"version":3,"sources":["../../src/server/hono.ts"],"names":[],"mappings":";;;;;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AA,GAAO,OAAA;AACxC,MAAA,KAAA,CAAM,KAAA,GAAQ,IAAA;AAAA,IAClB;AAAA,GACJ;AAEA,EAAA,OAAO,EAAE,GAAA,EAAwC,UAAA,EAAY,MAAM,IAAI,QAAA,CAAS,MAAM,KAAA,GAAQ,KAAA,CAAM,OAAO,IAAA,EAAM,EAAE,QAAQ,KAAA,CAAM,UAAA,EAAY,SAAS,KAAA,CAAM,OAAA,EAAS,CAAA,EAAE;AAC3K,CAAA;AAKO,IAAM,mBAAA,GAAsB,OAAO,CAAA,KAAkC;AACxE,EAAA,MAAM,GAAA,GAAM,iBAAiB,CAAC,CAAA;AAC9B,EAAA,MAAM,EAAE,GAAA,EAAK,UAAA,EAAW,GAAI,iBAAA,EAAkB;AAC9C,EAAA,MAAM,eAAA,CAAgB,KAAK,GAAG,CAAA;AAC9B,EAAA,OAAO,UAAA,EAAW;AACtB;AAKO,IAAM,sBAAA,GAAyB,CAAC,MAAA,KAAsE;AACzG,EAAA,MAAM,kBAAkB,MAAA,CAAO,WAAA;AAE/B,EAAA,MAAM,WAAA,GAAc,eAAA,GACd,OAAO,KAAA,KAAoE;AACvE,IAAA,IAAI,KAAA,CAAM,MAAA,KAAW,KAAA,EAAO,OAAO,gBAAgB,KAAK,CAAA;AACxD,IAAA,MAAM,WAAA,GAAe,KAAA,CAAM,GAAA,CAAgC,YAAY,CAAA;AACvE,IAAA,OAAO,gBAAgB,EAAE,MAAA,EAAQ,SAAA,EAAW,GAAA,EAAK,aAAa,CAAA;AAAA,EAClE,CAAA,GACA,MAAA;AAEN,EAAA,OAAO,kBAAA,CAAmB,EAAE,GAAG,MAAA,EAAQ,aAAoE,CAAA;AAC/G","file":"hono.js","sourcesContent":["// ** Hono Adapter for next-drive\n// ** Hono's `Context` is fetch-based (web `Request`/`Response`), while the core handler is written\n// ** against the Node `(req, res)` style (`NextApiRequest`/`NextApiResponse`) shared with the Next.js\n// ** and Express adapters. This bridges the two: builds a Node-shaped request/response from the\n// ** `Context`, runs it through the core handler, and returns a web `Response` for Hono to send.\nimport { Readable } from 'stream';\nimport type { Context } from 'hono';\nimport type { NextApiRequest, NextApiResponse } from 'next';\nimport type { TDriveConfigurationHono, TDriveConfigInformation } from '@/types/server/hono';\nimport type { TDriveInformationInput } from '@/types/server/config';\n\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\n\n// ** Marker used to stash the original Hono `Context` on the synthetic Node-style request built below,\n// ** so `driveConfigurationHono`'s `information` callback can hand the user back a real `Context`\n// ** (matching `TDriveConfigurationHono`'s declared type) instead of the internal Node-shaped stand-in.\nconst HONO_CONTEXT = Symbol('honoContext');\ntype TNodeRequestWithContext = NextApiRequest & { [HONO_CONTEXT]?: Context };\n\n// ** Builds a Node-`NextApiRequest`-shaped object - a real `Readable` instance carrying `.method`,\n// ** `.url`, `.headers` and `.query` - from a Hono `Context`'s underlying web `Request`. Being a real\n// ** `Readable` (rather than a plain object) matters for `?action=upload`: `handleUpload`\n// ** (src/server/tus.ts) calls `Readable.toWeb(req)` on whatever is passed as `req`, which requires an\n// ** actual stream instance.\nconst buildNodeRequest = (c: Context): TNodeRequestWithContext => {\n const raw = c.req.raw;\n const url = new URL(raw.url);\n\n const query: Record<string, string | string[]> = {};\n for (const key of url.searchParams.keys()) {\n if (key in query) continue;\n const values = url.searchParams.getAll(key);\n query[key] = values.length > 1 ? values : values[0];\n }\n\n const headers: Record<string, string> = {};\n raw.headers.forEach((value, key) => { headers[key] = value; });\n\n const stream = raw.body\n ? (Readable.fromWeb(raw.body as unknown as import('stream/web').ReadableStream) as unknown as Readable)\n : new Readable({ read() { this.push(null); } });\n\n return Object.assign(stream, { method: raw.method, url: url.pathname + url.search, headers, query, [HONO_CONTEXT]: c }) as unknown as TNodeRequestWithContext;\n};\n\n// ** Minimal Node-`ServerResponse`-shaped object that buffers status/headers/body (everything the core\n// ** handler, `applyCorsHeaders` and `handleUpload` call: `.status().json()`, `.setHeader()`, `.send()`,\n// ** `.end()`, and direct `.statusCode =` assignment) so it can be translated into a web `Response`.\nconst buildNodeResponse = (): { res: NextApiResponse; toResponse: () => Response } => {\n const state: { statusCode: number; headers: Headers; body: BodyInit | null; ended: boolean } = { statusCode: 200, headers: new Headers(), body: null, ended: false };\n\n const res = {\n get statusCode() { return state.statusCode; },\n set statusCode(code: number) { state.statusCode = code; },\n status(code: number) { state.statusCode = code; return res; },\n setHeader(name: string, value: string | number | readonly string[]) {\n state.headers.set(name, Array.isArray(value) ? value.join(', ') : String(value));\n return res;\n },\n json(payload: unknown) {\n if (!state.headers.has('content-type')) state.headers.set('content-type', 'application/json; charset=utf-8');\n state.body = JSON.stringify(payload);\n state.ended = true;\n },\n send(payload: unknown) {\n state.body = (payload ?? null) as BodyInit | null;\n state.ended = true;\n },\n end(payload?: unknown) {\n if (payload !== undefined) state.body = payload as BodyInit;\n state.ended = true;\n },\n };\n\n return { res: res as unknown as NextApiResponse, toResponse: () => new Response(state.ended ? state.body : null, { status: state.statusCode, headers: state.headers }) };\n};\n\n// ** Hono API Handler\n// ** Bridges a Hono `Context` into the core Node-style handler and returns a web `Response` - wire it\n// ** up as e.g. `app.all('/api/drive', (c) => driveAPIHandlerHono(c))`.\nexport const driveAPIHandlerHono = async (c: Context): Promise<Response> => {\n const req = buildNodeRequest(c);\n const { res, toResponse } = buildNodeResponse();\n await driveAPIHandler(req, res);\n return toResponse();\n};\n\n// ** Hono Configuration\n// ** Wraps the user's `information` callback so it receives the original Hono `Context` (matching\n// ** `TDriveConfigurationHono`'s declared type) instead of the internal Node-shaped request built above.\nexport const driveConfigurationHono = (config: TDriveConfigurationHono): Promise<TDriveConfigurationHono> => {\n const userInformation = config.information;\n\n const information = userInformation\n ? async (input: TDriveInformationInput): Promise<TDriveConfigInformation> => {\n if (input.method === 'KEY') return userInformation(input);\n const honoContext = (input.req as TNodeRequestWithContext)[HONO_CONTEXT] as Context;\n return userInformation({ method: 'REQUEST', req: honoContext });\n }\n : undefined;\n\n return driveConfiguration({ ...config, information } as unknown as Parameters<typeof driveConfiguration>[0]) as unknown as Promise<TDriveConfigurationHono>;\n};\n\n// ** Re-export utilities that work with any framework\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\nexport { getDriveConfig } from '@/server/config';\n\n// ** Re-export types\nexport type { TDriveConfigurationHono, TDriveConfigInformation } from '@/types/server/hono';\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muhgholy/next-drive",
3
- "version": "4.23.32",
3
+ "version": "4.23.33",
4
4
  "description": "File storage and management for Next.js applications",
5
5
  "type": "module",
6
6
  "exports": {