@cedarjs/api-server 4.1.1-next.1 → 4.1.1-next.55
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/bin.js +2 -1
- package/dist/cjs/bin.js +2 -1
- package/dist/cjs/plugins/lambdaLoader.js +2 -1
- package/dist/plugins/lambdaLoader.js +2 -1
- package/package.json +15 -14
- package/LICENSE +0 -21
- package/dist/cjs/udDispatcher.d.ts +0 -28
- package/dist/cjs/udDispatcher.d.ts.map +0 -1
- package/dist/cjs/udDispatcher.js +0 -192
- package/dist/udDispatcher.d.ts +0 -28
- package/dist/udDispatcher.d.ts.map +0 -1
- package/dist/udDispatcher.js +0 -158
package/dist/bin.js
CHANGED
|
@@ -388,8 +388,9 @@ var init_lambdaLoader = __esm({
|
|
|
388
388
|
);
|
|
389
389
|
}
|
|
390
390
|
cedarRouteManifest.push({
|
|
391
|
+
id: routePath,
|
|
391
392
|
path: routePath,
|
|
392
|
-
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [
|
|
393
|
+
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [],
|
|
393
394
|
type: routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function",
|
|
394
395
|
entry: fnPath
|
|
395
396
|
});
|
package/dist/cjs/bin.js
CHANGED
|
@@ -410,8 +410,9 @@ var init_lambdaLoader = __esm({
|
|
|
410
410
|
);
|
|
411
411
|
}
|
|
412
412
|
cedarRouteManifest.push({
|
|
413
|
+
id: routePath,
|
|
413
414
|
path: routePath,
|
|
414
|
-
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [
|
|
415
|
+
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [],
|
|
415
416
|
type: routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function",
|
|
416
417
|
entry: fnPath
|
|
417
418
|
});
|
|
@@ -97,8 +97,9 @@ const setLambdaFunctions = async (foundFunctions) => {
|
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
99
|
cedarRouteManifest.push({
|
|
100
|
+
id: routePath,
|
|
100
101
|
path: routePath,
|
|
101
|
-
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [
|
|
102
|
+
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [],
|
|
102
103
|
type: routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function",
|
|
103
104
|
entry: fnPath
|
|
104
105
|
});
|
|
@@ -59,8 +59,9 @@ const setLambdaFunctions = async (foundFunctions) => {
|
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
cedarRouteManifest.push({
|
|
62
|
+
id: routePath,
|
|
62
63
|
path: routePath,
|
|
63
|
-
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [
|
|
64
|
+
methods: routeName === "graphql" ? ["GET", "POST", "OPTIONS"] : [],
|
|
64
65
|
type: routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function",
|
|
65
66
|
entry: fnPath
|
|
66
67
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/api-server",
|
|
3
|
-
"version": "4.1.1-next.
|
|
3
|
+
"version": "4.1.1-next.55",
|
|
4
4
|
"description": "CedarJS's HTTP server for Serverless Functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -73,10 +73,14 @@
|
|
|
73
73
|
"types": "./dist/cjs/bothCLIConfigHandler.d.ts",
|
|
74
74
|
"default": "./dist/cjs/bothCLIConfigHandler.js"
|
|
75
75
|
},
|
|
76
|
-
"./
|
|
76
|
+
"./fastify": {
|
|
77
77
|
"import": {
|
|
78
|
-
"types": "./dist/
|
|
79
|
-
"default": "./dist/
|
|
78
|
+
"types": "./dist/fastify.d.ts",
|
|
79
|
+
"default": "./dist/fastify.js"
|
|
80
|
+
},
|
|
81
|
+
"require": {
|
|
82
|
+
"types": "./dist/cjs/fastify.d.ts",
|
|
83
|
+
"default": "./dist/cjs/fastify.js"
|
|
80
84
|
}
|
|
81
85
|
},
|
|
82
86
|
"./udFetchable": {
|
|
@@ -135,15 +139,14 @@
|
|
|
135
139
|
"test:watch": "vitest watch"
|
|
136
140
|
},
|
|
137
141
|
"dependencies": {
|
|
138
|
-
"@cedarjs/context": "4.1.
|
|
139
|
-
"@cedarjs/fastify-web": "4.1.
|
|
140
|
-
"@cedarjs/internal": "4.1.
|
|
141
|
-
"@cedarjs/project-config": "4.1.
|
|
142
|
-
"@cedarjs/web-server": "4.1.
|
|
142
|
+
"@cedarjs/context": "4.1.0",
|
|
143
|
+
"@cedarjs/fastify-web": "4.1.0",
|
|
144
|
+
"@cedarjs/internal": "4.1.0",
|
|
145
|
+
"@cedarjs/project-config": "4.1.0",
|
|
146
|
+
"@cedarjs/web-server": "4.1.0",
|
|
143
147
|
"@fastify/multipart": "9.4.0",
|
|
144
148
|
"@fastify/url-data": "6.0.3",
|
|
145
149
|
"@universal-deploy/node": "^0.1.6",
|
|
146
|
-
"@universal-deploy/store": "^0.2.1",
|
|
147
150
|
"ansis": "4.2.0",
|
|
148
151
|
"chokidar": "3.6.0",
|
|
149
152
|
"dotenv-defaults": "5.0.2",
|
|
@@ -154,14 +157,12 @@
|
|
|
154
157
|
"picoquery": "2.5.0",
|
|
155
158
|
"pretty-bytes": "5.6.0",
|
|
156
159
|
"pretty-ms": "7.0.1",
|
|
157
|
-
"rou3": "^0.8.1",
|
|
158
160
|
"split2": "4.2.0",
|
|
159
|
-
"srvx": "^0.11.9",
|
|
160
161
|
"termi-link": "1.1.0",
|
|
161
162
|
"yargs": "17.7.2"
|
|
162
163
|
},
|
|
163
164
|
"devDependencies": {
|
|
164
|
-
"@cedarjs/framework-tools": "4.1.1-next.
|
|
165
|
+
"@cedarjs/framework-tools": "4.1.1-next.55",
|
|
165
166
|
"@types/aws-lambda": "8.10.161",
|
|
166
167
|
"@types/dotenv-defaults": "^5.0.0",
|
|
167
168
|
"@types/split2": "4.2.3",
|
|
@@ -184,5 +185,5 @@
|
|
|
184
185
|
"publishConfig": {
|
|
185
186
|
"access": "public"
|
|
186
187
|
},
|
|
187
|
-
"gitHead": "
|
|
188
|
+
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
|
|
188
189
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Cedar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { EntryMeta } from '@universal-deploy/store';
|
|
2
|
-
import type { Fetchable } from './udFetchable.js';
|
|
3
|
-
export interface CedarDispatcherOptions {
|
|
4
|
-
apiRootPath?: string;
|
|
5
|
-
discoverFunctionsGlob?: string | string[];
|
|
6
|
-
/**
|
|
7
|
-
* Cache-bust token appended to dynamic ESM imports. Use this in dev to
|
|
8
|
-
* bypass Node.js's ESM module cache after a rebuild. Production builds
|
|
9
|
-
* should omit this.
|
|
10
|
-
*/
|
|
11
|
-
cacheBust?: string | number;
|
|
12
|
-
}
|
|
13
|
-
export interface CedarDispatcherResult {
|
|
14
|
-
fetchable: Fetchable;
|
|
15
|
-
registrations: EntryMeta[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Shared aggregate Cedar API dispatcher used by
|
|
19
|
-
* `cedarUniversalDeployPlugin` (via `virtual:cedar-api`).
|
|
20
|
-
*
|
|
21
|
-
* Discovers Cedar API functions in `api/dist/functions/`, builds a rou3 router
|
|
22
|
-
* and a map of route names to Fetchables, then returns a single Fetchable that
|
|
23
|
-
* routes incoming Fetch-API requests to the correct per-function handler.
|
|
24
|
-
* Also returns the list of `EntryMeta` registrations so callers can forward
|
|
25
|
-
* them to `@universal-deploy/store` via `addEntry()`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function buildCedarDispatcher(options?: CedarDispatcherOptions): Promise<CedarDispatcherResult>;
|
|
28
|
-
//# sourceMappingURL=udDispatcher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"udDispatcher.d.ts","sourceRoot":"","sources":["../../src/udDispatcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAUxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAgBjD,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,SAAS,CAAA;IACpB,aAAa,EAAE,SAAS,EAAE,CAAA;CAC3B;AA6BD;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,CAmNhC"}
|
package/dist/cjs/udDispatcher.js
DELETED
|
@@ -1,192 +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 udDispatcher_exports = {};
|
|
30
|
-
__export(udDispatcher_exports, {
|
|
31
|
-
buildCedarDispatcher: () => buildCedarDispatcher
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(udDispatcher_exports);
|
|
34
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
-
var import_node_url = require("node:url");
|
|
36
|
-
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
37
|
-
var import_rou3 = require("rou3");
|
|
38
|
-
var import_runtime = require("@cedarjs/api/runtime");
|
|
39
|
-
var import_store = require("@cedarjs/context/dist/store");
|
|
40
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
41
|
-
var import_udFetchable = require("./udFetchable.js");
|
|
42
|
-
const ALL_HTTP_METHODS = [
|
|
43
|
-
"GET",
|
|
44
|
-
"HEAD",
|
|
45
|
-
"POST",
|
|
46
|
-
"PUT",
|
|
47
|
-
"DELETE",
|
|
48
|
-
"PATCH",
|
|
49
|
-
"OPTIONS",
|
|
50
|
-
"CONNECT",
|
|
51
|
-
"TRACE"
|
|
52
|
-
];
|
|
53
|
-
const GRAPHQL_METHODS = ["GET", "POST", "OPTIONS"];
|
|
54
|
-
function normalizeApiRootPath(rootPath) {
|
|
55
|
-
let normalized = rootPath;
|
|
56
|
-
if (!normalized.startsWith("/")) {
|
|
57
|
-
normalized = "/" + normalized;
|
|
58
|
-
}
|
|
59
|
-
if (!normalized.endsWith("/")) {
|
|
60
|
-
normalized = normalized + "/";
|
|
61
|
-
}
|
|
62
|
-
return normalized;
|
|
63
|
-
}
|
|
64
|
-
async function buildCedarDispatcher(options) {
|
|
65
|
-
const normalizedApiRootPath = normalizeApiRootPath(
|
|
66
|
-
options?.apiRootPath ?? "/"
|
|
67
|
-
);
|
|
68
|
-
const discoverFunctionsGlob = options?.discoverFunctionsGlob ?? "dist/functions/**/*.{ts,js}";
|
|
69
|
-
const serverFunctions = import_fast_glob.default.sync(discoverFunctionsGlob, {
|
|
70
|
-
cwd: (0, import_project_config.getPaths)().api.base,
|
|
71
|
-
deep: 2,
|
|
72
|
-
absolute: true
|
|
73
|
-
});
|
|
74
|
-
const graphqlIdx = serverFunctions.findIndex(
|
|
75
|
-
(x) => import_node_path.default.basename(x, import_node_path.default.extname(x)) === "graphql"
|
|
76
|
-
);
|
|
77
|
-
if (graphqlIdx >= 0) {
|
|
78
|
-
const [graphqlFn] = serverFunctions.splice(graphqlIdx, 1);
|
|
79
|
-
serverFunctions.unshift(graphqlFn);
|
|
80
|
-
}
|
|
81
|
-
const fetchableMap = /* @__PURE__ */ new Map();
|
|
82
|
-
const router = (0, import_rou3.createRouter)();
|
|
83
|
-
const registrations = [];
|
|
84
|
-
for (const fnPath of serverFunctions) {
|
|
85
|
-
const routeName = import_node_path.default.basename(fnPath, import_node_path.default.extname(fnPath));
|
|
86
|
-
const routePath = routeName === "graphql" ? "/graphql" : `/${routeName}`;
|
|
87
|
-
const importUrl = options?.cacheBust ? `${(0, import_node_url.pathToFileURL)(fnPath).href}?t=${options.cacheBust}` : (0, import_node_url.pathToFileURL)(fnPath).href;
|
|
88
|
-
const fnImport = await import(importUrl);
|
|
89
|
-
if ("__rw_graphqlOptions" in fnImport && fnImport.__rw_graphqlOptions != null) {
|
|
90
|
-
const { createGraphQLYoga } = await import("@cedarjs/graphql-server");
|
|
91
|
-
const graphqlOptions = fnImport.__rw_graphqlOptions;
|
|
92
|
-
const { yoga } = await createGraphQLYoga(graphqlOptions);
|
|
93
|
-
const graphqlFetchable = {
|
|
94
|
-
async fetch(request) {
|
|
95
|
-
const cedarContext = await (0, import_runtime.buildCedarContext)(request, {
|
|
96
|
-
authDecoder: graphqlOptions.authDecoder
|
|
97
|
-
});
|
|
98
|
-
const event = await (0, import_runtime.requestToLegacyEvent)(request, cedarContext);
|
|
99
|
-
return yoga.handle(request, {
|
|
100
|
-
request,
|
|
101
|
-
cedarContext,
|
|
102
|
-
event,
|
|
103
|
-
requestContext: void 0
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
fetchableMap.set(routeName, graphqlFetchable);
|
|
108
|
-
registrations.push({
|
|
109
|
-
id: routePath,
|
|
110
|
-
route: routePath,
|
|
111
|
-
method: [...GRAPHQL_METHODS]
|
|
112
|
-
});
|
|
113
|
-
for (const method of GRAPHQL_METHODS) {
|
|
114
|
-
(0, import_rou3.addRoute)(router, method, routePath, routeName);
|
|
115
|
-
(0, import_rou3.addRoute)(router, method, `${routePath}/**`, routeName);
|
|
116
|
-
}
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
const cedarHandler = (() => {
|
|
120
|
-
if ("handle" in fnImport && typeof fnImport.handle === "function") {
|
|
121
|
-
return fnImport.handle;
|
|
122
|
-
}
|
|
123
|
-
if ("default" in fnImport && fnImport.default != null && "handle" in fnImport.default && typeof fnImport.default.handle === "function") {
|
|
124
|
-
return fnImport.default.handle;
|
|
125
|
-
}
|
|
126
|
-
return void 0;
|
|
127
|
-
})();
|
|
128
|
-
if (!cedarHandler) {
|
|
129
|
-
console.warn(
|
|
130
|
-
routeName,
|
|
131
|
-
"at",
|
|
132
|
-
fnPath,
|
|
133
|
-
"does not export a Fetch-native `handle` function and will not be served by the Universal Deploy server. Migrate to `export async function handle(request, ctx)` or use `yarn cedar serve` for legacy Lambda-shaped handler support."
|
|
134
|
-
);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
const handler = cedarHandler;
|
|
138
|
-
fetchableMap.set(routeName, (0, import_udFetchable.createCedarFetchable)(handler));
|
|
139
|
-
registrations.push({
|
|
140
|
-
id: routePath,
|
|
141
|
-
route: routePath
|
|
142
|
-
// method omitted → matches all HTTP methods per @universal-deploy/store docs
|
|
143
|
-
});
|
|
144
|
-
for (const method of ALL_HTTP_METHODS) {
|
|
145
|
-
(0, import_rou3.addRoute)(router, method, routePath, routeName);
|
|
146
|
-
(0, import_rou3.addRoute)(router, method, `${routePath}/**`, routeName);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
const fetchable = {
|
|
150
|
-
fetch(request) {
|
|
151
|
-
return (0, import_store.getAsyncStoreInstance)().run(
|
|
152
|
-
/* @__PURE__ */ new Map(),
|
|
153
|
-
async () => {
|
|
154
|
-
const url = new URL(request.url);
|
|
155
|
-
let routePathname = url.pathname;
|
|
156
|
-
if (normalizedApiRootPath !== "/" && routePathname.startsWith(normalizedApiRootPath)) {
|
|
157
|
-
routePathname = routePathname.slice(
|
|
158
|
-
normalizedApiRootPath.length - 1
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
if (!routePathname.startsWith("/")) {
|
|
162
|
-
routePathname = "/" + routePathname;
|
|
163
|
-
}
|
|
164
|
-
const match = (0, import_rou3.findRoute)(router, request.method, routePathname);
|
|
165
|
-
if (!match) {
|
|
166
|
-
return new Response("Not Found", { status: 404 });
|
|
167
|
-
}
|
|
168
|
-
const matchedRouteName = match.data;
|
|
169
|
-
const fnFetchable = fetchableMap.get(matchedRouteName);
|
|
170
|
-
if (!fnFetchable) {
|
|
171
|
-
return new Response("Not Found", { status: 404 });
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
return await fnFetchable.fetch(request);
|
|
175
|
-
} catch (err) {
|
|
176
|
-
console.error(
|
|
177
|
-
"Unhandled error in fetch handler for route",
|
|
178
|
-
matchedRouteName,
|
|
179
|
-
err
|
|
180
|
-
);
|
|
181
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
return { fetchable, registrations };
|
|
188
|
-
}
|
|
189
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
-
0 && (module.exports = {
|
|
191
|
-
buildCedarDispatcher
|
|
192
|
-
});
|
package/dist/udDispatcher.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { EntryMeta } from '@universal-deploy/store';
|
|
2
|
-
import type { Fetchable } from './udFetchable.js';
|
|
3
|
-
export interface CedarDispatcherOptions {
|
|
4
|
-
apiRootPath?: string;
|
|
5
|
-
discoverFunctionsGlob?: string | string[];
|
|
6
|
-
/**
|
|
7
|
-
* Cache-bust token appended to dynamic ESM imports. Use this in dev to
|
|
8
|
-
* bypass Node.js's ESM module cache after a rebuild. Production builds
|
|
9
|
-
* should omit this.
|
|
10
|
-
*/
|
|
11
|
-
cacheBust?: string | number;
|
|
12
|
-
}
|
|
13
|
-
export interface CedarDispatcherResult {
|
|
14
|
-
fetchable: Fetchable;
|
|
15
|
-
registrations: EntryMeta[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Shared aggregate Cedar API dispatcher used by
|
|
19
|
-
* `cedarUniversalDeployPlugin` (via `virtual:cedar-api`).
|
|
20
|
-
*
|
|
21
|
-
* Discovers Cedar API functions in `api/dist/functions/`, builds a rou3 router
|
|
22
|
-
* and a map of route names to Fetchables, then returns a single Fetchable that
|
|
23
|
-
* routes incoming Fetch-API requests to the correct per-function handler.
|
|
24
|
-
* Also returns the list of `EntryMeta` registrations so callers can forward
|
|
25
|
-
* them to `@universal-deploy/store` via `addEntry()`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function buildCedarDispatcher(options?: CedarDispatcherOptions): Promise<CedarDispatcherResult>;
|
|
28
|
-
//# sourceMappingURL=udDispatcher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"udDispatcher.d.ts","sourceRoot":"","sources":["../src/udDispatcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAUxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAgBjD,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,SAAS,CAAA;IACpB,aAAa,EAAE,SAAS,EAAE,CAAA;CAC3B;AA6BD;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,CAmNhC"}
|
package/dist/udDispatcher.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
|
-
import fg from "fast-glob";
|
|
4
|
-
import { addRoute, createRouter, findRoute } from "rou3";
|
|
5
|
-
import { buildCedarContext, requestToLegacyEvent } from "@cedarjs/api/runtime";
|
|
6
|
-
import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
|
|
7
|
-
import { getPaths } from "@cedarjs/project-config";
|
|
8
|
-
import { createCedarFetchable } from "./udFetchable.js";
|
|
9
|
-
const ALL_HTTP_METHODS = [
|
|
10
|
-
"GET",
|
|
11
|
-
"HEAD",
|
|
12
|
-
"POST",
|
|
13
|
-
"PUT",
|
|
14
|
-
"DELETE",
|
|
15
|
-
"PATCH",
|
|
16
|
-
"OPTIONS",
|
|
17
|
-
"CONNECT",
|
|
18
|
-
"TRACE"
|
|
19
|
-
];
|
|
20
|
-
const GRAPHQL_METHODS = ["GET", "POST", "OPTIONS"];
|
|
21
|
-
function normalizeApiRootPath(rootPath) {
|
|
22
|
-
let normalized = rootPath;
|
|
23
|
-
if (!normalized.startsWith("/")) {
|
|
24
|
-
normalized = "/" + normalized;
|
|
25
|
-
}
|
|
26
|
-
if (!normalized.endsWith("/")) {
|
|
27
|
-
normalized = normalized + "/";
|
|
28
|
-
}
|
|
29
|
-
return normalized;
|
|
30
|
-
}
|
|
31
|
-
async function buildCedarDispatcher(options) {
|
|
32
|
-
const normalizedApiRootPath = normalizeApiRootPath(
|
|
33
|
-
options?.apiRootPath ?? "/"
|
|
34
|
-
);
|
|
35
|
-
const discoverFunctionsGlob = options?.discoverFunctionsGlob ?? "dist/functions/**/*.{ts,js}";
|
|
36
|
-
const serverFunctions = fg.sync(discoverFunctionsGlob, {
|
|
37
|
-
cwd: getPaths().api.base,
|
|
38
|
-
deep: 2,
|
|
39
|
-
absolute: true
|
|
40
|
-
});
|
|
41
|
-
const graphqlIdx = serverFunctions.findIndex(
|
|
42
|
-
(x) => path.basename(x, path.extname(x)) === "graphql"
|
|
43
|
-
);
|
|
44
|
-
if (graphqlIdx >= 0) {
|
|
45
|
-
const [graphqlFn] = serverFunctions.splice(graphqlIdx, 1);
|
|
46
|
-
serverFunctions.unshift(graphqlFn);
|
|
47
|
-
}
|
|
48
|
-
const fetchableMap = /* @__PURE__ */ new Map();
|
|
49
|
-
const router = createRouter();
|
|
50
|
-
const registrations = [];
|
|
51
|
-
for (const fnPath of serverFunctions) {
|
|
52
|
-
const routeName = path.basename(fnPath, path.extname(fnPath));
|
|
53
|
-
const routePath = routeName === "graphql" ? "/graphql" : `/${routeName}`;
|
|
54
|
-
const importUrl = options?.cacheBust ? `${pathToFileURL(fnPath).href}?t=${options.cacheBust}` : pathToFileURL(fnPath).href;
|
|
55
|
-
const fnImport = await import(importUrl);
|
|
56
|
-
if ("__rw_graphqlOptions" in fnImport && fnImport.__rw_graphqlOptions != null) {
|
|
57
|
-
const { createGraphQLYoga } = await import("@cedarjs/graphql-server");
|
|
58
|
-
const graphqlOptions = fnImport.__rw_graphqlOptions;
|
|
59
|
-
const { yoga } = await createGraphQLYoga(graphqlOptions);
|
|
60
|
-
const graphqlFetchable = {
|
|
61
|
-
async fetch(request) {
|
|
62
|
-
const cedarContext = await buildCedarContext(request, {
|
|
63
|
-
authDecoder: graphqlOptions.authDecoder
|
|
64
|
-
});
|
|
65
|
-
const event = await requestToLegacyEvent(request, cedarContext);
|
|
66
|
-
return yoga.handle(request, {
|
|
67
|
-
request,
|
|
68
|
-
cedarContext,
|
|
69
|
-
event,
|
|
70
|
-
requestContext: void 0
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
fetchableMap.set(routeName, graphqlFetchable);
|
|
75
|
-
registrations.push({
|
|
76
|
-
id: routePath,
|
|
77
|
-
route: routePath,
|
|
78
|
-
method: [...GRAPHQL_METHODS]
|
|
79
|
-
});
|
|
80
|
-
for (const method of GRAPHQL_METHODS) {
|
|
81
|
-
addRoute(router, method, routePath, routeName);
|
|
82
|
-
addRoute(router, method, `${routePath}/**`, routeName);
|
|
83
|
-
}
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
const cedarHandler = (() => {
|
|
87
|
-
if ("handle" in fnImport && typeof fnImport.handle === "function") {
|
|
88
|
-
return fnImport.handle;
|
|
89
|
-
}
|
|
90
|
-
if ("default" in fnImport && fnImport.default != null && "handle" in fnImport.default && typeof fnImport.default.handle === "function") {
|
|
91
|
-
return fnImport.default.handle;
|
|
92
|
-
}
|
|
93
|
-
return void 0;
|
|
94
|
-
})();
|
|
95
|
-
if (!cedarHandler) {
|
|
96
|
-
console.warn(
|
|
97
|
-
routeName,
|
|
98
|
-
"at",
|
|
99
|
-
fnPath,
|
|
100
|
-
"does not export a Fetch-native `handle` function and will not be served by the Universal Deploy server. Migrate to `export async function handle(request, ctx)` or use `yarn cedar serve` for legacy Lambda-shaped handler support."
|
|
101
|
-
);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const handler = cedarHandler;
|
|
105
|
-
fetchableMap.set(routeName, createCedarFetchable(handler));
|
|
106
|
-
registrations.push({
|
|
107
|
-
id: routePath,
|
|
108
|
-
route: routePath
|
|
109
|
-
// method omitted → matches all HTTP methods per @universal-deploy/store docs
|
|
110
|
-
});
|
|
111
|
-
for (const method of ALL_HTTP_METHODS) {
|
|
112
|
-
addRoute(router, method, routePath, routeName);
|
|
113
|
-
addRoute(router, method, `${routePath}/**`, routeName);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const fetchable = {
|
|
117
|
-
fetch(request) {
|
|
118
|
-
return getAsyncStoreInstance().run(
|
|
119
|
-
/* @__PURE__ */ new Map(),
|
|
120
|
-
async () => {
|
|
121
|
-
const url = new URL(request.url);
|
|
122
|
-
let routePathname = url.pathname;
|
|
123
|
-
if (normalizedApiRootPath !== "/" && routePathname.startsWith(normalizedApiRootPath)) {
|
|
124
|
-
routePathname = routePathname.slice(
|
|
125
|
-
normalizedApiRootPath.length - 1
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
if (!routePathname.startsWith("/")) {
|
|
129
|
-
routePathname = "/" + routePathname;
|
|
130
|
-
}
|
|
131
|
-
const match = findRoute(router, request.method, routePathname);
|
|
132
|
-
if (!match) {
|
|
133
|
-
return new Response("Not Found", { status: 404 });
|
|
134
|
-
}
|
|
135
|
-
const matchedRouteName = match.data;
|
|
136
|
-
const fnFetchable = fetchableMap.get(matchedRouteName);
|
|
137
|
-
if (!fnFetchable) {
|
|
138
|
-
return new Response("Not Found", { status: 404 });
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
return await fnFetchable.fetch(request);
|
|
142
|
-
} catch (err) {
|
|
143
|
-
console.error(
|
|
144
|
-
"Unhandled error in fetch handler for route",
|
|
145
|
-
matchedRouteName,
|
|
146
|
-
err
|
|
147
|
-
);
|
|
148
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
return { fetchable, registrations };
|
|
155
|
-
}
|
|
156
|
-
export {
|
|
157
|
-
buildCedarDispatcher
|
|
158
|
-
};
|