@muhgholy/next-drive 4.23.32 → 4.23.34

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 (44) hide show
  1. package/README.md +79 -3
  2. package/dist/{chunk-HWNIRA6Y.cjs → chunk-DHIHCER6.cjs} +220 -71
  3. package/dist/chunk-DHIHCER6.cjs.map +1 -0
  4. package/dist/{chunk-2DCZENJ2.js → chunk-E72MTT6W.js} +3 -3
  5. package/dist/{chunk-2DCZENJ2.js.map → chunk-E72MTT6W.js.map} +1 -1
  6. package/dist/{chunk-WUG4ATLH.cjs → chunk-PKNXKHGS.cjs} +37 -37
  7. package/dist/{chunk-WUG4ATLH.cjs.map → chunk-PKNXKHGS.cjs.map} +1 -1
  8. package/dist/{chunk-IWV6G7HQ.js → chunk-QMPV4YSZ.js} +221 -73
  9. package/dist/chunk-QMPV4YSZ.js.map +1 -0
  10. package/dist/server/controllers/drive.d.ts +33 -2
  11. package/dist/server/controllers/drive.d.ts.map +1 -1
  12. package/dist/server/errors.d.ts +12 -0
  13. package/dist/server/errors.d.ts.map +1 -0
  14. package/dist/server/express.cjs +16 -12
  15. package/dist/server/express.cjs.map +1 -1
  16. package/dist/server/express.d.ts +3 -0
  17. package/dist/server/express.d.ts.map +1 -1
  18. package/dist/server/express.js +4 -4
  19. package/dist/server/express.js.map +1 -1
  20. package/dist/server/hono.cjs +82 -13
  21. package/dist/server/hono.cjs.map +1 -1
  22. package/dist/server/hono.d.ts +4 -1
  23. package/dist/server/hono.d.ts.map +1 -1
  24. package/dist/server/hono.js +72 -7
  25. package/dist/server/hono.js.map +1 -1
  26. package/dist/server/index.cjs +23 -19
  27. package/dist/server/index.d.ts +3 -0
  28. package/dist/server/index.d.ts.map +1 -1
  29. package/dist/server/index.js +2 -2
  30. package/dist/server/storage-adapters/google.d.ts.map +1 -1
  31. package/dist/server/tus.d.ts.map +1 -1
  32. package/dist/tus-EQ2IXSRE.cjs +20 -0
  33. package/dist/tus-EQ2IXSRE.cjs.map +1 -0
  34. package/dist/tus-ODCMFEBZ.js +3 -0
  35. package/dist/tus-ODCMFEBZ.js.map +1 -0
  36. package/dist/types/server/storage.d.ts +4 -1
  37. package/dist/types/server/storage.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-HWNIRA6Y.cjs.map +0 -1
  40. package/dist/chunk-IWV6G7HQ.js.map +0 -1
  41. package/dist/tus-5LLFMVQK.cjs +0 -20
  42. package/dist/tus-5LLFMVQK.cjs.map +0 -1
  43. package/dist/tus-C4T5ZDTG.js +0 -3
  44. package/dist/tus-C4T5ZDTG.js.map +0 -1
