@mionjs/platform-gcloud 0.8.10 → 0.13.0
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/index.cjs +8 -9
- package/.dist/cjs/src/constants.cjs +11 -4
- package/.dist/cjs/src/constants.cjs.map +1 -1
- package/.dist/cjs/src/constants.d.ts +1 -0
- package/.dist/cjs/src/googleCF.cjs +66 -91
- package/.dist/cjs/src/googleCF.cjs.map +1 -1
- package/.dist/cjs/src/headers.cjs +44 -43
- package/.dist/cjs/src/headers.cjs.map +1 -1
- package/.dist/cjs/src/types.cjs +0 -2
- package/.dist/cjs/src/types.d.ts +2 -2
- package/.dist/esm/index.js +2 -9
- package/.dist/esm/src/constants.d.ts +1 -0
- package/.dist/esm/src/constants.js +11 -6
- package/.dist/esm/src/constants.js.map +1 -1
- package/.dist/esm/src/googleCF.js +65 -94
- package/.dist/esm/src/googleCF.js.map +1 -1
- package/.dist/esm/src/headers.js +44 -45
- package/.dist/esm/src/headers.js.map +1 -1
- package/.dist/esm/src/types.d.ts +2 -2
- package/.dist/esm/src/types.js +0 -2
- package/LICENSE +1 -1
- package/README.md +4 -4
- package/package.json +18 -23
- package/.dist/cjs/index.cjs.map +0 -1
- package/.dist/cjs/index.d.ts.map +0 -1
- package/.dist/cjs/src/constants.d.ts.map +0 -1
- package/.dist/cjs/src/googleCF.d.ts.map +0 -1
- package/.dist/cjs/src/headers.d.ts.map +0 -1
- package/.dist/cjs/src/types.cjs.map +0 -1
- package/.dist/cjs/src/types.d.ts.map +0 -1
- package/.dist/esm/index.d.ts.map +0 -1
- package/.dist/esm/index.js.map +0 -1
- package/.dist/esm/src/constants.d.ts.map +0 -1
- package/.dist/esm/src/googleCF.d.ts.map +0 -1
- package/.dist/esm/src/headers.d.ts.map +0 -1
- package/.dist/esm/src/types.d.ts.map +0 -1
- package/.dist/esm/src/types.js.map +0 -1
- package/index.ts +0 -10
- package/src/constants.ts +0 -12
- package/src/googleCF.ts +0 -143
- package/src/headers.ts +0 -68
- package/src/types.ts +0 -13
|
@@ -1,106 +1,77 @@
|
|
|
1
|
-
import { SerializerModes, RpcError } from "@mionjs/core";
|
|
2
|
-
import { decodeQueryBody, dispatchRoute, getRouterFatalErrorResponse, resetRouter, setPlatformConfig } from "@mionjs/router";
|
|
3
1
|
import { DEFAULT_GOOGLE_CF_OPTIONS } from "./constants.js";
|
|
4
2
|
import { headersFromIncomingMessage, headersFromServerResponse } from "./headers.js";
|
|
5
|
-
|
|
3
|
+
import { SerializerModes } from "@mionjs/core";
|
|
4
|
+
import { createContextFromChain, decodeQueryBody, dispatchPlatformError, dispatchWithContext, getResponseDefaults, getRouterFatalErrorResponse, requestPayloadTooLarge, resetRouter, resolveExecutionChain, setPlatformConfig, toRpcError } from "@mionjs/router";
|
|
5
|
+
//#region src/googleCF.ts
|
|
6
|
+
var googleCFOptions = { ...DEFAULT_GOOGLE_CF_OPTIONS };
|
|
6
7
|
function resetGoogleCFOpts() {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
googleCFOptions = { ...DEFAULT_GOOGLE_CF_OPTIONS };
|
|
9
|
+
resetRouter();
|
|
9
10
|
}
|
|
10
11
|
function setGoogleCFOpts(routerOptions) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
googleCFOptions = {
|
|
13
|
+
...googleCFOptions,
|
|
14
|
+
...routerOptions
|
|
15
|
+
};
|
|
16
|
+
setPlatformConfig({ ...googleCFOptions });
|
|
17
|
+
return googleCFOptions;
|
|
17
18
|
}
|
|
19
|
+
/** Creates a Google Cloud Functions handler with optional platform config */
|
|
18
20
|
function createGoogleCFHandler(options) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
setGoogleCFOpts(options);
|
|
22
|
+
return googleCFHandler;
|
|
21
23
|
}
|
|
22
24
|
async function googleCFHandler(rawRequest, rawResponse) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
reply(routeResponse, rawResponse);
|
|
48
|
-
} catch (err) {
|
|
49
|
-
const error = err instanceof RpcError ? err : new RpcError({
|
|
50
|
-
publicMessage: "Internal Error",
|
|
51
|
-
originalError: err,
|
|
52
|
-
type: "unknown-error"
|
|
53
|
-
});
|
|
54
|
-
const routeResponse = getRouterFatalErrorResponse(error, respHeaders);
|
|
55
|
-
reply(routeResponse, rawResponse);
|
|
56
|
-
}
|
|
25
|
+
const reqHeaders = headersFromIncomingMessage(rawRequest);
|
|
26
|
+
const respHeaders = headersFromServerResponse(rawResponse, getResponseDefaults());
|
|
27
|
+
let rawBody = rawRequest.body;
|
|
28
|
+
let reqBodyType = typeof rawBody === "string" ? SerializerModes.stringifyJson : SerializerModes.json;
|
|
29
|
+
const originalUrl = rawRequest.originalUrl;
|
|
30
|
+
const queryIndex = originalUrl ? originalUrl.indexOf("?") : -1;
|
|
31
|
+
const urlQuery = queryIndex === -1 ? void 0 : originalUrl.slice(queryIndex + 1);
|
|
32
|
+
try {
|
|
33
|
+
const chain = resolveExecutionChain(rawRequest.path, urlQuery, rawRequest);
|
|
34
|
+
try {
|
|
35
|
+
rejectOversizedRequest(rawRequest, rawBody, chain.maxBodySize);
|
|
36
|
+
} catch (refusal) {
|
|
37
|
+
return reply(await dispatchPlatformError(chain, rawRequest.path, urlQuery, toRpcError(refusal), reqHeaders, respHeaders, rawRequest, rawResponse), rawResponse);
|
|
38
|
+
}
|
|
39
|
+
const queryBody = decodeQueryBody(urlQuery, bodyOrUndefined(rawBody));
|
|
40
|
+
if (queryBody) {
|
|
41
|
+
rawBody = queryBody.rawBody;
|
|
42
|
+
reqBodyType = queryBody.bodyType;
|
|
43
|
+
}
|
|
44
|
+
reply(await dispatchWithContext(createContextFromChain(chain, rawRequest.path, urlQuery, reqHeaders, respHeaders, rawBody, reqBodyType), rawRequest, rawResponse), rawResponse);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
reply(getRouterFatalErrorResponse(toRpcError(err), respHeaders), rawResponse);
|
|
47
|
+
}
|
|
57
48
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
case SerializerModes.binary: {
|
|
77
|
-
const serializer = mionResp.binSerializer;
|
|
78
|
-
resp.set("content-length", `${serializer.getLength()}`);
|
|
79
|
-
resp.end(Buffer.from(serializer.getBufferView()));
|
|
80
|
-
const onFinish = () => serializer.markAsEnded();
|
|
81
|
-
resp.on("finish", onFinish);
|
|
82
|
-
resp.on("close", onFinish);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
default: {
|
|
86
|
-
const error = new RpcError({
|
|
87
|
-
publicMessage: "unknown-mion-response-format",
|
|
88
|
-
type: "unknown-error",
|
|
89
|
-
errorData: { bodyType }
|
|
90
|
-
});
|
|
91
|
-
unexpectedFail(resp, mionResp.headers, error);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
49
|
+
/** express parses a body-less request into an EMPTY object, which is truthy, so `?data=` would never be read without this. */
|
|
50
|
+
function bodyOrUndefined(rawBody) {
|
|
51
|
+
if (!rawBody) return void 0;
|
|
52
|
+
if (typeof rawBody !== "object") return rawBody;
|
|
53
|
+
for (const key in rawBody) return rawBody;
|
|
54
|
+
}
|
|
55
|
+
/** express hands a JSON request over parsed and the router only measures strings, so the wire size is found here instead.
|
|
56
|
+
* `rawBody` is the exact bytes the Google functions framework keeps; a plain express host leaves only the parsed body. */
|
|
57
|
+
function rejectOversizedRequest(rawRequest, rawBody, maxBodySize) {
|
|
58
|
+
const declaredLength = rawRequest.headers["content-length"];
|
|
59
|
+
if (declaredLength !== void 0) {
|
|
60
|
+
if (Number(declaredLength) > maxBodySize) throw requestPayloadTooLarge();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof rawBody !== "object" || rawBody === null) return;
|
|
64
|
+
const wireBytes = rawRequest.rawBody;
|
|
65
|
+
if ((wireBytes ? wireBytes.byteLength : Buffer.byteLength(JSON.stringify(rawBody), "utf8")) > maxBodySize) throw requestPayloadTooLarge();
|
|
94
66
|
}
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
67
|
+
function reply(mionResp, resp) {
|
|
68
|
+
resp.status(mionResp.statusCode);
|
|
69
|
+
const jsonString = JSON.stringify(mionResp.body);
|
|
70
|
+
resp.set("content-type", mionResp.contentType);
|
|
71
|
+
resp.set("content-length", `${Buffer.byteLength(jsonString, "utf8")}`);
|
|
72
|
+
resp.end(jsonString, "utf8");
|
|
99
73
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
setGoogleCFOpts
|
|
105
|
-
};
|
|
106
|
-
//# sourceMappingURL=googleCF.js.map
|
|
74
|
+
//#endregion
|
|
75
|
+
export { createGoogleCFHandler, googleCFHandler, resetGoogleCFOpts, setGoogleCFOpts };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=googleCF.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"googleCF.js","sources":["../../../src/googleCF.ts"],"sourcesContent":["/* ########\n * 2023 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {
|
|
1
|
+
{"version":3,"file":"googleCF.js","names":[],"sources":["../../../src/googleCF.ts"],"sourcesContent":["/* ########\n * 2023 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {SerializerModes} from '@mionjs/core';\nimport type {SerializerCode} from '@mionjs/core';\nimport {\n dispatchWithContext,\n dispatchPlatformError,\n toRpcError,\n resolveExecutionChain,\n createContextFromChain,\n getRouterFatalErrorResponse,\n requestPayloadTooLarge,\n resetRouter,\n decodeQueryBody,\n setPlatformConfig,\n getResponseDefaults,\n} from '@mionjs/router';\nimport type {MionResponse} from '@mionjs/router';\nimport {Request, Response} from 'express';\nimport {DEFAULT_GOOGLE_CF_OPTIONS} from './constants.ts';\nimport {GoogleCFOptions} from './types.ts';\nimport {headersFromIncomingMessage, headersFromServerResponse} from './headers.ts';\n\n// ############# STATE #############\n\nlet googleCFOptions: Readonly<GoogleCFOptions> = {...DEFAULT_GOOGLE_CF_OPTIONS};\n\n// ############# PUBLIC METHODS #############\n\nexport function resetGoogleCFOpts() {\n googleCFOptions = {...DEFAULT_GOOGLE_CF_OPTIONS};\n resetRouter();\n}\n\nexport function setGoogleCFOpts(routerOptions?: Partial<GoogleCFOptions>) {\n googleCFOptions = {\n ...googleCFOptions,\n ...routerOptions,\n };\n setPlatformConfig({...googleCFOptions});\n return googleCFOptions;\n}\n\n/** Creates a Google Cloud Functions handler with optional platform config */\nexport function createGoogleCFHandler(options?: Partial<GoogleCFOptions>) {\n setGoogleCFOpts(options);\n return googleCFHandler;\n}\n\nexport async function googleCFHandler(rawRequest: Request, rawResponse: Response): Promise<void> {\n // express may hand the body over already parsed, so both a string and an object body are accepted\n\n // TODO use its own express headers wrapper instead headers from record\n const reqHeaders = headersFromIncomingMessage(rawRequest);\n const respHeaders = headersFromServerResponse(rawResponse, getResponseDefaults());\n let rawBody = rawRequest.body;\n let reqBodyType: SerializerCode = typeof rawBody === 'string' ? SerializerModes.stringifyJson : SerializerModes.json;\n // everything after the FIRST `?`: a second one is legal inside a query, so splitting on it would drop parameters\n const originalUrl = rawRequest.originalUrl;\n const queryIndex = originalUrl ? originalUrl.indexOf('?') : -1;\n const urlQuery = queryIndex === -1 ? undefined : originalUrl.slice(queryIndex + 1);\n\n try {\n // express already read the body, so the chain's limit is resolved first and the size check runs before the router sees it\n const chain = resolveExecutionChain(rawRequest.path, urlQuery, rawRequest);\n try {\n rejectOversizedRequest(rawRequest, rawBody, chain.maxBodySize);\n } catch (refusal) {\n // the route resolved, so the refusal still runs the chain's alwaysRun members\n const refused = await dispatchPlatformError(\n chain,\n rawRequest.path,\n urlQuery,\n toRpcError(refusal),\n reqHeaders,\n respHeaders,\n rawRequest,\n rawResponse\n );\n return reply(refused, rawResponse);\n }\n const queryBody = decodeQueryBody(urlQuery, bodyOrUndefined(rawBody));\n if (queryBody) {\n rawBody = queryBody.rawBody;\n reqBodyType = queryBody.bodyType;\n }\n const context = createContextFromChain(chain, rawRequest.path, urlQuery, reqHeaders, respHeaders, rawBody, reqBodyType);\n const routeResponse = await dispatchWithContext(context, rawRequest, rawResponse);\n reply(routeResponse, rawResponse);\n } catch (err) {\n const routeResponse = getRouterFatalErrorResponse(toRpcError(err), respHeaders);\n reply(routeResponse, rawResponse);\n }\n}\n\n// ############# PRIVATE METHODS #############\n\n/** express parses a body-less request into an EMPTY object, which is truthy, so `?data=` would never be read without this. */\nfunction bodyOrUndefined(rawBody: unknown): unknown {\n if (!rawBody) return undefined;\n if (typeof rawBody !== 'object') return rawBody;\n for (const key in rawBody) return rawBody;\n return undefined;\n}\n\n/** express hands a JSON request over parsed and the router only measures strings, so the wire size is found here instead.\n * `rawBody` is the exact bytes the Google functions framework keeps; a plain express host leaves only the parsed body. */\nfunction rejectOversizedRequest(rawRequest: Request, rawBody: unknown, maxBodySize: number): void {\n const declaredLength = rawRequest.headers['content-length'];\n if (declaredLength !== undefined) {\n if (Number(declaredLength) > maxBodySize) throw requestPayloadTooLarge();\n return;\n }\n // a string body is measured again by the router, so only a parsed one still needs a size here\n if (typeof rawBody !== 'object' || rawBody === null) return;\n const wireBytes = (rawRequest as {rawBody?: Buffer}).rawBody;\n const size = wireBytes ? wireBytes.byteLength : Buffer.byteLength(JSON.stringify(rawBody), 'utf8');\n if (size > maxBodySize) throw requestPayloadTooLarge();\n}\n\nfunction reply(mionResp: MionResponse, resp: Response): void {\n resp.status(mionResp.statusCode);\n const jsonString = JSON.stringify(mionResp.body);\n resp.set('content-type', mionResp.contentType);\n // byteLength measures without copying the response into a Buffer\n resp.set('content-length', `${Buffer.byteLength(jsonString, 'utf8')}`);\n resp.end(jsonString, 'utf8');\n}\n"],"mappings":";;;;;AA8BA,IAAI,kBAA6C,EAAC,GAAG,0BAAyB;AAI9E,SAAgB,oBAAoB;CAClC,kBAAkB,EAAC,GAAG,0BAAyB;CAC/C,YAAY;AACd;AAEA,SAAgB,gBAAgB,eAA0C;CACxE,kBAAkB;EAChB,GAAG;EACH,GAAG;CACL;CACA,kBAAkB,EAAC,GAAG,gBAAe,CAAC;CACtC,OAAO;AACT;;AAGA,SAAgB,sBAAsB,SAAoC;CACxE,gBAAgB,OAAO;CACvB,OAAO;AACT;AAEA,eAAsB,gBAAgB,YAAqB,aAAsC;CAI/F,MAAM,aAAa,2BAA2B,UAAU;CACxD,MAAM,cAAc,0BAA0B,aAAa,oBAAoB,CAAC;CAChF,IAAI,UAAU,WAAW;CACzB,IAAI,cAA8B,OAAO,YAAY,WAAW,gBAAgB,gBAAgB,gBAAgB;CAEhH,MAAM,cAAc,WAAW;CAC/B,MAAM,aAAa,cAAc,YAAY,QAAQ,GAAG,IAAI;CAC5D,MAAM,WAAW,eAAe,KAAK,KAAA,IAAY,YAAY,MAAM,aAAa,CAAC;CAEjF,IAAI;EAEF,MAAM,QAAQ,sBAAsB,WAAW,MAAM,UAAU,UAAU;EACzE,IAAI;GACF,uBAAuB,YAAY,SAAS,MAAM,WAAW;EAC/D,SAAS,SAAS;GAYhB,OAAO,MAAM,MAVS,sBACpB,OACA,WAAW,MACX,UACA,WAAW,OAAO,GAClB,YACA,aACA,YACA,WACF,GACsB,WAAW;EACnC;EACA,MAAM,YAAY,gBAAgB,UAAU,gBAAgB,OAAO,CAAC;EACpE,IAAI,WAAW;GACb,UAAU,UAAU;GACpB,cAAc,UAAU;EAC1B;EAGA,MAAM,MADsB,oBADZ,uBAAuB,OAAO,WAAW,MAAM,UAAU,YAAY,aAAa,SAAS,WAC3D,GAAS,YAAY,WAAW,GAC3D,WAAW;CAClC,SAAS,KAAK;EAEZ,MADsB,4BAA4B,WAAW,GAAG,GAAG,WAC7D,GAAe,WAAW;CAClC;AACF;;AAKA,SAAS,gBAAgB,SAA2B;CAClD,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,KAAK,MAAM,OAAO,SAAS,OAAO;AAEpC;;;AAIA,SAAS,uBAAuB,YAAqB,SAAkB,aAA2B;CAChG,MAAM,iBAAiB,WAAW,QAAQ;CAC1C,IAAI,mBAAmB,KAAA,GAAW;EAChC,IAAI,OAAO,cAAc,IAAI,aAAa,MAAM,uBAAuB;EACvE;CACF;CAEA,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM;CACrD,MAAM,YAAa,WAAkC;CAErD,KADa,YAAY,UAAU,aAAa,OAAO,WAAW,KAAK,UAAU,OAAO,GAAG,MAAM,KACtF,aAAa,MAAM,uBAAuB;AACvD;AAEA,SAAS,MAAM,UAAwB,MAAsB;CAC3D,KAAK,OAAO,SAAS,UAAU;CAC/B,MAAM,aAAa,KAAK,UAAU,SAAS,IAAI;CAC/C,KAAK,IAAI,gBAAgB,SAAS,WAAW;CAE7C,KAAK,IAAI,kBAAkB,GAAG,OAAO,WAAW,YAAY,MAAM,GAAG;CACrE,KAAK,IAAI,YAAY,MAAM;AAC7B"}
|
package/.dist/esm/src/headers.js
CHANGED
|
@@ -1,51 +1,50 @@
|
|
|
1
1
|
import { headersFromRecord } from "@mionjs/router";
|
|
2
|
+
//#region src/headers.ts
|
|
2
3
|
function headersFromIncomingMessage(rawRequest) {
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
class ServerResponseHeadersImpl {
|
|
6
|
-
constructor(resp) {
|
|
7
|
-
this.resp = resp;
|
|
8
|
-
}
|
|
9
|
-
append(name, value) {
|
|
10
|
-
this.resp.appendHeader(name, value);
|
|
11
|
-
}
|
|
12
|
-
delete(name) {
|
|
13
|
-
this.resp.removeHeader(name);
|
|
14
|
-
}
|
|
15
|
-
get(name) {
|
|
16
|
-
const value = this.resp.getHeader(name);
|
|
17
|
-
if (Array.isArray(value)) return value.join(", ");
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
has(name) {
|
|
21
|
-
return this.resp.hasHeader(name);
|
|
22
|
-
}
|
|
23
|
-
set(name, value) {
|
|
24
|
-
this.resp.setHeader(name, value);
|
|
25
|
-
}
|
|
26
|
-
entries() {
|
|
27
|
-
return getSingleHeadersObj(this.resp).entries();
|
|
28
|
-
}
|
|
29
|
-
keys() {
|
|
30
|
-
return new Set(this.resp.getHeaderNames()).values();
|
|
31
|
-
}
|
|
32
|
-
values() {
|
|
33
|
-
return getSingleHeadersObj(this.resp).values();
|
|
34
|
-
}
|
|
4
|
+
return headersFromRecord(rawRequest.headers, true);
|
|
35
5
|
}
|
|
6
|
+
var ServerResponseHeadersImpl = class {
|
|
7
|
+
resp;
|
|
8
|
+
constructor(resp) {
|
|
9
|
+
this.resp = resp;
|
|
10
|
+
}
|
|
11
|
+
append(name, value) {
|
|
12
|
+
this.resp.appendHeader(name, value);
|
|
13
|
+
}
|
|
14
|
+
delete(name) {
|
|
15
|
+
this.resp.removeHeader(name);
|
|
16
|
+
}
|
|
17
|
+
get(name) {
|
|
18
|
+
const value = this.resp.getHeader(name);
|
|
19
|
+
if (Array.isArray(value)) return value.join(", ");
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
has(name) {
|
|
23
|
+
return this.resp.hasHeader(name);
|
|
24
|
+
}
|
|
25
|
+
set(name, value) {
|
|
26
|
+
this.resp.setHeader(name, value);
|
|
27
|
+
}
|
|
28
|
+
entries() {
|
|
29
|
+
return new Map(singleHeaderEntries(this.resp)).entries();
|
|
30
|
+
}
|
|
31
|
+
keys() {
|
|
32
|
+
return new Map(singleHeaderEntries(this.resp)).keys();
|
|
33
|
+
}
|
|
34
|
+
values() {
|
|
35
|
+
return new Map(singleHeaderEntries(this.resp)).values();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
36
38
|
function headersFromServerResponse(resp, initialHeaders) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
if (initialHeaders) {
|
|
40
|
+
for (const name in initialHeaders) if (name !== "content-type") resp.setHeader(name, initialHeaders[name]);
|
|
41
|
+
}
|
|
42
|
+
return new ServerResponseHeadersImpl(resp);
|
|
39
43
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
name,
|
|
43
|
-
Array.isArray(value) ? value.join(", ") : value
|
|
44
|
-
]);
|
|
45
|
-
return Object.fromEntries(entries);
|
|
44
|
+
function singleHeaderEntries(resp) {
|
|
45
|
+
return Object.entries(resp.getHeaders()).filter(([, value]) => value !== void 0).map(([name, value]) => [name, Array.isArray(value) ? value.join(", ") : String(value)]);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=headers.js.map
|
|
47
|
+
//#endregion
|
|
48
|
+
export { headersFromIncomingMessage, headersFromServerResponse };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sources":["../../../src/headers.ts"],"sourcesContent":["/* ########\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {MionHeaders, headersFromRecord} from '@mionjs/router';\nimport {IncomingMessage, ServerResponse} from 'http';\n\nexport function headersFromIncomingMessage(rawRequest: IncomingMessage): MionHeaders {\n
|
|
1
|
+
{"version":3,"file":"headers.js","names":[],"sources":["../../../src/headers.ts"],"sourcesContent":["/* ########\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {MionHeaders, headersFromRecord} from '@mionjs/router';\nimport {IncomingMessage, ServerResponse} from 'http';\n\nexport function headersFromIncomingMessage(rawRequest: IncomingMessage): MionHeaders {\n // node already lower-cased these and express passes its object straight through; NOT safe on API Gateway, which keeps case\n return headersFromRecord(rawRequest.headers as Record<string, string>, true);\n}\n\nclass ServerResponseHeadersImpl implements MionHeaders {\n constructor(private resp: ServerResponse) {}\n\n append(name: string, value: string): void {\n this.resp.appendHeader(name, value);\n }\n\n delete(name: string): void {\n this.resp.removeHeader(name);\n }\n\n get(name: string): string | undefined | null {\n const value = this.resp.getHeader(name);\n if (Array.isArray(value)) return value.join(', ');\n return value as string;\n }\n\n has(name: string): boolean {\n return this.resp.hasHeader(name);\n }\n\n set(name: string, value: string): void {\n this.resp.setHeader(name, value);\n }\n\n entries(): IterableIterator<[string, string]> {\n return new Map(singleHeaderEntries(this.resp)).entries();\n }\n\n keys(): IterableIterator<string> {\n return new Map(singleHeaderEntries(this.resp)).keys();\n }\n\n values(): IterableIterator<string> {\n return new Map(singleHeaderEntries(this.resp)).values();\n }\n}\n\nexport function headersFromServerResponse(resp: ServerResponse, initialHeaders: Record<string, string> | null): MionHeaders {\n // for...in allocates no entries array and no closure\n // content-type is the reply's: a raw middleware that ends the response itself must not send the JSON one\n if (initialHeaders) for (const name in initialHeaders) if (name !== 'content-type') resp.setHeader(name, initialHeaders[name]);\n return new ServerResponseHeadersImpl(resp);\n}\n\nfunction singleHeaderEntries(resp: ServerResponse): [string, string][] {\n return Object.entries(resp.getHeaders())\n .filter(([, value]) => value !== undefined)\n .map(([name, value]) => [name, Array.isArray(value) ? value.join(', ') : String(value)]);\n}\n"],"mappings":";;AAUA,SAAgB,2BAA2B,YAA0C;CAEnF,OAAO,kBAAkB,WAAW,SAAmC,IAAI;AAC7E;AAEA,IAAM,4BAAN,MAAuD;CACjC;CAApB,YAAY,MAA8B;EAAtB,KAAA,OAAA;CAAuB;CAE3C,OAAO,MAAc,OAAqB;EACxC,KAAK,KAAK,aAAa,MAAM,KAAK;CACpC;CAEA,OAAO,MAAoB;EACzB,KAAK,KAAK,aAAa,IAAI;CAC7B;CAEA,IAAI,MAAyC;EAC3C,MAAM,QAAQ,KAAK,KAAK,UAAU,IAAI;EACtC,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,KAAK,IAAI;EAChD,OAAO;CACT;CAEA,IAAI,MAAuB;EACzB,OAAO,KAAK,KAAK,UAAU,IAAI;CACjC;CAEA,IAAI,MAAc,OAAqB;EACrC,KAAK,KAAK,UAAU,MAAM,KAAK;CACjC;CAEA,UAA8C;EAC5C,OAAO,IAAI,IAAI,oBAAoB,KAAK,IAAI,CAAC,EAAE,QAAQ;CACzD;CAEA,OAAiC;EAC/B,OAAO,IAAI,IAAI,oBAAoB,KAAK,IAAI,CAAC,EAAE,KAAK;CACtD;CAEA,SAAmC;EACjC,OAAO,IAAI,IAAI,oBAAoB,KAAK,IAAI,CAAC,EAAE,OAAO;CACxD;AACF;AAEA,SAAgB,0BAA0B,MAAsB,gBAA4D;CAG1H,IAAI;OAAqB,MAAM,QAAQ,gBAAgB,IAAI,SAAS,gBAAgB,KAAK,UAAU,MAAM,eAAe,KAAK;CAAA;CAC7H,OAAO,IAAI,0BAA0B,IAAI;AAC3C;AAEA,SAAS,oBAAoB,MAA0C;CACrE,OAAO,OAAO,QAAQ,KAAK,WAAW,CAAC,EACpC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,EACzC,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,KAAK,CAAC,CAAC;AAC3F"}
|
package/.dist/esm/src/types.d.ts
CHANGED
package/.dist/esm/src/types.js
CHANGED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/MionKit/mion/
|
|
4
|
-
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/MionKit/mion/
|
|
5
|
-
<img alt='mion, a mikro kit for Typescript Serverless APIs' src='https://raw.githubusercontent.com/MionKit/mion/
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/MionKit/mion/main/assets/public/bannerx90-dark.png">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/MionKit/mion/main/assets/public/bannerx90.png">
|
|
5
|
+
<img alt='mion, a mikro kit for Typescript Serverless APIs' src='https://raw.githubusercontent.com/MionKit/mion/main/assets/public/bannerx90.png'>
|
|
6
6
|
</picture>
|
|
7
7
|
</p>
|
|
8
8
|
<p align="center">
|
|
@@ -22,7 +22,7 @@ This package contains handler functions to run mion on [Google Cloud functions](
|
|
|
22
22
|
|
|
23
23
|
## Check Out The [Website And Documentation](http://mion.io) 📚
|
|
24
24
|
|
|
25
|
-
[](http://mion.io)
|
|
26
26
|
|
|
27
27
|
---
|
|
28
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mionjs/platform-gcloud",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Google Cloud functions wrapper for mion router.",
|
|
6
6
|
"keywords": [
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"source": "./index.ts",
|
|
24
23
|
"types": "./.dist/esm/index.d.ts",
|
|
25
24
|
"require": "./.dist/cjs/index.cjs",
|
|
26
25
|
"default": "./.dist/esm/index.js"
|
|
@@ -31,10 +30,8 @@
|
|
|
31
30
|
},
|
|
32
31
|
"files": [
|
|
33
32
|
".dist",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"!src/**/*.spec.ts",
|
|
37
|
-
"!src/**/*.test.ts"
|
|
33
|
+
"!.dist/**/*.tsbuildinfo",
|
|
34
|
+
"!.dist/**/*.d.ts.map"
|
|
38
35
|
],
|
|
39
36
|
"repository": {
|
|
40
37
|
"type": "git",
|
|
@@ -43,26 +40,24 @@
|
|
|
43
40
|
"publishConfig": {
|
|
44
41
|
"access": "public"
|
|
45
42
|
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/MionKit/mion/issues"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@google-cloud/functions-framework": "3.5.1",
|
|
48
|
+
"@mionjs/core": "0.13.0",
|
|
49
|
+
"@mionjs/router": "0.13.0"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "afd6e1d61525b4bf11bb84b3f85089038d70062d",
|
|
46
52
|
"scripts": {
|
|
53
|
+
"typecheck:test": "tsc -p tsconfig.json --noEmit",
|
|
47
54
|
"test": "vitest run",
|
|
48
55
|
"dev": "vite build --watch",
|
|
49
56
|
"dev:test": "vitest watch",
|
|
50
|
-
"lint": "
|
|
57
|
+
"lint": "eslint src",
|
|
51
58
|
"format": "prettier --write src/**/*.ts",
|
|
52
59
|
"build": "vite build",
|
|
53
|
-
"clean": "rimraf .dist
|
|
54
|
-
"fresh-start": "
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
"url": "https://github.com/MionKit/mion/issues"
|
|
58
|
-
},
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"@google-cloud/functions-framework": "^3.3.0",
|
|
61
|
-
"@mionjs/core": "0.8.10",
|
|
62
|
-
"@mionjs/router": "0.8.10"
|
|
63
|
-
},
|
|
64
|
-
"devDependencies": {
|
|
65
|
-
"@types/express": "^4.17.20"
|
|
66
|
-
},
|
|
67
|
-
"gitHead": "3e2b3b633ceb0b054fc1f1aad914d779ddd6c8b0"
|
|
68
|
-
}
|
|
60
|
+
"clean": "rimraf .dist .coverage .mion",
|
|
61
|
+
"fresh-start": "pnpm run clean && rimraf node_modules"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/.dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
package/.dist/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAOA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,yBAAyB,EAAE,eAEvC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"googleCF.d.ts","sourceRoot":"","sources":["../../../src/googleCF.ts"],"names":[],"mappings":"AAWA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAS3C,wBAAgB,iBAAiB,SAGhC;AAED,wBAAgB,eAAe,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,6BAOvE;AAGD,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,0BAGvE;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiD/F"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/headers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,MAAM,CAAC;AAErD,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,eAAe,GAAG,WAAW,CAEnF;AA4CD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,WAAW,CAG1H"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,eAAe;IAE5B,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD"}
|
package/.dist/esm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAOA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
package/.dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,yBAAyB,EAAE,eAEvC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"googleCF.d.ts","sourceRoot":"","sources":["../../../src/googleCF.ts"],"names":[],"mappings":"AAWA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAS3C,wBAAgB,iBAAiB,SAGhC;AAED,wBAAgB,eAAe,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,6BAOvE;AAGD,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,0BAGvE;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiD/F"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/headers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,MAAM,CAAC;AAErD,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,eAAe,GAAG,WAAW,CAEnF;AA4CD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,WAAW,CAG1H"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,eAAe;IAE5B,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/index.ts
DELETED
package/src/constants.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* ########
|
|
2
|
-
* 2023 mion
|
|
3
|
-
* Author: Ma-jerez
|
|
4
|
-
* License: MIT
|
|
5
|
-
* The software is provided "as is", without warranty of any kind.
|
|
6
|
-
* ######## */
|
|
7
|
-
|
|
8
|
-
import {GoogleCFOptions} from './types.ts';
|
|
9
|
-
|
|
10
|
-
export const DEFAULT_GOOGLE_CF_OPTIONS: GoogleCFOptions = {
|
|
11
|
-
defaultResponseHeaders: {},
|
|
12
|
-
};
|