@kiyasov/platform-hono 1.0.8 → 1.0.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/.yarn/install-state.gz +0 -0
- package/Readme.md +0 -7
- 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 +44 -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 +45 -0
- package/dist/cjs/src/drivers/graphQLUpload/processRequest.js.map +1 -0
- package/dist/cjs/src/drivers/graphql.driver.d.ts +7 -4
- package/dist/cjs/src/drivers/graphql.driver.js +23 -11
- package/dist/cjs/src/drivers/graphql.driver.js.map +1 -1
- package/dist/cjs/src/drivers/index.d.ts +1 -0
- package/dist/cjs/src/drivers/index.js +1 -0
- package/dist/cjs/src/drivers/index.js.map +1 -1
- package/dist/cjs/src/drivers/services/processRequest.d.ts +2 -0
- package/dist/cjs/src/drivers/services/processRequest.js +45 -0
- package/dist/cjs/src/drivers/services/processRequest.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- 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 +44 -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 +41 -0
- package/dist/esm/src/drivers/graphQLUpload/processRequest.js.map +1 -0
- package/dist/esm/src/drivers/graphql.driver.d.ts +7 -4
- package/dist/esm/src/drivers/graphql.driver.js +28 -16
- package/dist/esm/src/drivers/graphql.driver.js.map +1 -1
- package/dist/esm/src/drivers/index.d.ts +1 -0
- package/dist/esm/src/drivers/index.js +1 -0
- package/dist/esm/src/drivers/index.js.map +1 -1
- package/dist/esm/src/drivers/services/processRequest.d.ts +2 -0
- package/dist/esm/src/drivers/services/processRequest.js +41 -0
- package/dist/esm/src/drivers/services/processRequest.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/drivers/graphQLUpload/GraphQLUpload.ts +86 -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 +50 -0
- package/src/drivers/graphql.driver.ts +38 -23
- package/src/drivers/index.ts +1 -0
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/Readme.md
CHANGED
|
@@ -19,13 +19,6 @@ const app = await NestFactory.create<NestHonoApplication>(
|
|
|
19
19
|
AppModule,
|
|
20
20
|
new HonoAdapter()
|
|
21
21
|
);
|
|
22
|
-
|
|
23
|
-
// You can also pass your own instance of Hono app to the adapter
|
|
24
|
-
const hono = new Hono();
|
|
25
|
-
const app = await NestFactory.create<NestHonoApplication>(
|
|
26
|
-
AppModule,
|
|
27
|
-
new HonoAdapter(hono)
|
|
28
|
-
);
|
|
29
22
|
```
|
|
30
23
|
|
|
31
24
|
### Exception filters
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLUpload = void 0;
|
|
4
|
+
const Upload_1 = require("./Upload");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
exports.GraphQLUpload = new graphql_1.GraphQLScalarType({
|
|
7
|
+
name: "Upload",
|
|
8
|
+
description: "The `Upload` scalar type represents a file upload.",
|
|
9
|
+
parseValue(value) {
|
|
10
|
+
if (value instanceof Upload_1.Upload)
|
|
11
|
+
return value.promise;
|
|
12
|
+
throw new graphql_1.GraphQLError("Upload value invalid.");
|
|
13
|
+
},
|
|
14
|
+
parseLiteral(node) {
|
|
15
|
+
throw new graphql_1.GraphQLError("Upload literal unsupported.", { nodes: node });
|
|
16
|
+
},
|
|
17
|
+
serialize() {
|
|
18
|
+
throw new graphql_1.GraphQLError("Upload serialization unsupported.");
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=GraphQLUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphQLUpload.js","sourceRoot":"","sources":["../../../../../src/drivers/graphQLUpload/GraphQLUpload.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,qCAAmE;AAuEtD,QAAA,aAAa,GAAG,IAAI,2BAAiB,CAAC;IACjD,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,oDAAoD;IACjE,UAAU,CAAC,KAAmC;QAC5C,IAAI,KAAK,YAAY,eAAM;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC;QAClD,MAAM,IAAI,sBAAY,CAAC,uBAAuB,CAAC,CAAC;IAClD,CAAC;IACD,YAAY,CAAC,IAAyB;QACpC,MAAM,IAAI,sBAAY,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,SAAS;QACP,MAAM,IAAI,sBAAY,CAAC,mCAAmC,CAAC,CAAC;IAC9D,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReadStream, ReadStreamOptions, WriteStream } from "./fs-capacitor";
|
|
2
|
+
export interface FileUpload {
|
|
3
|
+
filename: string;
|
|
4
|
+
fieldName: string;
|
|
5
|
+
mimetype: string;
|
|
6
|
+
encoding: string;
|
|
7
|
+
createReadStream(options?: ReadStreamOptions): ReadStream;
|
|
8
|
+
capacitor: WriteStream;
|
|
9
|
+
}
|
|
10
|
+
export declare class Upload {
|
|
11
|
+
promise: Promise<FileUpload>;
|
|
12
|
+
resolve: (file?: FileUpload) => void;
|
|
13
|
+
reject: (error?: Error | string) => void;
|
|
14
|
+
file?: FileUpload;
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Upload = void 0;
|
|
4
|
+
class Upload {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.promise = new Promise((resolve, reject) => {
|
|
7
|
+
this.resolve = (file) => {
|
|
8
|
+
this.file = file;
|
|
9
|
+
resolve(file);
|
|
10
|
+
};
|
|
11
|
+
this.reject = reject;
|
|
12
|
+
});
|
|
13
|
+
this.promise.catch(() => { });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.Upload = Upload;
|
|
17
|
+
//# sourceMappingURL=Upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Upload.js","sourceRoot":"","sources":["../../../../../src/drivers/graphQLUpload/Upload.ts"],"names":[],"mappings":";;;AAaA,MAAa,MAAM;IAMjB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC7C,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,EAAE,EAAE;gBACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBAEjB,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,CAAC;YAEF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CAAC;QAIH,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;CACF;AArBD,wBAqBC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable, ReadableOptions, Writable, WritableOptions } from "stream";
|
|
4
|
+
export declare class ReadAfterDestroyedError extends Error {
|
|
5
|
+
}
|
|
6
|
+
export declare class ReadAfterReleasedError extends Error {
|
|
7
|
+
}
|
|
8
|
+
export interface ReadStreamOptions {
|
|
9
|
+
highWaterMark?: ReadableOptions["highWaterMark"];
|
|
10
|
+
encoding?: ReadableOptions["encoding"];
|
|
11
|
+
}
|
|
12
|
+
export declare class ReadStream extends Readable {
|
|
13
|
+
private _pos;
|
|
14
|
+
private _writeStream;
|
|
15
|
+
constructor(writeStream: WriteStream, options?: ReadStreamOptions);
|
|
16
|
+
_read(n: number): void;
|
|
17
|
+
}
|
|
18
|
+
export interface WriteStreamOptions {
|
|
19
|
+
highWaterMark?: WritableOptions["highWaterMark"];
|
|
20
|
+
defaultEncoding?: WritableOptions["defaultEncoding"];
|
|
21
|
+
tmpdir?: () => string;
|
|
22
|
+
}
|
|
23
|
+
export declare class WriteStream extends Writable {
|
|
24
|
+
private _fd;
|
|
25
|
+
private _path;
|
|
26
|
+
private _pos;
|
|
27
|
+
private _readStreams;
|
|
28
|
+
private _released;
|
|
29
|
+
constructor(options?: WriteStreamOptions);
|
|
30
|
+
_cleanup: (callback: (error: null | Error) => void) => void;
|
|
31
|
+
_cleanupSync: () => void;
|
|
32
|
+
_final(callback: (error?: null | Error) => any): void;
|
|
33
|
+
_write(chunk: Buffer, encoding: string, callback: (error?: null | Error) => any): void;
|
|
34
|
+
release(): void;
|
|
35
|
+
_destroy(error: undefined | null | Error, callback: (error?: null | Error) => any): void;
|
|
36
|
+
createReadStream(options?: ReadStreamOptions): ReadStream;
|
|
37
|
+
}
|
|
38
|
+
declare const _default: {
|
|
39
|
+
WriteStream: typeof WriteStream;
|
|
40
|
+
ReadStream: typeof ReadStream;
|
|
41
|
+
ReadAfterDestroyedError: typeof ReadAfterDestroyedError;
|
|
42
|
+
ReadAfterReleasedError: typeof ReadAfterReleasedError;
|
|
43
|
+
};
|
|
44
|
+
export default _default;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WriteStream = exports.ReadStream = exports.ReadAfterReleasedError = exports.ReadAfterDestroyedError = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const stream_1 = require("stream");
|
|
9
|
+
const events_1 = require("events");
|
|
10
|
+
class ReadAfterDestroyedError extends Error {
|
|
11
|
+
}
|
|
12
|
+
exports.ReadAfterDestroyedError = ReadAfterDestroyedError;
|
|
13
|
+
class ReadAfterReleasedError extends Error {
|
|
14
|
+
}
|
|
15
|
+
exports.ReadAfterReleasedError = ReadAfterReleasedError;
|
|
16
|
+
const processExitProxy = new events_1.EventEmitter();
|
|
17
|
+
processExitProxy.setMaxListeners(Infinity);
|
|
18
|
+
process.once("exit", () => processExitProxy.emit("exit"));
|
|
19
|
+
class ReadStream extends stream_1.Readable {
|
|
20
|
+
constructor(writeStream, options) {
|
|
21
|
+
super({
|
|
22
|
+
highWaterMark: options?.highWaterMark,
|
|
23
|
+
encoding: options?.encoding,
|
|
24
|
+
autoDestroy: true,
|
|
25
|
+
});
|
|
26
|
+
this._pos = 0;
|
|
27
|
+
this._writeStream = writeStream;
|
|
28
|
+
}
|
|
29
|
+
_read(n) {
|
|
30
|
+
if (this.destroyed)
|
|
31
|
+
return;
|
|
32
|
+
if (typeof this._writeStream["_fd"] !== "number") {
|
|
33
|
+
this._writeStream.once("ready", () => this._read(n));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const buf = Buffer.allocUnsafe(n);
|
|
37
|
+
(0, fs_1.read)(this._writeStream["_fd"], buf, 0, n, this._pos, (error, bytesRead) => {
|
|
38
|
+
if (error)
|
|
39
|
+
this.destroy(error);
|
|
40
|
+
if (bytesRead) {
|
|
41
|
+
this._pos += bytesRead;
|
|
42
|
+
this.push(buf.slice(0, bytesRead));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (this._writeStream._writableState.finished) {
|
|
46
|
+
if (this._pos < this._writeStream._pos)
|
|
47
|
+
this._read(n);
|
|
48
|
+
else
|
|
49
|
+
this.push(null);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const retry = () => {
|
|
53
|
+
this._writeStream.off("finish", retry);
|
|
54
|
+
this._writeStream.off("write", retry);
|
|
55
|
+
this._read(n);
|
|
56
|
+
};
|
|
57
|
+
this._writeStream.on("finish", retry);
|
|
58
|
+
this._writeStream.on("write", retry);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ReadStream = ReadStream;
|
|
63
|
+
class WriteStream extends stream_1.Writable {
|
|
64
|
+
constructor(options) {
|
|
65
|
+
super({
|
|
66
|
+
highWaterMark: options?.highWaterMark,
|
|
67
|
+
defaultEncoding: options?.defaultEncoding,
|
|
68
|
+
autoDestroy: false,
|
|
69
|
+
});
|
|
70
|
+
this._fd = null;
|
|
71
|
+
this._path = null;
|
|
72
|
+
this._pos = 0;
|
|
73
|
+
this._readStreams = new Set();
|
|
74
|
+
this._released = false;
|
|
75
|
+
this._cleanup = (callback) => {
|
|
76
|
+
const fd = this._fd;
|
|
77
|
+
const path = this._path;
|
|
78
|
+
if (typeof fd !== "number" || typeof path !== "string") {
|
|
79
|
+
callback(null);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
(0, fs_1.close)(fd, (closeError) => {
|
|
83
|
+
(0, fs_1.unlink)(path, (unlinkError) => {
|
|
84
|
+
this._fd = null;
|
|
85
|
+
processExitProxy.off("exit", this._cleanupSync);
|
|
86
|
+
callback(unlinkError ?? closeError);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
this._cleanupSync = () => {
|
|
91
|
+
processExitProxy.off("exit", this._cleanupSync);
|
|
92
|
+
if (typeof this._fd === "number")
|
|
93
|
+
try {
|
|
94
|
+
(0, fs_1.closeSync)(this._fd);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
if (this._path !== null) {
|
|
100
|
+
(0, fs_1.unlinkSync)(this._path);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
(0, crypto_1.randomBytes)(16, (error, buffer) => {
|
|
107
|
+
if (error) {
|
|
108
|
+
this.destroy(error);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this._path = (0, path_1.join)((options?.tmpdir ?? os_1.tmpdir)(), `capacitor-${buffer.toString("hex")}.tmp`);
|
|
112
|
+
(0, fs_1.open)(this._path, "wx+", 0o600, (error, fd) => {
|
|
113
|
+
if (error) {
|
|
114
|
+
this.destroy(error);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
processExitProxy.once("exit", this._cleanupSync);
|
|
118
|
+
this._fd = fd;
|
|
119
|
+
this.emit("ready");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
_final(callback) {
|
|
124
|
+
if (typeof this._fd !== "number") {
|
|
125
|
+
this.once("ready", () => this._final(callback));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
callback();
|
|
129
|
+
}
|
|
130
|
+
_write(chunk, encoding, callback) {
|
|
131
|
+
if (typeof this._fd !== "number") {
|
|
132
|
+
this.once("ready", () => this._write(chunk, encoding, callback));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
(0, fs_1.write)(this._fd, chunk, 0, chunk.length, this._pos, (error) => {
|
|
136
|
+
if (error) {
|
|
137
|
+
callback(error);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this._pos += chunk.length;
|
|
141
|
+
this.emit("write");
|
|
142
|
+
callback();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
release() {
|
|
146
|
+
this._released = true;
|
|
147
|
+
if (this._readStreams.size === 0)
|
|
148
|
+
this.destroy();
|
|
149
|
+
}
|
|
150
|
+
_destroy(error, callback) {
|
|
151
|
+
for (const readStream of this._readStreams) {
|
|
152
|
+
readStream.destroy(error || undefined);
|
|
153
|
+
}
|
|
154
|
+
if (typeof this._fd === "number" && typeof this._path === "string") {
|
|
155
|
+
this._cleanup((cleanupError) => callback(cleanupError ?? error));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
this.once("ready", () => {
|
|
159
|
+
this._cleanup((cleanupError) => {
|
|
160
|
+
if (cleanupError) {
|
|
161
|
+
this.emit("error", cleanupError);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
callback(error);
|
|
166
|
+
}
|
|
167
|
+
createReadStream(options) {
|
|
168
|
+
if (this.destroyed)
|
|
169
|
+
throw new ReadAfterDestroyedError("A ReadStream cannot be created from a destroyed WriteStream.");
|
|
170
|
+
if (this._released)
|
|
171
|
+
throw new ReadAfterReleasedError("A ReadStream cannot be created from a released WriteStream.");
|
|
172
|
+
const readStream = new ReadStream(this, options);
|
|
173
|
+
this._readStreams.add(readStream);
|
|
174
|
+
readStream.once("close", () => {
|
|
175
|
+
this._readStreams.delete(readStream);
|
|
176
|
+
if (this._released && this._readStreams.size === 0) {
|
|
177
|
+
this.destroy();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
return readStream;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.WriteStream = WriteStream;
|
|
184
|
+
exports.default = {
|
|
185
|
+
WriteStream,
|
|
186
|
+
ReadStream,
|
|
187
|
+
ReadAfterDestroyedError,
|
|
188
|
+
ReadAfterReleasedError,
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=fs-capacitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-capacitor.js","sourceRoot":"","sources":["../../../../../src/drivers/graphQLUpload/fs-capacitor.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AACrC,2BAA6E;AAC7E,2BAA4B;AAC5B,+BAA4B;AAC5B,mCAA8E;AAC9E,mCAAsC;AAEtC,MAAa,uBAAwB,SAAQ,KAAK;CAAG;AAArD,0DAAqD;AACrD,MAAa,sBAAuB,SAAQ,KAAK;CAAG;AAApD,wDAAoD;AAWpD,MAAM,gBAAgB,GAAG,IAAI,qBAAY,EAAE,CAAC;AAC5C,gBAAgB,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AAC3C,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAE1D,M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,UAAU,CAAC,CAAC;QAElC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,GAAS,EAAE;YAClC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAErC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACnD,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAvLD,kCAuLC;AAED,kBAAe;IACb,WAAW;IACX,UAAU;IACV,uBAAuB;IACvB,sBAAsB;CACvB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fs-capacitor"), exports);
|
|
18
|
+
__exportStar(require("./Upload"), exports);
|
|
19
|
+
__exportStar(require("./GraphQLUpload"), exports);
|
|
20
|
+
__exportStar(require("./processRequest"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drivers/graphQLUpload/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,2CAAyB;AACzB,kDAAgC;AAChC,mDAAiC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processRequest = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
async function processRequest(ctx) {
|
|
7
|
+
const body = await ctx.req.parseBody();
|
|
8
|
+
const operations = JSON.parse(body.operations);
|
|
9
|
+
const map = new Map(Object.entries(JSON.parse(body.map)));
|
|
10
|
+
for (const [fieldName, file] of Object.entries(body)) {
|
|
11
|
+
if (fieldName === "operations" ||
|
|
12
|
+
fieldName === "map" ||
|
|
13
|
+
!(file instanceof File))
|
|
14
|
+
continue;
|
|
15
|
+
const fileKeys = map.get(fieldName);
|
|
16
|
+
if (!Array.isArray(fileKeys) || !fileKeys.length)
|
|
17
|
+
continue;
|
|
18
|
+
const buffer = Buffer.from(await file.arrayBuffer());
|
|
19
|
+
const capacitor = new _1.WriteStream();
|
|
20
|
+
stream_1.Readable.from(buffer).pipe(capacitor);
|
|
21
|
+
const upload = new _1.Upload();
|
|
22
|
+
upload.file = {
|
|
23
|
+
filename: file.name,
|
|
24
|
+
mimetype: file.type,
|
|
25
|
+
fieldName,
|
|
26
|
+
encoding: "7bit",
|
|
27
|
+
createReadStream: (options) => capacitor.createReadStream(options),
|
|
28
|
+
capacitor,
|
|
29
|
+
};
|
|
30
|
+
upload.resolve(upload.file);
|
|
31
|
+
for (const fileKey of fileKeys) {
|
|
32
|
+
const pathSegments = fileKey.split(".");
|
|
33
|
+
let current = operations;
|
|
34
|
+
for (let i = 0; i < pathSegments.length - 1; i++) {
|
|
35
|
+
if (!current[pathSegments[i]])
|
|
36
|
+
current[pathSegments[i]] = {};
|
|
37
|
+
current = current[pathSegments[i]];
|
|
38
|
+
}
|
|
39
|
+
current[pathSegments[pathSegments.length - 1]] = upload;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return operations;
|
|
43
|
+
}
|
|
44
|
+
exports.processRequest = processRequest;
|
|
45
|
+
//# sourceMappingURL=processRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../../../../src/drivers/graphQLUpload/processRequest.ts"],"names":[],"mappings":";;;AACA,wBAAwC;AACxC,mCAAkC;AAE3B,KAAK,UAAU,cAAc,CAClC,GAAY;IAEZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAoB,CAAC,CAAC;IACzD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAa,CAAC,CAAC,CAAC,CAAC;IAEpE,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,IACE,SAAS,KAAK,YAAY;YAC1B,SAAS,KAAK,KAAK;YACnB,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC;YAEvB,SAAS;QAEX,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,SAAS;QAE3D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACrD,MAAM,SAAS,GAAG,IAAI,cAAW,EAAE,CAAC;QACpC,i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|
|
3
|
+
import { ModulesContainer } from "@nestjs/core";
|
|
4
|
+
import { AbstractGraphQLDriver } from "@nestjs/graphql";
|
|
5
|
+
import { ApolloDriverConfig } from "@nestjs/apollo";
|
|
6
|
+
import http from "http";
|
|
5
7
|
export declare class HonoGraphQLDriver<T extends Record<string, any> = ApolloDriverConfig> extends AbstractGraphQLDriver {
|
|
6
8
|
protected apolloServer: ApolloServer<BaseContext>;
|
|
7
9
|
private _subscriptionService?;
|
|
@@ -15,6 +17,7 @@ export declare class HonoGraphQLDriver<T extends Record<string, any> = ApolloDri
|
|
|
15
17
|
stop(): Promise<void>;
|
|
16
18
|
private httpHeadersToMap;
|
|
17
19
|
private parseBody;
|
|
20
|
+
headersToRecord(headers: Headers): http.IncomingHttpHeaders;
|
|
18
21
|
private logError;
|
|
19
22
|
private parseFormURL;
|
|
20
23
|
}
|
|
@@ -6,6 +6,7 @@ const graphql_1 = require("@nestjs/graphql");
|
|
|
6
6
|
const drainHttpServer_1 = require("@apollo/server/plugin/drainHttpServer");
|
|
7
7
|
const common_1 = require("@nestjs/common");
|
|
8
8
|
const plugins_explorer_service_1 = require("./services/plugins-explorer.service");
|
|
9
|
+
const graphQLUpload_1 = require("./graphQLUpload");
|
|
9
10
|
class HonoGraphQLDriver extends graphql_1.AbstractGraphQLDriver {
|
|
10
11
|
constructor(modulesContainer) {
|
|
11
12
|
super();
|
|
@@ -17,12 +18,12 @@ class HonoGraphQLDriver extends graphql_1.AbstractGraphQLDriver {
|
|
|
17
18
|
async start(options) {
|
|
18
19
|
const { httpAdapter } = this.httpAdapterHost;
|
|
19
20
|
const platformName = httpAdapter.getType();
|
|
20
|
-
if (platformName !==
|
|
21
|
-
throw new Error(
|
|
21
|
+
if (platformName !== "hono") {
|
|
22
|
+
throw new Error("This driver is only compatible with the Hono platform");
|
|
22
23
|
}
|
|
23
24
|
await this.registerHono(options);
|
|
24
25
|
if (options.installSubscriptionHandlers || options.subscriptions) {
|
|
25
|
-
const subscriptionsOptions = options.subscriptions || {
|
|
26
|
+
const subscriptionsOptions = options.subscriptions || { "subscriptions-transport-ws": {} };
|
|
26
27
|
this._subscriptionService = new graphql_1.GqlSubscriptionService({
|
|
27
28
|
schema: options.schema,
|
|
28
29
|
path: options.path,
|
|
@@ -48,7 +49,7 @@ class HonoGraphQLDriver extends graphql_1.AbstractGraphQLDriver {
|
|
|
48
49
|
});
|
|
49
50
|
await server.start();
|
|
50
51
|
app.use(path, async (ctx) => {
|
|
51
|
-
const bodyData = await this.parseBody(ctx
|
|
52
|
+
const bodyData = await this.parseBody(ctx);
|
|
52
53
|
const defaultContext = () => Promise.resolve({});
|
|
53
54
|
const contextFunction = options?.context ?? defaultContext;
|
|
54
55
|
const httpGraphQLResponse = await server.executeHTTPGraphQLRequest({
|
|
@@ -70,7 +71,7 @@ class HonoGraphQLDriver extends graphql_1.AbstractGraphQLDriver {
|
|
|
70
71
|
ctx.header(headerKey, headerValue);
|
|
71
72
|
}
|
|
72
73
|
ctx.status(status === undefined ? 200 : status);
|
|
73
|
-
if (body.kind ===
|
|
74
|
+
if (body.kind === "complete") {
|
|
74
75
|
return ctx.body(body.string);
|
|
75
76
|
}
|
|
76
77
|
const readableStream = new ReadableStream({
|
|
@@ -82,7 +83,7 @@ class HonoGraphQLDriver extends graphql_1.AbstractGraphQLDriver {
|
|
|
82
83
|
},
|
|
83
84
|
});
|
|
84
85
|
return new Response(readableStream, {
|
|
85
|
-
headers: {
|
|
86
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
86
87
|
});
|
|
87
88
|
});
|
|
88
89
|
this.apolloServer = server;
|
|
@@ -96,16 +97,27 @@ class HonoGraphQLDriver extends graphql_1.AbstractGraphQLDriver {
|
|
|
96
97
|
headers.forEach((value, key) => map.set(key, value));
|
|
97
98
|
return map;
|
|
98
99
|
}
|
|
99
|
-
async parseBody(
|
|
100
|
-
const
|
|
101
|
-
|
|
100
|
+
async parseBody(ctx) {
|
|
101
|
+
const req = ctx.req;
|
|
102
|
+
const contentType = req.header("content-type");
|
|
103
|
+
if (contentType === "application/graphql")
|
|
102
104
|
return { query: await req.text() };
|
|
103
|
-
if (contentType ===
|
|
105
|
+
if (contentType === "application/json")
|
|
104
106
|
return req.json().catch(this.logError);
|
|
105
|
-
if (contentType ===
|
|
107
|
+
if (contentType === "application/x-www-form-urlencoded")
|
|
106
108
|
return this.parseFormURL(req);
|
|
109
|
+
if (contentType?.startsWith("multipart/form-data")) {
|
|
110
|
+
return (0, graphQLUpload_1.processRequest)(ctx);
|
|
111
|
+
}
|
|
107
112
|
return {};
|
|
108
113
|
}
|
|
114
|
+
headersToRecord(headers) {
|
|
115
|
+
const obj = {};
|
|
116
|
+
headers.forEach((value, key) => {
|
|
117
|
+
obj[key] = value;
|
|
118
|
+
});
|
|
119
|
+
return obj;
|
|
120
|
+
}
|
|
109
121
|
logError(e) {
|
|
110
122
|
if (e instanceof Error) {
|
|
111
123
|
common_1.Logger.error(e.stack || e.message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.driver.js","sourceRoot":"","sources":["../../../../src/drivers/graphql.driver.ts"],"names":[],"mappings":";;;AAAA,2CAAsE;
|
|
1
|
+
{"version":3,"file":"graphql.driver.js","sourceRoot":"","sources":["../../../../src/drivers/graphql.driver.ts"],"names":[],"mappings":";;;AAAA,2CAAsE;AAEtE,6CAIyB;AACzB,2EAA0F;AAI1F,2CAAwC;AAGxC,kFAA6E;AAC7E,mDAAiD;AAEjD,MAAa,iBAEX,SAAQ,+BAAqB;IAK7B,YAAY,gBAAkC;QAC5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,sBAAsB,GAAG,IAAI,iDAAsB,CAAC,gBAAgB,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAU;QACpB,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QAC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O,EAAE,CAAC,CAAC;IACpD,CAAC;CACF;AAlKD,8CAkKC"}
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./graphql.driver"), exports);
|
|
18
|
+
__exportStar(require("./graphQLUpload"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/drivers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/drivers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,kDAAgC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processRequest = void 0;
|
|
4
|
+
const graphql_upload_ts_1 = require("graphql-upload-ts");
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
async function processRequest(ctx) {
|
|
7
|
+
const body = await ctx.req.parseBody();
|
|
8
|
+
const operations = JSON.parse(body.operations);
|
|
9
|
+
const map = new Map(Object.entries(JSON.parse(body.map)));
|
|
10
|
+
for (const [fieldName, file] of Object.entries(body)) {
|
|
11
|
+
if (fieldName === 'operations' ||
|
|
12
|
+
fieldName === 'map' ||
|
|
13
|
+
!(file instanceof File))
|
|
14
|
+
continue;
|
|
15
|
+
const fileKeys = map.get(fieldName);
|
|
16
|
+
if (!Array.isArray(fileKeys) || !fileKeys.length)
|
|
17
|
+
continue;
|
|
18
|
+
const buffer = Buffer.from(await file.arrayBuffer());
|
|
19
|
+
const capacitor = new graphql_upload_ts_1.WriteStream();
|
|
20
|
+
stream_1.Readable.from(buffer).pipe(capacitor);
|
|
21
|
+
const upload = new graphql_upload_ts_1.Upload();
|
|
22
|
+
upload.file = {
|
|
23
|
+
filename: file.name,
|
|
24
|
+
mimetype: file.type,
|
|
25
|
+
fieldName,
|
|
26
|
+
encoding: '7bit',
|
|
27
|
+
createReadStream: (options) => capacitor.createReadStream(options),
|
|
28
|
+
capacitor,
|
|
29
|
+
};
|
|
30
|
+
upload.resolve(upload.file);
|
|
31
|
+
for (const fileKey of fileKeys) {
|
|
32
|
+
const pathSegments = fileKey.split('.');
|
|
33
|
+
let current = operations;
|
|
34
|
+
for (let i = 0; i < pathSegments.length - 1; i++) {
|
|
35
|
+
if (!current[pathSegments[i]])
|
|
36
|
+
current[pathSegments[i]] = {};
|
|
37
|
+
current = current[pathSegments[i]];
|
|
38
|
+
}
|
|
39
|
+
current[pathSegments[pathSegments.length - 1]] = upload;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return operations;
|
|
43
|
+
}
|
|
44
|
+
exports.processRequest = processRequest;
|
|
45
|
+
//# sourceMappingURL=processRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../../../../src/drivers/services/processRequest.ts"],"names":[],"mappings":";;;AACA,yDAAwD;AACxD,mCAAkC;AAE3B,KAAK,UAAU,cAAc,CAClC,GAAY;IAEZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAoB,CAAC,CAAC;IACzD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAa,CAAC,CAAC,CAAC,CAAC;IAEpE,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,IACE,SAAS,KAAK,YAAY;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