@farm.js/core 0.2.0 → 0.2.2
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-xPua9Zdz.d.ts → agent-mcp.d-DuZjglYX.d.ts} +1 -1
- package/dist/{agent-mcp.d-DhZf5-v0.d.mts → agent-mcp.d-gI3ahrF6.d.mts} +1 -1
- package/dist/agent-runtime.d.mts +4 -4
- package/dist/agent-runtime.d.ts +4 -4
- package/dist/analyzer-ENHO4SA5.cjs +17 -0
- package/dist/{analyzer-LQ4LVDCW.mjs → analyzer-UXWYUTBK.mjs} +2 -2
- package/dist/api/node.d.mts +6 -6
- package/dist/api/node.d.ts +6 -6
- package/dist/api/route-manager.cjs +3 -3
- package/dist/api/route-manager.d.mts +6 -6
- package/dist/api/route-manager.d.ts +6 -6
- package/dist/api/route-manager.mjs +2 -2
- package/dist/api/runtime.d.mts +5 -5
- package/dist/api/runtime.d.ts +5 -5
- package/dist/api.cjs +4 -4
- package/dist/api.d.mts +7 -7
- package/dist/api.d.ts +7 -7
- package/dist/api.mjs +3 -3
- package/dist/{app-manifest.d-D6l1Wkn6.d.ts → app-manifest.d-B3h89j6a.d.ts} +1 -1
- package/dist/{app-manifest.d-Bq9VWtpk.d.mts → app-manifest.d-bHK9EGPI.d.mts} +1 -1
- package/dist/app-markdown.d.mts +5 -5
- package/dist/app-markdown.d.ts +5 -5
- package/dist/{app.d-gnTrW72o.d.ts → app.d-C3uyET_L.d.ts} +4 -4
- package/dist/{app.d-Bn1bqBkf.d.mts → app.d-Cr7fXGvJ.d.mts} +4 -4
- package/dist/{chunk-MUQP2APN.cjs → chunk-2T4GGCQT.cjs} +2 -2
- package/dist/{chunk-VFZQXADS.cjs → chunk-56F4CDKE.cjs} +139 -137
- package/dist/{chunk-O47IT4CS.cjs → chunk-5AOARZJT.cjs} +4 -4
- package/dist/{chunk-YQXLBYY2.cjs → chunk-5B2Y4EVS.cjs} +32 -8
- package/dist/{chunk-JKNQMGZE.cjs → chunk-5CG2UD6B.cjs} +12 -12
- package/dist/{chunk-QCVP22KW.cjs → chunk-5RYBQKBY.cjs} +3 -3
- package/dist/{chunk-MEIZIRMK.mjs → chunk-6VMBLDWY.mjs} +1 -1
- package/dist/{chunk-DVL3UVYT.mjs → chunk-6XABTMXR.mjs} +2 -2
- package/dist/chunk-7QGA6UX6.cjs +26 -0
- package/dist/{chunk-Z7YIQ7AJ.cjs → chunk-A4AYTO2E.cjs} +1 -1
- package/dist/{chunk-V36K4TSU.mjs → chunk-ADKPJZPP.mjs} +1 -1
- package/dist/{chunk-ZVEKOMZS.mjs → chunk-ALGAGXWB.mjs} +1 -1
- package/dist/{chunk-2LHO4HTP.cjs → chunk-B7CZ7T2I.cjs} +2 -2
- package/dist/{chunk-VWPGK6UV.cjs → chunk-BEAQVRMQ.cjs} +58 -58
- package/dist/{chunk-WOPQQCP3.mjs → chunk-CPL7WIMP.mjs} +1 -1
- package/dist/{chunk-RMLXUVR5.cjs → chunk-CS6GXE42.cjs} +91 -21
- package/dist/{chunk-MLMDOIBY.mjs → chunk-CZMMU3FP.mjs} +2 -2
- package/dist/{chunk-ZTNU4XCC.cjs → chunk-D2VLHRBN.cjs} +3 -3
- package/dist/{chunk-4ER5KYSC.cjs → chunk-FDS6U2NT.cjs} +3 -3
- package/dist/{chunk-54INSSWI.mjs → chunk-FEWGKBMM.mjs} +32 -19
- package/dist/chunk-G7LNCHTS.mjs +21 -0
- package/dist/{chunk-FFROR7QD.mjs → chunk-GKDOKES3.mjs} +1 -1
- package/dist/{chunk-T4VF6BYV.cjs → chunk-GL4SPJTE.cjs} +2 -2
- package/dist/{chunk-ZF7N222A.mjs → chunk-IEXZMDF4.mjs} +2 -2
- package/dist/{chunk-SIHHYNX4.mjs → chunk-JCERO6YF.mjs} +1 -1
- package/dist/{chunk-LGL5QKUJ.cjs → chunk-JM5VSEYC.cjs} +2 -2
- package/dist/{chunk-MZG5M4JS.cjs → chunk-L7Z6OAE2.cjs} +4 -4
- package/dist/{chunk-RDT2LJES.mjs → chunk-MEXGQE4T.mjs} +6 -6
- package/dist/{chunk-KKXGBQ2K.mjs → chunk-MYJPW4XN.mjs} +2 -2
- package/dist/{chunk-GK2RCRT2.mjs → chunk-NPR6SCEV.mjs} +1 -1
- package/dist/chunk-O77EKGAS.mjs +36 -0
- package/dist/{chunk-GAD63TH7.mjs → chunk-Q4CPBKPT.mjs} +4 -4
- package/dist/{chunk-DNERKYN4.cjs → chunk-Q4FHYBFT.cjs} +11 -11
- package/dist/{chunk-ZCT6B5PQ.cjs → chunk-SJQ24IB5.cjs} +6 -6
- package/dist/{chunk-HYYOVRED.mjs → chunk-SPVXL37B.mjs} +1 -1
- package/dist/{chunk-D7KBMJ7L.mjs → chunk-ST3U7XVO.mjs} +1 -1
- package/dist/{chunk-MX4G24YS.mjs → chunk-TK2JJCP5.mjs} +17 -15
- package/dist/{chunk-LO5BNR6Y.mjs → chunk-W5T3ZAFU.mjs} +25 -1
- package/dist/{chunk-ADCVSTFV.cjs → chunk-WAQIO2VD.cjs} +2 -2
- package/dist/{chunk-KJW6KEOZ.mjs → chunk-WRT775N6.mjs} +92 -22
- package/dist/{chunk-MNBFSAWF.cjs → chunk-YCGOQKVC.cjs} +20 -1
- package/dist/{chunk-J6JAUJPC.cjs → chunk-ZND5D4IC.cjs} +163 -150
- package/dist/{chunk-PATIHHC7.cjs → chunk-ZQOHL6TX.cjs} +2 -2
- package/dist/{chunk-RP55BUJM.mjs → chunk-ZVT2F3JU.mjs} +1 -1
- package/dist/{client-component.d-DT5OKBZu.d.ts → client-component.d-BavTzqsn.d.ts} +1 -1
- package/dist/{client-component.d-34DDMZcl.d.mts → client-component.d-X3j9FOZ2.d.mts} +1 -1
- package/dist/{client-plugins.d-D9CnUvZ5.d.ts → client-plugins.d-CqTr5IrQ.d.ts} +64 -4
- package/dist/{client-plugins.d-D7k9t9Ge.d.mts → client-plugins.d-DnnAopKG.d.mts} +64 -4
- package/dist/client-plugins.d.mts +4 -4
- package/dist/client-plugins.d.ts +4 -4
- package/dist/client.d.mts +10 -10
- package/dist/client.d.ts +10 -10
- package/dist/config.d.mts +4 -4
- package/dist/config.d.ts +4 -4
- package/dist/desktop.cjs +5 -1
- package/dist/desktop.d.mts +11 -7
- package/dist/desktop.d.ts +11 -7
- package/dist/desktop.mjs +4 -0
- package/dist/{dev-guard-M3ZCDWCK.cjs → dev-guard-5NUIX6IZ.cjs} +4 -3
- package/dist/{dev-guard-TFVWJNIB.mjs → dev-guard-L42ZZRCZ.mjs} +2 -1
- package/dist/{devtools-IUU4SWQL.cjs → devtools-4LMM3DDJ.cjs} +2 -2
- package/dist/{devtools-R77KAJA4.mjs → devtools-RFVGDHXH.mjs} +1 -1
- package/dist/docs.cjs +3 -3
- package/dist/docs.d.mts +6 -6
- package/dist/docs.d.ts +6 -6
- package/dist/docs.mjs +2 -2
- package/dist/environment/vite.cjs +3 -3
- package/dist/environment/vite.d.mts +1 -1
- package/dist/environment/vite.d.ts +1 -1
- package/dist/environment/vite.mjs +2 -2
- package/dist/{generate-route-types.d-BFOMM8Ef.d.mts → generate-route-types.d-CAiRw4N0.d.mts} +1 -1
- package/dist/{generate-route-types.d-C2m8myHb.d.ts → generate-route-types.d-Dz8MOQ3u.d.ts} +1 -1
- package/dist/{handler.d-fxTjv3Nn.d.mts → handler.d-BSlpYCDB.d.mts} +2 -2
- package/dist/{handler.d-DbZvbwNi.d.ts → handler.d-DgX7gPO6.d.ts} +2 -2
- package/dist/{headers.d-OBHpGTF_.d.mts → headers.d-Cf8l5LMo.d.mts} +1 -1
- package/dist/{headers.d-oeWybIk8.d.ts → headers.d-CmxW42R2.d.ts} +1 -1
- package/dist/index.cjs +25 -24
- package/dist/{index.d-CRrPQwlO.d.mts → index.d-7xoJqKRZ.d.mts} +1 -1
- package/dist/{index.d-BM-dKdzH.d.ts → index.d-BZZt7kxO.d.ts} +1 -1
- package/dist/index.d.mts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.mjs +20 -19
- package/dist/integrations/orm.d.mts +4 -4
- package/dist/integrations/orm.d.ts +4 -4
- package/dist/integrations.d.mts +4 -4
- package/dist/integrations.d.ts +4 -4
- package/dist/internal/app-markdown-runtime.d.mts +5 -5
- package/dist/internal/app-markdown-runtime.d.ts +5 -5
- package/dist/internal/build-runtime.cjs +21 -20
- package/dist/internal/build-runtime.d.mts +7 -7
- package/dist/internal/build-runtime.d.ts +7 -7
- package/dist/internal/build-runtime.mjs +20 -19
- package/dist/internal/cli-runtime.cjs +8 -5
- package/dist/internal/cli-runtime.d.mts +20 -12
- package/dist/internal/cli-runtime.d.ts +20 -12
- package/dist/internal/cli-runtime.mjs +7 -4
- 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 +8 -8
- package/dist/internal/client-runtime.d.ts +8 -8
- package/dist/internal/compression-runtime.d.mts +4 -4
- package/dist/internal/compression-runtime.d.ts +4 -4
- package/dist/internal/config-runtime.cjs +5 -4
- package/dist/internal/config-runtime.d.mts +8 -8
- package/dist/internal/config-runtime.d.ts +8 -8
- package/dist/internal/config-runtime.mjs +4 -3
- 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 +4 -4
- package/dist/internal/production-runtime.d.mts +13 -13
- package/dist/internal/production-runtime.d.ts +13 -13
- package/dist/internal/production-runtime.mjs +3 -3
- package/dist/internal/spa-router.d.mts +6 -6
- package/dist/internal/spa-router.d.ts +6 -6
- package/dist/internal/start-manifest.d.mts +4 -4
- package/dist/internal/start-manifest.d.ts +4 -4
- package/dist/{layers.d-CH0bC4QL.d.ts → layers.d-dNBkiNE9.d.mts} +1 -1
- package/dist/{layers.d-CH0bC4QL.d.mts → layers.d-dNBkiNE9.d.ts} +1 -1
- package/dist/{manager-STAB5TVZ.cjs → manager-YRIENS63.cjs} +4 -4
- package/dist/{manager-EFPBRS3U.mjs → manager-YTJOAHII.mjs} +3 -3
- package/dist/markdown.d.mts +4 -4
- package/dist/markdown.d.ts +4 -4
- package/dist/middleware.d.mts +4 -4
- package/dist/middleware.d.ts +4 -4
- package/dist/mobile.d.mts +4 -4
- package/dist/mobile.d.ts +4 -4
- package/dist/{mount.d-TnD-Mebk.d.ts → mount.d-CD-xVBu7.d.ts} +1 -1
- package/dist/{mount.d-B7RiwjiO.d.mts → mount.d-Dd0xeRMl.d.mts} +1 -1
- package/dist/{navigation-delegate.d-VBCF0EeN.d.ts → navigation-delegate.d-Bses_F-y.d.ts} +1 -1
- package/dist/{navigation-delegate.d-Boz2511c.d.mts → navigation-delegate.d-dBNg976E.d.mts} +1 -1
- package/dist/navigation.d.mts +7 -7
- package/dist/navigation.d.ts +7 -7
- package/dist/plugin.cjs +16 -15
- package/dist/plugin.d.mts +8 -8
- package/dist/plugin.d.ts +8 -8
- package/dist/plugin.mjs +15 -14
- package/dist/{render-plan.d-BrumV_ZE.d.ts → render-plan.d-DaIwnRK2.d.ts} +1 -1
- package/dist/{render-plan.d-BwnmyfNk.d.mts → render-plan.d-vOdZHHLI.d.mts} +1 -1
- package/dist/renderer-client.d.mts +8 -8
- package/dist/renderer-client.d.ts +8 -8
- package/dist/{request.d-Dd5nRTO5.d.mts → request.d-B8U4pVFP.d.mts} +1 -1
- package/dist/{request.d-NUi01-5e.d.ts → request.d-CgXp3EEc.d.ts} +1 -1
- package/dist/request.d.mts +5 -5
- package/dist/request.d.ts +5 -5
- package/dist/{route-rendering.d-BK0Pf7_k.d.mts → route-rendering.d-BQvNYQqu.d.mts} +1 -1
- package/dist/{route-rendering.d-CJR5BPXV.d.ts → route-rendering.d-Di0AxFix.d.ts} +1 -1
- package/dist/{router.d-C-JSFCPU.d.ts → router.d-BJVGhSAJ.d.ts} +1 -1
- package/dist/{router.d-CNUS3x1j.d.mts → router.d-hNedVdoB.d.mts} +1 -1
- package/dist/{routes.d-D7RWvfqL.d.ts → routes.d-CYe98R_8.d.ts} +1 -1
- package/dist/{routes.d-BWvpUoYu.d.mts → routes.d-DBGnKaUQ.d.mts} +1 -1
- package/dist/routes.d.mts +4 -4
- package/dist/routes.d.ts +4 -4
- package/dist/{rsc-pipeline-UBWVU3NF.cjs → rsc-pipeline-HT4G3QGT.cjs} +7 -6
- package/dist/{rsc-pipeline-DHISDFT7.mjs → rsc-pipeline-NCJ3NIE5.mjs} +6 -5
- package/dist/{runtime-XKRQW3YT.cjs → runtime-6UF5XKUP.cjs} +4 -4
- package/dist/{runtime-VUKMY44G.mjs → runtime-VHXIEXL7.mjs} +2 -2
- package/dist/{runtime.d-B2T4bM5_.d.ts → runtime.d-0R8nHCM6.d.ts} +1 -1
- package/dist/{runtime.d-CsOpO6yQ.d.mts → runtime.d-DpeuF_T-.d.mts} +1 -1
- package/dist/{cli-runtime.d-LwIb0swO.d.mts → schema-dependencies.d-_Wyey4Wv.d.mts} +21 -13
- package/dist/{cli-runtime.d-Vvxf-Z8a.d.ts → schema-dependencies.d-tkUHREqz.d.ts} +21 -13
- package/dist/{schema.d-BM-uVGpx.d.mts → schema.d-HlGSe1on.d.mts} +1 -1
- package/dist/{schema.d-BM-uVGpx.d.ts → schema.d-HlGSe1on.d.ts} +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/{server-components-status.d-DOYt4E_Q.d.ts → server-components-status.d-B2Z5WvO5.d.ts} +2 -2
- package/dist/{server-components-status.d-Cc5rir0l.d.mts → server-components-status.d-sN7ju-ie.d.mts} +2 -2
- package/dist/server-plugins.d.mts +6 -6
- package/dist/server-plugins.d.ts +6 -6
- package/dist/server.cjs +43 -42
- package/dist/server.d.mts +14 -14
- package/dist/server.d.ts +14 -14
- package/dist/server.mjs +17 -16
- package/dist/{spa-router.d-Cq5UFJvq.d.mts → spa-router.d-D3AtR2Bc.d.mts} +2 -2
- package/dist/{spa-router.d-C7FcpLxU.d.ts → spa-router.d-MjT6sGb9.d.ts} +2 -2
- package/dist/{ssg.d-BzNZemk7.d.mts → ssg.d-B32Cp_XW.d.mts} +3 -3
- package/dist/{ssg.d-DUhacIxj.d.ts → ssg.d-C1SNuPz5.d.ts} +3 -3
- package/dist/storage.d.mts +2 -2
- package/dist/storage.d.ts +2 -2
- package/dist/{store-core.d-BX3yXrxA.d.ts → store-core.d-BZ3YXs70.d.ts} +2 -2
- package/dist/{store-core.d-DbUAtSBK.d.mts → store-core.d-BbVdaoA0.d.mts} +2 -2
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.mts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.mjs +2 -2
- package/dist/{types.d-C5hlNbHa.d.mts → types.d-CRiwa0jj.d.mts} +1 -1
- package/dist/{types.d-C5hlNbHa.d.ts → types.d-CRiwa0jj.d.ts} +1 -1
- package/dist/{utils.d-BhJJEXzo.d.ts → utils.d-Bjbm44fP.d.ts} +1 -1
- package/dist/{utils.d-NOMkLFpC.d.mts → utils.d-CoLozp7-.d.mts} +1 -1
- package/dist/version.cjs +2 -2
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +16 -15
- package/dist/vite.d.mts +9 -9
- package/dist/vite.d.ts +9 -9
- package/dist/vite.mjs +15 -14
- package/package.json +1 -1
- package/dist/analyzer-ZFC2L6NZ.cjs +0 -17
- package/dist/chunk-OZAVCLXY.mjs +0 -17
- /package/dist/{chunk-OAAVIFOJ.cjs → chunk-COXMHCIV.cjs} +0 -0
- /package/dist/{chunk-ZRTBDHO2.mjs → chunk-JL2HNLMC.mjs} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/api/route-files.ts
|
|
2
|
+
function hasPolyroutePlugin(plugins) {
|
|
3
|
+
return plugins?.some((plugin) => plugin.name === "polyroute") === true;
|
|
4
|
+
}
|
|
5
|
+
async function hasPolyroutePluginOption(option) {
|
|
6
|
+
const value = await option;
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
for (const entry of value) {
|
|
9
|
+
if (await hasPolyroutePluginOption(entry)) return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return typeof value === "object" && value !== null && value.name === "polyroute";
|
|
14
|
+
}
|
|
15
|
+
function isPolyrouteRouteFileName(fileName) {
|
|
16
|
+
return fileName === "route.rs" || fileName === "route.go" || fileName === "route.py";
|
|
17
|
+
}
|
|
18
|
+
function getPolyrouteRouteDeclarationFileName(routeFileName) {
|
|
19
|
+
return routeFileName.replace(/^route\./, "route.d.") + ".ts";
|
|
20
|
+
}
|
|
21
|
+
function isPolyrouteRouteDeclarationFileName(fileName) {
|
|
22
|
+
return fileName === "route.d.rs.ts" || fileName === "route.d.go.ts" || fileName === "route.d.py.ts";
|
|
23
|
+
}
|
|
24
|
+
function isFarmAPIRouteFileName(fileName, polyroute = false) {
|
|
25
|
+
if (polyroute && isPolyrouteRouteFileName(fileName)) return true;
|
|
26
|
+
return /^route\.(?:ts|tsx|js|jsx)$/.test(fileName);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
hasPolyroutePlugin,
|
|
31
|
+
hasPolyroutePluginOption,
|
|
32
|
+
isPolyrouteRouteFileName,
|
|
33
|
+
getPolyrouteRouteDeclarationFileName,
|
|
34
|
+
isPolyrouteRouteDeclarationFileName,
|
|
35
|
+
isFarmAPIRouteFileName
|
|
36
|
+
};
|
|
@@ -3,19 +3,19 @@ import {
|
|
|
3
3
|
} from "./chunk-RLEAVG6G.mjs";
|
|
4
4
|
import {
|
|
5
5
|
resolveDeployOutputPath
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JL2HNLMC.mjs";
|
|
7
7
|
import {
|
|
8
8
|
farmDesktopDevGuardPlugin,
|
|
9
9
|
loadFarmReactPlugin
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-6XABTMXR.mjs";
|
|
11
11
|
import {
|
|
12
12
|
generateFarmClientPluginEntryCode,
|
|
13
13
|
hasFarmServerRuntimePlugins,
|
|
14
14
|
loadTailwindVitePlugin
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-ADKPJZPP.mjs";
|
|
16
16
|
import {
|
|
17
17
|
resolveFarmPlatform
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-W5T3ZAFU.mjs";
|
|
19
19
|
import {
|
|
20
20
|
FARM_RSC_INSTALL_HINT,
|
|
21
21
|
findFarmAppPackageDir,
|
|
@@ -9,14 +9,14 @@ var _chunkIVEV44O2cjs = require('./chunk-IVEV44O2.cjs');
|
|
|
9
9
|
var _chunkKSRWTQ6Jcjs = require('./chunk-KSRWTQ6J.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkD2VLHRBNcjs = require('./chunk-D2VLHRBN.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
var _chunkPRKFECGTcjs = require('./chunk-PRKFECGT.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunkYCGOQKVCcjs = require('./chunk-YCGOQKVC.cjs');
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
@@ -156,7 +156,7 @@ function farmApiPlugin(options = {}) {
|
|
|
156
156
|
const existing = apiRoutesCache.get(routePath);
|
|
157
157
|
const existingFile = _optionalChain([endpointSources, 'access', _4 => _4.get, 'call', _5 => _5(routePath), 'optionalAccess', _6 => _6.get, 'call', _7 => _7(normalizedMethod)]);
|
|
158
158
|
if (existingFile) {
|
|
159
|
-
throw new (0,
|
|
159
|
+
throw new (0, _chunkD2VLHRBNcjs.APIRouteConflictError)(routePath, normalizedMethod, existingFile, filePath);
|
|
160
160
|
}
|
|
161
161
|
if (existing) {
|
|
162
162
|
if (!existing.methods.includes(normalizedMethod)) {
|
|
@@ -284,7 +284,7 @@ function farmApiPlugin(options = {}) {
|
|
|
284
284
|
name: "@farm.js/core:api",
|
|
285
285
|
enforce: "pre",
|
|
286
286
|
configureServer(server) {
|
|
287
|
-
const polyroute =
|
|
287
|
+
const polyroute = _chunkYCGOQKVCcjs.hasPolyroutePlugin.call(void 0, server.config.plugins);
|
|
288
288
|
projectRoot = server.config.root;
|
|
289
289
|
devServer = server;
|
|
290
290
|
const discoverFileRoutes = async (apiDir) => {
|
|
@@ -302,7 +302,7 @@ function farmApiPlugin(options = {}) {
|
|
|
302
302
|
const fullPath = path.join(dir, entry.name);
|
|
303
303
|
if (entry.isDirectory()) {
|
|
304
304
|
files.push(...findRouteFiles(fullPath));
|
|
305
|
-
} else if (
|
|
305
|
+
} else if (_chunkYCGOQKVCcjs.isFarmAPIRouteFileName.call(void 0, entry.name, polyroute)) {
|
|
306
306
|
files.push(fullPath);
|
|
307
307
|
}
|
|
308
308
|
}
|
|
@@ -332,7 +332,7 @@ function farmApiPlugin(options = {}) {
|
|
|
332
332
|
log(`API route discovered: ${availableMethods.join(", ")} ${routePath}`);
|
|
333
333
|
}
|
|
334
334
|
} catch (e) {
|
|
335
|
-
if (e instanceof
|
|
335
|
+
if (e instanceof _chunkD2VLHRBNcjs.APIRouteConflictError || e instanceof _chunkT4YCWRCJcjs.AmbiguousRouteError) throw e;
|
|
336
336
|
log(`API route load failed at ${filePath}: ${e.message}`);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
@@ -359,7 +359,7 @@ function farmApiPlugin(options = {}) {
|
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
} catch (e) {
|
|
362
|
-
if (e instanceof
|
|
362
|
+
if (e instanceof _chunkD2VLHRBNcjs.APIRouteConflictError || e instanceof _chunkT4YCWRCJcjs.AmbiguousRouteError) throw e;
|
|
363
363
|
log(`Root routes.ts load failed: ${e.message}`);
|
|
364
364
|
}
|
|
365
365
|
break;
|
|
@@ -390,7 +390,7 @@ function farmApiPlugin(options = {}) {
|
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
} catch (e) {
|
|
393
|
-
if (e instanceof
|
|
393
|
+
if (e instanceof _chunkD2VLHRBNcjs.APIRouteConflictError || e instanceof _chunkT4YCWRCJcjs.AmbiguousRouteError) throw e;
|
|
394
394
|
log(`Programmatic routes file load failed at ${routeFile}: ${e.message}`);
|
|
395
395
|
}
|
|
396
396
|
}
|
|
@@ -615,12 +615,12 @@ function farmApiPlugin(options = {}) {
|
|
|
615
615
|
log(`API router recreated`);
|
|
616
616
|
} catch (e) {
|
|
617
617
|
restoreRouteState(previousState);
|
|
618
|
-
if (e instanceof
|
|
618
|
+
if (e instanceof _chunkD2VLHRBNcjs.APIRouteConflictError || e instanceof _chunkT4YCWRCJcjs.AmbiguousRouteError) throw e;
|
|
619
619
|
log(`Root routes.ts HMR failed: ${e.message}`);
|
|
620
620
|
}
|
|
621
621
|
return [];
|
|
622
622
|
}
|
|
623
|
-
if (normalizedFile.includes("/api/") &&
|
|
623
|
+
if (normalizedFile.includes("/api/") && _chunkYCGOQKVCcjs.isFarmAPIRouteFileName.call(void 0, fileName, _chunkYCGOQKVCcjs.hasPolyroutePlugin.call(void 0, server.config.plugins))) {
|
|
624
624
|
const shortPath = normalizedFile.split("/api/")[1] || normalizedFile;
|
|
625
625
|
log(`API route updated: ${shortPath}`);
|
|
626
626
|
for (const mod of modules) {
|
|
@@ -653,7 +653,7 @@ function farmApiPlugin(options = {}) {
|
|
|
653
653
|
log(`API router recreated`);
|
|
654
654
|
} catch (e) {
|
|
655
655
|
restoreRouteState(previousState);
|
|
656
|
-
if (e instanceof
|
|
656
|
+
if (e instanceof _chunkD2VLHRBNcjs.APIRouteConflictError || e instanceof _chunkT4YCWRCJcjs.AmbiguousRouteError) throw e;
|
|
657
657
|
log(`API route HMR failed: ${e.message}`);
|
|
658
658
|
}
|
|
659
659
|
return [];
|
|
@@ -31,7 +31,7 @@ var _chunkPYPHM7AScjs = require('./chunk-PYPHM7AS.cjs');
|
|
|
31
31
|
var _chunk7ZDLE77Pcjs = require('./chunk-7ZDLE77P.cjs');
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
var
|
|
34
|
+
var _chunkA4AYTO2Ecjs = require('./chunk-A4AYTO2E.cjs');
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
var _chunkUGL4BDNBcjs = require('./chunk-UGL4BDNB.cjs');
|
|
@@ -980,7 +980,7 @@ function usePackageScanCacheFile(file) {
|
|
|
980
980
|
const stored = /* @__PURE__ */ new Map();
|
|
981
981
|
try {
|
|
982
982
|
const value = JSON.parse(_fs2.default.readFileSync(file, "utf8"));
|
|
983
|
-
if (_optionalChain([value, 'optionalAccess', _68 => _68.schema]) === PACKAGE_SCAN_CACHE_SCHEMA && value.farm ===
|
|
983
|
+
if (_optionalChain([value, 'optionalAccess', _68 => _68.schema]) === PACKAGE_SCAN_CACHE_SCHEMA && value.farm === _chunkA4AYTO2Ecjs.FARM_VERSION && value.scans && typeof value.scans === "object") {
|
|
984
984
|
for (const [directory, scan] of Object.entries(value.scans)) {
|
|
985
985
|
if (isStoredPackageScan(scan)) stored.set(directory, scan);
|
|
986
986
|
}
|
|
@@ -1009,7 +1009,7 @@ function persistPackageScanCache() {
|
|
|
1009
1009
|
_fs2.default.mkdirSync(_path2.default.dirname(cache2.file), { recursive: true });
|
|
1010
1010
|
_fs2.default.writeFileSync(
|
|
1011
1011
|
temporary,
|
|
1012
|
-
JSON.stringify({ schema: PACKAGE_SCAN_CACHE_SCHEMA, farm:
|
|
1012
|
+
JSON.stringify({ schema: PACKAGE_SCAN_CACHE_SCHEMA, farm: _chunkA4AYTO2Ecjs.FARM_VERSION, scans })
|
|
1013
1013
|
);
|
|
1014
1014
|
_fs2.default.renameSync(temporary, cache2.file);
|
|
1015
1015
|
cache2.dirty = false;
|
|
@@ -2322,7 +2322,7 @@ var PackageClientBoundaryCache = class {
|
|
|
2322
2322
|
}
|
|
2323
2323
|
const contents = JSON.stringify({
|
|
2324
2324
|
schema: SCHEMA_VERSION,
|
|
2325
|
-
farm:
|
|
2325
|
+
farm: _chunkA4AYTO2Ecjs.FARM_VERSION,
|
|
2326
2326
|
paths,
|
|
2327
2327
|
entries
|
|
2328
2328
|
});
|
|
@@ -2362,7 +2362,7 @@ function readStoredCache(file) {
|
|
|
2362
2362
|
} catch (e38) {
|
|
2363
2363
|
return null;
|
|
2364
2364
|
}
|
|
2365
|
-
if (!isRecord(value) || value.schema !== SCHEMA_VERSION || value.farm !==
|
|
2365
|
+
if (!isRecord(value) || value.schema !== SCHEMA_VERSION || value.farm !== _chunkA4AYTO2Ecjs.FARM_VERSION) {
|
|
2366
2366
|
return null;
|
|
2367
2367
|
}
|
|
2368
2368
|
const { paths, entries } = value;
|
|
@@ -2373,7 +2373,7 @@ function readStoredCache(file) {
|
|
|
2373
2373
|
const usable = variants.filter((entry) => isStoredEntry(entry, paths.length));
|
|
2374
2374
|
if (usable.length > 0) valid[key] = usable;
|
|
2375
2375
|
}
|
|
2376
|
-
return { schema: SCHEMA_VERSION, farm:
|
|
2376
|
+
return { schema: SCHEMA_VERSION, farm: _chunkA4AYTO2Ecjs.FARM_VERSION, paths, entries: valid };
|
|
2377
2377
|
}
|
|
2378
2378
|
function isRecord(value) {
|
|
2379
2379
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
import {
|
|
33
33
|
collectFarmNativeServerFns,
|
|
34
34
|
findFarmNativeScreenFiles
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-GKDOKES3.mjs";
|
|
36
36
|
import {
|
|
37
37
|
assertFarmDocsAdapterServesNoGuardedPages,
|
|
38
38
|
compileFarmDocsAdapterEdgeManifest,
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
listFarmDocsAdapterPages,
|
|
42
42
|
listFarmDocsAdapterRoutes,
|
|
43
43
|
listFarmDocsPagePaths
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-JCERO6YF.mjs";
|
|
45
45
|
import {
|
|
46
46
|
FARM_DOCS_LAST_MODIFIED_MANIFEST,
|
|
47
47
|
createFarmDocsHandler,
|
|
@@ -71,7 +71,7 @@ import {
|
|
|
71
71
|
getDeployTargetForPreset,
|
|
72
72
|
hasCustomFarmRouteContext,
|
|
73
73
|
resolveDeployOutputPath
|
|
74
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-JL2HNLMC.mjs";
|
|
75
75
|
import {
|
|
76
76
|
resolveFarmInstrumentationFile
|
|
77
77
|
} from "./chunk-QRNYSISP.mjs";
|
|
@@ -117,14 +117,14 @@ import {
|
|
|
117
117
|
resolveFarmNotFoundComponentPath,
|
|
118
118
|
resolveFarmRouteRootStrategy,
|
|
119
119
|
toBakedMarkdownSourcePath
|
|
120
|
-
} from "./chunk-
|
|
120
|
+
} from "./chunk-MEXGQE4T.mjs";
|
|
121
121
|
import {
|
|
122
122
|
TAILWIND_CSS_BROWSER_TARGET,
|
|
123
123
|
generateFarmClientPluginEntryCode,
|
|
124
124
|
hasFarmServerRuntimePlugins,
|
|
125
125
|
includesTailwindVitePlugin,
|
|
126
126
|
loadTailwindVitePlugin
|
|
127
|
-
} from "./chunk-
|
|
127
|
+
} from "./chunk-ADKPJZPP.mjs";
|
|
128
128
|
import {
|
|
129
129
|
PluginManager
|
|
130
130
|
} from "./chunk-6IKUYFNQ.mjs";
|
|
@@ -133,11 +133,11 @@ import {
|
|
|
133
133
|
readRouteRenderingDirectiveFromFile,
|
|
134
134
|
resolveRouteRenderingConfig,
|
|
135
135
|
resolveRouteRenderingConfigFromFile
|
|
136
|
-
} from "./chunk-
|
|
136
|
+
} from "./chunk-CZMMU3FP.mjs";
|
|
137
137
|
import {
|
|
138
138
|
FARM_PRERENDER_ENV,
|
|
139
139
|
_farmWebMCPReportsEnabled
|
|
140
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-ST3U7XVO.mjs";
|
|
141
141
|
import {
|
|
142
142
|
HOISTED_HEAD_ELEMENT,
|
|
143
143
|
appMiddlewareMayHandlePath,
|
|
@@ -165,7 +165,7 @@ import {
|
|
|
165
165
|
listFarmBuiltInRoutePaths,
|
|
166
166
|
resolveFarmApiCatalogInput,
|
|
167
167
|
resolveFarmAppManifestInput
|
|
168
|
-
} from "./chunk-
|
|
168
|
+
} from "./chunk-IEXZMDF4.mjs";
|
|
169
169
|
import {
|
|
170
170
|
FARM_DEFAULT_MCP_PATH,
|
|
171
171
|
createFarmDefaultMCPServer,
|
|
@@ -173,7 +173,7 @@ import {
|
|
|
173
173
|
} from "./chunk-WABOJXAA.mjs";
|
|
174
174
|
import {
|
|
175
175
|
isFarmPreviewDeploymentEnvironment
|
|
176
|
-
} from "./chunk-
|
|
176
|
+
} from "./chunk-NPR6SCEV.mjs";
|
|
177
177
|
import {
|
|
178
178
|
FARM_NATIVE_SERVER_FN_PLUGIN
|
|
179
179
|
} from "./chunk-L4RTTTVE.mjs";
|
|
@@ -194,7 +194,7 @@ import {
|
|
|
194
194
|
withFarmSourceSnapshot,
|
|
195
195
|
withFarmSourceSnapshotOf,
|
|
196
196
|
withPackageClientBoundaryCache
|
|
197
|
-
} from "./chunk-
|
|
197
|
+
} from "./chunk-ZVT2F3JU.mjs";
|
|
198
198
|
import {
|
|
199
199
|
generateFarmDocsAdapterClientRuntime,
|
|
200
200
|
getFarmDocsAdapterConfigModule
|
|
@@ -288,11 +288,11 @@ import {
|
|
|
288
288
|
} from "./chunk-QD34VE4N.mjs";
|
|
289
289
|
import {
|
|
290
290
|
APIRouteManager
|
|
291
|
-
} from "./chunk-
|
|
291
|
+
} from "./chunk-CPL7WIMP.mjs";
|
|
292
292
|
import {
|
|
293
293
|
hasPolyroutePlugin,
|
|
294
294
|
isPolyrouteRouteFileName
|
|
295
|
-
} from "./chunk-
|
|
295
|
+
} from "./chunk-O77EKGAS.mjs";
|
|
296
296
|
import {
|
|
297
297
|
readFarmI18nCatalogs
|
|
298
298
|
} from "./chunk-VO55MMBX.mjs";
|
|
@@ -320,7 +320,7 @@ import {
|
|
|
320
320
|
} from "./chunk-2I6PUKWJ.mjs";
|
|
321
321
|
import {
|
|
322
322
|
FARM_VERSION
|
|
323
|
-
} from "./chunk-
|
|
323
|
+
} from "./chunk-6VMBLDWY.mjs";
|
|
324
324
|
import {
|
|
325
325
|
FARM_VIDEO_PLAYER_PATH
|
|
326
326
|
} from "./chunk-23NBOP43.mjs";
|
|
@@ -7652,7 +7652,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
7652
7652
|
const appDirs = getFarmAppDirectories(config);
|
|
7653
7653
|
let openAPIReference = null;
|
|
7654
7654
|
if (config.openapi.enabled && config.openapi.route) {
|
|
7655
|
-
const { OpenAPIManager, renderOpenAPIReferenceHTML } = await import("./manager-
|
|
7655
|
+
const { OpenAPIManager, renderOpenAPIReferenceHTML } = await import("./manager-YTJOAHII.mjs");
|
|
7656
7656
|
const openAPIManager = new OpenAPIManager(appDirs, config.openapi, {
|
|
7657
7657
|
mode: "production",
|
|
7658
7658
|
apiBaseURL: config.api.baseURL,
|
|
@@ -16243,7 +16243,9 @@ async function buildWithProductionNodeEnv(inputConfig, options) {
|
|
|
16243
16243
|
suppressLintOnLink: config.suppressLintOnLink,
|
|
16244
16244
|
componentExtensions: config.renderer.componentExtensions,
|
|
16245
16245
|
renderer: config.renderer,
|
|
16246
|
-
i18nConfig: config.i18n
|
|
16246
|
+
i18nConfig: config.i18n,
|
|
16247
|
+
// Match the routes the API route manager below discovers through this server.
|
|
16248
|
+
polyroute: hasPolyroutePlugin(projectModuleServer.config.plugins)
|
|
16247
16249
|
}).catch((error) => {
|
|
16248
16250
|
const message = error instanceof Error ? error.message : String(error);
|
|
16249
16251
|
logger.warn(`Route type generation failed (farm.d.ts may be stale): ${message}`);
|
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
resolvePlatformBlock,
|
|
7
7
|
resolvePlatformProfile
|
|
8
8
|
} from "./chunk-UB7RVEMX.mjs";
|
|
9
|
+
import {
|
|
10
|
+
FARM_DESKTOP_PERMISSIONS
|
|
11
|
+
} from "./chunk-G7LNCHTS.mjs";
|
|
9
12
|
|
|
10
13
|
// src/desktop/config.ts
|
|
11
14
|
import { existsSync } from "fs";
|
|
@@ -21,8 +24,9 @@ function resolveFarmPlatform(env = process.env) {
|
|
|
21
24
|
const value = env[FARM_PLATFORM_ENV];
|
|
22
25
|
return value === "desktop" || value === "mobile" ? value : "web";
|
|
23
26
|
}
|
|
24
|
-
var DESKTOP_KEYS = /* @__PURE__ */ new Set(["name", "id", "version", "icon", "window", "shell"]);
|
|
27
|
+
var DESKTOP_KEYS = /* @__PURE__ */ new Set(["name", "id", "version", "icon", "window", "permissions", "shell"]);
|
|
25
28
|
var WINDOW_KEYS = /* @__PURE__ */ new Set(["width", "height", "title", "hideOnClose"]);
|
|
29
|
+
var PERMISSION_KEYS = new Set(FARM_DESKTOP_PERMISSIONS);
|
|
26
30
|
var APP_ID = /^[A-Za-z][A-Za-z0-9-]*(?:\.[A-Za-z0-9][A-Za-z0-9-]*)+$/;
|
|
27
31
|
var SHELL_NAME = /^[a-z][a-z0-9-]*$/;
|
|
28
32
|
var SHELL_PACKAGE = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)*$/;
|
|
@@ -70,6 +74,20 @@ function validateFarmDesktopConfig(input, context) {
|
|
|
70
74
|
fail("window.hideOnClose must be true or false.");
|
|
71
75
|
}
|
|
72
76
|
}
|
|
77
|
+
if (input.permissions !== void 0) {
|
|
78
|
+
if (!isPlainObject(input.permissions)) {
|
|
79
|
+
fail('permissions must be an object, such as { microphone: "Notes records voice memos." }.');
|
|
80
|
+
}
|
|
81
|
+
checkKeys(input.permissions, PERMISSION_KEYS, "permissions.");
|
|
82
|
+
for (const key of PERMISSION_KEYS) {
|
|
83
|
+
const value = input.permissions[key];
|
|
84
|
+
if (value !== void 0 && (typeof value !== "string" || !value.trim())) {
|
|
85
|
+
fail(
|
|
86
|
+
`permissions.${key} must be the sentence macOS shows when it asks for access, such as "Notes records voice memos.", or left out for no access.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
73
91
|
const shell = optionalString(input.shell, "shell");
|
|
74
92
|
if (shell !== void 0 && !SHELL_NAME.test(shell) && !shell.includes("/")) {
|
|
75
93
|
fail(`shell must be an adapter name such as "electrobun" or a package name, got "${shell}".`);
|
|
@@ -94,6 +112,11 @@ function resolveFarmDesktopConfig(input, root, context) {
|
|
|
94
112
|
const icon = config.icon ? path.resolve(root, config.icon.trim()) : void 0;
|
|
95
113
|
if (icon && !existsSync(icon))
|
|
96
114
|
desktopChecker(context).fail(`icon ${config.icon} was not found in ${root}.`);
|
|
115
|
+
const permissions = {};
|
|
116
|
+
for (const key of FARM_DESKTOP_PERMISSIONS) {
|
|
117
|
+
const sentence = config.permissions?.[key]?.trim();
|
|
118
|
+
if (sentence) permissions[key] = sentence;
|
|
119
|
+
}
|
|
97
120
|
return {
|
|
98
121
|
name,
|
|
99
122
|
id: config.id?.trim() || `local.farm.${slug(name)}`,
|
|
@@ -105,6 +128,7 @@ function resolveFarmDesktopConfig(input, root, context) {
|
|
|
105
128
|
title: config.window?.title?.trim() || name,
|
|
106
129
|
hideOnClose: config.window?.hideOnClose === true
|
|
107
130
|
},
|
|
131
|
+
...Object.keys(permissions).length ? { permissions } : {},
|
|
108
132
|
shell,
|
|
109
133
|
shellPackage: resolveFarmDesktopShellPackage(shell)
|
|
110
134
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _chunk5B2Y4EVScjs = require('./chunk-5B2Y4EVS.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkN4AM7Q34cjs = require('./chunk-N4AM7Q34.cjs');
|
|
@@ -62,7 +62,7 @@ function resolveFarmClientPlugins(plugins, _root) {
|
|
|
62
62
|
];
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function generateFarmClientPluginEntryCode(plugins, root, srcDir = "src", appPublicData, platform =
|
|
65
|
+
function generateFarmClientPluginEntryCode(plugins, root, srcDir = "src", appPublicData, platform = _chunk5B2Y4EVScjs.resolveFarmPlatform.call(void 0, )) {
|
|
66
66
|
const resolved = resolveFarmClientPlugins(plugins, root);
|
|
67
67
|
const appClientEntry = root ? resolveFarmAppClientEntry(root, srcDir) : void 0;
|
|
68
68
|
const appImport = appClientEntry ? `import farmAppClientDefinition from ${JSON.stringify(appClientEntry.replace(/\\/g, "/"))};` : "";
|
|
@@ -2,28 +2,59 @@ import {
|
|
|
2
2
|
writeFileIfChanged
|
|
3
3
|
} from "./chunk-YFTGIHNC.mjs";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
getPolyrouteRouteDeclarationFileName,
|
|
6
|
+
isFarmAPIRouteFileName,
|
|
7
|
+
isPolyrouteRouteFileName
|
|
8
|
+
} from "./chunk-O77EKGAS.mjs";
|
|
7
9
|
import {
|
|
8
10
|
registerAPIRouteShape
|
|
9
11
|
} from "./chunk-2LKUR5QJ.mjs";
|
|
10
12
|
|
|
11
13
|
// src/type-generator.ts
|
|
12
|
-
import { readFileSync, existsSync, readdirSync, mkdirSync } from "fs";
|
|
14
|
+
import { readFileSync, existsSync, readdirSync, mkdirSync, statSync } from "fs";
|
|
13
15
|
import { createRequire } from "module";
|
|
14
|
-
import { join, relative, dirname, extname } from "path";
|
|
16
|
+
import { basename, join, relative, dirname, extname } from "path";
|
|
15
17
|
import { initSync, parse } from "es-module-lexer";
|
|
16
18
|
var moduleLexerInitialized = false;
|
|
19
|
+
var HTTP_METHODS = ["GET", "HEAD", "QUERY", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
|
|
17
20
|
var JSX_ROUTE_LANGS = { ".jsx": "jsx", ".tsx": "tsx" };
|
|
18
|
-
var
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
+
var oxcUtils;
|
|
22
|
+
function loadOxcUtils() {
|
|
23
|
+
return oxcUtils ?? (oxcUtils = createRequire(typeof __filename === "string" ? __filename : import.meta.url)(
|
|
21
24
|
"rolldown/utils"
|
|
22
|
-
)
|
|
23
|
-
|
|
25
|
+
));
|
|
26
|
+
}
|
|
27
|
+
function transformJSXRoute(content, lang, filePath) {
|
|
28
|
+
const result = loadOxcUtils().transformSync(filePath, content, { lang, sourceType: "module" });
|
|
24
29
|
if (result.errors.length > 0) throw result.errors[0];
|
|
25
30
|
return result.code;
|
|
26
31
|
}
|
|
32
|
+
function extractDeclaredMethods(content, filePath) {
|
|
33
|
+
const { program, errors } = loadOxcUtils().parseSync(filePath, content, { lang: "dts" });
|
|
34
|
+
if (errors.length > 0) throw new Error(`${filePath}: ${errors[0].message}`);
|
|
35
|
+
const names = /* @__PURE__ */ new Set();
|
|
36
|
+
for (const statement of program.body) {
|
|
37
|
+
if (statement.type !== "ExportNamedDeclaration") continue;
|
|
38
|
+
const declaration = statement.declaration;
|
|
39
|
+
if (declaration?.type === "VariableDeclaration") {
|
|
40
|
+
for (const declarator of declaration.declarations) {
|
|
41
|
+
if (declarator.id.type === "Identifier") names.add(declarator.id.name);
|
|
42
|
+
}
|
|
43
|
+
} else if ((declaration?.type === "FunctionDeclaration" || declaration?.type === "TSDeclareFunction") && declaration.id) {
|
|
44
|
+
names.add(declaration.id.name);
|
|
45
|
+
} else if (!declaration && statement.exportKind !== "type") {
|
|
46
|
+
for (const specifier of statement.specifiers) {
|
|
47
|
+
if (specifier.exportKind === "type") continue;
|
|
48
|
+
const exported = specifier.exported;
|
|
49
|
+
names.add(exported.type === "Literal" ? String(exported.value) : exported.name);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return HTTP_METHODS.filter((method) => names.has(method));
|
|
54
|
+
}
|
|
55
|
+
function isFile(filePath) {
|
|
56
|
+
return statSync(filePath, { throwIfNoEntry: false })?.isFile() === true;
|
|
57
|
+
}
|
|
27
58
|
var API_CLIENT_METHOD_SEGMENTS = /* @__PURE__ */ new Set([
|
|
28
59
|
"get",
|
|
29
60
|
"head",
|
|
@@ -35,8 +66,9 @@ var API_CLIENT_METHOD_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
35
66
|
"options"
|
|
36
67
|
]);
|
|
37
68
|
var APITypeGenerator = class {
|
|
38
|
-
constructor(appDir) {
|
|
69
|
+
constructor(appDir, options = {}) {
|
|
39
70
|
this.appDirs = Array.isArray(appDir) ? [...appDir] : [appDir];
|
|
71
|
+
this.polyroute = options.polyroute === true;
|
|
40
72
|
}
|
|
41
73
|
/**
|
|
42
74
|
* Scan all API route files and extract route information
|
|
@@ -84,7 +116,7 @@ var APITypeGenerator = class {
|
|
|
84
116
|
if (item.isDirectory()) {
|
|
85
117
|
const newBasePath = basePath ? `${basePath}/${item.name}` : item.name;
|
|
86
118
|
this.scanDirectory(fullPath, appDir, routes, newBasePath);
|
|
87
|
-
} else if (isFarmAPIRouteFileName(item.name)) {
|
|
119
|
+
} else if (isFarmAPIRouteFileName(item.name, this.polyroute)) {
|
|
88
120
|
const routeInfo = this.extractRouteInfo(fullPath, appDir, basePath);
|
|
89
121
|
if (routeInfo) {
|
|
90
122
|
routes.push(routeInfo);
|
|
@@ -93,14 +125,44 @@ var APITypeGenerator = class {
|
|
|
93
125
|
}
|
|
94
126
|
}
|
|
95
127
|
extractRouteInfo(filePath, appDir, basePath) {
|
|
128
|
+
const relativePath = relative(appDir, filePath);
|
|
129
|
+
const apiPath = basePath ? `/api/${basePath}` : "/api";
|
|
130
|
+
const fileName = basename(filePath);
|
|
131
|
+
if (isPolyrouteRouteFileName(fileName)) {
|
|
132
|
+
const declarationPath = join(
|
|
133
|
+
dirname(filePath),
|
|
134
|
+
getPolyrouteRouteDeclarationFileName(fileName)
|
|
135
|
+
);
|
|
136
|
+
if (!isFile(declarationPath)) {
|
|
137
|
+
return { path: apiPath, methods: [...HTTP_METHODS], filePath, relativePath };
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const methods = extractDeclaredMethods(
|
|
141
|
+
readFileSync(declarationPath, "utf-8"),
|
|
142
|
+
declarationPath
|
|
143
|
+
);
|
|
144
|
+
if (methods.length === 0) return null;
|
|
145
|
+
return {
|
|
146
|
+
path: apiPath,
|
|
147
|
+
methods,
|
|
148
|
+
filePath,
|
|
149
|
+
relativePath,
|
|
150
|
+
declaration: {
|
|
151
|
+
filePath: declarationPath,
|
|
152
|
+
relativePath: relative(appDir, declarationPath)
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.warn(`Failed to read route declaration ${declarationPath}:`, error);
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
96
160
|
try {
|
|
97
161
|
const content = readFileSync(filePath, "utf-8");
|
|
98
162
|
const methods = this.extractExportedMethods(content, filePath);
|
|
99
163
|
if (methods.length === 0) {
|
|
100
164
|
return null;
|
|
101
165
|
}
|
|
102
|
-
const relativePath = relative(appDir, filePath);
|
|
103
|
-
const apiPath = basePath ? `/api/${basePath}` : "/api";
|
|
104
166
|
return {
|
|
105
167
|
path: apiPath,
|
|
106
168
|
methods,
|
|
@@ -117,7 +179,7 @@ var APITypeGenerator = class {
|
|
|
117
179
|
initSync();
|
|
118
180
|
moduleLexerInitialized = true;
|
|
119
181
|
}
|
|
120
|
-
const httpMethods =
|
|
182
|
+
const httpMethods = HTTP_METHODS;
|
|
121
183
|
const lang = JSX_ROUTE_LANGS[extname(filePath)];
|
|
122
184
|
const source = lang ? transformJSXRoute(content, lang, filePath) : content;
|
|
123
185
|
const [, exports] = parse(source);
|
|
@@ -154,9 +216,10 @@ var APITypeGenerator = class {
|
|
|
154
216
|
*/
|
|
155
217
|
generateAPIRouter(routes, options = {}) {
|
|
156
218
|
const imports = [];
|
|
219
|
+
const coreAPITypes = [];
|
|
157
220
|
const pluginTypes = [];
|
|
158
221
|
if (options.pluginConfigs?.length) {
|
|
159
|
-
|
|
222
|
+
coreAPITypes.push("PluginAPIRouter");
|
|
160
223
|
options.pluginConfigs.forEach((filePath, index) => {
|
|
161
224
|
const importPath = this.getRouteImportPath({ filePath }, options.outFile);
|
|
162
225
|
imports.push(`import type FarmPluginConfig${index} from ${JSON.stringify(importPath)};`);
|
|
@@ -197,18 +260,24 @@ var APITypeGenerator = class {
|
|
|
197
260
|
for (const method of route.methods) methodSources.set(method, route);
|
|
198
261
|
}
|
|
199
262
|
const allMethods = [...methodSources.keys()];
|
|
263
|
+
const methodTypes = /* @__PURE__ */ new Map();
|
|
200
264
|
for (const method of allMethods) {
|
|
201
|
-
const
|
|
265
|
+
const source = methodSources.get(method);
|
|
266
|
+
if (!source.declaration && isPolyrouteRouteFileName(basename(source.filePath))) {
|
|
267
|
+
if (!coreAPITypes.includes("TypedEndpoint")) coreAPITypes.push("TypedEndpoint");
|
|
268
|
+
methodTypes.set(method, "TypedEndpoint<any, any>");
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const importPath = this.getRouteImportPath(source.declaration ?? source, options.outFile);
|
|
202
272
|
const importName = `${method}_${routeName}`;
|
|
203
273
|
imports.push(
|
|
204
274
|
`import type { ${method} as ${importName} } from ${JSON.stringify(importPath)};`
|
|
205
275
|
);
|
|
276
|
+
methodTypes.set(method, `typeof ${importName}`);
|
|
206
277
|
}
|
|
207
278
|
if (parts.length === 0) {
|
|
208
279
|
for (const method of allMethods) {
|
|
209
|
-
|
|
210
|
-
const methodName = method.toLowerCase();
|
|
211
|
-
nestedStructure[methodName] = `typeof ${importName}`;
|
|
280
|
+
nestedStructure[method.toLowerCase()] = methodTypes.get(method);
|
|
212
281
|
}
|
|
213
282
|
} else {
|
|
214
283
|
const hasMethodCollision = parts.some((part, index) => {
|
|
@@ -224,9 +293,7 @@ var APITypeGenerator = class {
|
|
|
224
293
|
if (i === typePath.length - 1) {
|
|
225
294
|
current[part] = createRouteTreeNode();
|
|
226
295
|
for (const method of allMethods) {
|
|
227
|
-
|
|
228
|
-
const methodName = method.toLowerCase();
|
|
229
|
-
current[part][methodName] = `typeof ${importName}`;
|
|
296
|
+
current[part][method.toLowerCase()] = methodTypes.get(method);
|
|
230
297
|
}
|
|
231
298
|
} else {
|
|
232
299
|
if (!Object.prototype.hasOwnProperty.call(current, part)) {
|
|
@@ -263,6 +330,9 @@ ${routeManifest.map(
|
|
|
263
330
|
},`
|
|
264
331
|
).join("\n")}
|
|
265
332
|
]` : "[]";
|
|
333
|
+
if (coreAPITypes.length) {
|
|
334
|
+
imports.unshift(`import type { ${coreAPITypes.join(", ")} } from "@farm.js/core/api";`);
|
|
335
|
+
}
|
|
266
336
|
return `/**
|
|
267
337
|
* Auto-generated API router types
|
|
268
338
|
* This file is automatically generated - do not edit manually
|