@cedarjs/vite 5.0.3 → 5.0.4-next.167

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.
Files changed (143) hide show
  1. package/dist/api/vite-plugin-cedar-vitest-api-preset.d.ts.map +1 -1
  2. package/dist/api/vite-plugin-cedar-vitest-api-preset.js +4 -0
  3. package/dist/apiDevMiddleware.d.ts.map +1 -1
  4. package/dist/apiDevMiddleware.js +105 -9
  5. package/dist/buildApp.d.ts.map +1 -1
  6. package/dist/buildApp.js +79 -18
  7. package/dist/buildRouteHooks.d.ts.map +1 -1
  8. package/dist/buildRouteHooks.js +36 -4
  9. package/dist/bundled/react-server-dom-webpack.server.js +192 -99
  10. package/dist/cedar-unified-dev.d.ts +18 -0
  11. package/dist/cedar-unified-dev.d.ts.map +1 -1
  12. package/dist/cedar-unified-dev.js +39 -5
  13. package/dist/devFeServer.js +3 -8
  14. package/dist/index.d.ts +10 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +45 -19
  17. package/dist/lib/generateDiffSourceMap.d.ts +18 -0
  18. package/dist/lib/generateDiffSourceMap.d.ts.map +1 -0
  19. package/dist/lib/generateDiffSourceMap.js +151 -0
  20. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  21. package/dist/lib/getMergedConfig.js +4 -0
  22. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
  23. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
  24. package/dist/plugins/vite-plugin-cedar-auto-import.js +8 -1
  25. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  26. package/dist/plugins/vite-plugin-cedar-cell.js +2 -1
  27. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
  28. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
  29. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
  30. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +12 -0
  31. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +1 -0
  32. package/dist/plugins/vite-plugin-cedar-directory-named-import.js +35 -0
  33. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
  34. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
  35. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
  36. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +42 -0
  37. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
  38. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +93 -0
  39. package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
  40. package/dist/plugins/vite-plugin-cedar-import-dir.js +33 -15
  41. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +28 -0
  42. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +1 -0
  43. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +67 -0
  44. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +28 -0
  45. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +1 -0
  46. package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +247 -0
  47. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +39 -0
  48. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +1 -0
  49. package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +200 -0
  50. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
  51. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -1
  52. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +14 -0
  53. package/dist/plugins/{vite-plugin-cedar-context-wrapping.d.ts → vite-plugin-handler-als-wrapping.d.ts} +12 -12
  54. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
  55. package/dist/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +16 -16
  56. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +3 -0
  57. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
  58. package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
  59. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  60. package/dist/rsc/rscBuildForSsr.js +3 -5
  61. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
  62. package/dist/streaming/buildForStreamingServer.js +3 -5
  63. package/package.json +42 -52
  64. package/dist/cjs/ClientRouter.d.ts +0 -1
  65. package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +0 -37
  66. package/dist/cjs/apiDevMiddleware.js +0 -371
  67. package/dist/cjs/build/build.d.ts +0 -1
  68. package/dist/cjs/build/build.js +0 -58
  69. package/dist/cjs/buildApp.js +0 -306
  70. package/dist/cjs/buildFeServer.d.ts +0 -1
  71. package/dist/cjs/buildFeServer.js +0 -63
  72. package/dist/cjs/buildRouteHooks.js +0 -80
  73. package/dist/cjs/buildRouteManifest.js +0 -92
  74. package/dist/cjs/buildRscClientAndServer.js +0 -54
  75. package/dist/cjs/cedar-unified-dev.js +0 -310
  76. package/dist/cjs/client.d.ts +0 -1
  77. package/dist/cjs/clientSsr.d.ts +0 -1
  78. package/dist/cjs/devFeServer.js +0 -157
  79. package/dist/cjs/index.d.ts +0 -1
  80. package/dist/cjs/index.js +0 -141
  81. package/dist/cjs/lib/StatusError.js +0 -37
  82. package/dist/cjs/lib/entries.js +0 -52
  83. package/dist/cjs/lib/getMergedConfig.js +0 -185
  84. package/dist/cjs/lib/onWarn.js +0 -36
  85. package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -102
  86. package/dist/cjs/lib/workspacePackageAliases.js +0 -107
  87. package/dist/cjs/middleware/index.js +0 -22
  88. package/dist/cjs/middleware/invokeMiddleware.js +0 -52
  89. package/dist/cjs/middleware/register.js +0 -105
  90. package/dist/cjs/middleware/types.js +0 -16
  91. package/dist/cjs/package.json +0 -1
  92. package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +0 -107
  93. package/dist/cjs/plugins/vite-plugin-cedar-cell.js +0 -183
  94. package/dist/cjs/plugins/vite-plugin-cedar-cjs-compat.js +0 -341
  95. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +0 -95
  96. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +0 -107
  97. package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +0 -67
  98. package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +0 -118
  99. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
  100. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +0 -61
  101. package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +0 -76
  102. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -126
  103. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +0 -346
  104. package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +0 -134
  105. package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +0 -134
  106. package/dist/cjs/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +0 -106
  107. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +0 -42
  108. package/dist/cjs/plugins/vite-plugin-merged-config.js +0 -39
  109. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +0 -104
  110. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +0 -75
  111. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +0 -159
  112. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +0 -125
  113. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +0 -75
  114. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +0 -228
  115. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -398
  116. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +0 -46
  117. package/dist/cjs/rsc/rscBuildAnalyze.js +0 -126
  118. package/dist/cjs/rsc/rscBuildClient.js +0 -91
  119. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +0 -56
  120. package/dist/cjs/rsc/rscBuildEntriesFile.js +0 -115
  121. package/dist/cjs/rsc/rscBuildForServer.js +0 -168
  122. package/dist/cjs/rsc/rscBuildForSsr.js +0 -173
  123. package/dist/cjs/rsc/rscBuildRwEnvVars.js +0 -56
  124. package/dist/cjs/rsc/rscRenderer.js +0 -165
  125. package/dist/cjs/rsc/rscRequestHandler.js +0 -162
  126. package/dist/cjs/rsc/rscStudioHandlers.js +0 -156
  127. package/dist/cjs/runFeServer.js +0 -165
  128. package/dist/cjs/streaming/buildForStreamingServer.js +0 -65
  129. package/dist/cjs/streaming/collectCss.js +0 -52
  130. package/dist/cjs/streaming/createReactStreamingHandler.js +0 -173
  131. package/dist/cjs/streaming/streamHelpers.js +0 -230
  132. package/dist/cjs/streaming/transforms/bufferedTransform.js +0 -61
  133. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +0 -34
  134. package/dist/cjs/streaming/transforms/encode-decode.js +0 -36
  135. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +0 -84
  136. package/dist/cjs/streaming/triggerRouteHooks.js +0 -96
  137. package/dist/cjs/types.js +0 -16
  138. package/dist/cjs/utils.js +0 -92
  139. package/dist/package.json +0 -1
  140. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
  141. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
  142. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
  143. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
