@cedarjs/vite 5.0.0-canary.2374 → 5.0.0-canary.2375
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/plugins/vite-plugin-cedar-universal-deploy.js +102 -11
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +102 -11
- package/package.json +13 -44
- package/dist/cjs/ud-handlers/catch-all.js +0 -65
- package/dist/cjs/ud-handlers/function.js +0 -46
- package/dist/cjs/ud-handlers/graphql.js +0 -58
- package/dist/ud-handlers/catch-all.d.ts +0 -15
- package/dist/ud-handlers/catch-all.d.ts.map +0 -1
- package/dist/ud-handlers/catch-all.js +0 -41
- package/dist/ud-handlers/function.d.ts +0 -5
- package/dist/ud-handlers/function.d.ts.map +0 -1
- package/dist/ud-handlers/function.js +0 -22
- package/dist/ud-handlers/graphql.d.ts +0 -7
- package/dist/ud-handlers/graphql.d.ts.map +0 -1
- package/dist/ud-handlers/graphql.js +0 -34
|
@@ -155,7 +155,7 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
return void 0;
|
|
157
157
|
},
|
|
158
|
-
load(id) {
|
|
158
|
+
async load(id) {
|
|
159
159
|
if (this.environment?.name !== "ssr") {
|
|
160
160
|
return void 0;
|
|
161
161
|
}
|
|
@@ -174,20 +174,111 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
function
|
|
178
|
-
const
|
|
179
|
-
const
|
|
177
|
+
async function bundleDistFile(distPath) {
|
|
178
|
+
const { build } = await import("esbuild");
|
|
179
|
+
const result = await build({
|
|
180
|
+
entryPoints: [distPath],
|
|
181
|
+
bundle: true,
|
|
182
|
+
write: false,
|
|
183
|
+
format: "esm",
|
|
184
|
+
platform: "node",
|
|
185
|
+
target: "node24",
|
|
186
|
+
packages: "external",
|
|
187
|
+
logLevel: "silent"
|
|
188
|
+
});
|
|
189
|
+
let text = result.outputFiles[0].text;
|
|
190
|
+
const exportBlock = text.match(/\nexport\s*\{([^}]*)\};\s*$/);
|
|
191
|
+
if (exportBlock) {
|
|
192
|
+
const defaultExportMatch = exportBlock[1].match(
|
|
193
|
+
/(?:^|,)\s*(\w+)\s+as\s+default\s*(?:,|$)/
|
|
194
|
+
);
|
|
195
|
+
if (defaultExportMatch) {
|
|
196
|
+
const defaultBinding = defaultExportMatch[1];
|
|
197
|
+
text = text.replace(/\nexport\s*\{[^}]*\};\s*$/, "") + `
|
|
198
|
+
const __cedar_default = ${defaultBinding};`;
|
|
199
|
+
} else {
|
|
200
|
+
text = text.replace(/\nexport\s*\{[^}]*\};\s*$/, "");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return text;
|
|
204
|
+
}
|
|
205
|
+
async function generateGraphQLModule(distPath) {
|
|
206
|
+
const bundledCode = await bundleDistFile(distPath);
|
|
180
207
|
return `
|
|
181
|
-
import {
|
|
182
|
-
|
|
208
|
+
import { buildCedarContext, requestToLegacyEvent } from '@cedarjs/api/runtime';
|
|
209
|
+
import { createGraphQLYoga } from '@cedarjs/graphql-server';
|
|
210
|
+
|
|
211
|
+
// Inlined bundle of ${import_node_path.default.basename(distPath)} (node_modules kept external)
|
|
212
|
+
${bundledCode}
|
|
213
|
+
|
|
214
|
+
let yogaInitPromise = null;
|
|
215
|
+
|
|
216
|
+
function getYoga() {
|
|
217
|
+
if (!yogaInitPromise) {
|
|
218
|
+
yogaInitPromise = createGraphQLYoga(__rw_graphqlOptions).then(
|
|
219
|
+
({ yoga }) => ({ yoga, graphqlOptions: __rw_graphqlOptions })
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return yogaInitPromise;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export default {
|
|
226
|
+
async fetch(request) {
|
|
227
|
+
const { yoga, graphqlOptions } = await getYoga();
|
|
228
|
+
const cedarContext = await buildCedarContext(request, {
|
|
229
|
+
authDecoder: graphqlOptions ? graphqlOptions.authDecoder : undefined,
|
|
230
|
+
});
|
|
231
|
+
const event = await requestToLegacyEvent(request, cedarContext);
|
|
232
|
+
return yoga.handle(request, { request, cedarContext, event, requestContext: undefined });
|
|
233
|
+
}
|
|
234
|
+
};
|
|
183
235
|
`;
|
|
184
236
|
}
|
|
185
|
-
function generateFunctionModule(distPath) {
|
|
186
|
-
const
|
|
187
|
-
const
|
|
237
|
+
async function generateFunctionModule(distPath) {
|
|
238
|
+
const bundledCode = await bundleDistFile(distPath);
|
|
239
|
+
const notFoundMsg = JSON.stringify(
|
|
240
|
+
`Handler not found in ${import_node_path.default.basename(distPath)}. Expected \`export async function handleRequest(request, ctx)\`, \`export default async (request, ctx) => Response\`, \`export default { handleRequest }\`, or a legacy Lambda-shaped \`handler\`.`
|
|
241
|
+
);
|
|
188
242
|
return `
|
|
189
|
-
import {
|
|
190
|
-
|
|
243
|
+
import { wrapLegacyHandler, buildCedarContext } from '@cedarjs/api/runtime';
|
|
244
|
+
|
|
245
|
+
// Inlined bundle of ${import_node_path.default.basename(distPath)} (node_modules kept external)
|
|
246
|
+
${bundledCode}
|
|
247
|
+
|
|
248
|
+
const nativeHandler = (() => {
|
|
249
|
+
// Prefer named handleRequest export
|
|
250
|
+
if (typeof handleRequest !== 'undefined') { return handleRequest; }
|
|
251
|
+
// Handle export default { handleRequest } pattern
|
|
252
|
+
if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handleRequest === 'function') {
|
|
253
|
+
return __cedar_default.handleRequest;
|
|
254
|
+
}
|
|
255
|
+
// Handle plain default-exported async function: export default async (req) => Response
|
|
256
|
+
if (typeof __cedar_default !== 'undefined' && typeof __cedar_default === 'function') {
|
|
257
|
+
return __cedar_default;
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
})();
|
|
261
|
+
|
|
262
|
+
const legacyFn = (() => {
|
|
263
|
+
if (typeof handler !== 'undefined') { return handler; }
|
|
264
|
+
if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handler === 'function') {
|
|
265
|
+
return __cedar_default.handler;
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
})();
|
|
269
|
+
|
|
270
|
+
if (!nativeHandler && !legacyFn) {
|
|
271
|
+
throw new Error(${notFoundMsg});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const _handler = nativeHandler ?? wrapLegacyHandler(legacyFn);
|
|
275
|
+
|
|
276
|
+
export default {
|
|
277
|
+
async fetch(request) {
|
|
278
|
+
const ctx = await buildCedarContext(request);
|
|
279
|
+
return _handler(request, ctx);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
191
282
|
`;
|
|
192
283
|
}
|
|
193
284
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -122,7 +122,7 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
122
122
|
}
|
|
123
123
|
return void 0;
|
|
124
124
|
},
|
|
125
|
-
load(id) {
|
|
125
|
+
async load(id) {
|
|
126
126
|
if (this.environment?.name !== "ssr") {
|
|
127
127
|
return void 0;
|
|
128
128
|
}
|
|
@@ -141,20 +141,111 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
function
|
|
145
|
-
const
|
|
146
|
-
const
|
|
144
|
+
async function bundleDistFile(distPath) {
|
|
145
|
+
const { build } = await import("esbuild");
|
|
146
|
+
const result = await build({
|
|
147
|
+
entryPoints: [distPath],
|
|
148
|
+
bundle: true,
|
|
149
|
+
write: false,
|
|
150
|
+
format: "esm",
|
|
151
|
+
platform: "node",
|
|
152
|
+
target: "node24",
|
|
153
|
+
packages: "external",
|
|
154
|
+
logLevel: "silent"
|
|
155
|
+
});
|
|
156
|
+
let text = result.outputFiles[0].text;
|
|
157
|
+
const exportBlock = text.match(/\nexport\s*\{([^}]*)\};\s*$/);
|
|
158
|
+
if (exportBlock) {
|
|
159
|
+
const defaultExportMatch = exportBlock[1].match(
|
|
160
|
+
/(?:^|,)\s*(\w+)\s+as\s+default\s*(?:,|$)/
|
|
161
|
+
);
|
|
162
|
+
if (defaultExportMatch) {
|
|
163
|
+
const defaultBinding = defaultExportMatch[1];
|
|
164
|
+
text = text.replace(/\nexport\s*\{[^}]*\};\s*$/, "") + `
|
|
165
|
+
const __cedar_default = ${defaultBinding};`;
|
|
166
|
+
} else {
|
|
167
|
+
text = text.replace(/\nexport\s*\{[^}]*\};\s*$/, "");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return text;
|
|
171
|
+
}
|
|
172
|
+
async function generateGraphQLModule(distPath) {
|
|
173
|
+
const bundledCode = await bundleDistFile(distPath);
|
|
147
174
|
return `
|
|
148
|
-
import {
|
|
149
|
-
|
|
175
|
+
import { buildCedarContext, requestToLegacyEvent } from '@cedarjs/api/runtime';
|
|
176
|
+
import { createGraphQLYoga } from '@cedarjs/graphql-server';
|
|
177
|
+
|
|
178
|
+
// Inlined bundle of ${path.basename(distPath)} (node_modules kept external)
|
|
179
|
+
${bundledCode}
|
|
180
|
+
|
|
181
|
+
let yogaInitPromise = null;
|
|
182
|
+
|
|
183
|
+
function getYoga() {
|
|
184
|
+
if (!yogaInitPromise) {
|
|
185
|
+
yogaInitPromise = createGraphQLYoga(__rw_graphqlOptions).then(
|
|
186
|
+
({ yoga }) => ({ yoga, graphqlOptions: __rw_graphqlOptions })
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return yogaInitPromise;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export default {
|
|
193
|
+
async fetch(request) {
|
|
194
|
+
const { yoga, graphqlOptions } = await getYoga();
|
|
195
|
+
const cedarContext = await buildCedarContext(request, {
|
|
196
|
+
authDecoder: graphqlOptions ? graphqlOptions.authDecoder : undefined,
|
|
197
|
+
});
|
|
198
|
+
const event = await requestToLegacyEvent(request, cedarContext);
|
|
199
|
+
return yoga.handle(request, { request, cedarContext, event, requestContext: undefined });
|
|
200
|
+
}
|
|
201
|
+
};
|
|
150
202
|
`;
|
|
151
203
|
}
|
|
152
|
-
function generateFunctionModule(distPath) {
|
|
153
|
-
const
|
|
154
|
-
const
|
|
204
|
+
async function generateFunctionModule(distPath) {
|
|
205
|
+
const bundledCode = await bundleDistFile(distPath);
|
|
206
|
+
const notFoundMsg = JSON.stringify(
|
|
207
|
+
`Handler not found in ${path.basename(distPath)}. Expected \`export async function handleRequest(request, ctx)\`, \`export default async (request, ctx) => Response\`, \`export default { handleRequest }\`, or a legacy Lambda-shaped \`handler\`.`
|
|
208
|
+
);
|
|
155
209
|
return `
|
|
156
|
-
import {
|
|
157
|
-
|
|
210
|
+
import { wrapLegacyHandler, buildCedarContext } from '@cedarjs/api/runtime';
|
|
211
|
+
|
|
212
|
+
// Inlined bundle of ${path.basename(distPath)} (node_modules kept external)
|
|
213
|
+
${bundledCode}
|
|
214
|
+
|
|
215
|
+
const nativeHandler = (() => {
|
|
216
|
+
// Prefer named handleRequest export
|
|
217
|
+
if (typeof handleRequest !== 'undefined') { return handleRequest; }
|
|
218
|
+
// Handle export default { handleRequest } pattern
|
|
219
|
+
if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handleRequest === 'function') {
|
|
220
|
+
return __cedar_default.handleRequest;
|
|
221
|
+
}
|
|
222
|
+
// Handle plain default-exported async function: export default async (req) => Response
|
|
223
|
+
if (typeof __cedar_default !== 'undefined' && typeof __cedar_default === 'function') {
|
|
224
|
+
return __cedar_default;
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
})();
|
|
228
|
+
|
|
229
|
+
const legacyFn = (() => {
|
|
230
|
+
if (typeof handler !== 'undefined') { return handler; }
|
|
231
|
+
if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handler === 'function') {
|
|
232
|
+
return __cedar_default.handler;
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
})();
|
|
236
|
+
|
|
237
|
+
if (!nativeHandler && !legacyFn) {
|
|
238
|
+
throw new Error(${notFoundMsg});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const _handler = nativeHandler ?? wrapLegacyHandler(legacyFn);
|
|
242
|
+
|
|
243
|
+
export default {
|
|
244
|
+
async fetch(request) {
|
|
245
|
+
const ctx = await buildCedarContext(request);
|
|
246
|
+
return _handler(request, ctx);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
158
249
|
`;
|
|
159
250
|
}
|
|
160
251
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "5.0.0-canary.
|
|
3
|
+
"version": "5.0.0-canary.2375",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,37 +40,7 @@
|
|
|
40
40
|
"import": "./dist/build/build.js",
|
|
41
41
|
"default": "./dist/cjs/build/build.js"
|
|
42
42
|
},
|
|
43
|
-
"./bins/cedar-vite-build.mjs": "./bins/cedar-vite-build.mjs"
|
|
44
|
-
"./ud-handlers/graphql": {
|
|
45
|
-
"import": {
|
|
46
|
-
"types": "./dist/ud-handlers/graphql.d.ts",
|
|
47
|
-
"default": "./dist/ud-handlers/graphql.js"
|
|
48
|
-
},
|
|
49
|
-
"require": {
|
|
50
|
-
"types": "./dist/cjs/ud-handlers/graphql.d.ts",
|
|
51
|
-
"default": "./dist/cjs/ud-handlers/graphql.js"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"./ud-handlers/function": {
|
|
55
|
-
"import": {
|
|
56
|
-
"types": "./dist/ud-handlers/function.d.ts",
|
|
57
|
-
"default": "./dist/ud-handlers/function.js"
|
|
58
|
-
},
|
|
59
|
-
"require": {
|
|
60
|
-
"types": "./dist/cjs/ud-handlers/function.d.ts",
|
|
61
|
-
"default": "./dist/cjs/ud-handlers/function.js"
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"./ud-handlers/catch-all": {
|
|
65
|
-
"import": {
|
|
66
|
-
"types": "./dist/ud-handlers/catch-all.d.ts",
|
|
67
|
-
"default": "./dist/ud-handlers/catch-all.js"
|
|
68
|
-
},
|
|
69
|
-
"require": {
|
|
70
|
-
"types": "./dist/cjs/ud-handlers/catch-all.d.ts",
|
|
71
|
-
"default": "./dist/cjs/ud-handlers/catch-all.js"
|
|
72
|
-
}
|
|
73
|
-
}
|
|
43
|
+
"./bins/cedar-vite-build.mjs": "./bins/cedar-vite-build.mjs"
|
|
74
44
|
},
|
|
75
45
|
"bin": {
|
|
76
46
|
"cedar-dev-fe": "./dist/devFeServer.js",
|
|
@@ -99,18 +69,17 @@
|
|
|
99
69
|
"@babel/generator": "7.29.1",
|
|
100
70
|
"@babel/parser": "7.29.3",
|
|
101
71
|
"@babel/traverse": "7.29.0",
|
|
102
|
-
"@cedarjs/api": "5.0.0-canary.
|
|
103
|
-
"@cedarjs/
|
|
104
|
-
"@cedarjs/
|
|
105
|
-
"@cedarjs/
|
|
106
|
-
"@cedarjs/
|
|
107
|
-
"@cedarjs/
|
|
108
|
-
"@cedarjs/
|
|
109
|
-
"@cedarjs/
|
|
110
|
-
"@cedarjs/
|
|
111
|
-
"@cedarjs/
|
|
112
|
-
"@cedarjs/
|
|
113
|
-
"@cedarjs/web": "5.0.0-canary.2374",
|
|
72
|
+
"@cedarjs/api": "5.0.0-canary.2375",
|
|
73
|
+
"@cedarjs/auth": "5.0.0-canary.2375",
|
|
74
|
+
"@cedarjs/babel-config": "5.0.0-canary.2375",
|
|
75
|
+
"@cedarjs/context": "5.0.0-canary.2375",
|
|
76
|
+
"@cedarjs/cookie-jar": "5.0.0-canary.2375",
|
|
77
|
+
"@cedarjs/graphql-server": "5.0.0-canary.2375",
|
|
78
|
+
"@cedarjs/internal": "5.0.0-canary.2375",
|
|
79
|
+
"@cedarjs/project-config": "5.0.0-canary.2375",
|
|
80
|
+
"@cedarjs/server-store": "5.0.0-canary.2375",
|
|
81
|
+
"@cedarjs/testing": "5.0.0-canary.2375",
|
|
82
|
+
"@cedarjs/web": "5.0.0-canary.2375",
|
|
114
83
|
"@fastify/url-data": "6.0.3",
|
|
115
84
|
"@swc/core": "1.15.33",
|
|
116
85
|
"@universal-deploy/store": "^0.2.1",
|
|
@@ -1,65 +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 catch_all_exports = {};
|
|
20
|
-
__export(catch_all_exports, {
|
|
21
|
-
createCatchAllHandler: () => createCatchAllHandler
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(catch_all_exports);
|
|
24
|
-
var import_rou3 = require("rou3");
|
|
25
|
-
function createCatchAllHandler(options) {
|
|
26
|
-
const router = (0, import_rou3.createRouter)();
|
|
27
|
-
for (const route of options.routes) {
|
|
28
|
-
const methods = route.methods.length > 0 ? route.methods : ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
|
|
29
|
-
for (const method of methods) {
|
|
30
|
-
(0, import_rou3.addRoute)(router, method, route.path, route.module);
|
|
31
|
-
(0, import_rou3.addRoute)(router, method, `${route.path}/**`, route.module);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const apiRootPath = options.apiRootPath;
|
|
35
|
-
function normalizePathname(requestUrl) {
|
|
36
|
-
const url = new URL(requestUrl);
|
|
37
|
-
let pathname = url.pathname;
|
|
38
|
-
if (apiRootPath !== "/" && pathname.startsWith(apiRootPath)) {
|
|
39
|
-
pathname = pathname.slice(apiRootPath.length - 1);
|
|
40
|
-
}
|
|
41
|
-
if (!pathname.startsWith("/")) {
|
|
42
|
-
pathname = "/" + pathname;
|
|
43
|
-
}
|
|
44
|
-
return pathname;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
async fetch(request) {
|
|
48
|
-
const pathname = normalizePathname(request.url);
|
|
49
|
-
const match = (0, import_rou3.findRoute)(router, request.method, pathname);
|
|
50
|
-
if (!match) {
|
|
51
|
-
return new Response("Not Found", { status: 404 });
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
return await match.data.fetch(request);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
console.error("Unhandled error in fetch handler for", pathname, err);
|
|
57
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
-
0 && (module.exports = {
|
|
64
|
-
createCatchAllHandler
|
|
65
|
-
});
|
|
@@ -1,46 +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 function_exports = {};
|
|
20
|
-
__export(function_exports, {
|
|
21
|
-
createFunctionHandler: () => createFunctionHandler
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(function_exports);
|
|
24
|
-
var import_runtime = require("@cedarjs/api/runtime");
|
|
25
|
-
var import_udFetchable = require("@cedarjs/api-server/udFetchable");
|
|
26
|
-
function createFunctionHandler(options) {
|
|
27
|
-
const handleRequest = async (request, ctx) => {
|
|
28
|
-
const mod = await import(options.distUrl);
|
|
29
|
-
const nativeHandler = mod.handleRequest || mod.default?.handleRequest;
|
|
30
|
-
if (nativeHandler) {
|
|
31
|
-
return nativeHandler(request, ctx);
|
|
32
|
-
}
|
|
33
|
-
const legacyHandler = mod.handler || mod.default?.handler;
|
|
34
|
-
if (legacyHandler) {
|
|
35
|
-
return (0, import_runtime.wrapLegacyHandler)(legacyHandler)(request, ctx);
|
|
36
|
-
}
|
|
37
|
-
throw new Error(
|
|
38
|
-
`Handler not found in ${options.distUrl}. Expected \`export async function handleRequest(request, ctx)\`, \`export default { handleRequest }\`, or a legacy Lambda-shaped \`handler\`.`
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
return (0, import_udFetchable.createCedarFetchable)(handleRequest);
|
|
42
|
-
}
|
|
43
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
-
0 && (module.exports = {
|
|
45
|
-
createFunctionHandler
|
|
46
|
-
});
|
|
@@ -1,58 +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 graphql_exports = {};
|
|
20
|
-
__export(graphql_exports, {
|
|
21
|
-
createGraphQLHandler: () => createGraphQLHandler
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(graphql_exports);
|
|
24
|
-
var import_runtime = require("@cedarjs/api/runtime");
|
|
25
|
-
var import_graphql_server = require("@cedarjs/graphql-server");
|
|
26
|
-
function createGraphQLHandler(options) {
|
|
27
|
-
let yogaInitPromise = null;
|
|
28
|
-
async function getYoga() {
|
|
29
|
-
if (!yogaInitPromise) {
|
|
30
|
-
yogaInitPromise = (async () => {
|
|
31
|
-
const mod = await import(options.distUrl);
|
|
32
|
-
const opts = mod.__rw_graphqlOptions;
|
|
33
|
-
const { yoga } = await (0, import_graphql_server.createGraphQLYoga)(opts);
|
|
34
|
-
return { yoga, graphqlOptions: opts };
|
|
35
|
-
})();
|
|
36
|
-
}
|
|
37
|
-
return yogaInitPromise;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
async fetch(request) {
|
|
41
|
-
const { yoga, graphqlOptions } = await getYoga();
|
|
42
|
-
const cedarContext = await (0, import_runtime.buildCedarContext)(request, {
|
|
43
|
-
authDecoder: graphqlOptions?.authDecoder
|
|
44
|
-
});
|
|
45
|
-
const event = await (0, import_runtime.requestToLegacyEvent)(request, cedarContext);
|
|
46
|
-
return yoga.handle(request, {
|
|
47
|
-
request,
|
|
48
|
-
cedarContext,
|
|
49
|
-
event,
|
|
50
|
-
requestContext: void 0
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
-
0 && (module.exports = {
|
|
57
|
-
createGraphQLHandler
|
|
58
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface CatchAllRoute {
|
|
2
|
-
path: string;
|
|
3
|
-
methods: string[];
|
|
4
|
-
module: {
|
|
5
|
-
fetch: (request: Request) => Promise<Response> | Response;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export interface CatchAllHandlerOptions {
|
|
9
|
-
routes: CatchAllRoute[];
|
|
10
|
-
apiRootPath: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function createCatchAllHandler(options: CatchAllHandlerOptions): {
|
|
13
|
-
fetch(request: Request): Promise<Response>;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=catch-all.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"catch-all.d.ts","sourceRoot":"","sources":["../../src/ud-handlers/catch-all.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAA;KAAE,CAAA;CACtE;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB;mBAiC5C,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;EAgBnD"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createRouter, addRoute, findRoute } from "rou3";
|
|
2
|
-
function createCatchAllHandler(options) {
|
|
3
|
-
const router = createRouter();
|
|
4
|
-
for (const route of options.routes) {
|
|
5
|
-
const methods = route.methods.length > 0 ? route.methods : ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
|
|
6
|
-
for (const method of methods) {
|
|
7
|
-
addRoute(router, method, route.path, route.module);
|
|
8
|
-
addRoute(router, method, `${route.path}/**`, route.module);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
const apiRootPath = options.apiRootPath;
|
|
12
|
-
function normalizePathname(requestUrl) {
|
|
13
|
-
const url = new URL(requestUrl);
|
|
14
|
-
let pathname = url.pathname;
|
|
15
|
-
if (apiRootPath !== "/" && pathname.startsWith(apiRootPath)) {
|
|
16
|
-
pathname = pathname.slice(apiRootPath.length - 1);
|
|
17
|
-
}
|
|
18
|
-
if (!pathname.startsWith("/")) {
|
|
19
|
-
pathname = "/" + pathname;
|
|
20
|
-
}
|
|
21
|
-
return pathname;
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
async fetch(request) {
|
|
25
|
-
const pathname = normalizePathname(request.url);
|
|
26
|
-
const match = findRoute(router, request.method, pathname);
|
|
27
|
-
if (!match) {
|
|
28
|
-
return new Response("Not Found", { status: 404 });
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
return await match.data.fetch(request);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
console.error("Unhandled error in fetch handler for", pathname, err);
|
|
34
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
createCatchAllHandler
|
|
41
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/ud-handlers/function.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,uDAyBpE"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { wrapLegacyHandler } from "@cedarjs/api/runtime";
|
|
2
|
-
import { createCedarFetchable } from "@cedarjs/api-server/udFetchable";
|
|
3
|
-
function createFunctionHandler(options) {
|
|
4
|
-
const handleRequest = async (request, ctx) => {
|
|
5
|
-
const mod = await import(options.distUrl);
|
|
6
|
-
const nativeHandler = mod.handleRequest || mod.default?.handleRequest;
|
|
7
|
-
if (nativeHandler) {
|
|
8
|
-
return nativeHandler(request, ctx);
|
|
9
|
-
}
|
|
10
|
-
const legacyHandler = mod.handler || mod.default?.handler;
|
|
11
|
-
if (legacyHandler) {
|
|
12
|
-
return wrapLegacyHandler(legacyHandler)(request, ctx);
|
|
13
|
-
}
|
|
14
|
-
throw new Error(
|
|
15
|
-
`Handler not found in ${options.distUrl}. Expected \`export async function handleRequest(request, ctx)\`, \`export default { handleRequest }\`, or a legacy Lambda-shaped \`handler\`.`
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
return createCedarFetchable(handleRequest);
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
createFunctionHandler
|
|
22
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/ud-handlers/graphql.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB;mBAiB1C,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;EAenD"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { buildCedarContext, requestToLegacyEvent } from "@cedarjs/api/runtime";
|
|
2
|
-
import { createGraphQLYoga } from "@cedarjs/graphql-server";
|
|
3
|
-
function createGraphQLHandler(options) {
|
|
4
|
-
let yogaInitPromise = null;
|
|
5
|
-
async function getYoga() {
|
|
6
|
-
if (!yogaInitPromise) {
|
|
7
|
-
yogaInitPromise = (async () => {
|
|
8
|
-
const mod = await import(options.distUrl);
|
|
9
|
-
const opts = mod.__rw_graphqlOptions;
|
|
10
|
-
const { yoga } = await createGraphQLYoga(opts);
|
|
11
|
-
return { yoga, graphqlOptions: opts };
|
|
12
|
-
})();
|
|
13
|
-
}
|
|
14
|
-
return yogaInitPromise;
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
async fetch(request) {
|
|
18
|
-
const { yoga, graphqlOptions } = await getYoga();
|
|
19
|
-
const cedarContext = await buildCedarContext(request, {
|
|
20
|
-
authDecoder: graphqlOptions?.authDecoder
|
|
21
|
-
});
|
|
22
|
-
const event = await requestToLegacyEvent(request, cedarContext);
|
|
23
|
-
return yoga.handle(request, {
|
|
24
|
-
request,
|
|
25
|
-
cedarContext,
|
|
26
|
-
event,
|
|
27
|
-
requestContext: void 0
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
createGraphQLHandler
|
|
34
|
-
};
|