@cedarjs/vite 5.0.2-rc.5 → 6.0.0-canary.2619
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/apiDevMiddleware.d.ts.map +1 -1
- package/dist/apiDevMiddleware.js +16 -2
- package/dist/buildApp.d.ts.map +1 -1
- package/dist/buildApp.js +8 -3
- package/dist/bundled/react-server-dom-webpack.server.js +1224 -28521
- package/dist/cjs/apiDevMiddleware.js +16 -2
- package/dist/cjs/buildApp.js +8 -3
- package/dist/cjs/devFeServer.js +268 -15
- package/dist/cjs/index.js +21 -13
- package/dist/cjs/lib/registerFwGlobalsAndShims.js +9 -0
- package/dist/cjs/plugins/vite-plugin-cedar-data-uri-shim.js +67 -0
- package/dist/cjs/plugins/vite-plugin-cedar-gqlorm-inject.js +106 -0
- package/dist/cjs/plugins/vite-plugin-cedar-graphql-options-extract.js +113 -0
- package/dist/cjs/plugins/vite-plugin-cedar-otel-wrapping.js +225 -0
- package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
- package/dist/cjs/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +21 -21
- package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +4 -0
- package/dist/cjs/rsc/rscRenderer.js +23 -9
- package/dist/cjs/rsc/rscRequestHandler.js +6 -6
- package/dist/cjs/rsc/rscWebSocketServer.js +56 -0
- package/dist/cjs/rsc/utils.js +56 -0
- package/dist/cjs/runFeServer.js +3 -22
- package/dist/cjs/streaming/createReactStreamingHandler.js +13 -10
- package/dist/cjs/streaming/streamHelpers.js +49 -32
- package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
- package/dist/devFeServer.js +272 -16
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -9
- package/dist/lib/registerFwGlobalsAndShims.js +9 -0
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +38 -0
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +88 -0
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +39 -0
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +200 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +1 -1
- package/dist/plugins/{vite-plugin-cedar-context-wrapping.d.ts → vite-plugin-handler-als-wrapping.d.ts} +12 -12
- package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
- package/dist/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +16 -16
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-transform-server.js +4 -0
- package/dist/rsc/rscRenderer.d.ts.map +1 -1
- package/dist/rsc/rscRenderer.js +19 -5
- package/dist/rsc/rscRequestHandler.d.ts +2 -2
- package/dist/rsc/rscRequestHandler.d.ts.map +1 -1
- package/dist/rsc/rscRequestHandler.js +4 -4
- package/dist/rsc/rscWebSocketServer.d.ts +2 -0
- package/dist/rsc/rscWebSocketServer.d.ts.map +1 -0
- package/dist/rsc/rscWebSocketServer.js +22 -0
- package/dist/rsc/utils.d.ts +10 -0
- package/dist/rsc/utils.d.ts.map +1 -0
- package/dist/rsc/utils.js +21 -0
- package/dist/runFeServer.js +2 -21
- package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
- package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
- package/dist/streaming/createReactStreamingHandler.js +13 -10
- package/dist/streaming/streamHelpers.d.ts +2 -2
- package/dist/streaming/streamHelpers.d.ts.map +1 -1
- package/dist/streaming/streamHelpers.js +49 -31
- package/dist/streaming/triggerRouteHooks.d.ts +2 -2
- package/dist/streaming/triggerRouteHooks.d.ts.map +1 -1
- package/dist/streaming/triggerRouteHooks.js +3 -3
- package/package.json +19 -20
- package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
- package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
- package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
|
@@ -0,0 +1,106 @@
|
|
|
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 vite_plugin_cedar_gqlorm_inject_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_gqlorm_inject_exports, {
|
|
31
|
+
cedarGqlormInjectPlugin: () => cedarGqlormInjectPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_gqlorm_inject_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
+
function cedarGqlormInjectPlugin() {
|
|
38
|
+
return {
|
|
39
|
+
name: "cedar-gqlorm-inject",
|
|
40
|
+
transform(code, id) {
|
|
41
|
+
if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (code.includes("__gqlorm_sdl__")) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (!code.includes("createGraphQLHandler")) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
let config;
|
|
51
|
+
try {
|
|
52
|
+
config = (0, import_project_config.getConfig)();
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (!config.experimental?.gqlorm?.enabled) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
let paths;
|
|
60
|
+
try {
|
|
61
|
+
paths = (0, import_project_config.getPaths)();
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const backendPathWithoutExt = import_node_path.default.join(
|
|
66
|
+
paths.generated.base,
|
|
67
|
+
"gqlorm",
|
|
68
|
+
"backend"
|
|
69
|
+
);
|
|
70
|
+
if (!import_node_fs.default.existsSync(backendPathWithoutExt + ".ts")) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const handlerPattern = /^export\s+const\s+(\w+)\s*=\s*createGraphQLHandler\s*\(/m;
|
|
74
|
+
const handlerMatch = handlerPattern.exec(code);
|
|
75
|
+
if (!handlerMatch) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const handlerLineStart = code.lastIndexOf("\n", handlerMatch.index) + 1;
|
|
79
|
+
const relPath = (0, import_project_config.importStatementPath)(
|
|
80
|
+
import_node_path.default.relative(import_node_path.default.dirname(id), backendPathWithoutExt)
|
|
81
|
+
) + ".ts";
|
|
82
|
+
const dbSrcPath = import_node_path.default.join(paths.api.src, "lib", "db");
|
|
83
|
+
const relDbPath = (0, import_project_config.importStatementPath)(import_node_path.default.relative(import_node_path.default.dirname(id), dbSrcPath)) + ".ts";
|
|
84
|
+
const importDb = `import { db as __gqlorm_db__ } from '${relDbPath}'`;
|
|
85
|
+
const importSdl = `import * as __gqlorm_sdl__ from '${relPath}'`;
|
|
86
|
+
const importsToAdd = `${importDb}
|
|
87
|
+
${importSdl}
|
|
88
|
+
`;
|
|
89
|
+
const sdlsMutation = `Object.assign(sdls, {
|
|
90
|
+
__gqlorm__: {
|
|
91
|
+
schema: __gqlorm_sdl__.schema,
|
|
92
|
+
resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
`;
|
|
96
|
+
const transformed = importsToAdd + code.slice(0, handlerLineStart) + sdlsMutation + code.slice(handlerLineStart);
|
|
97
|
+
return {
|
|
98
|
+
code: transformed
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
cedarGqlormInjectPlugin
|
|
106
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
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 vite_plugin_cedar_graphql_options_extract_exports = {};
|
|
20
|
+
__export(vite_plugin_cedar_graphql_options_extract_exports, {
|
|
21
|
+
applyGraphqlOptionsExtract: () => applyGraphqlOptionsExtract,
|
|
22
|
+
cedarGraphqlOptionsExtractPlugin: () => cedarGraphqlOptionsExtractPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(vite_plugin_cedar_graphql_options_extract_exports);
|
|
25
|
+
var import_oxc_parser = require("oxc-parser");
|
|
26
|
+
function cedarGraphqlOptionsExtractPlugin() {
|
|
27
|
+
return {
|
|
28
|
+
name: "cedar-graphql-options-extract",
|
|
29
|
+
transform(code, id) {
|
|
30
|
+
if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!code.includes("createGraphQLHandler")) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const transformed = applyGraphqlOptionsExtract(code);
|
|
37
|
+
if (!transformed || transformed === code) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
code: transformed
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function applyGraphqlOptionsExtract(code) {
|
|
47
|
+
if (code.includes("__cedar_graphqlOptions")) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const { program } = (0, import_oxc_parser.parseSync)("graphql.ts", code, {
|
|
51
|
+
// lang is only a parse hint; 'ts' also parses JS (the graphql handler can
|
|
52
|
+
// be graphql.js in JS projects), so this is safe for both file types.
|
|
53
|
+
lang: "ts",
|
|
54
|
+
sourceType: "module"
|
|
55
|
+
});
|
|
56
|
+
const importNames = /* @__PURE__ */ new Set();
|
|
57
|
+
for (const node of program.body) {
|
|
58
|
+
if (node.type === "ImportDeclaration") {
|
|
59
|
+
if (node.source.value !== "@cedarjs/graphql-server") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
for (const specifier of node.specifiers) {
|
|
63
|
+
if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "createGraphQLHandler") {
|
|
64
|
+
importNames.add(specifier.local.name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (importNames.size === 0) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const callExpressionPaths = [];
|
|
73
|
+
new import_oxc_parser.Visitor({
|
|
74
|
+
CallExpression(node) {
|
|
75
|
+
if (node.callee.type === "Identifier" && importNames.has(node.callee.name)) {
|
|
76
|
+
callExpressionPaths.push(node);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}).visit(program);
|
|
80
|
+
if (callExpressionPaths.length > 1) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const callExpression = callExpressionPaths[0];
|
|
84
|
+
if (!callExpression) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const options = callExpression.arguments[0];
|
|
88
|
+
if (!options) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
if (options.type !== "Identifier" && options.type !== "ObjectExpression" && options.type !== "CallExpression" && options.type !== "ConditionalExpression") {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const optionsStart = options.start;
|
|
95
|
+
const optionsEnd = options.end;
|
|
96
|
+
const lineStart = code.lastIndexOf("\n", callExpression.start) + 1;
|
|
97
|
+
const indentMatch = /^[ \t]*/.exec(code.slice(lineStart));
|
|
98
|
+
const indent = indentMatch ? indentMatch[0] : "";
|
|
99
|
+
const optionsConst = `${indent}export const __cedar_graphqlOptions = ${code.slice(
|
|
100
|
+
optionsStart,
|
|
101
|
+
optionsEnd
|
|
102
|
+
)}
|
|
103
|
+
`;
|
|
104
|
+
const before = code.slice(0, lineStart);
|
|
105
|
+
const between = code.slice(lineStart, optionsStart);
|
|
106
|
+
const after = code.slice(optionsEnd);
|
|
107
|
+
return before + optionsConst + between + "__cedar_graphqlOptions" + after;
|
|
108
|
+
}
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
applyGraphqlOptionsExtract,
|
|
112
|
+
cedarGraphqlOptionsExtractPlugin
|
|
113
|
+
});
|
|
@@ -0,0 +1,225 @@
|
|
|
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 vite_plugin_cedar_otel_wrapping_exports = {};
|
|
20
|
+
__export(vite_plugin_cedar_otel_wrapping_exports, {
|
|
21
|
+
applyOtelWrapping: () => applyOtelWrapping,
|
|
22
|
+
cedarOtelWrappingPlugin: () => cedarOtelWrappingPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(vite_plugin_cedar_otel_wrapping_exports);
|
|
25
|
+
var import_oxc_parser = require("oxc-parser");
|
|
26
|
+
var import_vite = require("vite");
|
|
27
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
28
|
+
function cedarOtelWrappingPlugin() {
|
|
29
|
+
return {
|
|
30
|
+
name: "cedar-otel-wrapping",
|
|
31
|
+
transform(code, id) {
|
|
32
|
+
let apiSrc;
|
|
33
|
+
try {
|
|
34
|
+
apiSrc = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().api.src);
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (!(0, import_vite.normalizePath)(id).startsWith(apiSrc + "/")) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const relativePath = (0, import_vite.normalizePath)(id).slice(apiSrc.length + 1);
|
|
42
|
+
const apiFolder = relativePath.split("/")[0] ?? "?";
|
|
43
|
+
const result = applyOtelWrapping(code, id, apiFolder);
|
|
44
|
+
return result ? { code: result, map: null } : null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function applyOtelWrapping(code, filename, apiFolder) {
|
|
49
|
+
const parseResult = (0, import_oxc_parser.parseSync)(filename, code, { sourceType: "module" });
|
|
50
|
+
const replacements = [];
|
|
51
|
+
for (const node of parseResult.program.body) {
|
|
52
|
+
if (node.type !== "ExportNamedDeclaration") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const decl = node.declaration;
|
|
56
|
+
if (decl?.type !== "VariableDeclaration") {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const declarator = decl.declarations[0];
|
|
60
|
+
if (!declarator) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const fn = declarator.init;
|
|
64
|
+
if (fn?.type !== "ArrowFunctionExpression") {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (declarator.id.type !== "Identifier") {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const fnName = declarator.id.name;
|
|
71
|
+
const innerArgs = buildInnerArgs(fn.params);
|
|
72
|
+
if (innerArgs === null) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const fnHeader = code.slice(fn.start, fn.body.start);
|
|
76
|
+
const originalFnSrc = code.slice(fn.start, fn.end);
|
|
77
|
+
const isAsync = fn.async;
|
|
78
|
+
const awaitKw = isAsync ? "await " : "";
|
|
79
|
+
const asyncKw = isAsync ? "async " : "";
|
|
80
|
+
replacements.push({
|
|
81
|
+
start: node.start,
|
|
82
|
+
end: node.end,
|
|
83
|
+
src: buildWrappedExport(
|
|
84
|
+
fnName,
|
|
85
|
+
fnHeader,
|
|
86
|
+
originalFnSrc,
|
|
87
|
+
innerArgs,
|
|
88
|
+
awaitKw,
|
|
89
|
+
asyncKw,
|
|
90
|
+
apiFolder,
|
|
91
|
+
filename
|
|
92
|
+
)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (replacements.length === 0) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
let output = code;
|
|
99
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
100
|
+
const r = replacements[i];
|
|
101
|
+
output = output.slice(0, r.start) + r.src + output.slice(r.end);
|
|
102
|
+
}
|
|
103
|
+
return `import { trace as OTEL_TRACE } from '@opentelemetry/api'
|
|
104
|
+
` + output;
|
|
105
|
+
}
|
|
106
|
+
function buildInnerArgs(params) {
|
|
107
|
+
const args = [];
|
|
108
|
+
for (const param of params) {
|
|
109
|
+
if (param.type === "RestElement" || param.type === "ArrayPattern" || param.type === "TSParameterProperty") {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (param.type === "Identifier") {
|
|
113
|
+
args.push(param.name);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (param.type === "ObjectPattern") {
|
|
117
|
+
for (const prop of param.properties) {
|
|
118
|
+
if (prop.type === "RestElement") {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (prop.key.type !== "Identifier") {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const value = prop.value;
|
|
125
|
+
if (value.type !== "Identifier" && value.type !== "AssignmentPattern" && value.type !== "ObjectPattern") {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (value.type === "AssignmentPattern") {
|
|
129
|
+
if (value.left.type !== "Identifier" && value.left.type !== "ObjectPattern") {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const obj = buildObjectCallArg(param);
|
|
135
|
+
if (obj === null) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
args.push(obj);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (param.type === "AssignmentPattern") {
|
|
142
|
+
const ap = param;
|
|
143
|
+
if (ap.left.type === "Identifier") {
|
|
144
|
+
args.push(ap.left.name);
|
|
145
|
+
} else if (ap.left.type === "ObjectPattern") {
|
|
146
|
+
const obj = buildObjectCallArg(ap.left);
|
|
147
|
+
if (obj === null) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
args.push(obj);
|
|
151
|
+
} else {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return args.join(", ");
|
|
159
|
+
}
|
|
160
|
+
function buildObjectCallArg(pattern) {
|
|
161
|
+
const keys = [];
|
|
162
|
+
for (const prop of pattern.properties) {
|
|
163
|
+
if (prop.type === "RestElement") {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (prop.key.type !== "Identifier") {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const keyName = prop.key.name;
|
|
170
|
+
let valueName = null;
|
|
171
|
+
if (prop.value.type === "Identifier") {
|
|
172
|
+
valueName = prop.value.name;
|
|
173
|
+
} else if (prop.value.type === "AssignmentPattern") {
|
|
174
|
+
if (prop.value.left.type === "Identifier") {
|
|
175
|
+
valueName = prop.value.left.name;
|
|
176
|
+
} else {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (valueName !== keyName) {
|
|
183
|
+
keys.push(`${keyName}: ${valueName}`);
|
|
184
|
+
} else {
|
|
185
|
+
keys.push(keyName);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return `{ ${keys.join(", ")} }`;
|
|
189
|
+
}
|
|
190
|
+
function buildWrappedExport(fnName, fnHeader, originalFnSrc, innerArgs, awaitKw, asyncKw, apiFolder, filename) {
|
|
191
|
+
const privateName = `__${fnName}`;
|
|
192
|
+
const spanName = `redwoodjs:api:${apiFolder}:${fnName}`;
|
|
193
|
+
return `export const ${fnName} = ${fnHeader}{
|
|
194
|
+
const ${privateName} = ${originalFnSrc}
|
|
195
|
+
const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
|
|
196
|
+
const OTEL_RESULT = ${awaitKw}OTEL_TRACER.startActiveSpan(
|
|
197
|
+
'${spanName}',
|
|
198
|
+
${asyncKw}(span) => {
|
|
199
|
+
span.setAttribute('code.function', '${fnName}')
|
|
200
|
+
span.setAttribute('code.filepath', ${JSON.stringify(filename)})
|
|
201
|
+
try {
|
|
202
|
+
const OTEL_INNER_RESULT = ${awaitKw}${privateName}(${innerArgs})
|
|
203
|
+
span.end()
|
|
204
|
+
return OTEL_INNER_RESULT
|
|
205
|
+
} catch (error) {
|
|
206
|
+
span.recordException(error)
|
|
207
|
+
span.setStatus({
|
|
208
|
+
code: 2,
|
|
209
|
+
message:
|
|
210
|
+
error?.message?.split('\\n')[0] ??
|
|
211
|
+
error?.toString()?.split('\\n')[0],
|
|
212
|
+
})
|
|
213
|
+
span.end()
|
|
214
|
+
throw error
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
)
|
|
218
|
+
return OTEL_RESULT
|
|
219
|
+
}`;
|
|
220
|
+
}
|
|
221
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
+
0 && (module.exports = {
|
|
223
|
+
applyOtelWrapping,
|
|
224
|
+
cedarOtelWrappingPlugin
|
|
225
|
+
});
|
|
@@ -329,7 +329,7 @@ async function generateFunctionModule(distPath) {
|
|
|
329
329
|
const ctx = await buildCedarContext(request);
|
|
330
330
|
// Wrap the handler in an AsyncLocalStorage run so the global
|
|
331
331
|
// @cedarjs/context is available inside it (and isolated per request).
|
|
332
|
-
// Mirrors the GraphQL module above and the
|
|
332
|
+
// Mirrors the GraphQL module above and the handlerAlsWrappingPlugin
|
|
333
333
|
// used for non-UD builds.
|
|
334
334
|
const { getAsyncStoreInstance } = await import(
|
|
335
335
|
'@cedarjs/context/dist/store'
|
|
@@ -26,20 +26,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
var vite_plugin_handler_als_wrapping_exports = {};
|
|
30
|
+
__export(vite_plugin_handler_als_wrapping_exports, {
|
|
31
|
+
applyHandlerAlsWrapping: () => applyHandlerAlsWrapping,
|
|
32
|
+
handlerAlsWrappingPlugin: () => handlerAlsWrappingPlugin
|
|
33
33
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(vite_plugin_handler_als_wrapping_exports);
|
|
35
35
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
36
|
var import_vite = require("vite");
|
|
37
37
|
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
-
function
|
|
38
|
+
function handlerAlsWrappingPlugin({
|
|
39
39
|
projectIsEsm = false
|
|
40
40
|
} = {}) {
|
|
41
41
|
return {
|
|
42
|
-
name: "
|
|
42
|
+
name: "handler-als-wrapping",
|
|
43
43
|
transform(code, id) {
|
|
44
44
|
let paths;
|
|
45
45
|
try {
|
|
@@ -51,12 +51,12 @@ function cedarContextWrappingPlugin({
|
|
|
51
51
|
if (!(0, import_vite.normalizePath)(id).startsWith(functionsDir + "/")) {
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
-
const wrapped =
|
|
54
|
+
const wrapped = applyHandlerAlsWrapping(code, { projectIsEsm });
|
|
55
55
|
return wrapped ? { code: wrapped, map: null } : null;
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function applyHandlerAlsWrapping(code, { projectIsEsm = false } = {}) {
|
|
60
60
|
const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
|
|
61
61
|
const handlerMatch = handlerRe.exec(code);
|
|
62
62
|
if (!handlerMatch) {
|
|
@@ -65,31 +65,31 @@ function applyContextWrapping(code, { projectIsEsm = false } = {}) {
|
|
|
65
65
|
const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
|
|
66
66
|
const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
|
|
67
67
|
const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
|
|
68
|
-
const importStatement = `import { getAsyncStoreInstance as
|
|
68
|
+
const importStatement = `import { getAsyncStoreInstance as __cedar_getAsyncStoreInstance } from '${storePath}'
|
|
69
69
|
`;
|
|
70
70
|
const handlerStart = handlerMatch.index;
|
|
71
71
|
const before = code.slice(0, handlerStart);
|
|
72
72
|
const after = code.slice(handlerStart);
|
|
73
|
-
const renamed = after.replace(handlerRe, "const
|
|
73
|
+
const renamed = after.replace(handlerRe, "const __cedar_handler =");
|
|
74
74
|
const wrappedHandler = `
|
|
75
|
-
export const handler = ${isAsync ? "async " : ""}(
|
|
75
|
+
export const handler = ${isAsync ? "async " : ""}(__cedar_event, __cedar_context) => {
|
|
76
76
|
// The store will be undefined if no context isolation has been performed yet
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
return
|
|
77
|
+
const __cedar_contextStore = __cedar_getAsyncStoreInstance().getStore()
|
|
78
|
+
if (__cedar_contextStore === undefined) {
|
|
79
|
+
return __cedar_getAsyncStoreInstance().run(
|
|
80
80
|
new Map(),
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
__cedar_handler,
|
|
82
|
+
__cedar_event,
|
|
83
|
+
__cedar_context
|
|
84
84
|
)
|
|
85
85
|
}
|
|
86
|
-
return
|
|
86
|
+
return __cedar_handler(__cedar_event, __cedar_context)
|
|
87
87
|
}
|
|
88
88
|
`;
|
|
89
89
|
return before + importStatement + renamed + wrappedHandler;
|
|
90
90
|
}
|
|
91
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
92
92
|
0 && (module.exports = {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
applyHandlerAlsWrapping,
|
|
94
|
+
handlerAlsWrappingPlugin
|
|
95
95
|
});
|
|
@@ -44,8 +44,8 @@ function rscSsrRouterImport() {
|
|
|
44
44
|
const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
|
|
45
45
|
return {
|
|
46
46
|
name: "rsc-ssr-router-import",
|
|
47
|
-
transform: async function(code, id) {
|
|
48
|
-
if (id !== routesFileId) {
|
|
47
|
+
transform: async function(code, id, options) {
|
|
48
|
+
if (!options?.ssr || id !== routesFileId) {
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
const ext = import_node_path.default.extname(id);
|
|
@@ -41,6 +41,10 @@ function rscTransformUseServerPlugin(outDir, serverEntryFiles) {
|
|
|
41
41
|
if (!code.includes("use server")) {
|
|
42
42
|
return code;
|
|
43
43
|
}
|
|
44
|
+
if (id.includes("node_modules/.vite") || id.includes("/react-server-dom-webpack/") || id.includes("/react-server-dom-webpack.server")) {
|
|
45
|
+
console.log("vite-plugin-rsc-transform-server.ts: Skipping", id);
|
|
46
|
+
return code;
|
|
47
|
+
}
|
|
44
48
|
let mod;
|
|
45
49
|
const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
|
|
46
50
|
try {
|
|
@@ -33,20 +33,28 @@ __export(rscRenderer_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(rscRenderer_exports);
|
|
35
35
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
-
var import_react = require("react");
|
|
37
|
-
var import_server = require("react-server-dom-webpack/server.edge");
|
|
38
36
|
var import_project_config = require("@cedarjs/project-config");
|
|
39
37
|
var import_entries = require("../lib/entries.js");
|
|
40
38
|
var import_StatusError = require("../lib/StatusError.js");
|
|
39
|
+
var import_utils = require("./utils.js");
|
|
41
40
|
let absoluteClientEntries = {};
|
|
42
|
-
function renderRscToStream(input) {
|
|
41
|
+
async function renderRscToStream(input) {
|
|
43
42
|
return input.rscId ? renderRsc(input) : executeRsa(input);
|
|
44
43
|
}
|
|
45
44
|
async function loadServerFile(filePath) {
|
|
46
45
|
console.log("rscRenderer.ts loadServerFile filePath", filePath);
|
|
46
|
+
if (globalThis.__cedarjs__vite_rsc_runtime) {
|
|
47
|
+
const serverMod = await globalThis.__cedarjs__vite_rsc_runtime.import(filePath);
|
|
48
|
+
return serverMod.default ? serverMod.default : serverMod;
|
|
49
|
+
}
|
|
47
50
|
return import(`file://${filePath}`);
|
|
48
51
|
}
|
|
49
52
|
const getRoutesComponent = async () => {
|
|
53
|
+
if (globalThis.__cedarjs__vite_rsc_runtime) {
|
|
54
|
+
const routesPath2 = (0, import_project_config.getPaths)().web.routes;
|
|
55
|
+
const routesMod = await globalThis.__cedarjs__vite_rsc_runtime.import(routesPath2);
|
|
56
|
+
return routesMod.default;
|
|
57
|
+
}
|
|
50
58
|
const serverEntries = await (0, import_entries.getEntriesFromDist)();
|
|
51
59
|
console.log("rscRenderer.ts serverEntries", serverEntries);
|
|
52
60
|
const routesPath = import_node_path.default.join(
|
|
@@ -87,10 +95,12 @@ function getBundlerConfig() {
|
|
|
87
95
|
{},
|
|
88
96
|
{
|
|
89
97
|
get(_target, encodedId) {
|
|
90
|
-
console.log("Proxy get encodedId", encodedId);
|
|
98
|
+
console.log("rscRenderer.ts Proxy get encodedId", encodedId);
|
|
91
99
|
const [filePath, name] = encodedId.split("#");
|
|
100
|
+
console.log("filePath", filePath);
|
|
101
|
+
console.log("name", name);
|
|
92
102
|
const filePathSlash = filePath.replaceAll("\\", "/");
|
|
93
|
-
const id = absoluteClientEntries[filePathSlash];
|
|
103
|
+
const id = globalThis.__cedarjs__vite_rsc_runtime ? filePath : absoluteClientEntries[filePathSlash];
|
|
94
104
|
console.log("absoluteClientEntries", absoluteClientEntries);
|
|
95
105
|
console.log("filePath", filePathSlash);
|
|
96
106
|
if (!id) {
|
|
@@ -113,12 +123,14 @@ async function renderRsc(input) {
|
|
|
113
123
|
throw new Error("Unexpected input. Missing rscId or props.");
|
|
114
124
|
}
|
|
115
125
|
console.log("renderRsc input", input);
|
|
126
|
+
const { createElement } = await (0, import_utils.importRscReact)();
|
|
127
|
+
const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
|
|
116
128
|
const serverRoutes = await getRoutesComponent();
|
|
117
129
|
const model = {
|
|
118
|
-
__cedarjs__Routes:
|
|
130
|
+
__cedarjs__Routes: createElement(serverRoutes)
|
|
119
131
|
};
|
|
120
132
|
console.log("rscRenderer.ts renderRsc model", model);
|
|
121
|
-
return
|
|
133
|
+
return renderToReadableStream(model, getBundlerConfig());
|
|
122
134
|
}
|
|
123
135
|
function isSerializedFormData(data) {
|
|
124
136
|
return !!data && data?.__formData__;
|
|
@@ -149,14 +161,16 @@ async function executeRsa(input) {
|
|
|
149
161
|
console.log("rscRenderer.ts args", ...input.args);
|
|
150
162
|
const data = await method(...input.args);
|
|
151
163
|
console.log("rscRenderer.ts rsa return data", data);
|
|
164
|
+
const { createElement } = await (0, import_utils.importRscReact)();
|
|
165
|
+
const { renderToReadableStream } = await (0, import_utils.importRsdwServer)();
|
|
152
166
|
const serverRoutes = await getRoutesComponent();
|
|
153
167
|
console.log("rscRenderer.ts executeRsa serverRoutes", serverRoutes);
|
|
154
168
|
const model = {
|
|
155
|
-
__cedarjs__Routes:
|
|
169
|
+
__cedarjs__Routes: createElement(serverRoutes),
|
|
156
170
|
__cedarjs__rsa_data: data
|
|
157
171
|
};
|
|
158
172
|
console.log("rscRenderer.ts executeRsa model", model);
|
|
159
|
-
return
|
|
173
|
+
return renderToReadableStream(model, getBundlerConfig());
|
|
160
174
|
}
|
|
161
175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
162
176
|
0 && (module.exports = {
|
|
@@ -38,10 +38,10 @@ var import_busboy = __toESM(require("busboy"), 1);
|
|
|
38
38
|
var import_react_server_dom_webpack_server = require("../bundled/react-server-dom-webpack.server.js");
|
|
39
39
|
var import_StatusError = require("../lib/StatusError.js");
|
|
40
40
|
var import_invokeMiddleware = require("../middleware/invokeMiddleware.js");
|
|
41
|
-
var import_rscRenderer = require("./rscRenderer.js");
|
|
42
|
-
var import_rscStudioHandlers = require("./rscStudioHandlers.js");
|
|
43
41
|
const BASE_PATH = "/rw-rsc/";
|
|
44
|
-
function createRscRequestHandler(options) {
|
|
42
|
+
async function createRscRequestHandler(options) {
|
|
43
|
+
const { renderRscToStream } = await import("./rscRenderer.js");
|
|
44
|
+
const { sendRscFlightToStudio } = await import("./rscStudioHandlers.js");
|
|
45
45
|
return async (req, res, next) => {
|
|
46
46
|
console.log("BASE_PATH", BASE_PATH);
|
|
47
47
|
console.log("req.originalUrl", req.originalUrl, "req.url", req.url);
|
|
@@ -56,7 +56,7 @@ function createRscRequestHandler(options) {
|
|
|
56
56
|
matchedMw?.handler,
|
|
57
57
|
{
|
|
58
58
|
params: matchedMw?.params,
|
|
59
|
-
|
|
59
|
+
viteSsrDevServer: options.viteSsrDevServer
|
|
60
60
|
}
|
|
61
61
|
);
|
|
62
62
|
const webRes = mwResponse.toResponse();
|
|
@@ -101,9 +101,9 @@ function createRscRequestHandler(options) {
|
|
|
101
101
|
res.end(String(err));
|
|
102
102
|
};
|
|
103
103
|
try {
|
|
104
|
-
const readable = await
|
|
104
|
+
const readable = await renderRscToStream({ rscId, rsaId, args });
|
|
105
105
|
import_node_stream.Readable.fromWeb(readable).pipe(res);
|
|
106
|
-
await
|
|
106
|
+
await sendRscFlightToStudio({
|
|
107
107
|
rscId,
|
|
108
108
|
rsaId,
|
|
109
109
|
args,
|