@kiyasov/platform-hono 1.3.7 → 1.3.9
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.
- package/dist/cjs/src/adapters/hono-adapter.d.ts +57 -0
- package/dist/cjs/src/adapters/hono-adapter.js +259 -0
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -0
- package/dist/cjs/src/adapters/index.d.ts +1 -0
- package/dist/cjs/src/adapters/index.js +18 -0
- package/dist/cjs/src/adapters/index.js.map +1 -0
- package/dist/cjs/src/drivers/constants/apollo.constants.d.ts +1 -0
- package/dist/cjs/src/drivers/constants/apollo.constants.js +5 -0
- package/dist/cjs/src/drivers/constants/apollo.constants.js.map +1 -0
- package/dist/cjs/src/drivers/constants/index.d.ts +1 -0
- package/dist/cjs/src/drivers/constants/index.js +18 -0
- package/dist/cjs/src/drivers/constants/index.js.map +1 -0
- package/dist/cjs/src/drivers/graphQLUpload/GraphQLUpload.d.ts +3 -0
- package/dist/cjs/src/drivers/graphQLUpload/GraphQLUpload.js +21 -0
- package/dist/cjs/src/drivers/graphQLUpload/GraphQLUpload.js.map +1 -0
- package/dist/cjs/src/drivers/graphQLUpload/Upload.d.ts +16 -0
- package/dist/cjs/src/drivers/graphQLUpload/Upload.js +17 -0
- package/dist/cjs/src/drivers/graphQLUpload/Upload.js.map +1 -0
- package/dist/cjs/src/drivers/graphQLUpload/fs-capacitor.d.ts +42 -0
- package/dist/cjs/src/drivers/graphQLUpload/fs-capacitor.js +190 -0
- package/dist/cjs/src/drivers/graphQLUpload/fs-capacitor.js.map +1 -0
- package/dist/cjs/src/drivers/graphQLUpload/index.d.ts +4 -0
- package/dist/cjs/src/drivers/graphQLUpload/index.js +21 -0
- package/dist/cjs/src/drivers/graphQLUpload/index.js.map +1 -0
- package/dist/cjs/src/drivers/graphQLUpload/processRequest.d.ts +2 -0
- package/dist/cjs/src/drivers/graphQLUpload/processRequest.js +50 -0
- package/dist/cjs/src/drivers/graphQLUpload/processRequest.js.map +1 -0
- package/dist/cjs/src/drivers/graphql.driver.d.ts +20 -0
- package/dist/cjs/src/drivers/graphql.driver.js +126 -0
- package/dist/cjs/src/drivers/graphql.driver.js.map +1 -0
- package/dist/cjs/src/drivers/index.d.ts +2 -0
- package/dist/cjs/src/drivers/index.js +19 -0
- package/dist/cjs/src/drivers/index.js.map +1 -0
- package/dist/cjs/src/drivers/services/plugins-explorer.service.d.ts +9 -0
- package/dist/cjs/src/drivers/services/plugins-explorer.service.js +25 -0
- package/dist/cjs/src/drivers/services/plugins-explorer.service.js.map +1 -0
- package/dist/cjs/src/interfaces/hono.interface.d.ts +4 -0
- package/dist/cjs/src/interfaces/hono.interface.js +3 -0
- package/dist/cjs/src/interfaces/hono.interface.js.map +1 -0
- package/dist/cjs/src/interfaces/index.d.ts +2 -0
- package/dist/cjs/src/interfaces/index.js +19 -0
- package/dist/cjs/src/interfaces/index.js.map +1 -0
- package/dist/cjs/src/interfaces/nest-hono-application.interface.d.ts +18 -0
- package/dist/cjs/src/interfaces/nest-hono-application.interface.js +3 -0
- package/dist/cjs/src/interfaces/nest-hono-application.interface.js.map +1 -0
- package/dist/cjs/src/multer/crypto/index.d.ts +1 -0
- package/dist/cjs/src/multer/crypto/index.js +7 -0
- package/dist/cjs/src/multer/crypto/index.js.map +1 -0
- package/dist/cjs/src/multer/decorators/index.d.ts +2 -0
- package/dist/cjs/src/multer/decorators/index.js +19 -0
- package/dist/cjs/src/multer/decorators/index.js.map +1 -0
- package/dist/cjs/src/multer/decorators/uploaded-file-decorator.d.ts +1 -0
- package/dist/cjs/src/multer/decorators/uploaded-file-decorator.js +10 -0
- package/dist/cjs/src/multer/decorators/uploaded-file-decorator.js.map +1 -0
- package/dist/cjs/src/multer/decorators/uploaded-files-decorator.d.ts +1 -0
- package/dist/cjs/src/multer/decorators/uploaded-files-decorator.js +10 -0
- package/dist/cjs/src/multer/decorators/uploaded-files-decorator.js.map +1 -0
- package/dist/cjs/src/multer/fs/index.d.ts +2 -0
- package/dist/cjs/src/multer/fs/index.js +23 -0
- package/dist/cjs/src/multer/fs/index.js.map +1 -0
- package/dist/cjs/src/multer/index.d.ts +4 -0
- package/dist/cjs/src/multer/index.js +21 -0
- package/dist/cjs/src/multer/index.js.map +1 -0
- package/dist/cjs/src/multer/interceptors/any-files-interceptor.d.ts +3 -0
- package/dist/cjs/src/multer/interceptors/any-files-interceptor.js +29 -0
- package/dist/cjs/src/multer/interceptors/any-files-interceptor.js.map +1 -0
- package/dist/cjs/src/multer/interceptors/file-fields-interceptor.d.ts +4 -0
- package/dist/cjs/src/multer/interceptors/file-fields-interceptor.js +30 -0
- package/dist/cjs/src/multer/interceptors/file-fields-interceptor.js.map +1 -0
- package/dist/cjs/src/multer/interceptors/file-interceptor.d.ts +3 -0
- package/dist/cjs/src/multer/interceptors/file-interceptor.js +29 -0
- package/dist/cjs/src/multer/interceptors/file-interceptor.js.map +1 -0
- package/dist/cjs/src/multer/interceptors/files-interceptor.d.ts +3 -0
- package/dist/cjs/src/multer/interceptors/files-interceptor.js +29 -0
- package/dist/cjs/src/multer/interceptors/files-interceptor.js.map +1 -0
- package/dist/cjs/src/multer/interceptors/index.d.ts +4 -0
- package/dist/cjs/src/multer/interceptors/index.js +21 -0
- package/dist/cjs/src/multer/interceptors/index.js.map +1 -0
- package/dist/cjs/src/multer/multipart/exceptions.d.ts +1 -0
- package/dist/cjs/src/multer/multipart/exceptions.js +22 -0
- package/dist/cjs/src/multer/multipart/exceptions.js.map +1 -0
- package/dist/cjs/src/multer/multipart/file.d.ts +9 -0
- package/dist/cjs/src/multer/multipart/file.js +10 -0
- package/dist/cjs/src/multer/multipart/file.js.map +1 -0
- package/dist/cjs/src/multer/multipart/filter.d.ts +6 -0
- package/dist/cjs/src/multer/multipart/filter.js +22 -0
- package/dist/cjs/src/multer/multipart/filter.js.map +1 -0
- package/dist/cjs/src/multer/multipart/handlers/any-files.d.ts +8 -0
- package/dist/cjs/src/multer/multipart/handlers/any-files.js +33 -0
- package/dist/cjs/src/multer/multipart/handlers/any-files.js.map +1 -0
- package/dist/cjs/src/multer/multipart/handlers/file-fields.d.ts +14 -0
- package/dist/cjs/src/multer/multipart/handlers/file-fields.js +57 -0
- package/dist/cjs/src/multer/multipart/handlers/file-fields.js.map +1 -0
- package/dist/cjs/src/multer/multipart/handlers/index.d.ts +1 -0
- package/dist/cjs/src/multer/multipart/handlers/index.js +3 -0
- package/dist/cjs/src/multer/multipart/handlers/index.js.map +1 -0
- package/dist/cjs/src/multer/multipart/handlers/multiple-files.d.ts +8 -0
- package/dist/cjs/src/multer/multipart/handlers/multiple-files.js +40 -0
- package/dist/cjs/src/multer/multipart/handlers/multiple-files.js.map +1 -0
- package/dist/cjs/src/multer/multipart/handlers/single-file.d.ts +8 -0
- package/dist/cjs/src/multer/multipart/handlers/single-file.js +45 -0
- package/dist/cjs/src/multer/multipart/handlers/single-file.js.map +1 -0
- package/dist/cjs/src/multer/multipart/index.d.ts +3 -0
- package/dist/cjs/src/multer/multipart/index.js +19 -0
- package/dist/cjs/src/multer/multipart/index.js.map +1 -0
- package/dist/cjs/src/multer/multipart/options.d.ts +21 -0
- package/dist/cjs/src/multer/multipart/options.js +23 -0
- package/dist/cjs/src/multer/multipart/options.js.map +1 -0
- package/dist/cjs/src/multer/multipart/request.d.ts +14 -0
- package/dist/cjs/src/multer/multipart/request.js +22 -0
- package/dist/cjs/src/multer/multipart/request.js.map +1 -0
- package/dist/cjs/src/multer/storage/disk-storage.d.ts +31 -0
- package/dist/cjs/src/multer/storage/disk-storage.js +62 -0
- package/dist/cjs/src/multer/storage/disk-storage.js.map +1 -0
- package/dist/cjs/src/multer/storage/index.d.ts +3 -0
- package/dist/cjs/src/multer/storage/index.js +20 -0
- package/dist/cjs/src/multer/storage/index.js.map +1 -0
- package/dist/cjs/src/multer/storage/memory-storage.d.ts +16 -0
- package/dist/cjs/src/multer/storage/memory-storage.js +21 -0
- package/dist/cjs/src/multer/storage/memory-storage.js.map +1 -0
- package/dist/cjs/src/multer/storage/storage.d.ts +13 -0
- package/dist/cjs/src/multer/storage/storage.js +3 -0
- package/dist/cjs/src/multer/storage/storage.js.map +1 -0
- package/dist/cjs/src/multer/stream/index.d.ts +2 -0
- package/dist/cjs/src/multer/stream/index.js +7 -0
- package/dist/cjs/src/multer/stream/index.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.d.ts +57 -0
- package/dist/esm/src/adapters/hono-adapter.js +255 -0
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -0
- package/dist/esm/src/adapters/index.d.ts +1 -0
- package/dist/esm/src/adapters/index.js +2 -0
- package/dist/esm/src/adapters/index.js.map +1 -0
- package/dist/esm/src/drivers/constants/apollo.constants.d.ts +1 -0
- package/dist/esm/src/drivers/constants/apollo.constants.js +2 -0
- package/dist/esm/src/drivers/constants/apollo.constants.js.map +1 -0
- package/dist/esm/src/drivers/constants/index.d.ts +1 -0
- package/dist/esm/src/drivers/constants/index.js +2 -0
- package/dist/esm/src/drivers/constants/index.js.map +1 -0
- package/dist/esm/src/drivers/graphQLUpload/GraphQLUpload.d.ts +3 -0
- package/dist/esm/src/drivers/graphQLUpload/GraphQLUpload.js +18 -0
- package/dist/esm/src/drivers/graphQLUpload/GraphQLUpload.js.map +1 -0
- package/dist/esm/src/drivers/graphQLUpload/Upload.d.ts +16 -0
- package/dist/esm/src/drivers/graphQLUpload/Upload.js +13 -0
- package/dist/esm/src/drivers/graphQLUpload/Upload.js.map +1 -0
- package/dist/esm/src/drivers/graphQLUpload/fs-capacitor.d.ts +42 -0
- package/dist/esm/src/drivers/graphQLUpload/fs-capacitor.js +183 -0
- package/dist/esm/src/drivers/graphQLUpload/fs-capacitor.js.map +1 -0
- package/dist/esm/src/drivers/graphQLUpload/index.d.ts +4 -0
- package/dist/esm/src/drivers/graphQLUpload/index.js +5 -0
- package/dist/esm/src/drivers/graphQLUpload/index.js.map +1 -0
- package/dist/esm/src/drivers/graphQLUpload/processRequest.d.ts +2 -0
- package/dist/esm/src/drivers/graphQLUpload/processRequest.js +47 -0
- package/dist/esm/src/drivers/graphQLUpload/processRequest.js.map +1 -0
- package/dist/esm/src/drivers/graphql.driver.d.ts +20 -0
- package/dist/esm/src/drivers/graphql.driver.js +122 -0
- package/dist/esm/src/drivers/graphql.driver.js.map +1 -0
- package/dist/esm/src/drivers/index.d.ts +2 -0
- package/dist/esm/src/drivers/index.js +3 -0
- package/dist/esm/src/drivers/index.js.map +1 -0
- package/dist/esm/src/drivers/services/plugins-explorer.service.d.ts +9 -0
- package/dist/esm/src/drivers/services/plugins-explorer.service.js +21 -0
- package/dist/esm/src/drivers/services/plugins-explorer.service.js.map +1 -0
- package/dist/esm/src/interfaces/hono.interface.d.ts +4 -0
- package/dist/esm/src/interfaces/hono.interface.js +2 -0
- package/dist/esm/src/interfaces/hono.interface.js.map +1 -0
- package/dist/esm/src/interfaces/index.d.ts +2 -0
- package/dist/esm/src/interfaces/index.js +3 -0
- package/dist/esm/src/interfaces/index.js.map +1 -0
- package/dist/esm/src/interfaces/nest-hono-application.interface.d.ts +18 -0
- package/dist/esm/src/interfaces/nest-hono-application.interface.js +2 -0
- package/dist/esm/src/interfaces/nest-hono-application.interface.js.map +1 -0
- package/dist/esm/src/multer/crypto/index.d.ts +1 -0
- package/dist/esm/src/multer/crypto/index.js +4 -0
- package/dist/esm/src/multer/crypto/index.js.map +1 -0
- package/dist/esm/src/multer/decorators/index.d.ts +2 -0
- package/dist/esm/src/multer/decorators/index.js +3 -0
- package/dist/esm/src/multer/decorators/index.js.map +1 -0
- package/dist/esm/src/multer/decorators/uploaded-file-decorator.d.ts +1 -0
- package/dist/esm/src/multer/decorators/uploaded-file-decorator.js +7 -0
- package/dist/esm/src/multer/decorators/uploaded-file-decorator.js.map +1 -0
- package/dist/esm/src/multer/decorators/uploaded-files-decorator.d.ts +1 -0
- package/dist/esm/src/multer/decorators/uploaded-files-decorator.js +7 -0
- package/dist/esm/src/multer/decorators/uploaded-files-decorator.js.map +1 -0
- package/dist/esm/src/multer/fs/index.d.ts +2 -0
- package/dist/esm/src/multer/fs/index.js +18 -0
- package/dist/esm/src/multer/fs/index.js.map +1 -0
- package/dist/esm/src/multer/index.d.ts +4 -0
- package/dist/esm/src/multer/index.js +5 -0
- package/dist/esm/src/multer/index.js.map +1 -0
- package/dist/esm/src/multer/interceptors/any-files-interceptor.d.ts +3 -0
- package/dist/esm/src/multer/interceptors/any-files-interceptor.js +26 -0
- package/dist/esm/src/multer/interceptors/any-files-interceptor.js.map +1 -0
- package/dist/esm/src/multer/interceptors/file-fields-interceptor.d.ts +4 -0
- package/dist/esm/src/multer/interceptors/file-fields-interceptor.js +27 -0
- package/dist/esm/src/multer/interceptors/file-fields-interceptor.js.map +1 -0
- package/dist/esm/src/multer/interceptors/file-interceptor.d.ts +3 -0
- package/dist/esm/src/multer/interceptors/file-interceptor.js +26 -0
- package/dist/esm/src/multer/interceptors/file-interceptor.js.map +1 -0
- package/dist/esm/src/multer/interceptors/files-interceptor.d.ts +3 -0
- package/dist/esm/src/multer/interceptors/files-interceptor.js +26 -0
- package/dist/esm/src/multer/interceptors/files-interceptor.js.map +1 -0
- package/dist/esm/src/multer/interceptors/index.d.ts +4 -0
- package/dist/esm/src/multer/interceptors/index.js +5 -0
- package/dist/esm/src/multer/interceptors/index.js.map +1 -0
- package/dist/esm/src/multer/multipart/exceptions.d.ts +1 -0
- package/dist/esm/src/multer/multipart/exceptions.js +18 -0
- package/dist/esm/src/multer/multipart/exceptions.js.map +1 -0
- package/dist/esm/src/multer/multipart/file.d.ts +9 -0
- package/dist/esm/src/multer/multipart/file.js +6 -0
- package/dist/esm/src/multer/multipart/file.js.map +1 -0
- package/dist/esm/src/multer/multipart/filter.d.ts +6 -0
- package/dist/esm/src/multer/multipart/filter.js +18 -0
- package/dist/esm/src/multer/multipart/filter.js.map +1 -0
- package/dist/esm/src/multer/multipart/handlers/any-files.d.ts +8 -0
- package/dist/esm/src/multer/multipart/handlers/any-files.js +29 -0
- package/dist/esm/src/multer/multipart/handlers/any-files.js.map +1 -0
- package/dist/esm/src/multer/multipart/handlers/file-fields.d.ts +14 -0
- package/dist/esm/src/multer/multipart/handlers/file-fields.js +52 -0
- package/dist/esm/src/multer/multipart/handlers/file-fields.js.map +1 -0
- package/dist/esm/src/multer/multipart/handlers/index.d.ts +1 -0
- package/dist/esm/src/multer/multipart/handlers/index.js +2 -0
- package/dist/esm/src/multer/multipart/handlers/index.js.map +1 -0
- package/dist/esm/src/multer/multipart/handlers/multiple-files.d.ts +8 -0
- package/dist/esm/src/multer/multipart/handlers/multiple-files.js +36 -0
- package/dist/esm/src/multer/multipart/handlers/multiple-files.js.map +1 -0
- package/dist/esm/src/multer/multipart/handlers/single-file.d.ts +8 -0
- package/dist/esm/src/multer/multipart/handlers/single-file.js +41 -0
- package/dist/esm/src/multer/multipart/handlers/single-file.js.map +1 -0
- package/dist/esm/src/multer/multipart/index.d.ts +3 -0
- package/dist/esm/src/multer/multipart/index.js +3 -0
- package/dist/esm/src/multer/multipart/index.js.map +1 -0
- package/dist/esm/src/multer/multipart/options.d.ts +21 -0
- package/dist/esm/src/multer/multipart/options.js +19 -0
- package/dist/esm/src/multer/multipart/options.js.map +1 -0
- package/dist/esm/src/multer/multipart/request.d.ts +14 -0
- package/dist/esm/src/multer/multipart/request.js +17 -0
- package/dist/esm/src/multer/multipart/request.js.map +1 -0
- package/dist/esm/src/multer/storage/disk-storage.d.ts +31 -0
- package/dist/esm/src/multer/storage/disk-storage.js +58 -0
- package/dist/esm/src/multer/storage/disk-storage.js.map +1 -0
- package/dist/esm/src/multer/storage/index.d.ts +3 -0
- package/dist/esm/src/multer/storage/index.js +4 -0
- package/dist/esm/src/multer/storage/index.js.map +1 -0
- package/dist/esm/src/multer/storage/memory-storage.d.ts +16 -0
- package/dist/esm/src/multer/storage/memory-storage.js +17 -0
- package/dist/esm/src/multer/storage/memory-storage.js.map +1 -0
- package/dist/esm/src/multer/storage/storage.d.ts +13 -0
- package/dist/esm/src/multer/storage/storage.js +2 -0
- package/dist/esm/src/multer/storage/storage.js.map +1 -0
- package/dist/esm/src/multer/stream/index.d.ts +2 -0
- package/dist/esm/src/multer/stream/index.js +4 -0
- package/dist/esm/src/multer/stream/index.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/adapters/hono-adapter.ts +380 -0
- package/src/adapters/index.ts +1 -0
- package/src/drivers/constants/apollo.constants.ts +1 -0
- package/src/drivers/constants/index.ts +1 -0
- package/src/drivers/graphQLUpload/GraphQLUpload.ts +17 -0
- package/src/drivers/graphQLUpload/Upload.ts +35 -0
- package/src/drivers/graphQLUpload/fs-capacitor.ts +285 -0
- package/src/drivers/graphQLUpload/index.ts +4 -0
- package/src/drivers/graphQLUpload/processRequest.ts +57 -0
- package/src/drivers/graphql.driver.ts +171 -0
- package/src/drivers/index.ts +2 -0
- package/src/drivers/services/plugins-explorer.service.ts +27 -0
- package/src/interfaces/hono.interface.ts +5 -0
- package/src/interfaces/index.ts +2 -0
- package/src/interfaces/nest-hono-application.interface.ts +72 -0
- package/src/multer/crypto/index.ts +4 -0
- package/src/multer/decorators/index.ts +2 -0
- package/src/multer/decorators/uploaded-file-decorator.ts +12 -0
- package/src/multer/decorators/uploaded-files-decorator.ts +15 -0
- package/src/multer/fs/index.ts +22 -0
- package/src/multer/index.ts +4 -0
- package/src/multer/interceptors/any-files-interceptor.ts +50 -0
- package/src/multer/interceptors/file-fields-interceptor.ts +60 -0
- package/src/multer/interceptors/file-interceptor.ts +52 -0
- package/src/multer/interceptors/files-interceptor.ts +54 -0
- package/src/multer/interceptors/index.ts +4 -0
- package/src/multer/multipart/exceptions.ts +25 -0
- package/src/multer/multipart/file.ts +18 -0
- package/src/multer/multipart/filter.ts +38 -0
- package/src/multer/multipart/handlers/any-files.ts +39 -0
- package/src/multer/multipart/handlers/file-fields.ts +89 -0
- package/src/multer/multipart/handlers/index.ts +1 -0
- package/src/multer/multipart/handlers/multiple-files.ts +55 -0
- package/src/multer/multipart/handlers/single-file.ts +56 -0
- package/src/multer/multipart/index.ts +3 -0
- package/src/multer/multipart/options.ts +29 -0
- package/src/multer/multipart/request.ts +40 -0
- package/src/multer/storage/disk-storage.ts +107 -0
- package/src/multer/storage/index.ts +3 -0
- package/src/multer/storage/memory-storage.ts +25 -0
- package/src/multer/storage/storage.ts +15 -0
- package/src/multer/stream/index.ts +4 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { randomBytes } from "crypto";
|
|
2
|
+
import { read, open, closeSync, unlinkSync, write, close, unlink } from "fs";
|
|
3
|
+
import { tmpdir } from "os";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
import { Readable, ReadableOptions, Writable, WritableOptions } from "stream";
|
|
6
|
+
import { EventEmitter } from "events";
|
|
7
|
+
|
|
8
|
+
export class ReadAfterDestroyedError extends Error {}
|
|
9
|
+
export class ReadAfterReleasedError extends Error {}
|
|
10
|
+
|
|
11
|
+
export interface ReadStreamOptions {
|
|
12
|
+
highWaterMark?: ReadableOptions["highWaterMark"];
|
|
13
|
+
encoding?: ReadableOptions["encoding"];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Use a “proxy” event emitter configured to have an infinite maximum number of
|
|
17
|
+
// listeners to prevent Node.js max listeners exceeded warnings if many
|
|
18
|
+
// `fs-capacitor` `ReadStream` instances are created at the same time. See:
|
|
19
|
+
// https://github.com/mike-marcacci/fs-capacitor/issues/30
|
|
20
|
+
const processExitProxy = new EventEmitter();
|
|
21
|
+
processExitProxy.setMaxListeners(Infinity);
|
|
22
|
+
process.once("exit", () => processExitProxy.emit("exit"));
|
|
23
|
+
|
|
24
|
+
export class ReadStream extends Readable {
|
|
25
|
+
private _pos: number = 0;
|
|
26
|
+
private _writeStream: WriteStream;
|
|
27
|
+
|
|
28
|
+
constructor(writeStream: WriteStream, options?: ReadStreamOptions) {
|
|
29
|
+
super({
|
|
30
|
+
highWaterMark: options?.highWaterMark,
|
|
31
|
+
encoding: options?.encoding,
|
|
32
|
+
autoDestroy: true,
|
|
33
|
+
});
|
|
34
|
+
this._writeStream = writeStream;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_read(n: number): void {
|
|
38
|
+
if (this.destroyed) return;
|
|
39
|
+
|
|
40
|
+
if (typeof this._writeStream["_fd"] !== "number") {
|
|
41
|
+
this._writeStream.once("ready", () => this._read(n));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Using `allocUnsafe` here is OK because we return a slice the length of
|
|
46
|
+
// `bytesRead`, and discard the rest. This prevents node from having to zero
|
|
47
|
+
// out the entire allocation first.
|
|
48
|
+
const buf = Buffer.allocUnsafe(n);
|
|
49
|
+
read(this._writeStream["_fd"], buf, 0, n, this._pos, (error, bytesRead) => {
|
|
50
|
+
if (error) this.destroy(error);
|
|
51
|
+
|
|
52
|
+
// Push any read bytes into the local stream buffer.
|
|
53
|
+
if (bytesRead) {
|
|
54
|
+
this._pos += bytesRead;
|
|
55
|
+
this.push(buf.slice(0, bytesRead));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// If there were no more bytes to read and the write stream is finished,
|
|
60
|
+
// then this stream has reached the end.
|
|
61
|
+
if (
|
|
62
|
+
(
|
|
63
|
+
this._writeStream as any as {
|
|
64
|
+
_writableState: { finished: boolean };
|
|
65
|
+
}
|
|
66
|
+
)._writableState.finished
|
|
67
|
+
) {
|
|
68
|
+
// Check if we have consumed the whole file up to where
|
|
69
|
+
// the write stream has written before ending the stream
|
|
70
|
+
if (this._pos < (this._writeStream as any as { _pos: number })._pos)
|
|
71
|
+
this._read(n);
|
|
72
|
+
else this.push(null);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Otherwise, wait for the write stream to add more data or finish.
|
|
77
|
+
const retry = (): void => {
|
|
78
|
+
this._writeStream.off("finish", retry);
|
|
79
|
+
this._writeStream.off("write", retry);
|
|
80
|
+
this._read(n);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
this._writeStream.on("finish", retry);
|
|
84
|
+
this._writeStream.on("write", retry);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface WriteStreamOptions {
|
|
90
|
+
highWaterMark?: WritableOptions["highWaterMark"];
|
|
91
|
+
defaultEncoding?: WritableOptions["defaultEncoding"];
|
|
92
|
+
tmpdir?: () => string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class WriteStream extends Writable {
|
|
96
|
+
private _fd: null | number = null;
|
|
97
|
+
private _path: null | string = null;
|
|
98
|
+
private _pos: number = 0;
|
|
99
|
+
private _readStreams: Set<ReadStream> = new Set();
|
|
100
|
+
private _released: boolean = false;
|
|
101
|
+
|
|
102
|
+
constructor(options?: WriteStreamOptions) {
|
|
103
|
+
super({
|
|
104
|
+
highWaterMark: options?.highWaterMark,
|
|
105
|
+
defaultEncoding: options?.defaultEncoding,
|
|
106
|
+
autoDestroy: false,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Generate a random filename.
|
|
110
|
+
randomBytes(16, (error, buffer) => {
|
|
111
|
+
if (error) {
|
|
112
|
+
this.destroy(error);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this._path = join(
|
|
117
|
+
(options?.tmpdir ?? tmpdir)(),
|
|
118
|
+
`capacitor-${buffer.toString("hex")}.tmp`
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Create a file in the OS's temporary files directory.
|
|
122
|
+
open(this._path, "wx+", 0o600, (error, fd) => {
|
|
123
|
+
if (error) {
|
|
124
|
+
this.destroy(error);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Cleanup when the process exits or is killed.
|
|
129
|
+
processExitProxy.once("exit", this._cleanupSync);
|
|
130
|
+
|
|
131
|
+
this._fd = fd;
|
|
132
|
+
this.emit("ready");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_cleanup = (callback: (error: null | Error) => void): void => {
|
|
138
|
+
const fd = this._fd;
|
|
139
|
+
const path = this._path;
|
|
140
|
+
|
|
141
|
+
if (typeof fd !== "number" || typeof path !== "string") {
|
|
142
|
+
callback(null);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Close the file descriptor.
|
|
147
|
+
close(fd, (closeError) => {
|
|
148
|
+
// An error here probably means the fd was already closed, but we can
|
|
149
|
+
// still try to unlink the file.
|
|
150
|
+
unlink(path, (unlinkError) => {
|
|
151
|
+
// If we are unable to unlink the file, the operating system will
|
|
152
|
+
// clean up on next restart, since we use store thes in `os.tmpdir()`
|
|
153
|
+
this._fd = null;
|
|
154
|
+
|
|
155
|
+
// We avoid removing this until now in case an exit occurs while
|
|
156
|
+
// asyncronously cleaning up.
|
|
157
|
+
processExitProxy.off("exit", this._cleanupSync);
|
|
158
|
+
callback(unlinkError ?? closeError);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
_cleanupSync = (): void => {
|
|
164
|
+
processExitProxy.off("exit", this._cleanupSync);
|
|
165
|
+
|
|
166
|
+
if (typeof this._fd === "number")
|
|
167
|
+
try {
|
|
168
|
+
closeSync(this._fd);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
// An error here probably means the fd was already closed, but we can
|
|
171
|
+
// still try to unlink the file.
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
if (this._path !== null) {
|
|
176
|
+
unlinkSync(this._path);
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
// If we are unable to unlink the file, the operating system will clean
|
|
180
|
+
// up on next restart, since we use store thes in `os.tmpdir()`
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
_final(callback: (error?: null | Error) => any): void {
|
|
185
|
+
if (typeof this._fd !== "number") {
|
|
186
|
+
this.once("ready", () => this._final(callback));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
callback();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
_write(
|
|
193
|
+
chunk: Buffer,
|
|
194
|
+
encoding: string,
|
|
195
|
+
callback: (error?: null | Error) => any
|
|
196
|
+
): void {
|
|
197
|
+
if (typeof this._fd !== "number") {
|
|
198
|
+
this.once("ready", () => this._write(chunk, encoding, callback));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
write(this._fd, chunk, 0, chunk.length, this._pos, (error) => {
|
|
203
|
+
if (error) {
|
|
204
|
+
callback(error);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// It's safe to increment `this._pos` after flushing to the filesystem
|
|
209
|
+
// because node streams ensure that only one `_write()` is active at a
|
|
210
|
+
// time. If this assumption is broken, the behavior of this library is
|
|
211
|
+
// undefined, regardless of where this is incremented. Relocating this
|
|
212
|
+
// to increment syncronously would result in correct file contents, but
|
|
213
|
+
// the out-of-order writes would still open the potential for read streams
|
|
214
|
+
// to scan positions that have not yet been written.
|
|
215
|
+
this._pos += chunk.length;
|
|
216
|
+
this.emit("write");
|
|
217
|
+
callback();
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
release(): void {
|
|
222
|
+
this._released = true;
|
|
223
|
+
if (this._readStreams.size === 0) this.destroy();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
_destroy(
|
|
227
|
+
error: undefined | null | Error,
|
|
228
|
+
callback: (error?: null | Error) => any
|
|
229
|
+
): void {
|
|
230
|
+
// Destroy all attached read streams.
|
|
231
|
+
for (const readStream of this._readStreams) {
|
|
232
|
+
readStream.destroy(error || undefined);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// This capacitor is fully initialized.
|
|
236
|
+
if (typeof this._fd === "number" && typeof this._path === "string") {
|
|
237
|
+
this._cleanup((cleanupError) => callback(cleanupError ?? error));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// This capacitor has not yet finished initialization; if initialization
|
|
242
|
+
// does complete, immediately clean up after.
|
|
243
|
+
this.once("ready", () => {
|
|
244
|
+
this._cleanup((cleanupError) => {
|
|
245
|
+
if (cleanupError) {
|
|
246
|
+
this.emit("error", cleanupError);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
callback(error);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
createReadStream(options?: ReadStreamOptions): ReadStream {
|
|
255
|
+
if (this.destroyed)
|
|
256
|
+
throw new ReadAfterDestroyedError(
|
|
257
|
+
"A ReadStream cannot be created from a destroyed WriteStream."
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
if (this._released)
|
|
261
|
+
throw new ReadAfterReleasedError(
|
|
262
|
+
"A ReadStream cannot be created from a released WriteStream."
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const readStream = new ReadStream(this, options);
|
|
266
|
+
this._readStreams.add(readStream);
|
|
267
|
+
|
|
268
|
+
readStream.once("close", (): void => {
|
|
269
|
+
this._readStreams.delete(readStream);
|
|
270
|
+
|
|
271
|
+
if (this._released && this._readStreams.size === 0) {
|
|
272
|
+
this.destroy();
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
return readStream;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export default {
|
|
281
|
+
WriteStream,
|
|
282
|
+
ReadStream,
|
|
283
|
+
ReadAfterDestroyedError,
|
|
284
|
+
ReadAfterReleasedError,
|
|
285
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Context } from "hono";
|
|
2
|
+
import { WriteStream, Upload } from ".";
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
|
|
5
|
+
export async function processRequest(
|
|
6
|
+
ctx: Context
|
|
7
|
+
): Promise<Record<string, any>> {
|
|
8
|
+
const body = await ctx.req.parseBody();
|
|
9
|
+
const operations = JSON.parse(body.operations as string);
|
|
10
|
+
const map = new Map(Object.entries(JSON.parse(body.map as string)));
|
|
11
|
+
|
|
12
|
+
for (const [fieldName, file] of Object.entries(body)) {
|
|
13
|
+
if (
|
|
14
|
+
fieldName === "operations" ||
|
|
15
|
+
fieldName === "map" ||
|
|
16
|
+
!(file instanceof File)
|
|
17
|
+
)
|
|
18
|
+
continue;
|
|
19
|
+
|
|
20
|
+
const fileKeys = map.get(fieldName);
|
|
21
|
+
if (!Array.isArray(fileKeys) || !fileKeys.length) continue;
|
|
22
|
+
|
|
23
|
+
const buffer = Buffer.from(await file.arrayBuffer());
|
|
24
|
+
const capacitor = new WriteStream();
|
|
25
|
+
Readable.from(buffer).pipe(capacitor);
|
|
26
|
+
|
|
27
|
+
const upload = new Upload();
|
|
28
|
+
|
|
29
|
+
upload.file = {
|
|
30
|
+
filename: file.name,
|
|
31
|
+
mimetype: file.type,
|
|
32
|
+
fieldName,
|
|
33
|
+
encoding: "7bit",
|
|
34
|
+
createReadStream: (options) => {
|
|
35
|
+
const stream = capacitor.createReadStream(options);
|
|
36
|
+
stream.on("close", () => {
|
|
37
|
+
capacitor.release();
|
|
38
|
+
});
|
|
39
|
+
return stream;
|
|
40
|
+
},
|
|
41
|
+
capacitor,
|
|
42
|
+
};
|
|
43
|
+
upload.resolve(upload.file);
|
|
44
|
+
|
|
45
|
+
for (const fileKey of fileKeys) {
|
|
46
|
+
const pathSegments = fileKey.split(".");
|
|
47
|
+
let current = operations;
|
|
48
|
+
for (let i = 0; i < pathSegments.length - 1; i++) {
|
|
49
|
+
if (!current[pathSegments[i]]) current[pathSegments[i]] = {};
|
|
50
|
+
current = current[pathSegments[i]];
|
|
51
|
+
}
|
|
52
|
+
current[pathSegments[pathSegments.length - 1]] = upload;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return operations;
|
|
57
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { ApolloServer, BaseContext, HeaderMap } from "@apollo/server";
|
|
2
|
+
import { ModulesContainer } from "@nestjs/core";
|
|
3
|
+
import {
|
|
4
|
+
AbstractGraphQLDriver,
|
|
5
|
+
GqlSubscriptionService,
|
|
6
|
+
SubscriptionConfig,
|
|
7
|
+
} from "@nestjs/graphql";
|
|
8
|
+
import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
|
|
9
|
+
import { ApolloDriverConfig } from "@nestjs/apollo";
|
|
10
|
+
import { Context, HonoRequest } from "hono";
|
|
11
|
+
import { StatusCode } from "hono/utils/http-status";
|
|
12
|
+
import { Logger } from "@nestjs/common";
|
|
13
|
+
|
|
14
|
+
import { PluginsExplorerService } from "./services/plugins-explorer.service";
|
|
15
|
+
import { processRequest } from "./graphQLUpload";
|
|
16
|
+
|
|
17
|
+
export class HonoGraphQLDriver<
|
|
18
|
+
T extends Record<string, any> = ApolloDriverConfig
|
|
19
|
+
> extends AbstractGraphQLDriver {
|
|
20
|
+
protected apolloServer: ApolloServer<BaseContext>;
|
|
21
|
+
private _subscriptionService?: GqlSubscriptionService;
|
|
22
|
+
private readonly pluginsExplorerService: PluginsExplorerService;
|
|
23
|
+
|
|
24
|
+
constructor(modulesContainer: ModulesContainer) {
|
|
25
|
+
super();
|
|
26
|
+
this.pluginsExplorerService = new PluginsExplorerService(modulesContainer);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get instance(): ApolloServer<BaseContext> {
|
|
30
|
+
return this.apolloServer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async start(options: T): Promise<void> {
|
|
34
|
+
const { httpAdapter } = this.httpAdapterHost;
|
|
35
|
+
const platformName = httpAdapter.getType();
|
|
36
|
+
|
|
37
|
+
if (platformName !== "hono") {
|
|
38
|
+
throw new Error("This driver is only compatible with the Hono platform");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await this.registerHono(options);
|
|
42
|
+
|
|
43
|
+
if (options.installSubscriptionHandlers || options.subscriptions) {
|
|
44
|
+
const subscriptionsOptions: SubscriptionConfig =
|
|
45
|
+
options.subscriptions || { "subscriptions-transport-ws": {} };
|
|
46
|
+
this._subscriptionService = new GqlSubscriptionService(
|
|
47
|
+
{
|
|
48
|
+
schema: options.schema,
|
|
49
|
+
path: options.path,
|
|
50
|
+
context: options.context,
|
|
51
|
+
...subscriptionsOptions,
|
|
52
|
+
},
|
|
53
|
+
this.httpAdapterHost.httpAdapter?.getHttpServer()
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected async registerHono(
|
|
59
|
+
options: T,
|
|
60
|
+
{ preStartHook }: { preStartHook?: () => void } = {}
|
|
61
|
+
) {
|
|
62
|
+
const { path, typeDefs, resolvers, schema } = options;
|
|
63
|
+
const { httpAdapter } = this.httpAdapterHost;
|
|
64
|
+
const app = httpAdapter.getInstance();
|
|
65
|
+
const drainHttpServerPlugin = ApolloServerPluginDrainHttpServer({
|
|
66
|
+
httpServer: httpAdapter.getHttpServer(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
preStartHook?.();
|
|
70
|
+
|
|
71
|
+
const server = new ApolloServer({
|
|
72
|
+
typeDefs,
|
|
73
|
+
resolvers,
|
|
74
|
+
schema,
|
|
75
|
+
...options,
|
|
76
|
+
plugins: (options.plugins || []).concat(drainHttpServerPlugin),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
await server.start();
|
|
80
|
+
|
|
81
|
+
app.use(path, async (ctx: Context) => {
|
|
82
|
+
const bodyData = await this.parseBody(ctx);
|
|
83
|
+
|
|
84
|
+
const defaultContext = () => Promise.resolve({} as BaseContext);
|
|
85
|
+
|
|
86
|
+
const contextFunction = options?.context ?? defaultContext;
|
|
87
|
+
|
|
88
|
+
const httpGraphQLResponse = await server.executeHTTPGraphQLRequest({
|
|
89
|
+
httpGraphQLRequest: {
|
|
90
|
+
body: bodyData,
|
|
91
|
+
method: ctx.req.method,
|
|
92
|
+
headers: this.httpHeadersToMap(ctx.req.raw.headers),
|
|
93
|
+
search: new URL(ctx.req.url).search,
|
|
94
|
+
},
|
|
95
|
+
context: () =>
|
|
96
|
+
contextFunction(ctx, {
|
|
97
|
+
method: ctx.req.method,
|
|
98
|
+
url: ctx.req.url,
|
|
99
|
+
body: ctx.req.raw.body,
|
|
100
|
+
headers: Object.fromEntries(ctx.req.raw.headers),
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const { headers, body, status } = httpGraphQLResponse;
|
|
105
|
+
|
|
106
|
+
for (const [headerKey, headerValue] of headers) {
|
|
107
|
+
ctx.header(headerKey, headerValue);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
ctx.status(status === undefined ? 200 : (status as StatusCode));
|
|
111
|
+
|
|
112
|
+
if (body.kind === "complete") {
|
|
113
|
+
return ctx.body(body.string);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const readableStream = new ReadableStream({
|
|
117
|
+
async start(controller) {
|
|
118
|
+
for await (const chunk of body.asyncIterator) {
|
|
119
|
+
controller.enqueue(new TextEncoder().encode(chunk));
|
|
120
|
+
}
|
|
121
|
+
controller.close();
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return new Response(readableStream, {
|
|
126
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
this.apolloServer = server;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public async stop() {
|
|
134
|
+
await this._subscriptionService?.stop();
|
|
135
|
+
await this.apolloServer?.stop();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private httpHeadersToMap(headers: Headers) {
|
|
139
|
+
const map = new HeaderMap();
|
|
140
|
+
headers.forEach((value, key) => map.set(key, value));
|
|
141
|
+
return map;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private async parseBody(ctx: Context): Promise<Record<string, unknown>> {
|
|
145
|
+
const req = ctx.req;
|
|
146
|
+
const contentType = req.header("content-type");
|
|
147
|
+
|
|
148
|
+
if (contentType === "application/graphql")
|
|
149
|
+
return { query: await req.text() };
|
|
150
|
+
if (contentType === "application/json")
|
|
151
|
+
return req.json().catch(this.logError);
|
|
152
|
+
if (contentType === "application/x-www-form-urlencoded")
|
|
153
|
+
return this.parseFormURL(req);
|
|
154
|
+
if (contentType?.startsWith("multipart/form-data")) {
|
|
155
|
+
return processRequest(ctx);
|
|
156
|
+
}
|
|
157
|
+
return {};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private logError(e: unknown): void {
|
|
161
|
+
if (e instanceof Error) {
|
|
162
|
+
Logger.error(e.stack || e.message);
|
|
163
|
+
}
|
|
164
|
+
throw new Error(`POST body sent invalid JSON: ${e}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private async parseFormURL(req: HonoRequest) {
|
|
168
|
+
const searchParams = new URLSearchParams(await req.text());
|
|
169
|
+
return Object.fromEntries(searchParams.entries());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
2
|
+
import { ModulesContainer } from '@nestjs/core/injector/modules-container';
|
|
3
|
+
import { BaseExplorerService, GqlModuleOptions } from '@nestjs/graphql';
|
|
4
|
+
import { PLUGIN_METADATA } from '../constants';
|
|
5
|
+
|
|
6
|
+
export class PluginsExplorerService extends BaseExplorerService {
|
|
7
|
+
constructor(private readonly modulesContainer: ModulesContainer) {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
explore(options: GqlModuleOptions) {
|
|
12
|
+
const modules = this.getModules(
|
|
13
|
+
this.modulesContainer,
|
|
14
|
+
options.include || [],
|
|
15
|
+
);
|
|
16
|
+
return this.flatMap(modules, (instance) => this.filterPlugins(instance));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
filterPlugins<T = any>(wrapper: InstanceWrapper<T>) {
|
|
20
|
+
const { instance } = wrapper;
|
|
21
|
+
if (!instance) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const metadata = Reflect.getMetadata(PLUGIN_METADATA, instance.constructor);
|
|
25
|
+
return metadata ? instance : undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ServeStaticOptions } from "@hono/node-server/serve-static";
|
|
2
|
+
import { HttpServer, INestApplication } from "@nestjs/common";
|
|
3
|
+
import { Context, Hono, MiddlewareHandler } from "hono";
|
|
4
|
+
|
|
5
|
+
export type TypeBodyParser =
|
|
6
|
+
| "application/json"
|
|
7
|
+
| "text/plain"
|
|
8
|
+
| "application/x-www-form-urlencoded";
|
|
9
|
+
|
|
10
|
+
interface HonoViewOptions {
|
|
11
|
+
engine: string;
|
|
12
|
+
templates: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @publicApi
|
|
17
|
+
*/
|
|
18
|
+
export interface NestHonoApplication<TServer extends Hono = Hono>
|
|
19
|
+
extends INestApplication<TServer> {
|
|
20
|
+
/**
|
|
21
|
+
* Returns the underlying HTTP adapter bounded to a Hono app.
|
|
22
|
+
*
|
|
23
|
+
* @returns {HttpServer}
|
|
24
|
+
*/
|
|
25
|
+
getHttpAdapter(): HttpServer<Context, MiddlewareHandler, Hono>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Register Hono body parsers on the fly.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // enable the json parser with a parser limit of 50mb
|
|
32
|
+
* app.useBodyParser('application/json', 50 * 1024 * 1024);
|
|
33
|
+
*
|
|
34
|
+
* @returns {this}
|
|
35
|
+
*/
|
|
36
|
+
useBodyParser(type: TypeBodyParser, bodyLimit?: number): this;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sets a base directory for public assets.
|
|
40
|
+
* Example `app.useStaticAssets('public', { root: '/' })`
|
|
41
|
+
* @returns {this}
|
|
42
|
+
*/
|
|
43
|
+
useStaticAssets(path: string, options: ServeStaticOptions): this;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets a view engine for templates (views), for example: `pug`, `handlebars`, or `ejs`.
|
|
47
|
+
*
|
|
48
|
+
* Don't pass in a string. The string type in the argument is for compatibility reason and will cause an exception.
|
|
49
|
+
* @returns {this}
|
|
50
|
+
*/
|
|
51
|
+
setViewEngine(options: HonoViewOptions | string): this;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Starts the application.
|
|
55
|
+
* @returns A Promise that, when resolved, is a reference to the underlying HttpServer.
|
|
56
|
+
*/
|
|
57
|
+
listen(
|
|
58
|
+
port: number | string,
|
|
59
|
+
callback?: (err: Error, address: string) => void
|
|
60
|
+
): Promise<TServer>;
|
|
61
|
+
listen(
|
|
62
|
+
port: number | string,
|
|
63
|
+
address: string,
|
|
64
|
+
callback?: (err: Error, address: string) => void
|
|
65
|
+
): Promise<TServer>;
|
|
66
|
+
listen(
|
|
67
|
+
port: number | string,
|
|
68
|
+
address: string,
|
|
69
|
+
backlog: number,
|
|
70
|
+
callback?: (err: Error, address: string) => void
|
|
71
|
+
): Promise<TServer>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { getMultipartRequest } from '../multipart/request';
|
|
4
|
+
import { StorageFile } from '../storage/storage';
|
|
5
|
+
|
|
6
|
+
export const UploadedFile = createParamDecorator(
|
|
7
|
+
async (_data, ctx: ExecutionContext): Promise<StorageFile | undefined> => {
|
|
8
|
+
const req = getMultipartRequest(ctx.switchToHttp());
|
|
9
|
+
|
|
10
|
+
return req?.storageFile;
|
|
11
|
+
},
|
|
12
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { getMultipartRequest } from '../multipart/request';
|
|
4
|
+
import { StorageFile } from '../storage/storage';
|
|
5
|
+
|
|
6
|
+
export const UploadedFiles = createParamDecorator(
|
|
7
|
+
async (
|
|
8
|
+
_data: any,
|
|
9
|
+
ctx: ExecutionContext,
|
|
10
|
+
): Promise<Record<string, StorageFile[]> | StorageFile[] | undefined> => {
|
|
11
|
+
const req = getMultipartRequest(ctx.switchToHttp());
|
|
12
|
+
|
|
13
|
+
return req?.storageFiles;
|
|
14
|
+
},
|
|
15
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { extname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { randomBytes } from '../crypto';
|
|
5
|
+
|
|
6
|
+
export const pathExists = async (path: string) => {
|
|
7
|
+
try {
|
|
8
|
+
await fs.stat(path);
|
|
9
|
+
} catch (err) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return true;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const getUniqueFilename = async (filename: string) => {
|
|
17
|
+
const buffer = await randomBytes(16);
|
|
18
|
+
|
|
19
|
+
const ext = extname(filename);
|
|
20
|
+
|
|
21
|
+
return buffer.toString('hex') + ext;
|
|
22
|
+
};
|