@rpcbase/server 0.486.0 → 0.487.0
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/dev/coverage.d.ts +3 -0
- package/dist/dev/coverage.d.ts.map +1 -0
- package/dist/email-DEw8keax.js +1 -0
- package/dist/email-DEw8keax.js.map +1 -0
- package/dist/handler-BwK8qxLn.js +1 -0
- package/dist/handler-BwK8qxLn.js.map +1 -0
- package/dist/handler-CedzJJg0.js +1 -0
- package/dist/handler-CedzJJg0.js.map +1 -0
- package/dist/handler-Cohj3cz3.js +1 -0
- package/dist/handler-Cohj3cz3.js.map +1 -0
- package/dist/handler-qCAUmVgd.js +1 -0
- package/dist/handler-qCAUmVgd.js.map +1 -0
- package/dist/index.js +294 -10
- package/dist/index.js.map +1 -0
- package/dist/initServer.d.ts.map +1 -1
- package/dist/notifications.js +1 -0
- package/dist/notifications.js.map +1 -0
- package/dist/render_resend_false-MiC__Smr.js +1 -0
- package/dist/render_resend_false-MiC__Smr.js.map +1 -0
- package/dist/rts/index.js +1 -0
- package/dist/rts/index.js.map +1 -0
- package/dist/schemas-7qqi9OQy.js +1 -0
- package/dist/schemas-7qqi9OQy.js.map +1 -0
- package/dist/shared-BJomDDWK.js +1 -0
- package/dist/shared-BJomDDWK.js.map +1 -0
- package/dist/uploads.js +1 -0
- package/dist/uploads.js.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,13 +6,16 @@ import { MongoClient } from "mongodb";
|
|
|
6
6
|
import env from "@rpcbase/env";
|
|
7
7
|
import { initApiClient, SsrErrorFallback, SSR_ERROR_STATE_GLOBAL_KEY, serializeSsrErrorState } from "@rpcbase/client";
|
|
8
8
|
import { dirname, posix, sep } from "path";
|
|
9
|
-
import { createReadStream, readFileSync } from "node:fs";
|
|
9
|
+
import fs, { createReadStream, readFileSync } from "node:fs";
|
|
10
10
|
import { createInterface } from "node:readline";
|
|
11
11
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
12
12
|
import assert$1 from "assert";
|
|
13
13
|
import crypto, { hkdfSync, scrypt } from "crypto";
|
|
14
14
|
import httpProxy from "http-proxy-3";
|
|
15
|
-
import
|
|
15
|
+
import fsPromises from "node:fs/promises";
|
|
16
|
+
import inspector from "node:inspector";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
16
19
|
import { Transform } from "node:stream";
|
|
17
20
|
import { StrictMode, createElement } from "react";
|
|
18
21
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
@@ -216,8 +219,8 @@ function createGetModuleFromFilename(basePath = process.argv[1] ? dirname(proces
|
|
|
216
219
|
return decodedFile;
|
|
217
220
|
};
|
|
218
221
|
}
|
|
219
|
-
function normalizeWindowsPath(
|
|
220
|
-
return
|
|
222
|
+
function normalizeWindowsPath(path2) {
|
|
223
|
+
return path2.replace(/^[A-Z]:/, "").replace(/\\/g, "/");
|
|
221
224
|
}
|
|
222
225
|
const normalizeFlagsResponse = (flagsResponse) => {
|
|
223
226
|
if ("flags" in flagsResponse) {
|
|
@@ -1857,9 +1860,9 @@ async function addSourceContext(frames) {
|
|
|
1857
1860
|
LRU_FILE_CONTENTS_CACHE.reduce();
|
|
1858
1861
|
return frames;
|
|
1859
1862
|
}
|
|
1860
|
-
function getContextLinesFromFile(
|
|
1863
|
+
function getContextLinesFromFile(path2, ranges, output) {
|
|
1861
1864
|
return new Promise((resolve) => {
|
|
1862
|
-
const stream = createReadStream(
|
|
1865
|
+
const stream = createReadStream(path2);
|
|
1863
1866
|
const lineReaded = createInterface({
|
|
1864
1867
|
input: stream
|
|
1865
1868
|
});
|
|
@@ -1874,7 +1877,7 @@ function getContextLinesFromFile(path, ranges, output) {
|
|
|
1874
1877
|
let rangeStart = range[0];
|
|
1875
1878
|
let rangeEnd = range[1];
|
|
1876
1879
|
function onStreamError() {
|
|
1877
|
-
LRU_FILE_CONTENTS_FS_READ_FAILED.set(
|
|
1880
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(path2, 1);
|
|
1878
1881
|
lineReaded.close();
|
|
1879
1882
|
lineReaded.removeAllListeners();
|
|
1880
1883
|
destroyStreamAndResolve();
|
|
@@ -1935,8 +1938,8 @@ function clearLineContext(frame) {
|
|
|
1935
1938
|
delete frame.context_line;
|
|
1936
1939
|
delete frame.post_context;
|
|
1937
1940
|
}
|
|
1938
|
-
function shouldSkipContextLinesForFile(
|
|
1939
|
-
return
|
|
1941
|
+
function shouldSkipContextLinesForFile(path2) {
|
|
1942
|
+
return path2.startsWith("node:") || path2.endsWith(".min.js") || path2.endsWith(".min.cjs") || path2.endsWith(".min.mjs") || path2.startsWith("data:");
|
|
1940
1943
|
}
|
|
1941
1944
|
function shouldSkipContextLinesForFrame(frame) {
|
|
1942
1945
|
if (void 0 !== frame.lineno && frame.lineno > MAX_CONTEXTLINES_LINENO) return true;
|
|
@@ -3492,6 +3495,283 @@ const checkInitReplicaSet = async (serverEnv) => {
|
|
|
3492
3495
|
}
|
|
3493
3496
|
}
|
|
3494
3497
|
};
|
|
3498
|
+
const VITE_FS_PREFIX = "/@fs/";
|
|
3499
|
+
let activeRun = null;
|
|
3500
|
+
const post = async (session2, method, params) => {
|
|
3501
|
+
return await new Promise((resolve, reject) => {
|
|
3502
|
+
session2.post(method, params, (error, result) => {
|
|
3503
|
+
if (error) {
|
|
3504
|
+
reject(error);
|
|
3505
|
+
return;
|
|
3506
|
+
}
|
|
3507
|
+
resolve(result);
|
|
3508
|
+
});
|
|
3509
|
+
});
|
|
3510
|
+
};
|
|
3511
|
+
const describeError = (error) => {
|
|
3512
|
+
return error instanceof Error ? error.message : String(error);
|
|
3513
|
+
};
|
|
3514
|
+
const findWorkspaceRoot = (projectRoot) => {
|
|
3515
|
+
let dir = path.resolve(projectRoot);
|
|
3516
|
+
while (true) {
|
|
3517
|
+
const pkgPath = path.join(dir, "package.json");
|
|
3518
|
+
try {
|
|
3519
|
+
if (fs.existsSync(pkgPath)) {
|
|
3520
|
+
const parsed = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
3521
|
+
if (parsed && typeof parsed === "object" && parsed.workspaces) {
|
|
3522
|
+
return dir;
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
} catch {
|
|
3526
|
+
}
|
|
3527
|
+
const parent = path.dirname(dir);
|
|
3528
|
+
if (parent === dir) {
|
|
3529
|
+
return path.resolve(projectRoot);
|
|
3530
|
+
}
|
|
3531
|
+
dir = parent;
|
|
3532
|
+
}
|
|
3533
|
+
};
|
|
3534
|
+
const stripQuery = (url) => {
|
|
3535
|
+
const queryIndex = url.indexOf("?");
|
|
3536
|
+
const hashIndex = url.indexOf("#");
|
|
3537
|
+
const endIndex = Math.min(
|
|
3538
|
+
queryIndex === -1 ? Number.POSITIVE_INFINITY : queryIndex,
|
|
3539
|
+
hashIndex === -1 ? Number.POSITIVE_INFINITY : hashIndex
|
|
3540
|
+
);
|
|
3541
|
+
if (!Number.isFinite(endIndex)) {
|
|
3542
|
+
return url;
|
|
3543
|
+
}
|
|
3544
|
+
return url.slice(0, endIndex);
|
|
3545
|
+
};
|
|
3546
|
+
const resolveAbsoluteFromUrl = (rawUrl, roots) => {
|
|
3547
|
+
const cleaned = stripQuery(rawUrl);
|
|
3548
|
+
try {
|
|
3549
|
+
if (cleaned.startsWith("file://")) {
|
|
3550
|
+
return path.normalize(fileURLToPath(cleaned));
|
|
3551
|
+
}
|
|
3552
|
+
} catch {
|
|
3553
|
+
}
|
|
3554
|
+
let pathname = cleaned;
|
|
3555
|
+
try {
|
|
3556
|
+
const parsed = new URL(cleaned);
|
|
3557
|
+
pathname = parsed.pathname;
|
|
3558
|
+
} catch {
|
|
3559
|
+
}
|
|
3560
|
+
const decoded = decodeURIComponent(pathname);
|
|
3561
|
+
if (decoded.startsWith(VITE_FS_PREFIX)) {
|
|
3562
|
+
return path.normalize(decoded.slice(VITE_FS_PREFIX.length));
|
|
3563
|
+
}
|
|
3564
|
+
if (!path.isAbsolute(decoded)) {
|
|
3565
|
+
return null;
|
|
3566
|
+
}
|
|
3567
|
+
if (fs.existsSync(decoded)) {
|
|
3568
|
+
return path.normalize(decoded);
|
|
3569
|
+
}
|
|
3570
|
+
const projectRoot = path.resolve(roots.projectRoot);
|
|
3571
|
+
const workspaceRoot = path.resolve(roots.workspaceRoot);
|
|
3572
|
+
if (decoded.startsWith(projectRoot + path.sep) || decoded.startsWith(workspaceRoot + path.sep)) {
|
|
3573
|
+
return path.normalize(decoded);
|
|
3574
|
+
}
|
|
3575
|
+
return path.resolve(projectRoot, `.${decoded}`);
|
|
3576
|
+
};
|
|
3577
|
+
const normalizeScriptUrl = async (rawUrl, roots) => {
|
|
3578
|
+
if (!rawUrl || rawUrl.startsWith("node:")) {
|
|
3579
|
+
return null;
|
|
3580
|
+
}
|
|
3581
|
+
const absolute = resolveAbsoluteFromUrl(rawUrl, roots);
|
|
3582
|
+
if (!absolute) {
|
|
3583
|
+
return null;
|
|
3584
|
+
}
|
|
3585
|
+
let realPath = absolute;
|
|
3586
|
+
try {
|
|
3587
|
+
realPath = await fsPromises.realpath(absolute);
|
|
3588
|
+
} catch {
|
|
3589
|
+
}
|
|
3590
|
+
const normalized = path.normalize(realPath);
|
|
3591
|
+
if (normalized.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
3592
|
+
return null;
|
|
3593
|
+
}
|
|
3594
|
+
const workspaceRoot = path.resolve(roots.workspaceRoot);
|
|
3595
|
+
const projectRoot = path.resolve(roots.projectRoot);
|
|
3596
|
+
if (normalized.startsWith(workspaceRoot + path.sep) || normalized === workspaceRoot) {
|
|
3597
|
+
return {
|
|
3598
|
+
absolutePath: normalized,
|
|
3599
|
+
relativePath: path.relative(workspaceRoot, normalized)
|
|
3600
|
+
};
|
|
3601
|
+
}
|
|
3602
|
+
if (normalized.startsWith(projectRoot + path.sep) || normalized === projectRoot) {
|
|
3603
|
+
return {
|
|
3604
|
+
absolutePath: normalized,
|
|
3605
|
+
relativePath: path.relative(projectRoot, normalized)
|
|
3606
|
+
};
|
|
3607
|
+
}
|
|
3608
|
+
return null;
|
|
3609
|
+
};
|
|
3610
|
+
const fetchScriptSource = async (session2, scriptId) => {
|
|
3611
|
+
try {
|
|
3612
|
+
const response = await post(session2, "Debugger.getScriptSource", { scriptId });
|
|
3613
|
+
return typeof response?.scriptSource === "string" ? response.scriptSource : "";
|
|
3614
|
+
} catch {
|
|
3615
|
+
return "";
|
|
3616
|
+
}
|
|
3617
|
+
};
|
|
3618
|
+
const resolveScriptSource = async (session2, cache, scriptId) => {
|
|
3619
|
+
const cached = cache.get(scriptId);
|
|
3620
|
+
if (cached) {
|
|
3621
|
+
return await cached;
|
|
3622
|
+
}
|
|
3623
|
+
const promise = fetchScriptSource(session2, scriptId);
|
|
3624
|
+
cache.set(scriptId, promise);
|
|
3625
|
+
return await promise;
|
|
3626
|
+
};
|
|
3627
|
+
const shutdownSession = async (session2) => {
|
|
3628
|
+
await Promise.allSettled([
|
|
3629
|
+
post(session2, "Profiler.stopPreciseCoverage").catch(() => void 0),
|
|
3630
|
+
post(session2, "Profiler.disable").catch(() => void 0),
|
|
3631
|
+
post(session2, "Debugger.disable").catch(() => void 0)
|
|
3632
|
+
]);
|
|
3633
|
+
try {
|
|
3634
|
+
session2.disconnect();
|
|
3635
|
+
} catch {
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
const toPosixPath = (input) => input.split(path.sep).join("/");
|
|
3639
|
+
const isSubpath = (candidate, root) => {
|
|
3640
|
+
const relative = path.relative(root, candidate);
|
|
3641
|
+
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
3642
|
+
};
|
|
3643
|
+
const classifyServerTarget = (absolutePath, projectRoot) => {
|
|
3644
|
+
if (!isSubpath(absolutePath, projectRoot)) {
|
|
3645
|
+
return "ssr";
|
|
3646
|
+
}
|
|
3647
|
+
const relative = toPosixPath(path.relative(projectRoot, absolutePath));
|
|
3648
|
+
if (relative.startsWith("src/api/") || relative.includes("/src/api/")) {
|
|
3649
|
+
return "api";
|
|
3650
|
+
}
|
|
3651
|
+
if (relative.startsWith("src/worker/") || relative.includes("/src/worker/")) {
|
|
3652
|
+
return "worker";
|
|
3653
|
+
}
|
|
3654
|
+
if (relative.startsWith("src/server/") || relative.includes("/src/server/")) {
|
|
3655
|
+
return "ssr";
|
|
3656
|
+
}
|
|
3657
|
+
if (relative.startsWith("build/dist/api/") || relative.includes("/build/dist/api/")) {
|
|
3658
|
+
return "api";
|
|
3659
|
+
}
|
|
3660
|
+
if (relative.startsWith("build/dist/worker/") || relative.includes("/build/dist/worker/")) {
|
|
3661
|
+
return "worker";
|
|
3662
|
+
}
|
|
3663
|
+
if (relative.startsWith("build/dist/ssr/") || relative.includes("/build/dist/ssr/")) {
|
|
3664
|
+
return "ssr";
|
|
3665
|
+
}
|
|
3666
|
+
return "ssr";
|
|
3667
|
+
};
|
|
3668
|
+
function registerDevCoverageEndpoints(app) {
|
|
3669
|
+
app.post("/api/dev/coverage/start", async (_req, res) => {
|
|
3670
|
+
if (process.env.NODE_ENV === "production") {
|
|
3671
|
+
res.status(404).json({ error: "Not Found" });
|
|
3672
|
+
return;
|
|
3673
|
+
}
|
|
3674
|
+
if (activeRun) {
|
|
3675
|
+
res.json({ ok: true, status: "already_started", startedAt: activeRun.startedAt });
|
|
3676
|
+
return;
|
|
3677
|
+
}
|
|
3678
|
+
const roots = {
|
|
3679
|
+
projectRoot: path.resolve(process.cwd()),
|
|
3680
|
+
workspaceRoot: findWorkspaceRoot(process.cwd())
|
|
3681
|
+
};
|
|
3682
|
+
const session2 = new inspector.Session();
|
|
3683
|
+
session2.connect();
|
|
3684
|
+
try {
|
|
3685
|
+
await post(session2, "Debugger.enable");
|
|
3686
|
+
await post(session2, "Profiler.enable");
|
|
3687
|
+
await post(session2, "Profiler.startPreciseCoverage", { callCount: false, detailed: true });
|
|
3688
|
+
activeRun = {
|
|
3689
|
+
roots,
|
|
3690
|
+
session: session2,
|
|
3691
|
+
sourceCache: /* @__PURE__ */ new Map(),
|
|
3692
|
+
startedAt: Date.now()
|
|
3693
|
+
};
|
|
3694
|
+
res.json({ ok: true, status: "started", startedAt: activeRun.startedAt });
|
|
3695
|
+
} catch (error) {
|
|
3696
|
+
await shutdownSession(session2);
|
|
3697
|
+
activeRun = null;
|
|
3698
|
+
res.status(500).json({ ok: false, error: describeError(error) });
|
|
3699
|
+
}
|
|
3700
|
+
});
|
|
3701
|
+
app.post("/api/dev/coverage/stop", async (req, res) => {
|
|
3702
|
+
if (process.env.NODE_ENV === "production") {
|
|
3703
|
+
res.status(404).json({ error: "Not Found" });
|
|
3704
|
+
return;
|
|
3705
|
+
}
|
|
3706
|
+
const run = activeRun;
|
|
3707
|
+
if (!run) {
|
|
3708
|
+
res.status(409).json({ ok: false, error: "coverage_not_started" });
|
|
3709
|
+
return;
|
|
3710
|
+
}
|
|
3711
|
+
activeRun = null;
|
|
3712
|
+
const outputRoot = path.join(run.roots.projectRoot, "build", "coverage", "server");
|
|
3713
|
+
const outputFiles = {
|
|
3714
|
+
api: path.join(outputRoot, "api", "v8-coverage.json"),
|
|
3715
|
+
worker: path.join(outputRoot, "worker", "v8-coverage.json"),
|
|
3716
|
+
ssr: path.join(outputRoot, "ssr", "v8-coverage.json")
|
|
3717
|
+
};
|
|
3718
|
+
try {
|
|
3719
|
+
const taken = await post(run.session, "Profiler.takePreciseCoverage");
|
|
3720
|
+
const result = Array.isArray(taken?.result) ? taken.result : [];
|
|
3721
|
+
const scriptsByTarget = {
|
|
3722
|
+
api: [],
|
|
3723
|
+
worker: [],
|
|
3724
|
+
ssr: []
|
|
3725
|
+
};
|
|
3726
|
+
for (const entry of result) {
|
|
3727
|
+
const scriptId = typeof entry?.scriptId === "string" ? entry.scriptId : null;
|
|
3728
|
+
const url = typeof entry?.url === "string" ? entry.url : null;
|
|
3729
|
+
if (!scriptId || !url) {
|
|
3730
|
+
continue;
|
|
3731
|
+
}
|
|
3732
|
+
const normalized = await normalizeScriptUrl(url, run.roots);
|
|
3733
|
+
if (!normalized) {
|
|
3734
|
+
continue;
|
|
3735
|
+
}
|
|
3736
|
+
const source = await resolveScriptSource(run.session, run.sourceCache, scriptId);
|
|
3737
|
+
const script = {
|
|
3738
|
+
absolutePath: normalized.absolutePath,
|
|
3739
|
+
relativePath: normalized.relativePath,
|
|
3740
|
+
source,
|
|
3741
|
+
functions: Array.isArray(entry?.functions) ? entry.functions : [],
|
|
3742
|
+
url
|
|
3743
|
+
};
|
|
3744
|
+
const target = classifyServerTarget(script.absolutePath, run.roots.projectRoot);
|
|
3745
|
+
scriptsByTarget[target].push(script);
|
|
3746
|
+
}
|
|
3747
|
+
await Promise.all(
|
|
3748
|
+
Object.keys(outputFiles).map(async (target) => {
|
|
3749
|
+
const outputFile = outputFiles[target];
|
|
3750
|
+
const payload = {
|
|
3751
|
+
testId: `node-${target}`,
|
|
3752
|
+
scripts: scriptsByTarget[target]
|
|
3753
|
+
};
|
|
3754
|
+
await fsPromises.mkdir(path.dirname(outputFile), { recursive: true });
|
|
3755
|
+
await fsPromises.writeFile(outputFile, JSON.stringify(payload, null, 2), "utf8");
|
|
3756
|
+
})
|
|
3757
|
+
);
|
|
3758
|
+
res.json({
|
|
3759
|
+
ok: true,
|
|
3760
|
+
status: "stopped",
|
|
3761
|
+
outputFiles,
|
|
3762
|
+
scriptCount: {
|
|
3763
|
+
api: scriptsByTarget.api.length,
|
|
3764
|
+
worker: scriptsByTarget.worker.length,
|
|
3765
|
+
ssr: scriptsByTarget.ssr.length
|
|
3766
|
+
}
|
|
3767
|
+
});
|
|
3768
|
+
} catch (error) {
|
|
3769
|
+
res.status(500).json({ ok: false, error: describeError(error) });
|
|
3770
|
+
} finally {
|
|
3771
|
+
await shutdownSession(run.session);
|
|
3772
|
+
}
|
|
3773
|
+
});
|
|
3774
|
+
}
|
|
3495
3775
|
process.env = {
|
|
3496
3776
|
...env,
|
|
3497
3777
|
...__rb_env__,
|
|
@@ -3614,6 +3894,9 @@ const initServer = async (app, serverEnv) => {
|
|
|
3614
3894
|
sessionConfig.cookie.secure = "auto";
|
|
3615
3895
|
}
|
|
3616
3896
|
const sessionMiddleware = session(sessionConfig);
|
|
3897
|
+
if (!isProduction$1) {
|
|
3898
|
+
registerDevCoverageEndpoints(app);
|
|
3899
|
+
}
|
|
3617
3900
|
app.use(sessionMiddleware);
|
|
3618
3901
|
return {
|
|
3619
3902
|
sessionMiddleware
|
|
@@ -4225,7 +4508,7 @@ const ssrMiddleware = ({
|
|
|
4225
4508
|
if (isProduction) {
|
|
4226
4509
|
template = templateHtml;
|
|
4227
4510
|
} else {
|
|
4228
|
-
template = await
|
|
4511
|
+
template = await fsPromises.readFile("./src/client/index.html", "utf-8");
|
|
4229
4512
|
template = await viteInstance.transformIndexHtml(url, template);
|
|
4230
4513
|
}
|
|
4231
4514
|
const placeholderIndex = template.indexOf(APP_HTML_PLACEHOLDER);
|
|
@@ -4342,3 +4625,4 @@ export {
|
|
|
4342
4625
|
ssrMiddleware,
|
|
4343
4626
|
verifyPasswordFromStorage
|
|
4344
4627
|
};
|
|
4628
|
+
//# sourceMappingURL=index.js.map
|