@cedarjs/api-server 6.0.0-canary.2789 → 6.0.0-canary.2792
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/package.json +29 -72
- package/dist/cjs/apiCLIConfig.d.ts +0 -6
- package/dist/cjs/apiCLIConfig.d.ts.map +0 -1
- package/dist/cjs/apiCLIConfig.js +0 -71
- package/dist/cjs/apiCLIConfigHandler.d.ts +0 -3
- package/dist/cjs/apiCLIConfigHandler.d.ts.map +0 -1
- package/dist/cjs/apiCLIConfigHandler.js +0 -67
- package/dist/cjs/bin.d.ts +0 -2
- package/dist/cjs/bin.d.ts.map +0 -1
- package/dist/cjs/bin.js +0 -1007
- package/dist/cjs/bothCLIConfig.d.ts +0 -6
- package/dist/cjs/bothCLIConfig.d.ts.map +0 -1
- package/dist/cjs/bothCLIConfig.js +0 -76
- package/dist/cjs/bothCLIConfigHandler.d.ts +0 -3
- package/dist/cjs/bothCLIConfigHandler.d.ts.map +0 -1
- package/dist/cjs/bothCLIConfigHandler.js +0 -107
- package/dist/cjs/buildManager.d.ts +0 -15
- package/dist/cjs/buildManager.d.ts.map +0 -1
- package/dist/cjs/buildManager.js +0 -79
- package/dist/cjs/cliHelpers.d.ts +0 -6
- package/dist/cjs/cliHelpers.d.ts.map +0 -1
- package/dist/cjs/cliHelpers.js +0 -57
- package/dist/cjs/createServer.d.ts +0 -30
- package/dist/cjs/createServer.d.ts.map +0 -1
- package/dist/cjs/createServer.js +0 -145
- package/dist/cjs/createServerHelpers.d.ts +0 -38
- package/dist/cjs/createServerHelpers.d.ts.map +0 -1
- package/dist/cjs/createServerHelpers.js +0 -112
- package/dist/cjs/fastify.d.ts +0 -13
- package/dist/cjs/fastify.d.ts.map +0 -1
- package/dist/cjs/fastify.js +0 -96
- package/dist/cjs/logFormatter/ambient.d.js +0 -1
- package/dist/cjs/logFormatter/bin.d.ts +0 -2
- package/dist/cjs/logFormatter/bin.d.ts.map +0 -1
- package/dist/cjs/logFormatter/bin.js +0 -369
- package/dist/cjs/logFormatter/formatters.d.ts +0 -30
- package/dist/cjs/logFormatter/formatters.d.ts.map +0 -1
- package/dist/cjs/logFormatter/formatters.js +0 -275
- package/dist/cjs/logFormatter/index.d.ts +0 -2
- package/dist/cjs/logFormatter/index.d.ts.map +0 -1
- package/dist/cjs/logFormatter/index.js +0 -184
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/plugins/api.d.ts +0 -14
- package/dist/cjs/plugins/api.d.ts.map +0 -1
- package/dist/cjs/plugins/api.js +0 -78
- package/dist/cjs/plugins/graphql.d.ts +0 -10
- package/dist/cjs/plugins/graphql.d.ts.map +0 -1
- package/dist/cjs/plugins/graphql.js +0 -135
- package/dist/cjs/plugins/lambdaLoader.d.ts +0 -34
- package/dist/cjs/plugins/lambdaLoader.d.ts.map +0 -1
- package/dist/cjs/plugins/lambdaLoader.js +0 -199
- package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts +0 -5
- package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +0 -1
- package/dist/cjs/requestHandlers/awsLambdaFastify.js +0 -105
- package/dist/cjs/requestHandlers/utils.d.ts +0 -26
- package/dist/cjs/requestHandlers/utils.d.ts.map +0 -1
- package/dist/cjs/requestHandlers/utils.js +0 -55
- package/dist/cjs/serverManager.d.ts +0 -8
- package/dist/cjs/serverManager.d.ts.map +0 -1
- package/dist/cjs/serverManager.js +0 -137
- package/dist/cjs/types.d.ts +0 -19
- package/dist/cjs/types.d.ts.map +0 -1
- package/dist/cjs/utils.d.ts +0 -6
- package/dist/cjs/utils.d.ts.map +0 -1
- package/dist/cjs/utils.js +0 -58
- package/dist/cjs/watch.d.ts +0 -10
- package/dist/cjs/watch.d.ts.map +0 -1
- package/dist/cjs/watch.js +0 -399
- package/dist/cjs/watchPaths.d.ts +0 -3
- package/dist/cjs/watchPaths.d.ts.map +0 -1
- package/dist/cjs/watchPaths.js +0 -140
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var graphql_exports = {};
|
|
30
|
-
__export(graphql_exports, {
|
|
31
|
-
redwoodFastifyGraphQLServer: () => redwoodFastifyGraphQLServer
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(graphql_exports);
|
|
34
|
-
var import_node_url = require("node:url");
|
|
35
|
-
var import_multipart = __toESM(require("@fastify/multipart"), 1);
|
|
36
|
-
var import_url_data = __toESM(require("@fastify/url-data"), 1);
|
|
37
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
38
|
-
var import_runtime = require("@cedarjs/api/runtime");
|
|
39
|
-
var import_store = require("@cedarjs/context/dist/store");
|
|
40
|
-
var import_helpers = require("@cedarjs/fastify-web/dist/helpers.js");
|
|
41
|
-
var import_graphql_server = require("@cedarjs/graphql-server");
|
|
42
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
43
|
-
var import_awsLambdaFastify = require("../requestHandlers/awsLambdaFastify.js");
|
|
44
|
-
async function redwoodFastifyGraphQLServer(fastify, options) {
|
|
45
|
-
const redwoodOptions = options.redwood ?? {};
|
|
46
|
-
redwoodOptions.apiRootPath ??= "/";
|
|
47
|
-
redwoodOptions.apiRootPath = (0, import_helpers.coerceRootPath)(redwoodOptions.apiRootPath);
|
|
48
|
-
fastify.register(import_url_data.default);
|
|
49
|
-
fastify.register(import_multipart.default);
|
|
50
|
-
const method = ["GET", "POST", "OPTIONS"];
|
|
51
|
-
fastify.addHook("onRequest", (_req, _reply, done) => {
|
|
52
|
-
(0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
|
|
53
|
-
});
|
|
54
|
-
try {
|
|
55
|
-
if (!redwoodOptions.graphql) {
|
|
56
|
-
const [graphqlFunctionPath] = await (0, import_fast_glob.default)("dist/functions/graphql.{ts,js}", {
|
|
57
|
-
cwd: (0, import_project_config.getPaths)().api.base,
|
|
58
|
-
absolute: true
|
|
59
|
-
});
|
|
60
|
-
const filePath = (0, import_node_url.pathToFileURL)(graphqlFunctionPath).href;
|
|
61
|
-
const { __cedar_graphqlOptions } = await import(filePath);
|
|
62
|
-
if (!__cedar_graphqlOptions) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
redwoodOptions.graphql = __cedar_graphqlOptions;
|
|
66
|
-
}
|
|
67
|
-
const graphqlOptions = redwoodOptions.graphql;
|
|
68
|
-
if (graphqlOptions?.realtime?.subscriptions) {
|
|
69
|
-
method.push("PUT");
|
|
70
|
-
}
|
|
71
|
-
const { yoga } = await (0, import_graphql_server.createGraphQLYoga)(graphqlOptions);
|
|
72
|
-
const graphqlEndpoint = trimSlashes(yoga.graphqlEndpoint);
|
|
73
|
-
const routePaths = ["", "/health", "/readiness", "/stream"];
|
|
74
|
-
for (const routePath of routePaths) {
|
|
75
|
-
fastify.route({
|
|
76
|
-
url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
|
|
77
|
-
method,
|
|
78
|
-
handler: async (req, reply) => {
|
|
79
|
-
const request = createFetchRequest(req, reply);
|
|
80
|
-
const cedarContext = await (0, import_runtime.buildCedarContext)(request, {
|
|
81
|
-
authDecoder: graphqlOptions.authDecoder
|
|
82
|
-
});
|
|
83
|
-
try {
|
|
84
|
-
return await yoga.handle(request, {
|
|
85
|
-
request,
|
|
86
|
-
cedarContext,
|
|
87
|
-
event: (0, import_awsLambdaFastify.lambdaEventForFastifyRequest)(req),
|
|
88
|
-
requestContext: void 0
|
|
89
|
-
});
|
|
90
|
-
} catch (e) {
|
|
91
|
-
if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
92
|
-
return new Response(null, { status: 499 });
|
|
93
|
-
}
|
|
94
|
-
throw e;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
fastify.addHook("onReady", (done) => {
|
|
100
|
-
console.info(`GraphQL Yoga Server endpoint at ${graphqlEndpoint}`);
|
|
101
|
-
console.info(
|
|
102
|
-
`GraphQL Yoga Server Health Check endpoint at ${graphqlEndpoint}/health`
|
|
103
|
-
);
|
|
104
|
-
console.info(
|
|
105
|
-
`GraphQL Yoga Server Readiness endpoint at ${graphqlEndpoint}/readiness`
|
|
106
|
-
);
|
|
107
|
-
done();
|
|
108
|
-
});
|
|
109
|
-
} catch (e) {
|
|
110
|
-
console.log(e);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function trimSlashes(path) {
|
|
114
|
-
return path.replace(/^\/|\/$/g, "");
|
|
115
|
-
}
|
|
116
|
-
function createFetchRequest(req, reply) {
|
|
117
|
-
const controller = new AbortController();
|
|
118
|
-
reply.raw.on("close", () => {
|
|
119
|
-
if (!reply.raw.writableFinished) {
|
|
120
|
-
controller.abort();
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
const requestBody = req.method === "GET" || req.method === "HEAD" ? void 0 : typeof req.body === "string" ? req.body : req.body ? JSON.stringify(req.body) : void 0;
|
|
124
|
-
const href = `${req.protocol}://${req.hostname}${req.raw.url ?? "/"}`;
|
|
125
|
-
return new Request(href, {
|
|
126
|
-
method: req.method,
|
|
127
|
-
headers: req.headers,
|
|
128
|
-
body: requestBody,
|
|
129
|
-
signal: controller.signal
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
-
0 && (module.exports = {
|
|
134
|
-
redwoodFastifyGraphQLServer
|
|
135
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Handler } from 'aws-lambda';
|
|
2
|
-
import type { Options as FastGlobOptions } from 'fast-glob';
|
|
3
|
-
import type { FastifyReply, FastifyRequest, RequestGenericInterface } from 'fastify';
|
|
4
|
-
import type { CedarHandler, CedarRouteRecord } from '@cedarjs/api/runtime';
|
|
5
|
-
export declare const LAMBDA_FUNCTIONS: Map<string, Handler>;
|
|
6
|
-
export declare const CEDAR_HANDLERS: Map<string, CedarHandler>;
|
|
7
|
-
/**
|
|
8
|
-
* Exports a copy of the Cedar route manifest.
|
|
9
|
-
*
|
|
10
|
-
* This is intended to be used to later build WinterTC compatible `fetch`
|
|
11
|
-
* exports
|
|
12
|
-
*/
|
|
13
|
-
export declare const getCedarRouteManifest: () => CedarRouteRecord[];
|
|
14
|
-
export declare const setLambdaFunctions: (foundFunctions: string[]) => Promise<void>;
|
|
15
|
-
type LoadFunctionsFromDistOptions = {
|
|
16
|
-
fastGlobOptions?: FastGlobOptions;
|
|
17
|
-
discoverFunctionsGlob?: string | string[];
|
|
18
|
-
};
|
|
19
|
-
export declare const loadFunctionsFromDist: (options?: LoadFunctionsFromDistOptions) => Promise<void>;
|
|
20
|
-
interface LambdaHandlerRequest extends RequestGenericInterface {
|
|
21
|
-
Params: {
|
|
22
|
-
routeName: string;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* This will take a fastify request
|
|
27
|
-
* Then convert it to a lambdaEvent, and pass it to the the appropriate handler
|
|
28
|
-
* for the routeName
|
|
29
|
-
* The CEDAR_HANDLERS and LAMBDA_FUNCTIONS maps have been populated already by
|
|
30
|
-
* this point
|
|
31
|
-
*/
|
|
32
|
-
export declare const lambdaRequestHandler: (req: FastifyRequest<LambdaHandlerRequest>, reply: FastifyReply) => Promise<void>;
|
|
33
|
-
export {};
|
|
34
|
-
//# sourceMappingURL=lambdaLoader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lambdaLoader.d.ts","sourceRoot":"","sources":["../../../src/plugins/lambdaLoader.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAEjB,MAAM,sBAAsB,CAAA;AAO7B,eAAO,MAAM,gBAAgB,sBAA6B,CAAA;AAC1D,eAAO,MAAM,cAAc,2BAAkC,CAAA;AAG7D;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,0BAAgC,CAAA;AAIlE,eAAO,MAAM,kBAAkB,GAAU,gBAAgB,MAAM,EAAE,kBAuGhE,CAAA;AAED,KAAK,4BAA4B,GAAG;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC1C,CAAA;AAGD,eAAO,MAAM,qBAAqB,GAChC,UAAS,4BAAiC,kBAe3C,CAAA;AA0BD,UAAU,oBAAqB,SAAQ,uBAAuB;IAC5D,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,cAAc,CAAC,oBAAoB,CAAC,EACzC,OAAO,YAAY,kBAqEpB,CAAA"}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var lambdaLoader_exports = {};
|
|
30
|
-
__export(lambdaLoader_exports, {
|
|
31
|
-
CEDAR_HANDLERS: () => CEDAR_HANDLERS,
|
|
32
|
-
LAMBDA_FUNCTIONS: () => LAMBDA_FUNCTIONS,
|
|
33
|
-
getCedarRouteManifest: () => getCedarRouteManifest,
|
|
34
|
-
lambdaRequestHandler: () => lambdaRequestHandler,
|
|
35
|
-
loadFunctionsFromDist: () => loadFunctionsFromDist,
|
|
36
|
-
setLambdaFunctions: () => setLambdaFunctions
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(lambdaLoader_exports);
|
|
39
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
40
|
-
var import_node_url = require("node:url");
|
|
41
|
-
var import_ansis = __toESM(require("ansis"), 1);
|
|
42
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
43
|
-
var import_termi_link = require("termi-link");
|
|
44
|
-
var import_runtime = require("@cedarjs/api/runtime");
|
|
45
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
46
|
-
var import_awsLambdaFastify = require("../requestHandlers/awsLambdaFastify.js");
|
|
47
|
-
var import_utils = require("../utils.js");
|
|
48
|
-
const LAMBDA_FUNCTIONS = /* @__PURE__ */ new Map();
|
|
49
|
-
const CEDAR_HANDLERS = /* @__PURE__ */ new Map();
|
|
50
|
-
const cedarRouteManifest = [];
|
|
51
|
-
const getCedarRouteManifest = () => [...cedarRouteManifest];
|
|
52
|
-
const setLambdaFunctions = async (foundFunctions) => {
|
|
53
|
-
const tsImport = Date.now();
|
|
54
|
-
console.log(import_ansis.default.dim.italic("Importing Server Functions... "));
|
|
55
|
-
cedarRouteManifest.length = 0;
|
|
56
|
-
LAMBDA_FUNCTIONS.clear();
|
|
57
|
-
CEDAR_HANDLERS.clear();
|
|
58
|
-
const imports = foundFunctions.map(async (fnPath) => {
|
|
59
|
-
const ts = Date.now();
|
|
60
|
-
const routeName = import_node_path.default.basename(fnPath).replace(".js", "");
|
|
61
|
-
const routePath = `/${routeName}`;
|
|
62
|
-
const fnImport = await import((0, import_node_url.pathToFileURL)(fnPath).href);
|
|
63
|
-
const handler = (() => {
|
|
64
|
-
if ("handler" in fnImport) {
|
|
65
|
-
return fnImport.handler;
|
|
66
|
-
}
|
|
67
|
-
if ("default" in fnImport) {
|
|
68
|
-
if ("handler" in fnImport.default) {
|
|
69
|
-
return fnImport.default.handler;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return void 0;
|
|
73
|
-
})();
|
|
74
|
-
const cedarHandler = (() => {
|
|
75
|
-
if ("handleRequest" in fnImport && typeof fnImport.handleRequest === "function") {
|
|
76
|
-
return fnImport.handleRequest;
|
|
77
|
-
}
|
|
78
|
-
if ("default" in fnImport && fnImport.default && "handleRequest" in fnImport.default && typeof fnImport.default.handleRequest === "function") {
|
|
79
|
-
return fnImport.default.handleRequest;
|
|
80
|
-
}
|
|
81
|
-
return void 0;
|
|
82
|
-
})();
|
|
83
|
-
if (handler) {
|
|
84
|
-
LAMBDA_FUNCTIONS.set(routeName, handler);
|
|
85
|
-
}
|
|
86
|
-
if (cedarHandler) {
|
|
87
|
-
CEDAR_HANDLERS.set(routeName, cedarHandler);
|
|
88
|
-
} else if (handler) {
|
|
89
|
-
CEDAR_HANDLERS.set(routeName, (0, import_runtime.wrapLegacyHandler)(handler));
|
|
90
|
-
}
|
|
91
|
-
if (!handler && !cedarHandler) {
|
|
92
|
-
console.warn(
|
|
93
|
-
routeName,
|
|
94
|
-
"at",
|
|
95
|
-
fnPath,
|
|
96
|
-
"does not have a function called handler or handleRequest defined."
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
cedarRouteManifest.push({
|
|
100
|
-
id: routePath,
|
|
101
|
-
path: routePath,
|
|
102
|
-
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [],
|
|
103
|
-
type: routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function",
|
|
104
|
-
entry: fnPath
|
|
105
|
-
});
|
|
106
|
-
console.log(
|
|
107
|
-
(0, import_termi_link.terminalLink)(import_ansis.default.magenta("/" + routeName), (0, import_node_url.pathToFileURL)(fnPath).href),
|
|
108
|
-
import_ansis.default.dim.italic(Date.now() - ts + " ms")
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
await Promise.all(imports);
|
|
112
|
-
console.log(
|
|
113
|
-
import_ansis.default.dim.italic("...Done importing in " + (Date.now() - tsImport) + " ms")
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
const loadFunctionsFromDist = async (options = {}) => {
|
|
117
|
-
const serverFunctions = findApiDistFunctions({
|
|
118
|
-
cwd: (0, import_project_config.getPaths)().api.base,
|
|
119
|
-
options: options?.fastGlobOptions,
|
|
120
|
-
discoverFunctionsGlob: options?.discoverFunctionsGlob
|
|
121
|
-
});
|
|
122
|
-
const i = serverFunctions.findIndex((x) => import_node_path.default.basename(x) === "graphql.js");
|
|
123
|
-
if (i >= 0) {
|
|
124
|
-
const graphQLFn = serverFunctions.splice(i, 1)[0];
|
|
125
|
-
serverFunctions.unshift(graphQLFn);
|
|
126
|
-
}
|
|
127
|
-
await setLambdaFunctions(serverFunctions);
|
|
128
|
-
};
|
|
129
|
-
const findApiDistFunctions = (params) => {
|
|
130
|
-
const {
|
|
131
|
-
cwd = (0, import_project_config.getPaths)().api.base,
|
|
132
|
-
options = {},
|
|
133
|
-
discoverFunctionsGlob = "dist/functions/**/*.{ts,js}"
|
|
134
|
-
} = params;
|
|
135
|
-
return import_fast_glob.default.sync(discoverFunctionsGlob, {
|
|
136
|
-
cwd,
|
|
137
|
-
// We don't support deeply nested api functions, to maximise compatibility
|
|
138
|
-
// with deployment providers
|
|
139
|
-
deep: 2,
|
|
140
|
-
absolute: true,
|
|
141
|
-
...options
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
const lambdaRequestHandler = async (req, reply) => {
|
|
145
|
-
const { routeName } = req.params;
|
|
146
|
-
const cedarHandlerCandidate = CEDAR_HANDLERS.get(routeName);
|
|
147
|
-
const cedarHandler = typeof cedarHandlerCandidate === "function" ? cedarHandlerCandidate : void 0;
|
|
148
|
-
if (cedarHandler) {
|
|
149
|
-
const requestBody = req.method === "GET" || req.method === "HEAD" ? void 0 : typeof req.rawBody === "string" ? req.rawBody : req.rawBody ? Buffer.from(req.rawBody).toString() : void 0;
|
|
150
|
-
const href = `${req.protocol}://${req.hostname}${req.raw.url ?? "/"}`;
|
|
151
|
-
const request = new Request(href, {
|
|
152
|
-
method: req.method,
|
|
153
|
-
headers: req.headers,
|
|
154
|
-
body: requestBody
|
|
155
|
-
});
|
|
156
|
-
const ctx = await (0, import_runtime.buildCedarContext)(request, {
|
|
157
|
-
params: {
|
|
158
|
-
routeName
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
const response = await cedarHandler(request, ctx);
|
|
162
|
-
reply.status(response.status);
|
|
163
|
-
response.headers.forEach((value, name) => {
|
|
164
|
-
reply.header(name, value);
|
|
165
|
-
});
|
|
166
|
-
const body = await response.arrayBuffer();
|
|
167
|
-
reply.send(Buffer.from(body));
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const handler = LAMBDA_FUNCTIONS.get(routeName);
|
|
171
|
-
if (handler) {
|
|
172
|
-
return (0, import_awsLambdaFastify.requestHandler)(req, reply, handler);
|
|
173
|
-
} else {
|
|
174
|
-
const errorMessage = `Function "${routeName}" was not found.`;
|
|
175
|
-
req.log.error(errorMessage);
|
|
176
|
-
reply.status(404);
|
|
177
|
-
if (process.env.NODE_ENV === "development") {
|
|
178
|
-
const devError = {
|
|
179
|
-
error: errorMessage,
|
|
180
|
-
availableFunctions: [
|
|
181
|
-
.../* @__PURE__ */ new Set([...LAMBDA_FUNCTIONS.keys(), ...CEDAR_HANDLERS.keys()])
|
|
182
|
-
]
|
|
183
|
-
};
|
|
184
|
-
reply.send(devError);
|
|
185
|
-
} else {
|
|
186
|
-
reply.send((0, import_utils.escape)(errorMessage));
|
|
187
|
-
}
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
192
|
-
0 && (module.exports = {
|
|
193
|
-
CEDAR_HANDLERS,
|
|
194
|
-
LAMBDA_FUNCTIONS,
|
|
195
|
-
getCedarRouteManifest,
|
|
196
|
-
lambdaRequestHandler,
|
|
197
|
-
loadFunctionsFromDist,
|
|
198
|
-
setLambdaFunctions
|
|
199
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { APIGatewayProxyEvent, Handler } from 'aws-lambda';
|
|
2
|
-
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
3
|
-
export declare const lambdaEventForFastifyRequest: (request: FastifyRequest) => APIGatewayProxyEvent;
|
|
4
|
-
export declare const requestHandler: (req: FastifyRequest, reply: FastifyReply, handler: Handler) => Promise<void>;
|
|
5
|
-
//# sourceMappingURL=awsLambdaFastify.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"awsLambdaFastify.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/awsLambdaFastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACpB,OAAO,EAGR,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAK3D,eAAO,MAAM,4BAA4B,GACvC,SAAS,cAAc,KACtB,oBA6BF,CAAA;AAoCD,eAAO,MAAM,cAAc,GACzB,KAAK,cAAc,EACnB,OAAO,YAAY,EACnB,SAAS,OAAO,kBAmCjB,CAAA"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var awsLambdaFastify_exports = {};
|
|
20
|
-
__export(awsLambdaFastify_exports, {
|
|
21
|
-
lambdaEventForFastifyRequest: () => lambdaEventForFastifyRequest,
|
|
22
|
-
requestHandler: () => requestHandler
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(awsLambdaFastify_exports);
|
|
25
|
-
var import_picoquery = require("picoquery");
|
|
26
|
-
var import_utils = require("./utils.js");
|
|
27
|
-
const lambdaEventForFastifyRequest = (request) => {
|
|
28
|
-
const qsParams = (0, import_picoquery.parse)(
|
|
29
|
-
request.url.split(/\?(.+)/)[1],
|
|
30
|
-
{
|
|
31
|
-
nestingSyntax: "index",
|
|
32
|
-
arrayRepeat: true,
|
|
33
|
-
arrayRepeatSyntax: "bracket"
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
return {
|
|
37
|
-
httpMethod: request.method,
|
|
38
|
-
headers: {
|
|
39
|
-
"x-forwarded-proto": request.protocol,
|
|
40
|
-
...request.headers
|
|
41
|
-
},
|
|
42
|
-
path: request.urlData("path"),
|
|
43
|
-
queryStringParameters: qsParams,
|
|
44
|
-
requestContext: {
|
|
45
|
-
requestId: request.id,
|
|
46
|
-
identity: {
|
|
47
|
-
sourceIp: request.ip
|
|
48
|
-
},
|
|
49
|
-
domainName: request.hostname
|
|
50
|
-
},
|
|
51
|
-
...(0, import_utils.parseBody)(request.rawBody || "")
|
|
52
|
-
// adds `body` and `isBase64Encoded`
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
const fastifyResponseForLambdaResult = (reply, lambdaResult) => {
|
|
56
|
-
const {
|
|
57
|
-
statusCode = 200,
|
|
58
|
-
headers,
|
|
59
|
-
body = "",
|
|
60
|
-
multiValueHeaders
|
|
61
|
-
} = lambdaResult;
|
|
62
|
-
const mergedHeaders = (0, import_utils.mergeMultiValueHeaders)(headers, multiValueHeaders);
|
|
63
|
-
Object.entries(mergedHeaders).forEach(
|
|
64
|
-
([name, values]) => values.forEach((value) => reply.header(name, value))
|
|
65
|
-
);
|
|
66
|
-
reply.status(statusCode);
|
|
67
|
-
if (lambdaResult.isBase64Encoded) {
|
|
68
|
-
return reply.send(Buffer.from(body, "base64"));
|
|
69
|
-
} else {
|
|
70
|
-
return reply.send(body);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const fastifyResponseForLambdaError = (req, reply, error) => {
|
|
74
|
-
req.log.error(error);
|
|
75
|
-
reply.status(500).send();
|
|
76
|
-
};
|
|
77
|
-
const requestHandler = async (req, reply, handler) => {
|
|
78
|
-
const event = lambdaEventForFastifyRequest(req);
|
|
79
|
-
const handlerCallback = (reply2) => (error, lambdaResult) => {
|
|
80
|
-
if (error) {
|
|
81
|
-
fastifyResponseForLambdaError(req, reply2, error);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
fastifyResponseForLambdaResult(reply2, lambdaResult);
|
|
85
|
-
};
|
|
86
|
-
const handlerPromise = handler(
|
|
87
|
-
event,
|
|
88
|
-
// @ts-expect-error - Add support for context: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0bb210867d16170c4a08d9ce5d132817651a0f80/types/aws-lambda/index.d.ts#L443-L467
|
|
89
|
-
{},
|
|
90
|
-
handlerCallback(reply)
|
|
91
|
-
);
|
|
92
|
-
if (handlerPromise && typeof handlerPromise.then === "function") {
|
|
93
|
-
try {
|
|
94
|
-
const lambdaResponse = await handlerPromise;
|
|
95
|
-
return fastifyResponseForLambdaResult(reply, lambdaResponse);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
return fastifyResponseForLambdaError(req, reply, error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
-
0 && (module.exports = {
|
|
103
|
-
lambdaEventForFastifyRequest,
|
|
104
|
-
requestHandler
|
|
105
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
type ParseBodyResult = {
|
|
2
|
-
body: string;
|
|
3
|
-
isBase64Encoded: boolean;
|
|
4
|
-
};
|
|
5
|
-
type FastifyHeaderValue = string | number | boolean;
|
|
6
|
-
type FastifyMergedHeaders = {
|
|
7
|
-
[name: string]: FastifyHeaderValue[];
|
|
8
|
-
};
|
|
9
|
-
type FastifyRequestHeader = {
|
|
10
|
-
[header: string]: FastifyHeaderValue;
|
|
11
|
-
};
|
|
12
|
-
type FastifyLambdaHeaders = FastifyRequestHeader | undefined;
|
|
13
|
-
type FastifyLambdaMultiValueHeaders = FastifyMergedHeaders | undefined;
|
|
14
|
-
export declare const parseBody: (rawBody: string | Buffer) => ParseBodyResult;
|
|
15
|
-
/**
|
|
16
|
-
* `headers` and `multiValueHeaders` are merged into a single object where the
|
|
17
|
-
* key is the header name in lower-case and the value is a list of values for
|
|
18
|
-
* that header. Most multi-values are merged into a single value separated by a
|
|
19
|
-
* semi-colon. The only exception is set-cookie. set-cookie headers should not
|
|
20
|
-
* be merged, they should be set individually by multiple calls to
|
|
21
|
-
* reply.header(). See
|
|
22
|
-
* https://www.fastify.io/docs/latest/Reference/Reply/#set-cookie
|
|
23
|
-
*/
|
|
24
|
-
export declare const mergeMultiValueHeaders: (headers: FastifyLambdaHeaders, multiValueHeaders: FastifyLambdaMultiValueHeaders) => FastifyMergedHeaders;
|
|
25
|
-
export {};
|
|
26
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/utils.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,OAAO,CAAA;CACzB,CAAA;AAED,KAAK,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAEnD,KAAK,oBAAoB,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAAA;CAAE,CAAA;AAEpE,KAAK,oBAAoB,GAAG;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAAA;CAAE,CAAA;AAEpE,KAAK,oBAAoB,GAAG,oBAAoB,GAAG,SAAS,CAAA;AAE5D,KAAK,8BAA8B,GAAG,oBAAoB,GAAG,SAAS,CAAA;AAEtE,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,GAAG,MAAM,KAAG,eAQpD,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,oBAAoB,EAC7B,mBAAmB,8BAA8B,yBAqBlD,CAAA"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var utils_exports = {};
|
|
20
|
-
__export(utils_exports, {
|
|
21
|
-
mergeMultiValueHeaders: () => mergeMultiValueHeaders,
|
|
22
|
-
parseBody: () => parseBody
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(utils_exports);
|
|
25
|
-
const parseBody = (rawBody) => {
|
|
26
|
-
if (typeof rawBody === "string") {
|
|
27
|
-
return { body: rawBody, isBase64Encoded: false };
|
|
28
|
-
}
|
|
29
|
-
if (rawBody instanceof Buffer) {
|
|
30
|
-
return { body: rawBody.toString("base64"), isBase64Encoded: true };
|
|
31
|
-
}
|
|
32
|
-
return { body: "", isBase64Encoded: false };
|
|
33
|
-
};
|
|
34
|
-
const mergeMultiValueHeaders = (headers, multiValueHeaders) => {
|
|
35
|
-
const mergedHeaders = Object.entries(
|
|
36
|
-
headers || {}
|
|
37
|
-
).reduce((acc, [name, value]) => {
|
|
38
|
-
acc[name.toLowerCase()] = [value];
|
|
39
|
-
return acc;
|
|
40
|
-
}, {});
|
|
41
|
-
Object.entries(multiValueHeaders || {}).forEach(([headerName, values]) => {
|
|
42
|
-
const name = headerName.toLowerCase();
|
|
43
|
-
if (name.toLowerCase() === "set-cookie") {
|
|
44
|
-
mergedHeaders["set-cookie"] = values;
|
|
45
|
-
} else {
|
|
46
|
-
mergedHeaders[name] = [values.join("; ")];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return mergedHeaders;
|
|
50
|
-
};
|
|
51
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
-
0 && (module.exports = {
|
|
53
|
-
mergeMultiValueHeaders,
|
|
54
|
-
parseBody
|
|
55
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serverManager.d.ts","sourceRoot":"","sources":["../../src/serverManager.ts"],"names":[],"mappings":"AA6BA,qBAAa,aAAa;IACxB,OAAO,CAAC,iBAAiB,CAA4B;YAEvC,cAAc;IAyDtB,gBAAgB;IAKhB,aAAa;CAmCpB;AAED,eAAO,MAAM,aAAa,eAAsB,CAAA"}
|