@@ -14,6 +14,10 @@ export declare const driveAddSignedUrlTokens: (items: TDatabaseDrive[], config:
14
14
  /**
15
15
  * Read a file and return a readable stream.
16
16
  * @param file - Either a file ID (string) or a TDatabaseDrive/IDatabaseDriveDocument object
17
+ * @param options - Optional progress/abort controls. `onProgress` fires for bytes piped through the
18
+ * returned stream (works uniformly for local files and Google Drive files, cache-hit or cache-miss
19
+ * alike). `signal` abort destroys the returned stream mid-read - the caller observes this as an
20
+ * `'error'` event on the stream carrying a `DriveError` with `code: 'ABORTED'`.
17
21
  * @returns Promise with readable stream, mime type, and file size
18
22
  * @example
19
23
  * ```typescript
@@ -24,9 +28,20 @@ export declare const driveAddSignedUrlTokens: (items: TDatabaseDrive[], config:
24
28
  * // Using database document
25
29
  * const drive = await Drive.findById(fileId);
26
30
  * const { stream, mime, size } = await driveReadFile(drive);
31
+ *
32
+ * // With progress and abort
33
+ * const controller = new AbortController();
34
+ * const { stream } = await driveReadFile(fileId, {
35
+ * onProgress: ({ percentage }) => console.log(`${percentage}%`),
36
+ * signal: controller.signal,
37
+ * });
38
+ * stream.on('error', (err) => { if (err instanceof DriveError && err.code === 'ABORTED') { ... } });
27
39
  * ```
28
40
  */
29
- export declare const driveReadFile: (file: string | IDatabaseDriveDocument | TDatabaseDrive) => Promise<{
41
+ export declare const driveReadFile: (file: string | IDatabaseDriveDocument | TDatabaseDrive, options?: {
42
+ onProgress?: (info: TDriveTransferProgress) => void;
43
+ signal?: AbortSignal;
44
+ }) => Promise<{
30
45
  stream: Readable;
31
46
  mime: string;
32
47
  size: number;
@@ -47,9 +62,15 @@ export declare const driveReadFile: (file: string | IDatabaseDriveDocument | TDa
47
62
  * ```
48
63
  */
49
64
  export declare const driveInfo: (source: string | TDriveFile) => Promise<import("../../types/client").TDriveInformation>;
65
+ export type TDriveTransferProgress = {
66
+ bytesDownloaded: number;
67
+ totalBytes: number;
68
+ percentage: number;
69
+ };
50
70
  /**
51
71
  * Get the local file system path for a file. For Google Drive files, downloads them to a local cache first.
52
72
  * @param file - Either a file ID (string) or a TDatabaseDrive/IDatabaseDriveDocument object
73
+ * @param options - Optional progress/abort controls, only relevant for a Google Drive cache-miss download
53
74
  * @returns Promise with readonly object containing the absolute file path and metadata
54
75
  * @example
55
76
  * ```typescript
@@ -61,9 +82,19 @@ export declare const driveInfo: (source: string | TDriveFile) => Promise<import(
61
82
  * const drive = await Drive.findById(fileId);
62
83
  * const { path, name, provider } = await driveFilePath(drive);
63
84
  * await processFile(path);
85
+ *
86
+ * // With progress and abort (only fires for an actual Google Drive cache-miss download)
87
+ * const controller = new AbortController();
88
+ * const result = await driveFilePath(fileId, {
89
+ * onProgress: ({ bytesDownloaded, totalBytes, percentage }) => console.log(`${percentage}%`),
90
+ * signal: controller.signal,
91
+ * });
64
92
  * ```
65
93
  */
66
- export declare const driveFilePath: (file: string | IDatabaseDriveDocument | TDatabaseDrive) => Promise<Readonly<{
94
+ export declare const driveFilePath: (file: string | IDatabaseDriveDocument | TDatabaseDrive, options?: {
95
+ onProgress?: (info: TDriveTransferProgress) => void;
96
+ signal?: AbortSignal;
97
+ }) => Promise<Readonly<{
67
98
  path: string;
68
99
  name: string;
69
100
  mime: string;
@@ -1 +1 @@
1
- {"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/server/controllers/drive.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,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drive server package. Every error thrown directly by
3
+ * `src/server/controllers/drive.ts` uses this class so callers can distinguish failure reasons
4
+ * programmatically (e.g. `err instanceof DriveError && err.code === 'NOT_FOUND'`) instead of
5
+ * matching on message text.
6
+ */
7
+ export type TDriveErrorCode = 'NOT_FOUND' | 'INVALID_REFERENCE' | 'INVALID_TYPE' | 'FILE_MISSING' | 'UNSUPPORTED_PROVIDER' | 'ACCESS_DENIED' | 'FOLDER_NOT_EMPTY' | 'INVALID_PATH' | 'INVALID_MIME_TYPE' | 'FILE_TOO_LARGE' | 'QUOTA_EXCEEDED' | 'MAX_DEPTH_EXCEEDED' | 'ABORTED' | 'DOWNLOAD_FAILED';
8
+ export declare class DriveError extends Error {
9
+ readonly code: TDriveErrorCode;
10
+ constructor(code: TDriveErrorCode, message: string);
11
+ }
12
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/server/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GACrB,WAAW,GACX,mBAAmB,GACnB,cAAc,GACd,cAAc,GACd,sBAAsB,GACtB,eAAe,GACf,kBAAkB,GAClB,cAAc,GACd,mBAAmB,GACnB,gBAAgB,GAChB,gBAAgB,GAChB,oBAAoB,GACpB,SAAS,GACT,iBAAiB,CAAC;AAExB,qBAAa,UAAW,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;gBAEnB,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;CAKrD"}
@@ -1,44 +1,48 @@
1
1
  'use strict';
2
2
 
3
- var chunkWUG4ATLH_cjs = require('../chunk-WUG4ATLH.cjs');
3
+ var chunkPKNXKHGS_cjs = require('../chunk-PKNXKHGS.cjs');
4
4
  require('../chunk-HQTC3554.cjs');
5
- var chunkHWNIRA6Y_cjs = require('../chunk-HWNIRA6Y.cjs');
5
+ var chunkDHIHCER6_cjs = require('../chunk-DHIHCER6.cjs');
6
6
 
7
7
  // src/server/express.ts
8
- var driveAPIHandlerExpress = chunkWUG4ATLH_cjs.driveAPIHandler;
9
- var driveConfigurationExpress = chunkHWNIRA6Y_cjs.driveConfiguration;
8
+ var driveAPIHandlerExpress = chunkPKNXKHGS_cjs.driveAPIHandler;
9
+ var driveConfigurationExpress = chunkDHIHCER6_cjs.driveConfiguration;
10
10
 
11
11
  Object.defineProperty(exports, "driveFileSchemaZod", {
12
12
  enumerable: true,
13
- get: function () { return chunkWUG4ATLH_cjs.driveFileSchemaZod; }
13
+ get: function () { return chunkPKNXKHGS_cjs.driveFileSchemaZod; }
14
+ });
15
+ Object.defineProperty(exports, "DriveError", {
16
+ enumerable: true,
17
+ get: function () { return chunkDHIHCER6_cjs.DriveError; }
14
18
  });
15
19
  Object.defineProperty(exports, "driveDelete", {
16
20
  enumerable: true,
17
- get: function () { return chunkHWNIRA6Y_cjs.driveDelete; }
21
+ get: function () { return chunkDHIHCER6_cjs.driveDelete; }
18
22
  });
19
23
  Object.defineProperty(exports, "driveFilePath", {
20
24
  enumerable: true,
21
- get: function () { return chunkHWNIRA6Y_cjs.driveFilePath; }
25
+ get: function () { return chunkDHIHCER6_cjs.driveFilePath; }
22
26
  });
23
27
  Object.defineProperty(exports, "driveGetUrl", {
24
28
  enumerable: true,
25
- get: function () { return chunkHWNIRA6Y_cjs.driveGetUrl; }
29
+ get: function () { return chunkDHIHCER6_cjs.driveGetUrl; }
26
30
  });
27
31
  Object.defineProperty(exports, "driveList", {
28
32
  enumerable: true,
29
- get: function () { return chunkHWNIRA6Y_cjs.driveList; }
33
+ get: function () { return chunkDHIHCER6_cjs.driveList; }
30
34
  });
31
35
  Object.defineProperty(exports, "driveReadFile", {
32
36
  enumerable: true,
33
- get: function () { return chunkHWNIRA6Y_cjs.driveReadFile; }
37
+ get: function () { return chunkDHIHCER6_cjs.driveReadFile; }
34
38
  });
35
39
  Object.defineProperty(exports, "driveUpload", {
36
40
  enumerable: true,
37
- get: function () { return chunkHWNIRA6Y_cjs.driveUpload; }
41
+ get: function () { return chunkDHIHCER6_cjs.driveUpload; }
38
42
  });
39
43
  Object.defineProperty(exports, "getDriveConfig", {
40
44
  enumerable: true,
41
- get: function () { return chunkHWNIRA6Y_cjs.getDriveConfig; }
45
+ get: function () { return chunkDHIHCER6_cjs.getDriveConfig; }
42
46
  });
43
47
  exports.driveAPIHandlerExpress = driveAPIHandlerExpress;
44
48
  exports.driveConfigurationExpress = driveConfigurationExpress;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server/express.ts"],"names":["driveAPIHandler","driveConfiguration"],"mappings":";;;;;;;AASO,IAAM,sBAAA,GAAyBA;AAI/B,IAAM,yBAAA,GAA4BC","file":"express.cjs","sourcesContent":["// ** Express Adapter for next-drive\r\n// ** Provides Express-compatible types for the drive API handler and configuration\r\nimport type { Request, Response } from 'express';\r\nimport type { TDriveConfigurationExpress } from '@/types/server/express';\r\n\r\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\r\n\r\n// ** Express API Handler\r\n// ** Type-cast wrapper that allows Express Request/Response to be used with the core handler\r\nexport const driveAPIHandlerExpress = driveAPIHandler as unknown as (req: Request, res: Response) => Promise<void>;\r\n\r\n// ** Express Configuration\r\n// ** Type-cast wrapper that accepts Express Request in the information callback\r\nexport const driveConfigurationExpress = driveConfiguration as unknown as (config: TDriveConfigurationExpress) => Promise<TDriveConfigurationExpress>;\r\n\r\n// ** Re-export utilities that work with any framework\r\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\r\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\r\nexport { getDriveConfig } from '@/server/config';\r\n\r\n// ** Re-export types\r\nexport type { TDriveConfigurationExpress, TDriveConfigInformation } from '@/types/server/express';\r\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\r\n"]}
1
+ {"version":3,"sources":["../../src/server/express.ts"],"names":["driveAPIHandler","driveConfiguration"],"mappings":";;;;;;;AASO,IAAM,sBAAA,GAAyBA;AAI/B,IAAM,yBAAA,GAA4BC","file":"express.cjs","sourcesContent":["// ** Express Adapter for next-drive\r\n// ** Provides Express-compatible types for the drive API handler and configuration\r\nimport type { Request, Response } from 'express';\r\nimport type { TDriveConfigurationExpress } from '@/types/server/express';\r\n\r\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\r\n\r\n// ** Express API Handler\r\n// ** Type-cast wrapper that allows Express Request/Response to be used with the core handler\r\nexport const driveAPIHandlerExpress = driveAPIHandler as unknown as (req: Request, res: Response) => Promise<void>;\r\n\r\n// ** Express Configuration\r\n// ** Type-cast wrapper that accepts Express Request in the information callback\r\nexport const driveConfigurationExpress = driveConfiguration as unknown as (config: TDriveConfigurationExpress) => Promise<TDriveConfigurationExpress>;\r\n\r\n// ** Re-export utilities that work with any framework\r\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\r\nexport type { TDriveTransferProgress } from '@/server/controllers/drive';\r\nexport { DriveError } from '@/server/errors';\r\nexport type { TDriveErrorCode } from '@/server/errors';\r\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\r\nexport { getDriveConfig } from '@/server/config';\r\n\r\n// ** Re-export types\r\nexport type { TDriveConfigurationExpress, TDriveConfigInformation } from '@/types/server/express';\r\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\r\n"]}
@@ -3,6 +3,9 @@ import type { TDriveConfigurationExpress } from '../types/server/express';
3
3
  export declare const driveAPIHandlerExpress: (req: Request, res: Response) => Promise<void>;
4
4
  export declare const driveConfigurationExpress: (config: TDriveConfigurationExpress) => Promise<TDriveConfigurationExpress>;
5
5
  export { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '../server/controllers/drive';
6
+ export type { TDriveTransferProgress } from '../server/controllers/drive';
7
+ export { DriveError } from '../server/errors';
8
+ export type { TDriveErrorCode } from '../server/errors';
6
9
  export { driveFileSchemaZod } from '../server/zod/schemas';
7
10
  export { getDriveConfig } from '../server/config';
8
11
  export type { TDriveConfigurationExpress, TDriveConfigInformation } from '../types/server/express';
@@ -1 +1 @@
1
- {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAMzE,eAAO,MAAM,sBAAsB,EAAiC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAInH,eAAO,MAAM,yBAAyB,EAAoC,CAAC,MAAM,EAAE,0BAA0B,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAGtJ,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5H,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,YAAY,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAClG,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAMzE,eAAO,MAAM,sBAAsB,EAAiC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAInH,eAAO,MAAM,yBAAyB,EAAoC,CAAC,MAAM,EAAE,0BAA0B,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAGtJ,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5H,YAAY,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,YAAY,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAClG,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,8 +1,8 @@
1
- import { driveAPIHandler } from '../chunk-2DCZENJ2.js';
2
- export { driveFileSchemaZod } from '../chunk-2DCZENJ2.js';
1
+ import { driveAPIHandler } from '../chunk-E72MTT6W.js';
2
+ export { driveFileSchemaZod } from '../chunk-E72MTT6W.js';
3
3
  import '../chunk-OSYRIHH4.js';
4
- import { driveConfiguration } from '../chunk-IWV6G7HQ.js';
5
- export { driveDelete, driveFilePath, driveGetUrl, driveList, driveReadFile, driveUpload, getDriveConfig } from '../chunk-IWV6G7HQ.js';
4
+ import { driveConfiguration } from '../chunk-QMPV4YSZ.js';
5
+ export { DriveError, driveDelete, driveFilePath, driveGetUrl, driveList, driveReadFile, driveUpload, getDriveConfig } from '../chunk-QMPV4YSZ.js';
6
6
 
7
7
  // src/server/express.ts
8
8
  var driveAPIHandlerExpress = driveAPIHandler;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server/express.ts"],"names":[],"mappings":";;;;;;;AASO,IAAM,sBAAA,GAAyB;AAI/B,IAAM,yBAAA,GAA4B","file":"express.js","sourcesContent":["// ** Express Adapter for next-drive\r\n// ** Provides Express-compatible types for the drive API handler and configuration\r\nimport type { Request, Response } from 'express';\r\nimport type { TDriveConfigurationExpress } from '@/types/server/express';\r\n\r\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\r\n\r\n// ** Express API Handler\r\n// ** Type-cast wrapper that allows Express Request/Response to be used with the core handler\r\nexport const driveAPIHandlerExpress = driveAPIHandler as unknown as (req: Request, res: Response) => Promise<void>;\r\n\r\n// ** Express Configuration\r\n// ** Type-cast wrapper that accepts Express Request in the information callback\r\nexport const driveConfigurationExpress = driveConfiguration as unknown as (config: TDriveConfigurationExpress) => Promise<TDriveConfigurationExpress>;\r\n\r\n// ** Re-export utilities that work with any framework\r\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\r\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\r\nexport { getDriveConfig } from '@/server/config';\r\n\r\n// ** Re-export types\r\nexport type { TDriveConfigurationExpress, TDriveConfigInformation } from '@/types/server/express';\r\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\r\n"]}
1
+ {"version":3,"sources":["../../src/server/express.ts"],"names":[],"mappings":";;;;;;;AASO,IAAM,sBAAA,GAAyB;AAI/B,IAAM,yBAAA,GAA4B","file":"express.js","sourcesContent":["// ** Express Adapter for next-drive\r\n// ** Provides Express-compatible types for the drive API handler and configuration\r\nimport type { Request, Response } from 'express';\r\nimport type { TDriveConfigurationExpress } from '@/types/server/express';\r\n\r\nimport { driveAPIHandler, driveConfiguration } from '@/server/index';\r\n\r\n// ** Express API Handler\r\n// ** Type-cast wrapper that allows Express Request/Response to be used with the core handler\r\nexport const driveAPIHandlerExpress = driveAPIHandler as unknown as (req: Request, res: Response) => Promise<void>;\r\n\r\n// ** Express Configuration\r\n// ** Type-cast wrapper that accepts Express Request in the information callback\r\nexport const driveConfigurationExpress = driveConfiguration as unknown as (config: TDriveConfigurationExpress) => Promise<TDriveConfigurationExpress>;\r\n\r\n// ** Re-export utilities that work with any framework\r\nexport { driveGetUrl, driveReadFile, driveFilePath, driveUpload, driveDelete, driveList } from '@/server/controllers/drive';\r\nexport type { TDriveTransferProgress } from '@/server/controllers/drive';\r\nexport { DriveError } from '@/server/errors';\r\nexport type { TDriveErrorCode } from '@/server/errors';\r\nexport { driveFileSchemaZod } from '@/server/zod/schemas';\r\nexport { getDriveConfig } from '@/server/config';\r\n\r\n// ** Re-export types\r\nexport type { TDriveConfigurationExpress, TDriveConfigInformation } from '@/types/server/express';\r\nexport type { TDriveFile, TDriveInformation } from '@/types/client';\r\n"]}
@@ -1,44 +1,113 @@
1
1
  'use strict';
2
2
 
3
- var chunkWUG4ATLH_cjs = require('../chunk-WUG4ATLH.cjs');
3
+ var chunkPKNXKHGS_cjs = require('../chunk-PKNXKHGS.cjs');
4
4
  require('../chunk-HQTC3554.cjs');
5
- var chunkHWNIRA6Y_cjs = require('../chunk-HWNIRA6Y.cjs');
5
+ var chunkDHIHCER6_cjs = require('../chunk-DHIHCER6.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 chunkPKNXKHGS_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 chunkDHIHCER6_cjs.driveConfiguration({ ...config, information });
74
+ };
10
75
 
11
76
  Object.defineProperty(exports, "driveFileSchemaZod", {
12
77
  enumerable: true,
13
- get: function () { return chunkWUG4ATLH_cjs.driveFileSchemaZod; }
78
+ get: function () { return chunkPKNXKHGS_cjs.driveFileSchemaZod; }
79
+ });
80
+ Object.defineProperty(exports, "DriveError", {
81
+ enumerable: true,
82
+ get: function () { return chunkDHIHCER6_cjs.DriveError; }
14
83
  });
15
84
  Object.defineProperty(exports, "driveDelete", {
16
85
  enumerable: true,
17
- get: function () { return chunkHWNIRA6Y_cjs.driveDelete; }
86
+ get: function () { return chunkDHIHCER6_cjs.driveDelete; }
18
87
  });
19
88
  Object.defineProperty(exports, "driveFilePath", {
20
89
  enumerable: true,
21
- get: function () { return chunkHWNIRA6Y_cjs.driveFilePath; }
90
+ get: function () { return chunkDHIHCER6_cjs.driveFilePath; }
22
91
  });
23
92
  Object.defineProperty(exports, "driveGetUrl", {
24
93
  enumerable: true,
25
- get: function () { return chunkHWNIRA6Y_cjs.driveGetUrl; }
94
+ get: function () { return chunkDHIHCER6_cjs.driveGetUrl; }
26
95
  });
27
96
  Object.defineProperty(exports, "driveList", {
28
97
  enumerable: true,
29
- get: function () { return chunkHWNIRA6Y_cjs.driveList; }
98
+ get: function () { return chunkDHIHCER6_cjs.driveList; }
30
99
  });
31
100
  Object.defineProperty(exports, "driveReadFile", {
32
101
  enumerable: true,
33
- get: function () { return chunkHWNIRA6Y_cjs.driveReadFile; }
102
+ get: function () { return chunkDHIHCER6_cjs.driveReadFile; }
34
103
  });
35
104
  Object.defineProperty(exports, "driveUpload", {
36
105
  enumerable: true,
37
- get: function () { return chunkHWNIRA6Y_cjs.driveUpload; }
106
+ get: function () { return chunkDHIHCER6_cjs.driveUpload; }
38
107
  });
39
108
  Object.defineProperty(exports, "getDriveConfig", {
40
109
  enumerable: true,
41
- get: function () { return chunkHWNIRA6Y_cjs.getDriveConfig; }
110
+ get: function () { return chunkDHIHCER6_cjs.getDriveConfig; }
42
111
  });
43
112
  exports.driveAPIHandlerHono = driveAPIHandlerHono;
44
113
  exports.driveConfigurationHono = driveConfigurationHono;
@@ -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,EAA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AsE;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,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 type { TDriveTransferProgress } from '@/server/controllers/drive';\nexport { DriveError } from '@/server/errors';\nexport type { TDriveErrorCode } from '@/server/errors';\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,8 +1,11 @@
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
+ export type { TDriveTransferProgress } from '../server/controllers/drive';
7
+ export { DriveError } from '../server/errors';
8
+ export type { TDriveErrorCode } from '../server/errors';
6
9
  export { driveFileSchemaZod } from '../server/zod/schemas';
7
10
  export { getDriveConfig } from '../server/config';
8
11
  export type { TDriveConfigurationHono, TDriveConfigInformation } from '../types/server/hono';
@@ -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,EAAoC,CAAC,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAG7I,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5H,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,YAAY,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC5F,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../src/server/hono.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,uBAAuB,EAA2B,MAAM,qBAAqB,CAAC;AAwE5F,eAAO,MAAM,mBAAmB,GAAU,GAAG,OAAO,KAAG,OAAO,CAAC,QAAQ,CAKtE,CAAC;AAKF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,uBAAuB,KAAG,OAAO,CAAC,uBAAuB,CAYvG,CAAC;AAGF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5H,YAAY,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,YAAY,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC5F,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,12 +1,77 @@
1
- import { driveAPIHandler } from '../chunk-2DCZENJ2.js';
2
- export { driveFileSchemaZod } from '../chunk-2DCZENJ2.js';
1
+ import { driveAPIHandler } from '../chunk-E72MTT6W.js';
2
+ export { driveFileSchemaZod } from '../chunk-E72MTT6W.js';
3
3
  import '../chunk-OSYRIHH4.js';
4
- import { driveConfiguration } from '../chunk-IWV6G7HQ.js';
5
- export { driveDelete, driveFilePath, driveGetUrl, driveList, driveReadFile, driveUpload, getDriveConfig } from '../chunk-IWV6G7HQ.js';
4
+ import { driveConfiguration } from '../chunk-QMPV4YSZ.js';
5
+ export { DriveError, driveDelete, driveFilePath, driveGetUrl, driveList, driveReadFile, driveUpload, getDriveConfig } from '../chunk-QMPV4YSZ.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":";;;;;;;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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M,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 type { TDriveTransferProgress } from '@/server/controllers/drive';\nexport { DriveError } from '@/server/errors';\nexport type { TDriveErrorCode } from '@/server/errors';\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,18 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var chunkWUG4ATLH_cjs = require('../chunk-WUG4ATLH.cjs');
3
+ var chunkPKNXKHGS_cjs = require('../chunk-PKNXKHGS.cjs');
4
4
  var chunkHQTC3554_cjs = require('../chunk-HQTC3554.cjs');
5
- var chunkHWNIRA6Y_cjs = require('../chunk-HWNIRA6Y.cjs');
5
+ var chunkDHIHCER6_cjs = require('../chunk-DHIHCER6.cjs');
6
6
 
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, "driveAPIHandler", {
10
10
  enumerable: true,
11
- get: function () { return chunkWUG4ATLH_cjs.driveAPIHandler; }
11
+ get: function () { return chunkPKNXKHGS_cjs.driveAPIHandler; }
12
12
  });
13
13
  Object.defineProperty(exports, "driveFileSchemaZod", {
14
14
  enumerable: true,
15
- get: function () { return chunkWUG4ATLH_cjs.driveFileSchemaZod; }
15
+ get: function () { return chunkPKNXKHGS_cjs.driveFileSchemaZod; }
16
16
  });
17
17
  Object.defineProperty(exports, "driveCreateUrl", {
18
18
  enumerable: true,
@@ -20,63 +20,67 @@ Object.defineProperty(exports, "driveCreateUrl", {
20
20
  });
21
21
  Object.defineProperty(exports, "DatabaseMongoDrive", {
22
22
  enumerable: true,
23
- get: function () { return chunkHWNIRA6Y_cjs.drive_default; }
23
+ get: function () { return chunkDHIHCER6_cjs.drive_default; }
24
+ });
25
+ Object.defineProperty(exports, "DriveError", {
26
+ enumerable: true,
27
+ get: function () { return chunkDHIHCER6_cjs.DriveError; }
24
28
  });
25
29
  Object.defineProperty(exports, "driveCleanup", {
26
30
  enumerable: true,
27
- get: function () { return chunkHWNIRA6Y_cjs.driveCleanup; }
31
+ get: function () { return chunkDHIHCER6_cjs.driveCleanup; }
28
32
  });
29
33
  Object.defineProperty(exports, "driveConfiguration", {
30
34
  enumerable: true,
31
- get: function () { return chunkHWNIRA6Y_cjs.driveConfiguration; }
35
+ get: function () { return chunkDHIHCER6_cjs.driveConfiguration; }
32
36
  });
33
37
  Object.defineProperty(exports, "driveConfirm", {
34
38
  enumerable: true,
35
- get: function () { return chunkHWNIRA6Y_cjs.driveConfirm; }
39
+ get: function () { return chunkDHIHCER6_cjs.driveConfirm; }
36
40
  });
37
41
  Object.defineProperty(exports, "driveDelete", {
38
42
  enumerable: true,
39
- get: function () { return chunkHWNIRA6Y_cjs.driveDelete; }
43
+ get: function () { return chunkDHIHCER6_cjs.driveDelete; }
40
44
  });
41
45
  Object.defineProperty(exports, "driveFilePath", {
42
46
  enumerable: true,
43
- get: function () { return chunkHWNIRA6Y_cjs.driveFilePath; }
47
+ get: function () { return chunkDHIHCER6_cjs.driveFilePath; }
44
48
  });
45
49
  Object.defineProperty(exports, "driveGetUrl", {
46
50
  enumerable: true,
47
- get: function () { return chunkHWNIRA6Y_cjs.driveGetUrl; }
51
+ get: function () { return chunkDHIHCER6_cjs.driveGetUrl; }
48
52
  });
49
53
  Object.defineProperty(exports, "driveInfo", {
50
54
  enumerable: true,
51
- get: function () { return chunkHWNIRA6Y_cjs.driveInfo; }
55
+ get: function () { return chunkDHIHCER6_cjs.driveInfo; }
52
56
  });
53
57
  Object.defineProperty(exports, "driveList", {
54
58
  enumerable: true,
55
- get: function () { return chunkHWNIRA6Y_cjs.driveList; }
59
+ get: function () { return chunkDHIHCER6_cjs.driveList; }
56
60
  });
57
61
  Object.defineProperty(exports, "driveListFiles", {
58
62
  enumerable: true,
59
- get: function () { return chunkHWNIRA6Y_cjs.driveListFiles; }
63
+ get: function () { return chunkDHIHCER6_cjs.driveListFiles; }
60
64
  });
61
65
  Object.defineProperty(exports, "drivePurgeExpired", {
62
66
  enumerable: true,
63
- get: function () { return chunkHWNIRA6Y_cjs.drivePurgeExpired; }
67
+ get: function () { return chunkDHIHCER6_cjs.drivePurgeExpired; }
64
68
  });
65
69
  Object.defineProperty(exports, "driveReadFile", {
66
70
  enumerable: true,
67
- get: function () { return chunkHWNIRA6Y_cjs.driveReadFile; }
71
+ get: function () { return chunkDHIHCER6_cjs.driveReadFile; }
68
72
  });
69
73
  Object.defineProperty(exports, "driveUpload", {
70
74
  enumerable: true,
71
- get: function () { return chunkHWNIRA6Y_cjs.driveUpload; }
75
+ get: function () { return chunkDHIHCER6_cjs.driveUpload; }
72
76
  });
73
77
  Object.defineProperty(exports, "getDriveConfig", {
74
78
  enumerable: true,
75
- get: function () { return chunkHWNIRA6Y_cjs.getDriveConfig; }
79
+ get: function () { return chunkDHIHCER6_cjs.getDriveConfig; }
76
80
  });
77
81
  Object.defineProperty(exports, "getDriveInformation", {
78
82
  enumerable: true,
79
- get: function () { return chunkHWNIRA6Y_cjs.getDriveInformation; }
83
+ get: function () { return chunkDHIHCER6_cjs.getDriveInformation; }
80
84
  });
81
85
  //# sourceMappingURL=index.cjs.map
82
86
  //# sourceMappingURL=index.cjs.map