@farm.js/core 0.1.75 → 0.1.77
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/{agent-mcp.d-Djvao5eV.d.ts → agent-mcp.d-B1h3RznZ.d.ts} +1 -1
- package/dist/{agent-mcp.d-wA13pwmS.d.mts → agent-mcp.d-WFQotg8M.d.mts} +1 -1
- package/dist/agent-runtime.cjs +2 -2
- package/dist/agent-runtime.d.mts +7 -5
- package/dist/agent-runtime.d.ts +7 -5
- package/dist/agent-runtime.mjs +1 -1
- package/dist/{analyzer-LJHMFCDW.mjs → analyzer-64YS2OXQ.mjs} +2 -2
- package/dist/analyzer-HTNXLX6N.cjs +16 -0
- package/dist/api/node.d.mts +9 -7
- package/dist/api/node.d.ts +9 -7
- package/dist/api/route-manager.d.mts +9 -7
- package/dist/api/route-manager.d.ts +9 -7
- package/dist/api/runtime.d.mts +8 -6
- package/dist/api/runtime.d.ts +8 -6
- package/dist/api.d.mts +10 -8
- package/dist/api.d.ts +10 -8
- package/dist/{app-manifest.d-DIuqSi9k.d.mts → app-manifest.d-EZEYG-tD.d.mts} +1 -1
- package/dist/{app-manifest.d-BukcP_EV.d.ts → app-manifest.d-Ktsqsuk9.d.ts} +1 -1
- package/dist/app-markdown.d.mts +8 -6
- package/dist/app-markdown.d.ts +8 -6
- package/dist/{app.d-BQqmM6Gy.d.ts → app.d-CSh3y8w8.d.ts} +5 -4
- package/dist/{app.d-YVuFb10p.d.mts → app.d-DTkqYcIr.d.mts} +5 -4
- package/dist/{chunk-CL2ONP73.cjs → chunk-2PE5STAR.cjs} +36 -27
- package/dist/{chunk-HV2WZFUW.mjs → chunk-2QPTZMGK.mjs} +1 -1
- package/dist/{chunk-E7VF3LQ5.mjs → chunk-4STJ6LGR.mjs} +13 -1
- package/dist/{chunk-LQBV2Y37.mjs → chunk-65XXHTVJ.mjs} +38 -2
- package/dist/{chunk-XGDI4OUB.cjs → chunk-6ZFGWB75.cjs} +13 -1
- package/dist/{chunk-IDOUCM2X.mjs → chunk-7EXFAJST.mjs} +57 -44
- package/dist/{chunk-HVJ7IACB.cjs → chunk-7SAGHWWU.cjs} +2 -2
- package/dist/{chunk-GNY7BO7R.mjs → chunk-BTHNOAOF.mjs} +2 -2
- package/dist/{chunk-TJVUTGED.mjs → chunk-D2RLADWN.mjs} +285 -93
- package/dist/chunk-DS2KZ5BT.mjs +16 -0
- package/dist/{chunk-WHCNJVYU.cjs → chunk-DSRWQ4SJ.cjs} +3 -3
- package/dist/{chunk-ZPCZWEU3.cjs → chunk-FCHEO3LG.cjs} +2 -2
- package/dist/{chunk-75XSZIRE.mjs → chunk-FD6BMUA3.mjs} +35 -26
- package/dist/{chunk-4T2RB4JA.mjs → chunk-FNVGK72M.mjs} +5 -5
- package/dist/{chunk-TFEODQLG.mjs → chunk-FPGSIOWS.mjs} +2 -2
- package/dist/{chunk-4BS3HSY7.cjs → chunk-FTQUNBRN.cjs} +2 -2
- package/dist/{chunk-ZV76IQG7.cjs → chunk-FVVGEGQ2.cjs} +2 -2
- package/dist/{chunk-7564NP5Z.cjs → chunk-GC2BSXQS.cjs} +39 -3
- package/dist/{chunk-HT2SZKXG.mjs → chunk-H76C5AOU.mjs} +12 -0
- package/dist/{chunk-OFIFRB62.mjs → chunk-IHMSLS2O.mjs} +36 -20
- package/dist/{chunk-BUC3FDYC.cjs → chunk-IIVZTGGP.cjs} +2 -2
- package/dist/{chunk-6MATGOEF.mjs → chunk-IXC6WDMT.mjs} +1 -1
- package/dist/{chunk-KPYQ32BA.cjs → chunk-JD42G6BN.cjs} +2 -2
- package/dist/{chunk-WJ5CCQBM.cjs → chunk-LTDMJD2F.cjs} +4 -4
- package/dist/{chunk-XX6ZA2IO.cjs → chunk-MQW4LHJR.cjs} +1 -1
- package/dist/{chunk-BNTRXJL4.cjs → chunk-NQZWLIPT.cjs} +3 -3
- package/dist/{chunk-QGYHE6VJ.mjs → chunk-NTHAZLVS.mjs} +28 -27
- package/dist/{chunk-OCLCA3X3.mjs → chunk-OCKQ3YOH.mjs} +1 -1
- package/dist/{chunk-PBQGIA27.cjs → chunk-OQZF6H6G.cjs} +4 -4
- package/dist/{chunk-YSTKSZD2.mjs → chunk-ORWXJDUN.mjs} +1 -1
- package/dist/{chunk-JNZDTE75.cjs → chunk-PMKUTZGR.cjs} +8 -8
- package/dist/{chunk-4ZSZI6XL.cjs → chunk-PUEPDMWY.cjs} +16 -16
- package/dist/{chunk-MTBDJ326.cjs → chunk-QMR2TUVZ.cjs} +13 -1
- package/dist/{chunk-A5F55ZFA.mjs → chunk-QODXWUGQ.mjs} +2 -2
- package/dist/chunk-RFXEQYPH.cjs +723 -0
- package/dist/{chunk-IK33N2AN.cjs → chunk-SIYELCIX.cjs} +158 -142
- package/dist/{chunk-MFU7SXAB.mjs → chunk-SL2BSPDJ.mjs} +1 -1
- package/dist/{chunk-H7QY7ZE4.mjs → chunk-SMYDCZBW.mjs} +1 -1
- package/dist/{chunk-GLF44JKY.mjs → chunk-TQOYIPMQ.mjs} +1 -1
- package/dist/{chunk-IVBDRAOR.cjs → chunk-UYACD4SH.cjs} +1 -1
- package/dist/{chunk-B4CWYGCG.mjs → chunk-WHNNDFCJ.mjs} +1 -1
- package/dist/{chunk-4MU4QCX4.mjs → chunk-WXMR3OHY.mjs} +1 -1
- package/dist/{chunk-YL7BKHYE.cjs → chunk-WZVESREI.cjs} +291 -278
- package/dist/chunk-XRRHPBG2.cjs +16 -0
- package/dist/{chunk-NPGXX7HN.cjs → chunk-YROK6CJC.cjs} +7 -7
- package/dist/{chunk-OZARLCYQ.cjs → chunk-YRQ44JTF.cjs} +179 -178
- package/dist/{chunk-2NQ3S2SJ.mjs → chunk-YTGNMKRA.mjs} +1 -1
- package/dist/{chunk-YCNKS6SD.mjs → chunk-ZBE5EHVJ.mjs} +4 -4
- package/dist/cli-runtime.d-DljFfr8T.d.ts +537 -0
- package/dist/cli-runtime.d-HSkdfvoq.d.mts +537 -0
- package/dist/client/lifecycle.d.mts +1 -1
- package/dist/client/lifecycle.d.ts +1 -1
- package/dist/{client-component.d-BeqVuqy2.d.mts → client-component.d-B-1dIlsw.d.mts} +2 -137
- package/dist/{client-component.d-CZ1NpHAY.d.ts → client-component.d-_otXB__v.d.ts} +2 -137
- package/dist/{client-plugins.d-ChceYO9t.d.mts → client-plugins.d-BmBzvfSP.d.mts} +4 -4
- package/dist/{client-plugins.d-D9kWC0QB.d.ts → client-plugins.d-MjxlvbCK.d.ts} +4 -4
- package/dist/client-plugins.d.mts +7 -5
- package/dist/client-plugins.d.ts +7 -5
- package/dist/client.d.mts +12 -10
- package/dist/client.d.ts +12 -10
- package/dist/config.d.mts +7 -5
- package/dist/config.d.ts +7 -5
- package/dist/desktop.d.mts +8 -6
- package/dist/desktop.d.ts +8 -6
- package/dist/{devtools-B3W3DLPG.mjs → devtools-7LHXG2VS.mjs} +4 -3
- package/dist/{devtools-T5I2WHRX.cjs → devtools-NNQN66EZ.cjs} +5 -4
- package/dist/docs.cjs +6 -5
- package/dist/docs.d.mts +10 -65
- package/dist/docs.d.ts +10 -65
- package/dist/docs.mjs +5 -4
- package/dist/environment/vite.cjs +5 -4
- package/dist/environment/vite.mjs +4 -3
- package/dist/handler.d-C53zFDmp.d.ts +62 -0
- package/dist/handler.d-CaYopqaD.d.mts +62 -0
- package/dist/{headers.d-Aux4JVnm.d.ts → headers.d-BvtpC90T.d.ts} +1 -1
- package/dist/{headers.d-BawakaPv.d.mts → headers.d-MBkD9ZLf.d.mts} +1 -1
- package/dist/index.cjs +31 -24
- package/dist/index.d-2hQpPZ-P.d.ts +16 -0
- package/dist/index.d-Mikf-tdP.d.mts +16 -0
- package/dist/index.d.mts +39 -556
- package/dist/index.d.ts +39 -556
- package/dist/index.mjs +30 -23
- package/dist/integrations/orm.cjs +4 -3
- package/dist/integrations/orm.d.mts +6 -4
- package/dist/integrations/orm.d.ts +6 -4
- package/dist/integrations/orm.mjs +3 -2
- package/dist/integrations.cjs +2 -2
- package/dist/integrations.d.mts +7 -5
- package/dist/integrations.d.ts +7 -5
- package/dist/integrations.mjs +1 -1
- package/dist/internal/app-markdown-runtime.d.mts +8 -6
- package/dist/internal/app-markdown-runtime.d.ts +8 -6
- package/dist/internal/build-runtime.cjs +23 -22
- package/dist/internal/build-runtime.d.mts +10 -7
- package/dist/internal/build-runtime.d.ts +10 -7
- package/dist/internal/build-runtime.mjs +22 -21
- package/dist/internal/cli-runtime.cjs +17 -9
- package/dist/internal/cli-runtime.d.mts +46 -0
- package/dist/internal/cli-runtime.d.ts +46 -0
- package/dist/internal/cli-runtime.mjs +16 -8
- package/dist/internal/client-error-overlay.cjs +4 -4
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/client-runtime.d.mts +11 -9
- package/dist/internal/client-runtime.d.ts +11 -9
- package/dist/internal/compression-runtime.cjs +2 -2
- package/dist/internal/compression-runtime.d.mts +11 -6
- package/dist/internal/compression-runtime.d.ts +11 -6
- package/dist/internal/compression-runtime.mjs +1 -1
- package/dist/internal/config-runtime.cjs +6 -5
- package/dist/internal/config-runtime.d.mts +9 -7
- package/dist/internal/config-runtime.d.ts +9 -7
- package/dist/internal/config-runtime.mjs +5 -4
- package/dist/internal/infra-analytics-runtime.cjs +6 -6
- package/dist/internal/infra-analytics-runtime.mjs +4 -4
- package/dist/internal/native-server-fns.cjs +4 -4
- package/dist/internal/native-server-fns.mjs +3 -3
- package/dist/internal/product-telemetry-runtime.cjs +3 -3
- package/dist/internal/product-telemetry-runtime.mjs +2 -2
- package/dist/internal/production-runtime.cjs +8 -7
- package/dist/internal/production-runtime.d.mts +16 -14
- package/dist/internal/production-runtime.d.ts +16 -14
- package/dist/internal/production-runtime.mjs +7 -6
- package/dist/internal/start-manifest.d.mts +7 -5
- package/dist/internal/start-manifest.d.ts +7 -5
- package/dist/{layers-XQ7VFMWO.mjs → layers-I7VE5Q2Y.mjs} +2 -1
- package/dist/layers-WP5K5F7W.cjs +21 -0
- package/dist/{lifecycle.d-OtGWAvJT.d.ts → lifecycle.d-VzcXyEyn.d.mts} +1 -1
- package/dist/{lifecycle.d-OtGWAvJT.d.mts → lifecycle.d-VzcXyEyn.d.ts} +1 -1
- package/dist/markdown.d.mts +7 -5
- package/dist/markdown.d.ts +7 -5
- package/dist/middleware.d.mts +7 -5
- package/dist/middleware.d.ts +7 -5
- package/dist/{mount.d-BomEt2kV.d.mts → mount.d-DsP46XCy.d.mts} +1 -1
- package/dist/{mount.d-Ca8eb9GB.d.ts → mount.d-GU-tNxbE.d.ts} +1 -1
- package/dist/{navigation-delegate.d-B1ujRkYo.d.mts → navigation-delegate.d-CUtNOYLi.d.mts} +1 -1
- package/dist/{navigation-delegate.d-DJCC2jXF.d.ts → navigation-delegate.d-DsxNPrLT.d.ts} +1 -1
- package/dist/navigation.d.mts +10 -8
- package/dist/navigation.d.ts +10 -8
- package/dist/{plugin-FD4S2QEJ.mjs → plugin-2KWR2X4B.mjs} +1 -1
- package/dist/{plugin-5BNPYCER.cjs → plugin-MW7IDV76.cjs} +2 -2
- package/dist/plugin.cjs +15 -14
- package/dist/plugin.d.mts +11 -8
- package/dist/plugin.d.ts +11 -8
- package/dist/plugin.mjs +14 -13
- package/dist/{render-plan.d-BxRbaxYA.d.ts → render-plan.d-8K6S0h0L.d.ts} +1 -1
- package/dist/{render-plan.d-CFod_Zf-.d.mts → render-plan.d-B7Xp-PPW.d.mts} +1 -1
- package/dist/renderer-client.d.mts +10 -8
- package/dist/renderer-client.d.ts +10 -8
- package/dist/{request.d-DRQgaXGG.d.ts → request.d-CuQxmOqX.d.ts} +1 -1
- package/dist/{request.d-DG4TeXMM.d.mts → request.d-nhqciCAz.d.mts} +1 -1
- package/dist/request.d.mts +8 -6
- package/dist/request.d.ts +8 -6
- package/dist/{route-rendering.d-Db07UNVG.d.ts → route-rendering.d-BSsdDYC1.d.ts} +1 -1
- package/dist/{route-rendering.d-BXtZKgqu.d.mts → route-rendering.d-CeF1FOnl.d.mts} +1 -1
- package/dist/{router.d-BC3hyjf0.d.ts → router.d-C7yGlhDL.d.ts} +1 -1
- package/dist/{router.d-B61kXqxJ.d.mts → router.d-D462OX24.d.mts} +1 -1
- package/dist/routes.d.mts +7 -5
- package/dist/routes.d.ts +7 -5
- package/dist/{rsc-pipeline-VENBFYXW.cjs → rsc-pipeline-7PV6ARDS.cjs} +8 -7
- package/dist/{rsc-pipeline-LJ7YCGY6.mjs → rsc-pipeline-EZU4W4RL.mjs} +7 -6
- package/dist/{runtime-UNDTYGQS.cjs → runtime-QOE3NRXF.cjs} +8 -7
- package/dist/{runtime-4DWUXZHS.mjs → runtime-RWLFEPS3.mjs} +5 -4
- package/dist/{runtime.d-Cl6EBGmC.d.mts → runtime.d-C-BHQMy5.d.mts} +1 -1
- package/dist/{runtime.d-SC95yDzr.d.ts → runtime.d-CORDJQMy.d.ts} +1 -1
- package/dist/{schema.d-Dny9pnrm.d.mts → schema.d-BM-uVGpx.d.mts} +1 -1
- package/dist/{schema.d-Dny9pnrm.d.ts → schema.d-BM-uVGpx.d.ts} +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/{index.d-r1MLpgeE.d.ts → server-components-status.d-BJ6huueH.d.mts} +2 -15
- package/dist/{index.d-Ccq42CPU.d.mts → server-components-status.d-BbADqqjq.d.ts} +2 -15
- package/dist/server-plugins.cjs +2 -2
- package/dist/server-plugins.d.mts +9 -7
- package/dist/server-plugins.d.ts +9 -7
- package/dist/server-plugins.mjs +1 -1
- package/dist/server.cjs +46 -39
- package/dist/server.d.mts +17 -14
- package/dist/server.d.ts +17 -14
- package/dist/server.mjs +24 -17
- package/dist/session-OU7M4CIF.cjs +24 -0
- package/dist/{session-QZXZOPR2.mjs → session-WPAT6H76.mjs} +3 -2
- package/dist/{spa-router.d-DrlXgDqY.d.mts → spa-router.d-DfjafHyX.d.mts} +4 -4
- package/dist/{spa-router.d-DwM02Mwd.d.ts → spa-router.d-DyGJLQc_.d.ts} +4 -4
- package/dist/ssg.d-D11lz_wr.d.ts +138 -0
- package/dist/ssg.d-iiLTyLAO.d.mts +138 -0
- package/dist/storage.cjs +9 -2
- package/dist/storage.d.mts +266 -34
- package/dist/storage.d.ts +266 -34
- package/dist/storage.mjs +8 -1
- package/dist/testing.d.mts +7 -5
- package/dist/testing.d.ts +7 -5
- package/dist/types.d-DC97bnjj.d.mts +131 -0
- package/dist/types.d-DC97bnjj.d.ts +131 -0
- package/dist/{utils.d-C6KXz3uB.d.ts → utils.d-D-GQeEfa.d.ts} +1 -1
- package/dist/{utils.d-CHzxAshz.d.mts → utils.d-fW-95yEh.d.mts} +1 -1
- package/dist/version.cjs +2 -2
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +15 -14
- package/dist/vite.d.mts +12 -9
- package/dist/vite.d.ts +12 -9
- package/dist/vite.mjs +14 -13
- package/package.json +11 -4
- package/dist/analyzer-23GCBYFI.cjs +0 -16
- package/dist/chunk-JMYXO572.cjs +0 -531
- package/dist/layers-7P4RLKVX.cjs +0 -20
- package/dist/session-2Q72D4QV.cjs +0 -23
- package/dist/types.d-BnIqOn9w.d.mts +0 -73
- package/dist/types.d-BnIqOn9w.d.ts +0 -73
- /package/dist/{chunk-6DBBMQWT.cjs → chunk-AF3PNVVF.cjs} +0 -0
- /package/dist/{chunk-5O3SK3ZC.mjs → chunk-BEXH6BGH.mjs} +0 -0
- /package/dist/{chunk-PMU4U2W2.cjs → chunk-PC5OZ4YR.cjs} +0 -0
- /package/dist/{chunk-Z5ZZAGIH.mjs → chunk-RL47VZ6J.mjs} +0 -0
|
@@ -1,3 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isMountSchema
|
|
3
|
+
} from "./chunk-DS2KZ5BT.mjs";
|
|
4
|
+
|
|
5
|
+
// src/storage/managed-sqlite.ts
|
|
6
|
+
function managedSqliteName(mount, managed) {
|
|
7
|
+
const name = managed === true ? mount : managed && typeof managed === "object" && "name" in managed ? managed.name : void 0;
|
|
8
|
+
if (typeof name !== "string" || !/^[a-z][a-z0-9-]{0,62}$/.test(name))
|
|
9
|
+
throw new TypeError(
|
|
10
|
+
"Use a managed SQLite name of 1\u201363 lowercase letters, digits, or hyphens starting with a letter."
|
|
11
|
+
);
|
|
12
|
+
return name;
|
|
13
|
+
}
|
|
14
|
+
function secureUrl(value) {
|
|
15
|
+
const url = new URL(value);
|
|
16
|
+
const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
17
|
+
if (!(url.protocol === "https:" || local && url.protocol === "http:") || url.username || url.password || url.search || url.hash)
|
|
18
|
+
throw new Error("Use HTTPS or a loopback URL for Farm managed SQLite.");
|
|
19
|
+
return url;
|
|
20
|
+
}
|
|
21
|
+
async function requestSqliteResource(name, operation) {
|
|
22
|
+
const key = process.env.FARMJS_API_KEY;
|
|
23
|
+
if (!key) throw new Error("Set FARMJS_API_KEY on the server to access managed SQLite.");
|
|
24
|
+
const base = secureUrl(process.env.FARMJS_API_URL || "https://app.farmjs.dev");
|
|
25
|
+
const headers = new Headers({
|
|
26
|
+
authorization: "Bearer " + key,
|
|
27
|
+
"content-type": "application/json"
|
|
28
|
+
});
|
|
29
|
+
if (process.env.FARMJS_PROJECT_ID) headers.set("x-farm-project", process.env.FARMJS_PROJECT_ID);
|
|
30
|
+
const environment = process.env.FARMJS_ENVIRONMENT;
|
|
31
|
+
if (environment)
|
|
32
|
+
headers.set("x-farm-environment", environment === "preview" ? "staging" : environment);
|
|
33
|
+
const response = await fetch(new URL("/api/storage/sqlite/" + operation, base), {
|
|
34
|
+
method: operation === "token" ? "POST" : "PUT",
|
|
35
|
+
headers,
|
|
36
|
+
body: JSON.stringify({ name }),
|
|
37
|
+
redirect: "error",
|
|
38
|
+
signal: AbortSignal.timeout(15e3)
|
|
39
|
+
});
|
|
40
|
+
const result = await response.json();
|
|
41
|
+
if (!response.ok)
|
|
42
|
+
throw new Error(
|
|
43
|
+
typeof result?.message === "string" ? result.message : "Farm SQLite request failed (HTTP " + response.status + ")."
|
|
44
|
+
);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
async function credential(name) {
|
|
48
|
+
const result = await requestSqliteResource(name, "token");
|
|
49
|
+
if (!result || typeof result.url !== "string" || typeof result.token !== "string" || !result.token || !Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now())
|
|
50
|
+
throw new Error("Farm returned an invalid SQLite credential. Check the Infra service.");
|
|
51
|
+
return {
|
|
52
|
+
url: secureUrl(result.url).href,
|
|
53
|
+
token: result.token,
|
|
54
|
+
expires: Date.parse(result.expiresAt)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function connect(name, loadClient) {
|
|
58
|
+
const [{ createClient }, initial] = await Promise.all([loadClient(), credential(name)]);
|
|
59
|
+
let current = initial;
|
|
60
|
+
let refreshing;
|
|
61
|
+
return createClient({
|
|
62
|
+
url: current.url,
|
|
63
|
+
fetch: async (request) => {
|
|
64
|
+
if (new URL(request.url).origin !== new URL(initial.url).origin)
|
|
65
|
+
throw new Error("The database endpoint changed. Reconnect the managed SQLite mount.");
|
|
66
|
+
if (current.expires - Date.now() < 3e4) {
|
|
67
|
+
refreshing ?? (refreshing = credential(name).finally(() => {
|
|
68
|
+
refreshing = void 0;
|
|
69
|
+
}));
|
|
70
|
+
const renewed = await refreshing;
|
|
71
|
+
if (renewed.url !== initial.url)
|
|
72
|
+
throw new Error("The SQLite resource changed. Reconnect the mount.");
|
|
73
|
+
current = renewed;
|
|
74
|
+
}
|
|
75
|
+
const headers = new Headers(request.headers);
|
|
76
|
+
headers.set("authorization", "Bearer " + current.token);
|
|
77
|
+
return fetch(request, { headers, redirect: "error" });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
var databaseAccessor = /* @__PURE__ */ Symbol.for("farmjs.storage.managedDatabase");
|
|
82
|
+
var mountSchema = /* @__PURE__ */ Symbol.for("farmjs.storage.managedSchema");
|
|
83
|
+
function managedSqliteDriver(name, loadClient, schema) {
|
|
84
|
+
let pending;
|
|
85
|
+
let initialized;
|
|
86
|
+
let closed = false;
|
|
87
|
+
function client() {
|
|
88
|
+
if (closed) throw new Error("The managed SQLite mount has been disposed.");
|
|
89
|
+
return pending ?? (pending = connect(name, loadClient).catch((error) => {
|
|
90
|
+
pending = void 0;
|
|
91
|
+
throw error;
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
function kv() {
|
|
95
|
+
return initialized ?? (initialized = client().then(async (db) => {
|
|
96
|
+
await db.execute(
|
|
97
|
+
"CREATE TABLE IF NOT EXISTS _farm_kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)"
|
|
98
|
+
);
|
|
99
|
+
return db;
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
initialized = void 0;
|
|
102
|
+
throw error;
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
name: "farm-managed-sqlite",
|
|
107
|
+
[databaseAccessor]: client,
|
|
108
|
+
[mountSchema]: schema,
|
|
109
|
+
async hasItem(key) {
|
|
110
|
+
return (await (await kv()).execute({ sql: "SELECT 1 FROM _farm_kv WHERE key=?", args: [key] })).rows.length > 0;
|
|
111
|
+
},
|
|
112
|
+
async getItem(key) {
|
|
113
|
+
const { rows } = await (await kv()).execute({ sql: "SELECT value FROM _farm_kv WHERE key=?", args: [key] });
|
|
114
|
+
return rows[0]?.value ?? null;
|
|
115
|
+
},
|
|
116
|
+
async getKeys(base = "") {
|
|
117
|
+
const { rows } = await (await kv()).execute({
|
|
118
|
+
sql: "SELECT key FROM _farm_kv WHERE instr(key,?)=1 ORDER BY key",
|
|
119
|
+
args: [base]
|
|
120
|
+
});
|
|
121
|
+
return rows.map((row) => String(row.key));
|
|
122
|
+
},
|
|
123
|
+
async setItem(key, value) {
|
|
124
|
+
await (await kv()).execute({
|
|
125
|
+
sql: "INSERT INTO _farm_kv(key,value) VALUES (?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value",
|
|
126
|
+
args: [key, value]
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
async removeItem(key) {
|
|
130
|
+
await (await kv()).execute({ sql: "DELETE FROM _farm_kv WHERE key=?", args: [key] });
|
|
131
|
+
},
|
|
132
|
+
async clear(base = "") {
|
|
133
|
+
await (await kv()).execute({ sql: "DELETE FROM _farm_kv WHERE instr(key,?)=1", args: [base] });
|
|
134
|
+
},
|
|
135
|
+
async dispose() {
|
|
136
|
+
closed = true;
|
|
137
|
+
(await pending)?.close();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function sqlAdapter(client, tx) {
|
|
142
|
+
return {
|
|
143
|
+
dialect: "sqlite",
|
|
144
|
+
async query(sql, params) {
|
|
145
|
+
const result = await (tx ?? client).execute({ sql, args: params });
|
|
146
|
+
return {
|
|
147
|
+
rows: result.rows,
|
|
148
|
+
affectedRows: result.rowsAffected,
|
|
149
|
+
insertId: result.lastInsertRowid
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
async transaction(run) {
|
|
153
|
+
if (tx) throw new Error("Nested managed SQLite transactions are unsupported.");
|
|
154
|
+
const transaction = await client.transaction("write");
|
|
155
|
+
try {
|
|
156
|
+
const value = await run(sqlAdapter(client, transaction));
|
|
157
|
+
await transaction.commit();
|
|
158
|
+
return value;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (!transaction.closed) await transaction.rollback();
|
|
161
|
+
throw error;
|
|
162
|
+
} finally {
|
|
163
|
+
transaction.close();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async function managedOrm(client, schema) {
|
|
169
|
+
const [{ createOrm }, { createSqlDriverFromAdapter }] = await Promise.all([
|
|
170
|
+
import("@farming-labs/orm"),
|
|
171
|
+
import("@farming-labs/orm-sql")
|
|
172
|
+
]);
|
|
173
|
+
return createOrm({ schema, driver: createSqlDriverFromAdapter(sqlAdapter(client)) });
|
|
174
|
+
}
|
|
175
|
+
|
|
1
176
|
// src/storage/index.ts
|
|
2
177
|
import { createStorage, prefixStorage, builtinDrivers } from "unstorage";
|
|
3
178
|
import memoryDriver from "unstorage/drivers/memory";
|
|
@@ -118,6 +293,7 @@ function extractDriverOptions(config) {
|
|
|
118
293
|
client: _client,
|
|
119
294
|
driver: _driver,
|
|
120
295
|
mounts: _mounts,
|
|
296
|
+
managed: _managed,
|
|
121
297
|
options,
|
|
122
298
|
tableName: _tableName,
|
|
123
299
|
...inlineOptions
|
|
@@ -159,10 +335,19 @@ async function loadDatabaseDriver(config) {
|
|
|
159
335
|
}
|
|
160
336
|
};
|
|
161
337
|
}
|
|
162
|
-
async function resolveDriver(config) {
|
|
338
|
+
async function resolveDriver(config, mount) {
|
|
163
339
|
if (config && isStorageClient(config)) {
|
|
164
340
|
return config.resolveDriver();
|
|
165
341
|
}
|
|
342
|
+
const hosted = resolveManagedStorageMount(config);
|
|
343
|
+
if (hosted) {
|
|
344
|
+
if (!mount) throw new TypeError("Register managed SQLite in storage.mounts.");
|
|
345
|
+
return managedSqliteDriver(
|
|
346
|
+
managedSqliteName(mount, hosted.managed),
|
|
347
|
+
() => loadModule("@libsql/client/http"),
|
|
348
|
+
hosted.schema
|
|
349
|
+
);
|
|
350
|
+
}
|
|
166
351
|
const driverInput = config?.driver ?? "memory";
|
|
167
352
|
if (typeof driverInput === "function") {
|
|
168
353
|
return await driverInput();
|
|
@@ -245,12 +430,17 @@ function createStorageClientFromResolver(resolveDriver2, modules = []) {
|
|
|
245
430
|
function defineStorageClient(resolveDriver2) {
|
|
246
431
|
return createStorageClientFromResolver(resolveDriver2);
|
|
247
432
|
}
|
|
248
|
-
function
|
|
433
|
+
function configuredStorageClient(config) {
|
|
434
|
+
const hosted = resolveManagedStorageMount(config);
|
|
435
|
+
if (hosted) return hosted;
|
|
249
436
|
return createStorageClientFromResolver(
|
|
250
437
|
() => resolveDriver(config),
|
|
251
438
|
_collectFarmStorageModules(config)
|
|
252
439
|
);
|
|
253
440
|
}
|
|
441
|
+
function createStorageClient(config) {
|
|
442
|
+
return configuredStorageClient(config);
|
|
443
|
+
}
|
|
254
444
|
function driverStorage(driver) {
|
|
255
445
|
return defineStorageClient(() => typeof driver === "function" ? driver() : driver);
|
|
256
446
|
}
|
|
@@ -264,99 +454,81 @@ function databaseStorage(database, options = {}) {
|
|
|
264
454
|
return driver;
|
|
265
455
|
}, ["unstorage/drivers/db0"]);
|
|
266
456
|
}
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return createStorageClient({
|
|
272
|
-
driver: "local",
|
|
273
|
-
...options
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
function sqliteStorage(options) {
|
|
277
|
-
return createStorageClient({
|
|
278
|
-
driver: "sqlite",
|
|
279
|
-
...options
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
function mysqlStorage(options) {
|
|
283
|
-
return createStorageClient({
|
|
284
|
-
driver: "mysql",
|
|
285
|
-
...options
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
function mysql2Storage(options) {
|
|
289
|
-
return mysqlStorage(options);
|
|
290
|
-
}
|
|
291
|
-
function postgresStorage(options) {
|
|
292
|
-
return createStorageClient({
|
|
293
|
-
driver: "postgres",
|
|
294
|
-
...options
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
function pgStorage(options) {
|
|
298
|
-
return postgresStorage(options);
|
|
299
|
-
}
|
|
300
|
-
function pgliteStorage(options) {
|
|
301
|
-
return createStorageClient({
|
|
302
|
-
driver: "pglite",
|
|
303
|
-
...options
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
function planetscaleStorage(options) {
|
|
307
|
-
return createStorageClient({
|
|
308
|
-
driver: "planetscale",
|
|
309
|
-
...options
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
function libsqlStorage(options) {
|
|
313
|
-
return createStorageClient({
|
|
314
|
-
driver: "libsql",
|
|
315
|
-
...options
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
function redisStorage(options) {
|
|
319
|
-
return createStorageClient({
|
|
320
|
-
driver: "redis",
|
|
321
|
-
...options
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
function s3Storage(options) {
|
|
325
|
-
return createStorageClient({
|
|
326
|
-
driver: "s3",
|
|
327
|
-
...options
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
function mongodbStorage(options) {
|
|
331
|
-
return createStorageClient({
|
|
332
|
-
driver: "mongodb",
|
|
333
|
-
...options
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
function upstashStorage(options) {
|
|
337
|
-
return createStorageClient({
|
|
338
|
-
driver: "upstash",
|
|
339
|
-
...options
|
|
340
|
-
});
|
|
457
|
+
function assertMountSchema(schema) {
|
|
458
|
+
if (schema !== void 0 && !isMountSchema(schema)) {
|
|
459
|
+
throw new TypeError("Pass a schema created with defineSchema() from @farming-labs/orm.");
|
|
460
|
+
}
|
|
341
461
|
}
|
|
342
|
-
function
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
462
|
+
function farmStorage(options = {}) {
|
|
463
|
+
if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((key) => key !== "namespace" && key !== "managed" && key !== "schema"))
|
|
464
|
+
throw new TypeError(
|
|
465
|
+
"Use farmStorage() or pass only the `managed`, `namespace`, and `schema` options."
|
|
466
|
+
);
|
|
467
|
+
if (options.managed !== void 0 && options.managed !== true)
|
|
468
|
+
throw new TypeError("Set `managed` to true or omit it when using farmStorage().");
|
|
469
|
+
const managed = options.namespace === void 0 ? true : { name: options.namespace };
|
|
470
|
+
if (managed !== true) managedSqliteName("", managed);
|
|
471
|
+
assertMountSchema(options.schema);
|
|
472
|
+
return {
|
|
473
|
+
driver: "farm-managed-sqlite",
|
|
474
|
+
managed,
|
|
475
|
+
...options.schema && { schema: options.schema }
|
|
476
|
+
};
|
|
347
477
|
}
|
|
348
|
-
function
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
478
|
+
function resolveManagedStorageMount(config) {
|
|
479
|
+
if (!config || typeof config !== "object") return;
|
|
480
|
+
if ("schema" in config && isMountSchema(config.schema) && (!("managed" in config) || !config.managed)) {
|
|
481
|
+
throw new TypeError(
|
|
482
|
+
"Set `managed: true` or use farmStorage({ schema }) to bind an ORM schema."
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
if (!("managed" in config)) {
|
|
486
|
+
if ("driver" in config && config.driver === "farm-managed-sqlite")
|
|
487
|
+
throw new TypeError("Set `managed` to true on a hosted storage mount.");
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const { driver, managed, ...options } = config;
|
|
491
|
+
if ((managed === false || managed === void 0) && driver !== "farm-managed-sqlite") return;
|
|
492
|
+
if (typeof driver !== "string" || !(driver === "farm-managed-sqlite" || driver === "local" || driver === "vercel-kv" || Object.prototype.hasOwnProperty.call(DATABASE_CONNECTORS, driver) || driver !== "db0" && Object.prototype.hasOwnProperty.call(builtinDrivers, driver)))
|
|
493
|
+
throw new TypeError("Select a built-in storage driver to use `managed: true`.");
|
|
494
|
+
if (Object.keys(options).some((key) => key !== "namespace" && key !== "schema"))
|
|
495
|
+
throw new TypeError(
|
|
496
|
+
"Remove provider connection settings and driver options when using `managed: true`."
|
|
497
|
+
);
|
|
498
|
+
assertMountSchema(options.schema);
|
|
499
|
+
if (managed === true)
|
|
500
|
+
return farmStorage({
|
|
501
|
+
namespace: options.namespace,
|
|
502
|
+
schema: options.schema
|
|
503
|
+
});
|
|
504
|
+
if ((driver === "sqlite" || driver === "farm-managed-sqlite") && !("namespace" in options)) {
|
|
505
|
+
return farmStorage({ namespace: managedSqliteName("", managed), schema: options.schema });
|
|
506
|
+
}
|
|
507
|
+
throw new TypeError("Set `managed` to true and use `namespace` to select a hosted resource.");
|
|
353
508
|
}
|
|
354
|
-
function
|
|
355
|
-
|
|
356
|
-
driver
|
|
357
|
-
|
|
358
|
-
|
|
509
|
+
function providerStorage(driver) {
|
|
510
|
+
function storage(options) {
|
|
511
|
+
return configuredStorageClient({ ...options, driver });
|
|
512
|
+
}
|
|
513
|
+
return storage;
|
|
359
514
|
}
|
|
515
|
+
var memoryStorage = providerStorage("memory");
|
|
516
|
+
var localStorage = providerStorage("local");
|
|
517
|
+
var sqliteStorage = providerStorage("sqlite");
|
|
518
|
+
var mysqlStorage = providerStorage("mysql");
|
|
519
|
+
var mysql2Storage = mysqlStorage;
|
|
520
|
+
var postgresStorage = providerStorage("postgres");
|
|
521
|
+
var pgStorage = postgresStorage;
|
|
522
|
+
var pgliteStorage = providerStorage("pglite");
|
|
523
|
+
var planetscaleStorage = providerStorage("planetscale");
|
|
524
|
+
var libsqlStorage = providerStorage("libsql");
|
|
525
|
+
var redisStorage = providerStorage("redis");
|
|
526
|
+
var s3Storage = providerStorage("s3");
|
|
527
|
+
var mongodbStorage = providerStorage("mongodb");
|
|
528
|
+
var upstashStorage = providerStorage("upstash");
|
|
529
|
+
var netlifyBlobsStorage = providerStorage("netlify-blobs");
|
|
530
|
+
var vercelKVStorage = providerStorage("vercel-kv");
|
|
531
|
+
var vercelBlobStorage = providerStorage("vercel-blob");
|
|
360
532
|
function collectDriverModules(config, modules) {
|
|
361
533
|
if (!config || typeof config !== "object") return;
|
|
362
534
|
if (isStorageClient(config)) {
|
|
@@ -368,7 +540,9 @@ function collectDriverModules(config, modules) {
|
|
|
368
540
|
const source = config;
|
|
369
541
|
const driver = source.driver;
|
|
370
542
|
if (typeof driver === "string") {
|
|
371
|
-
if (
|
|
543
|
+
if (resolveManagedStorageMount(config)) {
|
|
544
|
+
modules.add("@libsql/client/http");
|
|
545
|
+
} else if (isDatabaseDriverName(driver)) {
|
|
372
546
|
modules.add("db0");
|
|
373
547
|
modules.add(DATABASE_CONNECTORS[driver].module);
|
|
374
548
|
modules.add("unstorage/drivers/db0");
|
|
@@ -392,7 +566,7 @@ async function mountNamespaces(storage, mounts) {
|
|
|
392
566
|
return;
|
|
393
567
|
}
|
|
394
568
|
for (const [base, config] of Object.entries(mounts)) {
|
|
395
|
-
storage.mount(normalizeMountKey(base), await resolveDriver(config));
|
|
569
|
+
storage.mount(normalizeMountKey(base), await resolveDriver(config, base));
|
|
396
570
|
}
|
|
397
571
|
}
|
|
398
572
|
async function createFarmStorage(config = {}) {
|
|
@@ -436,6 +610,19 @@ async function initStorage(config = {}) {
|
|
|
436
610
|
}
|
|
437
611
|
return globalStorage;
|
|
438
612
|
}
|
|
613
|
+
async function getDatabase(name, options) {
|
|
614
|
+
const key = normalizeMountKey(name);
|
|
615
|
+
const mount = getActiveGlobalStorage().getMount(key);
|
|
616
|
+
const driver = mount.driver;
|
|
617
|
+
if (!key || normalizeMountKey(mount.base) !== key || !driver[databaseAccessor])
|
|
618
|
+
throw new TypeError(
|
|
619
|
+
"Configure a managed SQLite mount named " + JSON.stringify(name) + " before calling getDatabase()."
|
|
620
|
+
);
|
|
621
|
+
const client = await driver[databaseAccessor]();
|
|
622
|
+
if (options && "raw" in options) return client;
|
|
623
|
+
const schema = options?.schema ?? driver[mountSchema];
|
|
624
|
+
return schema ? managedOrm(client, schema) : client;
|
|
625
|
+
}
|
|
439
626
|
function getStorage(namespace) {
|
|
440
627
|
globalStorage = getActiveGlobalStorage();
|
|
441
628
|
const base = normalizeMountKey(namespace);
|
|
@@ -500,11 +687,15 @@ async function disposeStorage() {
|
|
|
500
687
|
}
|
|
501
688
|
|
|
502
689
|
export {
|
|
690
|
+
managedSqliteName,
|
|
691
|
+
requestSqliteResource,
|
|
503
692
|
_registerFarmStorageModules,
|
|
504
693
|
defineStorageClient,
|
|
505
694
|
createStorageClient,
|
|
506
695
|
driverStorage,
|
|
507
696
|
databaseStorage,
|
|
697
|
+
farmStorage,
|
|
698
|
+
resolveManagedStorageMount,
|
|
508
699
|
memoryStorage,
|
|
509
700
|
localStorage,
|
|
510
701
|
sqliteStorage,
|
|
@@ -526,6 +717,7 @@ export {
|
|
|
526
717
|
createFarmStorage,
|
|
527
718
|
resolveStorageRuntimeClient,
|
|
528
719
|
initStorage,
|
|
720
|
+
getDatabase,
|
|
529
721
|
getStorage,
|
|
530
722
|
disposeStorage
|
|
531
723
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/storage/mount-schema.ts
|
|
2
|
+
function isMountSchema(value) {
|
|
3
|
+
return !!value && typeof value === "object" && "_tag" in value && value._tag === "schema" && "models" in value && !!value.models && typeof value.models === "object" && !Array.isArray(value.models);
|
|
4
|
+
}
|
|
5
|
+
function isManagedMount(value) {
|
|
6
|
+
return !!value && typeof value === "object" && "managed" in value && !!value.managed;
|
|
7
|
+
}
|
|
8
|
+
function hasManagedMountSchema(value) {
|
|
9
|
+
return isManagedMount(value) && "schema" in value && isMountSchema(value.schema);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
isMountSchema,
|
|
14
|
+
isManagedMount,
|
|
15
|
+
hasManagedMountSchema
|
|
16
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLTDMJD2Fcjs = require('./chunk-LTDMJD2F.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -329,7 +329,7 @@ function requestEvent(metadata, method, status, durationMs) {
|
|
|
329
329
|
id: uuid(),
|
|
330
330
|
requestId: metadata.id,
|
|
331
331
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
332
|
-
route: routeTemplate(
|
|
332
|
+
route: routeTemplate(_chunkLTDMJD2Fcjs.getFarmRouteLabel.call(void 0, metadata.route)),
|
|
333
333
|
...metadata.path ? { path: metadata.path } : {},
|
|
334
334
|
agent: metadata.agent,
|
|
335
335
|
kind: "request",
|
|
@@ -343,7 +343,7 @@ function toolEvent(metadata, event) {
|
|
|
343
343
|
id: uuid(),
|
|
344
344
|
requestId: metadata.id,
|
|
345
345
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
346
|
-
route: routeTemplate(
|
|
346
|
+
route: routeTemplate(_chunkLTDMJD2Fcjs.getFarmRouteLabel.call(void 0, metadata.route)),
|
|
347
347
|
...metadata.path ? { path: metadata.path } : {},
|
|
348
348
|
agent: metadata.agent,
|
|
349
349
|
kind: "mcp.tool",
|
|
@@ -18,7 +18,7 @@ var _chunk6D3CJFNUcjs = require('./chunk-6D3CJFNU.cjs');
|
|
|
18
18
|
var _chunkNDOE76QCcjs = require('./chunk-NDOE76QC.cjs');
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkYROK6CJCcjs = require('./chunk-YROK6CJC.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -593,7 +593,7 @@ async function resolveAPIContext(options) {
|
|
|
593
593
|
config: options.config,
|
|
594
594
|
configPath: options.configPath
|
|
595
595
|
}));
|
|
596
|
-
const docs = isResolvedDocsConfig(docsInput) ? docsInput : await
|
|
596
|
+
const docs = isResolvedDocsConfig(docsInput) ? docsInput : await _chunkYROK6CJCcjs.resolveDocsConfig.call(void 0, docsInput, { root, srcDir });
|
|
597
597
|
const guardedPaths = new Set(_nullishCoalesce(_optionalChain([runtimeConfig, 'optionalAccess', _28 => _28.guardedPaths]), () => ( [])));
|
|
598
598
|
return {
|
|
599
599
|
root,
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/plugins/compression.ts
|
|
6
6
|
import { pipeline, Readable } from "stream";
|
|
7
|
+
import { promisify } from "util";
|
|
7
8
|
import { brotliCompress, constants, createBrotliCompress, createGzip, gzip } from "zlib";
|
|
8
9
|
var Q_VALUE = /^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/;
|
|
9
10
|
function parseEncodingQuality(header) {
|
|
@@ -28,10 +29,10 @@ function selectEncoding(header) {
|
|
|
28
29
|
const qualities = parseEncodingQuality(header);
|
|
29
30
|
const wildcard = qualities.get("*") ?? 0;
|
|
30
31
|
const quality = (encoding) => qualities.get(encoding) ?? wildcard;
|
|
31
|
-
const
|
|
32
|
+
const brotli2 = quality("br");
|
|
32
33
|
const gzip2 = quality("gzip");
|
|
33
|
-
if (
|
|
34
|
-
return
|
|
34
|
+
if (brotli2 <= 0 && gzip2 <= 0) return void 0;
|
|
35
|
+
return brotli2 >= gzip2 ? "br" : "gzip";
|
|
35
36
|
}
|
|
36
37
|
var COMPRESSIBLE_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
37
38
|
"application/javascript",
|
|
@@ -86,32 +87,40 @@ function compressedHeaders(response, encoding) {
|
|
|
86
87
|
}
|
|
87
88
|
return headers;
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
+
var compressedShells = /* @__PURE__ */ new WeakMap();
|
|
91
|
+
var brotli = promisify(brotliCompress);
|
|
92
|
+
var gzipBuffer = promisify(gzip);
|
|
93
|
+
function encodeText(text, encoding) {
|
|
94
|
+
const input = Buffer.from(text);
|
|
95
|
+
return encoding === "br" ? brotli(input, { params: { [constants.BROTLI_PARAM_QUALITY]: BROTLI_QUALITY } }) : gzipBuffer(input);
|
|
96
|
+
}
|
|
97
|
+
function getEncodedShell(shell, encoding) {
|
|
98
|
+
let entry = compressedShells.get(shell);
|
|
99
|
+
if (entry?.html !== shell.html) {
|
|
100
|
+
entry = { html: shell.html };
|
|
101
|
+
compressedShells.set(shell, entry);
|
|
102
|
+
}
|
|
103
|
+
const variants = entry;
|
|
104
|
+
return variants[encoding] ?? (variants[encoding] = encodeText(shell.html, encoding).catch((error) => {
|
|
105
|
+
delete variants[encoding];
|
|
106
|
+
throw error;
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
function compressBufferedResponse(response, text, encoding, lazyBody, shell) {
|
|
90
110
|
const headers = compressedHeaders(response, encoding);
|
|
91
111
|
if (!lazyBody) response.body?.cancel().catch(() => {
|
|
92
112
|
});
|
|
93
|
-
const
|
|
113
|
+
const reuse = shell && shell.html === text;
|
|
114
|
+
const bytes = reuse ? getEncodedShell(shell, encoding) : encodeText(text, encoding);
|
|
94
115
|
let cancelled = false;
|
|
95
116
|
const body = new ReadableStream({
|
|
96
|
-
start(controller) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
controller.enqueue(new Uint8Array(output.buffer, output.byteOffset, output.byteLength));
|
|
104
|
-
controller.close();
|
|
105
|
-
};
|
|
106
|
-
if (encoding === "br") {
|
|
107
|
-
brotliCompress(
|
|
108
|
-
input,
|
|
109
|
-
{ params: { [constants.BROTLI_PARAM_QUALITY]: BROTLI_QUALITY } },
|
|
110
|
-
done
|
|
111
|
-
);
|
|
112
|
-
} else {
|
|
113
|
-
gzip(input, done);
|
|
114
|
-
}
|
|
117
|
+
async start(controller) {
|
|
118
|
+
const output = await bytes;
|
|
119
|
+
if (cancelled) return;
|
|
120
|
+
controller.enqueue(
|
|
121
|
+
reuse ? new Uint8Array(output) : new Uint8Array(output.buffer, output.byteOffset, output.byteLength)
|
|
122
|
+
);
|
|
123
|
+
controller.close();
|
|
115
124
|
},
|
|
116
125
|
cancel() {
|
|
117
126
|
cancelled = true;
|
|
@@ -141,12 +150,12 @@ function compressResponse(response, encoding) {
|
|
|
141
150
|
function varyIdentityResponse(response) {
|
|
142
151
|
return _withFarmResponseHeaders(response, (headers) => appendVary(headers, "Accept-Encoding"));
|
|
143
152
|
}
|
|
144
|
-
function compressFarmResponse(request, response, bufferedText, lazyBody = false) {
|
|
153
|
+
function compressFarmResponse(request, response, bufferedText, lazyBody = false, shell) {
|
|
145
154
|
if (!isCompressionEligible(request, response, bufferedText)) return response;
|
|
146
155
|
if (request.method === "HEAD") return varyIdentityResponse(response);
|
|
147
156
|
const encoding = selectEncoding(request.headers.get("accept-encoding") ?? "");
|
|
148
157
|
if (!encoding) return varyIdentityResponse(response);
|
|
149
|
-
return bufferedText === void 0 ? compressResponse(response, encoding) : compressBufferedResponse(response, bufferedText, encoding, lazyBody);
|
|
158
|
+
return bufferedText === void 0 ? compressResponse(response, encoding) : compressBufferedResponse(response, bufferedText, encoding, lazyBody, shell);
|
|
150
159
|
}
|
|
151
160
|
function createCompressionPlugin({
|
|
152
161
|
beforeRequest: overrideBeforeRequest,
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
formatFarmRscBlockingMessage,
|
|
5
5
|
inspectFarmServerComponents,
|
|
6
6
|
resolveFarmRscCheckConfig
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-OCKQ3YOH.mjs";
|
|
8
8
|
import {
|
|
9
9
|
createFarmDevLoopbackPlugin
|
|
10
10
|
} from "./chunk-IG2JE6WJ.mjs";
|
|
11
11
|
import {
|
|
12
12
|
resolveDeployOutputPath
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ZBE5EHVJ.mjs";
|
|
14
14
|
import {
|
|
15
15
|
farmDesktopDevGuardPlugin,
|
|
16
16
|
loadFarmReactPlugin
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
generateFarmClientPluginEntryCode,
|
|
20
20
|
hasFarmServerRuntimePlugins,
|
|
21
21
|
loadTailwindVitePlugin
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-SL2BSPDJ.mjs";
|
|
23
23
|
import {
|
|
24
24
|
resolveFarmPlatform
|
|
25
25
|
} from "./chunk-SMUW7UST.mjs";
|
|
@@ -183,7 +183,7 @@ async function resolveFarmRscServerPlugins(userConfig, config, root) {
|
|
|
183
183
|
const candidate = plugin;
|
|
184
184
|
return !!candidate && names.has(candidate.name) && hasFarmServerRuntimePlugins([candidate]);
|
|
185
185
|
};
|
|
186
|
-
const { findFarmConfigFile, loadFarmConfigFile, resolveFarmLayers } = await import("./layers-
|
|
186
|
+
const { findFarmConfigFile, loadFarmConfigFile, resolveFarmLayers } = await import("./layers-I7VE5Q2Y.mjs");
|
|
187
187
|
const files = [];
|
|
188
188
|
if (userConfig.extends) {
|
|
189
189
|
const { layers } = await resolveFarmLayers(userConfig, { root, mode: "production" });
|
|
@@ -210,7 +210,7 @@ async function resolveFarmRscServerPlugins(userConfig, config, root) {
|
|
|
210
210
|
}
|
|
211
211
|
async function configureFarmRscPlugins(config, command) {
|
|
212
212
|
if (config.plugins.length === 0) return config;
|
|
213
|
-
const { PluginManager } = await import("./plugin-
|
|
213
|
+
const { PluginManager } = await import("./plugin-2KWR2X4B.mjs");
|
|
214
214
|
const manager = new PluginManager({
|
|
215
215
|
config,
|
|
216
216
|
isDev: command === "serve",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveIntegrationOrmRuntimeClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WXMR3OHY.mjs";
|
|
4
4
|
import {
|
|
5
5
|
collectSchemaModels,
|
|
6
6
|
columnTypeFamily,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
} from "./chunk-UTUS6JUH.mjs";
|
|
26
26
|
import {
|
|
27
27
|
getIntegrationSchemas
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-BEXH6BGH.mjs";
|
|
29
29
|
import {
|
|
30
30
|
resolveSchemaModels
|
|
31
31
|
} from "./chunk-F3N52U7S.mjs";
|