@@ -1,371 +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 apiDevMiddleware_exports = {};
30
- __export(apiDevMiddleware_exports, {
31
- createApiFetchHandler: () => createApiFetchHandler,
32
- createApiViteServer: () => createApiViteServer,
33
- loadApiFunctions: () => loadApiFunctions,
34
- setupHmrHandlers: () => setupHmrHandlers,
35
- startApiDevMiddleware: () => startApiDevMiddleware
36
- });
37
- module.exports = __toCommonJS(apiDevMiddleware_exports);
38
- var import_promises = require("node:fs/promises");
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_vite = require("vite");
43
- var import_runtime = require("@cedarjs/api/runtime");
44
- var import_babel_config = require("@cedarjs/babel-config");
45
- var import_store = require("@cedarjs/context/dist/store");
46
- var import_graphql_server = require("@cedarjs/graphql-server");
47
- var import_project_config = require("@cedarjs/project-config");
48
- var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
49
- const LAMBDA_FUNCTIONS = {};
50
- let graphqlYoga = null;
51
- let loadApiFunctionsInFlight = null;
52
- let needsReloadAfterInFlight = false;
53
- async function loadApiFunctions(viteServer) {
54
- if (loadApiFunctionsInFlight) {
55
- needsReloadAfterInFlight = true;
56
- return;
57
- }
58
- do {
59
- needsReloadAfterInFlight = false;
60
- loadApiFunctionsInFlight = internalLoadApiFunctions(viteServer);
61
- try {
62
- await loadApiFunctionsInFlight;
63
- } finally {
64
- loadApiFunctionsInFlight = null;
65
- }
66
- } while (needsReloadAfterInFlight);
67
- }
68
- async function internalLoadApiFunctions(viteServer) {
69
- const cedarPaths = (0, import_project_config.getPaths)();
70
- for (const key of Object.keys(LAMBDA_FUNCTIONS)) {
71
- delete LAMBDA_FUNCTIONS[key];
72
- }
73
- let srcFunctions = [];
74
- try {
75
- srcFunctions = await Array.fromAsync(
76
- (0, import_promises.glob)("**/*.{ts,tsx,js,jsx}", {
77
- cwd: cedarPaths.api.functions,
78
- exclude: [
79
- "**/*.test.{ts,tsx,js,jsx}",
80
- "**/*.scenarios.{ts,tsx,js,jsx}",
81
- "**/*.fixtures.{ts,tsx,js,jsx}",
82
- "**/*.d.ts"
83
- ]
84
- }),
85
- (entry) => import_node_path.default.join(cedarPaths.api.functions, entry)
86
- );
87
- } catch {
88
- srcFunctions = [];
89
- }
90
- console.log(import_ansis.default.dim.italic("Importing Server Functions... "));
91
- const tsImport = Date.now();
92
- let extractedGraphqlOptions = null;
93
- const imports = srcFunctions.map(async (fnPath) => {
94
- const ts = Date.now();
95
- const routeName = import_node_path.default.basename(fnPath).replace(/\.(ts|tsx|js|jsx)$/, "");
96
- try {
97
- const mod = await viteServer.ssrLoadModule((0, import_node_url.pathToFileURL)(fnPath).href);
98
- const cedarHandler = (() => {
99
- if ("handleRequest" in mod) {
100
- return mod.handleRequest;
101
- }
102
- if ("default" in mod && mod.default && "handleRequest" in mod.default) {
103
- return mod.default.handleRequest;
104
- }
105
- let legacyHandler;
106
- if ("handler" in mod) {
107
- legacyHandler = mod.handler;
108
- } else if ("default" in mod && mod.default && "handler" in mod.default) {
109
- legacyHandler = mod.default.handler;
110
- }
111
- if (legacyHandler) {
112
- return (0, import_runtime.wrapLegacyHandler)(legacyHandler);
113
- }
114
- return void 0;
115
- })();
116
- if (cedarHandler) {
117
- LAMBDA_FUNCTIONS[routeName] = cedarHandler;
118
- console.log(
119
- import_ansis.default.magenta("/" + routeName),
120
- import_ansis.default.dim.italic(Date.now() - ts + " ms")
121
- );
122
- } else {
123
- console.warn(
124
- `[apiDevMiddleware] No handler or handleRequest export found in function: ${fnPath}`
125
- );
126
- }
127
- if (routeName === "graphql" && "__cedar_graphqlOptions" in mod) {
128
- extractedGraphqlOptions = mod.__cedar_graphqlOptions;
129
- }
130
- } catch (err) {
131
- viteServer.ssrFixStacktrace(err);
132
- console.error(
133
- `[apiDevMiddleware] Failed to load function "${routeName}" from ${fnPath}:`,
134
- err
135
- );
136
- }
137
- });
138
- await Promise.all(imports);
139
- if (extractedGraphqlOptions) {
140
- const { yoga } = await (0, import_graphql_server.createGraphQLYoga)(extractedGraphqlOptions);
141
- graphqlYoga = yoga;
142
- } else {
143
- graphqlYoga = null;
144
- }
145
- console.log(
146
- import_ansis.default.dim.italic("...Done importing in " + (Date.now() - tsImport) + " ms")
147
- );
148
- }
149
- async function createApiViteServer() {
150
- const cedarPaths = (0, import_project_config.getPaths)();
151
- const cedarConfig = (0, import_project_config.getConfig)();
152
- const isEsm = (0, import_project_config.projectSideIsEsm)("api");
153
- const normalizedBase = (0, import_vite.normalizePath)(cedarPaths.base);
154
- const babelPlugins = (0, import_babel_config.getApiSideBabelPlugins)({
155
- openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
156
- projectIsEsm: isEsm
157
- });
158
- const workspacePkgSourceMap = Object.fromEntries(
159
- Object.entries((0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig)).map(
160
- ([name, sourceFile]) => [name, (0, import_vite.normalizePath)(sourceFile)]
161
- )
162
- );
163
- const { createServer: createViteServer } = await import("vite");
164
- return createViteServer({
165
- configFile: false,
166
- root: cedarPaths.api.base,
167
- appType: "custom",
168
- clearScreen: false,
169
- logLevel: "warn",
170
- server: {
171
- middlewareMode: true
172
- },
173
- resolve: {
174
- alias: workspacePkgSourceMap
175
- },
176
- plugins: [
177
- {
178
- name: "cedar-api-babel-transform",
179
- enforce: "pre",
180
- async transform(code, id) {
181
- if (!/\.(ts|tsx|js|jsx)$/.test(id)) {
182
- return null;
183
- }
184
- if (id.includes("node_modules")) {
185
- return null;
186
- }
187
- if (!id.startsWith(normalizedBase)) {
188
- return null;
189
- }
190
- try {
191
- const result = await (0, import_babel_config.transformWithBabel)(
192
- code,
193
- id,
194
- babelPlugins,
195
- true
196
- );
197
- if (!result?.code) {
198
- return null;
199
- }
200
- return {
201
- code: result.code,
202
- map: result.map ?? null
203
- };
204
- } catch (err) {
205
- this.warn(
206
- `[cedar-api-babel-transform] Failed to transform ${id}: ${String(err)}`
207
- );
208
- return null;
209
- }
210
- }
211
- }
212
- ]
213
- });
214
- }
215
- function invalidateApiModules(viteServer, normalizedApiSrc) {
216
- const invalidated = /* @__PURE__ */ new Set();
217
- const invalidateWithImporters = (mod) => {
218
- if (!mod || invalidated.has(mod.id ?? mod.url)) {
219
- return;
220
- }
221
- invalidated.add(mod.id ?? mod.url);
222
- viteServer.moduleGraph.invalidateModule(mod);
223
- for (const importer of mod.importers) {
224
- invalidateWithImporters(importer);
225
- }
226
- };
227
- for (const mod of viteServer.moduleGraph.idToModuleMap.values()) {
228
- if (mod.id?.startsWith(normalizedApiSrc)) {
229
- invalidateWithImporters(mod);
230
- }
231
- }
232
- }
233
- function setupHmrHandlers(viteServer) {
234
- const cedarPaths = (0, import_project_config.getPaths)();
235
- const normalizedApiSrc = (0, import_vite.normalizePath)(cedarPaths.api.src);
236
- const normalizedApiBase = (0, import_vite.normalizePath)(cedarPaths.api.base);
237
- viteServer.watcher.on("change", async (filePath) => {
238
- const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
239
- if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
240
- return;
241
- }
242
- const displayPath = import_node_path.default.relative(normalizedApiBase, normalizedFilePath);
243
- console.log(import_ansis.default.dim(`[change] ${displayPath}`));
244
- const fileUrl = (0, import_node_url.pathToFileURL)(normalizedFilePath).href;
245
- const mod = viteServer.moduleGraph.getModuleById(normalizedFilePath) ?? viteServer.moduleGraph.getModuleById(fileUrl);
246
- if (mod) {
247
- const invalidated = /* @__PURE__ */ new Set();
248
- const invalidateWithImporters = (m) => {
249
- if (!m || invalidated.has(m.id ?? m.url)) {
250
- return;
251
- }
252
- invalidated.add(m.id ?? m.url);
253
- viteServer.moduleGraph.invalidateModule(m);
254
- for (const importer of m.importers) {
255
- invalidateWithImporters(importer);
256
- }
257
- };
258
- invalidateWithImporters(mod);
259
- }
260
- await loadApiFunctions(viteServer);
261
- });
262
- viteServer.watcher.on("add", async (filePath) => {
263
- const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
264
- if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
265
- return;
266
- }
267
- console.log(
268
- import_ansis.default.dim(
269
- `[add] ${import_node_path.default.relative(normalizedApiBase, normalizedFilePath)}`
270
- )
271
- );
272
- invalidateApiModules(viteServer, normalizedApiSrc);
273
- await loadApiFunctions(viteServer);
274
- });
275
- viteServer.watcher.on("unlink", async (filePath) => {
276
- const normalizedFilePath = (0, import_vite.normalizePath)(filePath);
277
- if (!normalizedFilePath.startsWith(normalizedApiSrc)) {
278
- return;
279
- }
280
- console.log(
281
- import_ansis.default.dim(
282
- `[unlink] ${import_node_path.default.relative(normalizedApiBase, normalizedFilePath)}`
283
- )
284
- );
285
- invalidateApiModules(viteServer, normalizedApiSrc);
286
- await loadApiFunctions(viteServer);
287
- });
288
- }
289
- function createApiFetchHandler() {
290
- const cedarConfig = (0, import_project_config.getConfig)();
291
- const apiUrlPrefix = cedarConfig.web.apiUrl.replace(/\/$/, "");
292
- return async (request) => {
293
- const url = new URL(request.url);
294
- let pathname = url.pathname;
295
- if (pathname.startsWith(apiUrlPrefix + "/")) {
296
- pathname = pathname.slice(apiUrlPrefix.length);
297
- } else if (pathname === apiUrlPrefix) {
298
- pathname = "/";
299
- }
300
- if (pathname === "/graphql" || pathname.startsWith("/graphql/")) {
301
- if (!graphqlYoga) {
302
- return new Response(
303
- JSON.stringify({ error: "GraphQL Yoga instance not initialized" }),
304
- { status: 503, headers: { "Content-Type": "application/json" } }
305
- );
306
- }
307
- const yoga = graphqlYoga;
308
- return (0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), async () => {
309
- try {
310
- return await yoga.handle(request, { request });
311
- } catch (e) {
312
- if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
313
- return new Response(null, { status: 499 });
314
- }
315
- throw e;
316
- }
317
- });
318
- }
319
- const match = pathname.match(/^\/([^/]+)(?:\/.*)?$/);
320
- if (!match) {
321
- return new Response("Not Found", { status: 404 });
322
- }
323
- const routeName = match[1];
324
- const handler = LAMBDA_FUNCTIONS[routeName];
325
- if (!handler) {
326
- return new Response(
327
- JSON.stringify({
328
- error: `Function "${routeName}" was not found.`,
329
- availableFunctions: Object.keys(LAMBDA_FUNCTIONS)
330
- }),
331
- { status: 404, headers: { "Content-Type": "application/json" } }
332
- );
333
- }
334
- try {
335
- const ctx = await (0, import_runtime.buildCedarContext)(request, {
336
- params: { routeName }
337
- });
338
- return await handler(request, ctx);
339
- } catch (err) {
340
- console.error(
341
- `[apiDevMiddleware] Error handling function "${routeName}":`,
342
- err
343
- );
344
- return new Response(
345
- JSON.stringify({
346
- error: err instanceof Error ? err.message : "Internal Server Error"
347
- }),
348
- { status: 500, headers: { "Content-Type": "application/json" } }
349
- );
350
- }
351
- };
352
- }
353
- async function startApiDevMiddleware() {
354
- const viteServer = await createApiViteServer();
355
- console.log(import_ansis.default.dim.italic("Starting API dev server..."));
356
- await loadApiFunctions(viteServer);
357
- setupHmrHandlers(viteServer);
358
- const close = async () => {
359
- await viteServer.close();
360
- };
361
- const handler = createApiFetchHandler();
362
- return { viteServer, close, handler };
363
- }
364
- // Annotate the CommonJS export names for ESM import in node:
365
- 0 && (module.exports = {
366
- createApiFetchHandler,
367
- createApiViteServer,
368
- loadApiFunctions,
369
- setupHmrHandlers,
370
- startApiDevMiddleware
371
- });
@@ -1 +0,0 @@
1
- export type * from "../../build/build.d.ts"
@@ -1,58 +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 build_exports = {};
30
- __export(build_exports, {
31
- buildCedarApp: () => import_buildApp.buildCedarApp,
32
- buildWeb: () => buildWeb
33
- });
34
- module.exports = __toCommonJS(build_exports);
35
- var import_project_config = require("@cedarjs/project-config");
36
- var import_buildApp = require("../buildApp.js");
37
- const buildWeb = async ({ verbose }) => {
38
- const { build } = await import("vite");
39
- const viteConfig = (0, import_project_config.getPaths)().web.viteConfig;
40
- if (process.cwd() !== (0, import_project_config.getPaths)().web.base) {
41
- throw new Error(
42
- "Looks like you are running the command from the wrong dir, this can lead to unintended consequences on CSS processing"
43
- );
44
- }
45
- if (!viteConfig) {
46
- throw new Error("Could not locate your web/vite.config.{js,ts} file");
47
- }
48
- return build({
49
- configFile: viteConfig,
50
- envFile: false,
51
- logLevel: verbose ? "info" : "warn"
52
- });
53
- };
54
- // Annotate the CommonJS export names for ESM import in node:
55
- 0 && (module.exports = {
56
- buildCedarApp,
57
- buildWeb
58
- });