grafserv 0.0.1-0.2 → 0.0.1-0.21
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/CHANGELOG.md +220 -0
- package/README.md +248 -3
- package/dist/accept.d.ts +8 -0
- package/dist/accept.d.ts.map +1 -0
- package/dist/accept.js +419 -0
- package/dist/accept.js.map +1 -0
- package/dist/core/base.d.ts +38 -0
- package/dist/core/base.d.ts.map +1 -0
- package/dist/core/base.js +440 -0
- package/dist/core/base.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +176 -23
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js +2 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/mapIterator.d.ts +2 -0
- package/dist/mapIterator.d.ts.map +1 -0
- package/dist/mapIterator.js +65 -0
- package/dist/mapIterator.js.map +1 -0
- package/dist/middleware/graphiql.d.ts +3 -3
- package/dist/middleware/graphiql.d.ts.map +1 -1
- package/dist/middleware/graphiql.js +14 -4
- package/dist/middleware/graphiql.js.map +1 -1
- package/dist/middleware/graphql.d.ts +8 -3
- package/dist/middleware/graphql.d.ts.map +1 -1
- package/dist/middleware/graphql.js +325 -23
- package/dist/middleware/graphql.js.map +1 -1
- package/dist/options.d.ts +23 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +114 -0
- package/dist/options.js.map +1 -0
- package/dist/servers/express/v4/index.d.ts +24 -0
- package/dist/servers/express/v4/index.d.ts.map +1 -0
- package/dist/servers/express/v4/index.js +62 -0
- package/dist/servers/express/v4/index.js.map +1 -0
- package/dist/servers/fastify/v4/index.d.ts +21 -0
- package/dist/servers/fastify/v4/index.d.ts.map +1 -0
- package/dist/servers/fastify/v4/index.js +198 -0
- package/dist/servers/fastify/v4/index.js.map +1 -0
- package/dist/servers/koa/v2/index.d.ts +25 -0
- package/dist/servers/koa/v2/index.d.ts.map +1 -0
- package/dist/servers/koa/v2/index.js +137 -0
- package/dist/servers/koa/v2/index.js.map +1 -0
- package/dist/servers/node/index.d.ts +32 -0
- package/dist/servers/node/index.d.ts.map +1 -0
- package/dist/servers/node/index.js +269 -0
- package/dist/servers/node/index.js.map +1 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +145 -0
- package/dist/utils.js.map +1 -0
- package/package.json +42 -8
- package/dist/middleware/index.d.ts +0 -12
- package/dist/middleware/index.d.ts.map +0 -1
- package/dist/middleware/index.js +0 -431
- package/dist/middleware/index.js.map +0 -1
- package/dist/middleware/interfaces.d.ts +0 -40
- package/dist/middleware/interfaces.d.ts.map +0 -1
- package/dist/middleware/interfaces.js +0 -3
- package/dist/middleware/interfaces.js.map +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grafserv = exports.ExpressGrafserv = void 0;
|
|
4
|
+
const utils_js_1 = require("../../../utils.js");
|
|
5
|
+
const index_js_1 = require("../../node/index.js");
|
|
6
|
+
class ExpressGrafserv extends index_js_1.NodeGrafservBase {
|
|
7
|
+
getDigest(dynamicOptions, req, res) {
|
|
8
|
+
return {
|
|
9
|
+
httpVersionMajor: req.httpVersionMajor,
|
|
10
|
+
httpVersionMinor: req.httpVersionMinor,
|
|
11
|
+
isSecure: req.secure,
|
|
12
|
+
method: req.method,
|
|
13
|
+
path: req.path,
|
|
14
|
+
headers: (0, utils_js_1.processHeaders)(req.headers),
|
|
15
|
+
getQueryParams() {
|
|
16
|
+
return req.query;
|
|
17
|
+
},
|
|
18
|
+
getBody() {
|
|
19
|
+
if (req.body != null) {
|
|
20
|
+
return (0, utils_js_1.getBodyFromFrameworkBody)(req.body);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return (0, utils_js_1.getBodyFromRequest)(req, dynamicOptions.maxRequestLength);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
requestContext: {
|
|
27
|
+
node: {
|
|
28
|
+
req,
|
|
29
|
+
res,
|
|
30
|
+
},
|
|
31
|
+
expressv4: {
|
|
32
|
+
req,
|
|
33
|
+
res,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async addTo(app, server) {
|
|
39
|
+
app.use(this._createHandler());
|
|
40
|
+
if (this.resolvedPreset.grafserv?.websockets) {
|
|
41
|
+
if (server) {
|
|
42
|
+
// If user explicitly passes server, bind to it:
|
|
43
|
+
(0, index_js_1.attachWebsocketsToServer)(this, server);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// If not, hope they're calling `app.listen()` and intercept that call.
|
|
47
|
+
const oldListen = app.listen;
|
|
48
|
+
app.listen = (...args) => {
|
|
49
|
+
const server = oldListen.apply(app, args);
|
|
50
|
+
(0, index_js_1.attachWebsocketsToServer)(this, server);
|
|
51
|
+
return server;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.ExpressGrafserv = ExpressGrafserv;
|
|
58
|
+
function grafserv(config) {
|
|
59
|
+
return new ExpressGrafserv(config);
|
|
60
|
+
}
|
|
61
|
+
exports.grafserv = grafserv;
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/servers/express/v4/index.ts"],"names":[],"mappings":";;;AAMA,gDAI2B;AAC3B,kDAG6B;AAa7B,MAAa,eAAgB,SAAQ,2BAAgB;IACzC,SAAS,CACjB,cAAiC,EACjC,GAAY,EACZ,GAAa;QAEb,OAAO;YACL,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;YACtC,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;YACtC,QAAQ,EAAE,GAAG,CAAC,MAAM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CAAC,MAAsB;IAC7C,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAFD,4BAEC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
3
|
+
import { GrafservBase } from "../../../core/base.js";
|
|
4
|
+
import type { GrafservConfig, Result } from "../../../interfaces.js";
|
|
5
|
+
declare global {
|
|
6
|
+
namespace Grafast {
|
|
7
|
+
interface RequestContext {
|
|
8
|
+
fastifyv4: {
|
|
9
|
+
request: FastifyRequest;
|
|
10
|
+
reply: FastifyReply;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare class FastifyGrafserv extends GrafservBase {
|
|
16
|
+
constructor(config: GrafservConfig);
|
|
17
|
+
send(request: FastifyRequest, reply: FastifyReply, result: Result | null): Promise<Buffer | import("../../../interfaces.js").JSONValue>;
|
|
18
|
+
addTo(app: FastifyInstance): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function grafserv(config: GrafservConfig): FastifyGrafserv;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/servers/fastify/v4/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI7E,OAAO,EAEL,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAEV,cAAc,EAEd,MAAM,EACP,MAAM,wBAAwB,CAAC;AAQhC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,cAAc;YACtB,SAAS,EAAE;gBACT,OAAO,EAAE,cAAc,CAAC;gBACxB,KAAK,EAAE,YAAY,CAAC;aACrB,CAAC;SACH;KACF;CACF;AAkCD,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,MAAM,EAAE,cAAc;IAIrB,IAAI,CACf,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,GAAG,IAAI;IAsFjB,KAAK,CAAC,GAAG,EAAE,eAAe;CA6EjC;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,mBAE9C"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grafserv = exports.FastifyGrafserv = void 0;
|
|
4
|
+
const websocket_1 = require("graphql-ws/lib/use/@fastify/websocket");
|
|
5
|
+
const node_stream_1 = require("node:stream");
|
|
6
|
+
const base_js_1 = require("../../../core/base.js");
|
|
7
|
+
const utils_js_1 = require("../../../utils.js");
|
|
8
|
+
function getDigest(request, reply) {
|
|
9
|
+
return {
|
|
10
|
+
httpVersionMajor: request.raw.httpVersionMajor,
|
|
11
|
+
httpVersionMinor: request.raw.httpVersionMinor,
|
|
12
|
+
// TODO: check Fastify respects X-Forwarded-Proto when configured to trust the proxy
|
|
13
|
+
isSecure: request.protocol === "https",
|
|
14
|
+
method: request.method,
|
|
15
|
+
path: request.url,
|
|
16
|
+
headers: (0, utils_js_1.processHeaders)(request.headers),
|
|
17
|
+
getQueryParams() {
|
|
18
|
+
return request.query;
|
|
19
|
+
},
|
|
20
|
+
getBody() {
|
|
21
|
+
return (0, utils_js_1.getBodyFromFrameworkBody)(request.body);
|
|
22
|
+
},
|
|
23
|
+
requestContext: {
|
|
24
|
+
node: {
|
|
25
|
+
req: request.raw,
|
|
26
|
+
res: reply.raw,
|
|
27
|
+
},
|
|
28
|
+
fastifyv4: {
|
|
29
|
+
request,
|
|
30
|
+
reply,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
preferJSON: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
class FastifyGrafserv extends base_js_1.GrafservBase {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
super(config);
|
|
39
|
+
}
|
|
40
|
+
async send(request, reply, result) {
|
|
41
|
+
if (result === null) {
|
|
42
|
+
// 404
|
|
43
|
+
reply.statusCode = 404;
|
|
44
|
+
return "¯\\_(ツ)_/¯";
|
|
45
|
+
}
|
|
46
|
+
switch (result.type) {
|
|
47
|
+
case "error": {
|
|
48
|
+
const { statusCode, headers } = result;
|
|
49
|
+
reply.headers(headers);
|
|
50
|
+
reply.statusCode = statusCode;
|
|
51
|
+
// TODO: mutating the error is probably bad form...
|
|
52
|
+
const errorWithStatus = Object.assign(result.error, {
|
|
53
|
+
status: statusCode,
|
|
54
|
+
});
|
|
55
|
+
throw errorWithStatus;
|
|
56
|
+
}
|
|
57
|
+
case "buffer": {
|
|
58
|
+
const { statusCode, headers, buffer } = result;
|
|
59
|
+
reply.headers(headers);
|
|
60
|
+
reply.statusCode = statusCode;
|
|
61
|
+
return buffer;
|
|
62
|
+
}
|
|
63
|
+
case "json": {
|
|
64
|
+
const { statusCode, headers, json } = result;
|
|
65
|
+
reply.headers(headers);
|
|
66
|
+
reply.statusCode = statusCode;
|
|
67
|
+
return json;
|
|
68
|
+
}
|
|
69
|
+
case "noContent": {
|
|
70
|
+
const { statusCode, headers } = result;
|
|
71
|
+
reply.headers(headers);
|
|
72
|
+
reply.statusCode = statusCode;
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
case "bufferStream": {
|
|
76
|
+
const { statusCode, headers, lowLatency, bufferIterator } = result;
|
|
77
|
+
if (lowLatency) {
|
|
78
|
+
request.raw.socket.setTimeout(0);
|
|
79
|
+
request.raw.socket.setNoDelay(true);
|
|
80
|
+
request.raw.socket.setKeepAlive(true);
|
|
81
|
+
}
|
|
82
|
+
reply.headers(headers);
|
|
83
|
+
reply.statusCode = statusCode;
|
|
84
|
+
const stream = new node_stream_1.PassThrough();
|
|
85
|
+
reply.send(stream);
|
|
86
|
+
// Fork off and convert bufferIterator to
|
|
87
|
+
try {
|
|
88
|
+
for await (const buffer of bufferIterator) {
|
|
89
|
+
stream.write(buffer);
|
|
90
|
+
}
|
|
91
|
+
stream.end();
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
try {
|
|
95
|
+
stream.end();
|
|
96
|
+
}
|
|
97
|
+
catch (e2) {
|
|
98
|
+
/* nom nom nom */
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
// TODO: what should we really do here?
|
|
102
|
+
if (bufferIterator.return) {
|
|
103
|
+
bufferIterator.return();
|
|
104
|
+
}
|
|
105
|
+
else if (bufferIterator.throw) {
|
|
106
|
+
bufferIterator.throw(e);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e2) {
|
|
110
|
+
/* nom nom nom */
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return reply;
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
const never = result;
|
|
117
|
+
console.log("Unhandled:");
|
|
118
|
+
console.dir(never);
|
|
119
|
+
reply.type("text/plain");
|
|
120
|
+
reply.statusCode = 503;
|
|
121
|
+
return "Server hasn't implemented this yet";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async addTo(app) {
|
|
126
|
+
// application/graphql-request+json isn't currently an official serialization format:
|
|
127
|
+
// https://graphql.github.io/graphql-over-http/draft/#sec-Media-Types
|
|
128
|
+
/*
|
|
129
|
+
app.addContentTypeParser(
|
|
130
|
+
"application/graphql-request+json",
|
|
131
|
+
{ parseAs: "string" },
|
|
132
|
+
app.getDefaultJsonParser("ignore", "ignore"),
|
|
133
|
+
);
|
|
134
|
+
*/
|
|
135
|
+
const dynamicOptions = this.dynamicOptions;
|
|
136
|
+
app.route({
|
|
137
|
+
method: this.dynamicOptions.graphqlOverGET ||
|
|
138
|
+
this.dynamicOptions.graphiqlOnGraphQLGET
|
|
139
|
+
? ["GET", "POST"]
|
|
140
|
+
: ["POST"],
|
|
141
|
+
url: this.dynamicOptions.graphqlPath,
|
|
142
|
+
exposeHeadRoute: true,
|
|
143
|
+
bodyLimit: this.dynamicOptions.maxRequestLength,
|
|
144
|
+
handler: async (request, reply) => {
|
|
145
|
+
const digest = getDigest(request, reply);
|
|
146
|
+
const handlerResult = await this.graphqlHandler((0, utils_js_1.normalizeRequest)(digest), this.graphiqlHandler);
|
|
147
|
+
const result = await (0, base_js_1.convertHandlerResultToResult)(handlerResult);
|
|
148
|
+
return this.send(request, reply, result);
|
|
149
|
+
},
|
|
150
|
+
...(this.resolvedPreset.grafserv?.websockets
|
|
151
|
+
? {
|
|
152
|
+
wsHandler: (0, websocket_1.makeHandler)((0, utils_js_1.makeGraphQLWSConfig)(this)),
|
|
153
|
+
}
|
|
154
|
+
: null),
|
|
155
|
+
});
|
|
156
|
+
if (dynamicOptions.graphiql) {
|
|
157
|
+
app.route({
|
|
158
|
+
method: "GET",
|
|
159
|
+
url: this.dynamicOptions.graphiqlPath,
|
|
160
|
+
exposeHeadRoute: true,
|
|
161
|
+
bodyLimit: this.dynamicOptions.maxRequestLength,
|
|
162
|
+
handler: async (request, reply) => {
|
|
163
|
+
const digest = getDigest(request, reply);
|
|
164
|
+
const handlerResult = await this.graphiqlHandler((0, utils_js_1.normalizeRequest)(digest));
|
|
165
|
+
const result = await (0, base_js_1.convertHandlerResultToResult)(handlerResult);
|
|
166
|
+
return this.send(request, reply, result);
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (dynamicOptions.watch) {
|
|
171
|
+
app.route({
|
|
172
|
+
method: "GET",
|
|
173
|
+
url: this.dynamicOptions.eventStreamRoute,
|
|
174
|
+
exposeHeadRoute: true,
|
|
175
|
+
bodyLimit: this.dynamicOptions.maxRequestLength,
|
|
176
|
+
handler: async (request, reply) => {
|
|
177
|
+
const digest = getDigest(request, reply);
|
|
178
|
+
// TODO: refactor this to use the eventStreamHandler once we write that...
|
|
179
|
+
const handlerResult = {
|
|
180
|
+
type: "event-stream",
|
|
181
|
+
request: (0, utils_js_1.normalizeRequest)(digest),
|
|
182
|
+
dynamicOptions,
|
|
183
|
+
payload: this.makeStream(),
|
|
184
|
+
statusCode: 200,
|
|
185
|
+
};
|
|
186
|
+
const result = await (0, base_js_1.convertHandlerResultToResult)(handlerResult);
|
|
187
|
+
return this.send(request, reply, result);
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.FastifyGrafserv = FastifyGrafserv;
|
|
194
|
+
function grafserv(config) {
|
|
195
|
+
return new FastifyGrafserv(config);
|
|
196
|
+
}
|
|
197
|
+
exports.grafserv = grafserv;
|
|
198
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/servers/fastify/v4/index.ts"],"names":[],"mappings":";;;AACA,qEAAoE;AACpE,6CAA0C;AAE1C,mDAG+B;AAO/B,gDAK2B;AAa3B,SAAS,SAAS,CAChB,OAAuB,EACvB,KAAmB;IAEnB,OAAO;QACL,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;QAC9C,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;QAC9C,oFAAoF;QACpF,QAAQ,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;QACtC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,OAAO,CAAC,GAAG;QACjB,OAAO,EAAE,IAAA,yBAAc,EAAC,OAAO,CAAC,OAAO,CAAC;QACxC,cAAc;YACZ,OAAO,OAAO,CAAC,KAA+B,CAAC;QACjD,CAAC;QACD,OAAO;YACL,OAAO,IAAA,mCAAwB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC;QACD,cAAc,EAAE;YACd,IAAI,EAAE;gBACJ,GAAG,EAAE,OAAO,CA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K,EAAE,EAAE;oBAChC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;oBACzC,0EAA0E;oBAC1E,MAAM,aAAa,GAA8B;wBAC/C,IAAI,EAAE,cAAc;wBACpB,OAAO,EAAE,IAAA,2BAAgB,EAAC,MAAM,CAAC;wBACjC,cAAc;wBACd,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;wBAC1B,UAAU,EAAE,GAAG;qBAChB,CAAC;oBACF,MAAM,MAAM,GAAG,MAAM,IAAA,sCAA4B,EAAC,aAAa,CAAC,CAAC;oBACjE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;gBAC3C,CAAC;aACF,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AA3KD,0CA2KC;AAED,SAAgB,QAAQ,CAAC,MAAsB;IAC7C,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAFD,4BAEC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="koa-bodyparser" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { Context } from "koa";
|
|
5
|
+
import type Koa from "koa";
|
|
6
|
+
import type { Server as HTTPServer } from "node:http";
|
|
7
|
+
import type { Server as HTTPSServer } from "node:https";
|
|
8
|
+
import { GrafservBase } from "../../../core/base.js";
|
|
9
|
+
import type { GrafservConfig } from "../../../interfaces.js";
|
|
10
|
+
declare global {
|
|
11
|
+
namespace Grafast {
|
|
12
|
+
interface RequestContext {
|
|
13
|
+
koav2: {
|
|
14
|
+
ctx: Context;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export declare class KoaGrafserv extends GrafservBase {
|
|
20
|
+
constructor(config: GrafservConfig);
|
|
21
|
+
protected _createHandler(): (ctx: Context, next: (err?: Error) => void) => void;
|
|
22
|
+
addTo(app: Koa, server: HTTPServer | HTTPSServer | null): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function grafserv(config: GrafservConfig): KoaGrafserv;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/servers/koa/v2/index.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,wBAAwB,CAAC;AAS5E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,cAAc;YACtB,KAAK,EAAE;gBACL,GAAG,EAAE,OAAO,CAAC;aACd,CAAC;SACH;KACF;CACF;AAsCD,qBAAa,WAAY,SAAQ,YAAY;gBAC/B,MAAM,EAAE,cAAc;IAIlC,SAAS,CAAC,cAAc,IAAI,CAC1B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,KACxB,IAAI;IAwEH,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI;CAiB9D;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,eAE9C"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grafserv = exports.KoaGrafserv = void 0;
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
|
+
const base_js_1 = require("../../../core/base.js");
|
|
6
|
+
const utils_js_1 = require("../../../utils.js");
|
|
7
|
+
const index_js_1 = require("../../node/index.js");
|
|
8
|
+
function getDigest(dynamicOptions, ctx) {
|
|
9
|
+
return {
|
|
10
|
+
httpVersionMajor: ctx.req.httpVersionMajor,
|
|
11
|
+
httpVersionMinor: ctx.req.httpVersionMinor,
|
|
12
|
+
// TODO: check Koa respects X-Forwarded-Proto when configured to trust the proxy
|
|
13
|
+
isSecure: ctx.secure,
|
|
14
|
+
method: ctx.request.method,
|
|
15
|
+
path: ctx.request.url,
|
|
16
|
+
headers: (0, utils_js_1.processHeaders)(ctx.request.headers),
|
|
17
|
+
getQueryParams() {
|
|
18
|
+
return ctx.request.query;
|
|
19
|
+
},
|
|
20
|
+
getBody() {
|
|
21
|
+
if ("body" in ctx.request) {
|
|
22
|
+
return (0, utils_js_1.getBodyFromFrameworkBody)(ctx.request.body);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// No koa-bodyparser, let's just read the body ourself
|
|
26
|
+
return (0, utils_js_1.getBodyFromRequest)(ctx.req, dynamicOptions.maxRequestLength);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
requestContext: {
|
|
30
|
+
node: {
|
|
31
|
+
req: ctx.req,
|
|
32
|
+
res: ctx.res,
|
|
33
|
+
},
|
|
34
|
+
koav2: {
|
|
35
|
+
ctx,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
preferJSON: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
class KoaGrafserv extends base_js_1.GrafservBase {
|
|
42
|
+
constructor(config) {
|
|
43
|
+
super(config);
|
|
44
|
+
}
|
|
45
|
+
_createHandler() {
|
|
46
|
+
const dynamicOptions = this.dynamicOptions;
|
|
47
|
+
return async (ctx, next) => {
|
|
48
|
+
const request = getDigest(dynamicOptions, ctx);
|
|
49
|
+
const result = await this.processRequest(request);
|
|
50
|
+
if (result === null) {
|
|
51
|
+
return next();
|
|
52
|
+
}
|
|
53
|
+
switch (result.type) {
|
|
54
|
+
case "error": {
|
|
55
|
+
const { statusCode, headers } = result;
|
|
56
|
+
ctx.response.set(headers);
|
|
57
|
+
ctx.response.status = statusCode;
|
|
58
|
+
// TODO: mutating the error is probably bad form...
|
|
59
|
+
const errorWithStatus = Object.assign(result.error, {
|
|
60
|
+
status: statusCode,
|
|
61
|
+
});
|
|
62
|
+
throw errorWithStatus;
|
|
63
|
+
}
|
|
64
|
+
case "buffer": {
|
|
65
|
+
const { statusCode, headers, buffer } = result;
|
|
66
|
+
ctx.response.set(headers);
|
|
67
|
+
ctx.response.status = statusCode;
|
|
68
|
+
ctx.response.body = buffer;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
case "json": {
|
|
72
|
+
const { statusCode, headers, json } = result;
|
|
73
|
+
ctx.response.set(headers);
|
|
74
|
+
ctx.response.status = statusCode;
|
|
75
|
+
ctx.response.body = json;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
case "noContent": {
|
|
79
|
+
const { statusCode, headers } = result;
|
|
80
|
+
ctx.response.set(headers);
|
|
81
|
+
ctx.response.status = statusCode;
|
|
82
|
+
ctx.response.body = null;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
case "bufferStream": {
|
|
86
|
+
const { statusCode, headers, lowLatency, bufferIterator } = result;
|
|
87
|
+
if (lowLatency) {
|
|
88
|
+
ctx.req.socket.setTimeout(0);
|
|
89
|
+
ctx.req.socket.setNoDelay(true);
|
|
90
|
+
ctx.req.socket.setKeepAlive(true);
|
|
91
|
+
}
|
|
92
|
+
ctx.response.set(headers);
|
|
93
|
+
ctx.response.status = statusCode;
|
|
94
|
+
const stream = new node_stream_1.PassThrough();
|
|
95
|
+
ctx.response.body = stream;
|
|
96
|
+
for await (const buffer of bufferIterator) {
|
|
97
|
+
stream.write(buffer);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
default: {
|
|
102
|
+
const never = result;
|
|
103
|
+
console.log("Unhandled:");
|
|
104
|
+
console.dir(never);
|
|
105
|
+
ctx.response.type = "text/plain";
|
|
106
|
+
ctx.response.status = 503;
|
|
107
|
+
ctx.response.body = "Server hasn't implemented this yet";
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async addTo(app, server) {
|
|
114
|
+
app.use(this._createHandler());
|
|
115
|
+
if (this.resolvedPreset.grafserv?.websockets) {
|
|
116
|
+
if (server) {
|
|
117
|
+
// If user explicitly passes server, bind to it:
|
|
118
|
+
(0, index_js_1.attachWebsocketsToServer)(this, server);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// If not, hope they're calling `app.listen()` and intercept that call.
|
|
122
|
+
const oldListen = app.listen;
|
|
123
|
+
app.listen = (...args) => {
|
|
124
|
+
const server = oldListen.apply(app, args);
|
|
125
|
+
(0, index_js_1.attachWebsocketsToServer)(this, server);
|
|
126
|
+
return server;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.KoaGrafserv = KoaGrafserv;
|
|
133
|
+
function grafserv(config) {
|
|
134
|
+
return new KoaGrafserv(config);
|
|
135
|
+
}
|
|
136
|
+
exports.grafserv = grafserv;
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/servers/koa/v2/index.ts"],"names":[],"mappings":";;;AAIA,6CAA0C;AAE1C,mDAAqD;AAGrD,gDAI2B;AAC3B,kDAA+D;AAY/D,SAAS,SAAS,CAChB,cAAiC,EACjC,GAAY;IAEZ,OAAO;QACL,gBAAgB,EAAE,GAAG,CAAC,GAAG,CAAC,gBAAgB;QAC1C,gBAAgB,EAAE,GAAG,CAAC,GAAG,CAAC,gBAAgB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CAAC,cAAc,EAAE,CAAC,CAAC;QAC/B,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,UAAU,EAAE;YAC5C,IAAI,MAAM,EAAE;gBACV,gDAAgD;gBAChD,IAAA,mCAAwB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;aACxC;iBAAM;gBACL,uEAAuE;gBACvE,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC;gBAC7B,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;oBAC5B,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;oBAC1C,IAAA,mCAAwB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;oBACvC,OAAO,MAAM,CAAC;gBAChB,CAAC,CAAC;aACH;SACF;IACH,CAAC;CACF;AAjGD,kCAiGC;AAED,SAAgB,QAAQ,CAAC,MAAsB;IAC7C,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAFD,4BAEC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { IncomingMessage, Server as HTTPServer, ServerResponse } from "node:http";
|
|
4
|
+
import type { Server as HTTPSServer } from "node:https";
|
|
5
|
+
import { GrafservBase } from "../../core/base.js";
|
|
6
|
+
import type { GrafservConfig, RequestDigest } from "../../interfaces.js";
|
|
7
|
+
import type { OptionsFromConfig } from "../../options.js";
|
|
8
|
+
declare global {
|
|
9
|
+
namespace Grafast {
|
|
10
|
+
interface RequestContext {
|
|
11
|
+
node: {
|
|
12
|
+
req: IncomingMessage;
|
|
13
|
+
res: ServerResponse;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare class NodeGrafservBase extends GrafservBase {
|
|
19
|
+
constructor(config: GrafservConfig);
|
|
20
|
+
protected getDigest(dynamicOptions: OptionsFromConfig, req: IncomingMessage, res: ServerResponse, isHTTPS: boolean): RequestDigest;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Please user serv.addTo instead, so that websockets can be automatically supported
|
|
23
|
+
*/
|
|
24
|
+
createHandler(isHTTPS?: boolean): (req: IncomingMessage, res: ServerResponse, next?: (err?: Error) => void) => void;
|
|
25
|
+
protected _createHandler(isHTTPS?: boolean): (req: IncomingMessage, res: ServerResponse, next?: (err?: Error) => void) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare class NodeGrafserv extends NodeGrafservBase {
|
|
28
|
+
addTo(server: HTTPServer | HTTPSServer): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare function grafserv(config: GrafservConfig): NodeGrafserv;
|
|
31
|
+
export declare function attachWebsocketsToServer(instance: GrafservBase, server: HTTPServer | HTTPSServer): Promise<void>;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/servers/node/index.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,EACV,eAAe,EACf,MAAM,IAAI,UAAU,EACpB,cAAc,EACf,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AAKxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAO1D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,cAAc;YACtB,IAAI,EAAE;gBACJ,GAAG,EAAE,eAAe,CAAC;gBACrB,GAAG,EAAE,cAAc,CAAC;aACrB,CAAC;SACH;KACF;CACF;AAED,qBAAa,gBAAiB,SAAQ,YAAY;g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