@farm.js/core 0.1.17 → 0.1.19
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/after.cjs +12 -225
- package/dist/agent-runtime.cjs +83 -2800
- package/dist/api/client.cjs +17 -4060
- package/dist/api/route-manager.cjs +34 -4354
- package/dist/api/runtime.cjs +29 -2696
- package/dist/api.cjs +88 -8434
- package/dist/app-markdown.cjs +39 -280
- package/dist/app-markdown.mjs +3 -3
- package/dist/cache.cjs +38 -1560
- package/dist/chunk-22GUSVNJ.cjs +351 -0
- package/dist/{chunk-EN7WTEAY.mjs → chunk-2ANEVVF7.mjs} +1 -1
- package/dist/chunk-2CQ74SP6.cjs +13 -0
- package/dist/{chunk-YD4J4XCI.mjs → chunk-2GNATDDE.mjs} +1 -1
- package/dist/chunk-2SJ4RQ6P.cjs +57 -0
- package/dist/chunk-3376ZTRC.cjs +1 -0
- package/dist/chunk-4PNUXIVU.cjs +472 -0
- package/dist/chunk-4PPEPOZZ.cjs +21 -0
- package/dist/chunk-4ZFL5GFN.cjs +520 -0
- package/dist/chunk-5OVTOKGH.cjs +65 -0
- package/dist/chunk-5QIKR7RR.cjs +224 -0
- package/dist/chunk-5ZSWG4UX.cjs +127 -0
- package/dist/chunk-62YJ2IEB.cjs +238 -0
- package/dist/chunk-6EODJYCX.cjs +183 -0
- package/dist/chunk-6EXBPJ24.cjs +434 -0
- package/dist/chunk-6QQDAAAZ.cjs +38 -0
- package/dist/chunk-6V4TDWEC.cjs +455 -0
- package/dist/chunk-72ADZ6GQ.cjs +19 -0
- package/dist/chunk-75BRBIFP.cjs +172 -0
- package/dist/{chunk-ZCNJKLA2.mjs → chunk-7BC6GAL7.mjs} +1 -1
- package/dist/chunk-7W3CPVXS.cjs +24 -0
- package/dist/chunk-A6WIQH5Z.cjs +31 -0
- package/dist/chunk-A777V5WU.cjs +725 -0
- package/dist/chunk-AFOD3LYZ.cjs +377 -0
- package/dist/chunk-AH7HOAQ3.cjs +151 -0
- package/dist/chunk-AMDMVWMI.cjs +39 -0
- package/dist/chunk-AORPIPNB.cjs +552 -0
- package/dist/chunk-ARJWXNQL.cjs +256 -0
- package/dist/chunk-AYJR42WX.cjs +711 -0
- package/dist/chunk-BBVSJVBZ.cjs +600 -0
- package/dist/chunk-BIDYX3SL.cjs +91 -0
- package/dist/chunk-BYODCJD6.cjs +663 -0
- package/dist/chunk-C3VRMB6H.cjs +85 -0
- package/dist/chunk-C5GUTBZK.cjs +173 -0
- package/dist/chunk-CIAGU2X4.cjs +337 -0
- package/dist/chunk-CMGMGHUZ.cjs +27 -0
- package/dist/chunk-CXP5U3RW.cjs +54 -0
- package/dist/chunk-D2ULAULS.cjs +166 -0
- package/dist/chunk-D7JTOLFK.cjs +285 -0
- package/dist/chunk-DVM4FKZL.cjs +169 -0
- package/dist/chunk-DYEJQTDN.cjs +49 -0
- package/dist/chunk-E2ROOWQC.cjs +2225 -0
- package/dist/chunk-E3UK5IIB.cjs +593 -0
- package/dist/chunk-EM6SBQKM.cjs +470 -0
- package/dist/chunk-FJSWYIR7.cjs +482 -0
- package/dist/chunk-FK6GO24V.cjs +54 -0
- package/dist/{chunk-MVIWBEJF.mjs → chunk-FVZGEVTO.mjs} +7 -7
- package/dist/chunk-FXUUWYAX.cjs +654 -0
- package/dist/chunk-G3HRIVEY.cjs +395 -0
- package/dist/chunk-G643DQCH.cjs +13 -0
- package/dist/chunk-G7HXGLEC.cjs +175 -0
- package/dist/chunk-GDSHDTJ4.cjs +152 -0
- package/dist/chunk-GPVTX3HT.cjs +1415 -0
- package/dist/chunk-H6G5INWM.cjs +1094 -0
- package/dist/{chunk-DHDVMXYK.mjs → chunk-HALDNTIV.mjs} +30 -4
- package/dist/chunk-HBTUGXHS.cjs +180 -0
- package/dist/chunk-HREOKQWT.cjs +45 -0
- package/dist/{chunk-5QOEPUYE.mjs → chunk-HSDL2AUR.mjs} +1 -1
- package/dist/chunk-I4J452B7.cjs +435 -0
- package/dist/chunk-I57LW5VZ.cjs +94 -0
- package/dist/chunk-I5YBCWQ6.cjs +40 -0
- package/dist/chunk-I7PUUDGY.cjs +389 -0
- package/dist/chunk-IAMRBF3Z.cjs +86 -0
- package/dist/chunk-IQXFRNY2.cjs +169 -0
- package/dist/chunk-ISTFC3MZ.cjs +1357 -0
- package/dist/chunk-IXTFU4PL.cjs +2355 -0
- package/dist/chunk-J3LOGE4T.cjs +42 -0
- package/dist/chunk-J7FSKED3.cjs +93 -0
- package/dist/chunk-JDNHKPTD.cjs +22 -0
- package/dist/chunk-JSROZYYO.cjs +164 -0
- package/dist/chunk-K6FNHVDR.cjs +696 -0
- package/dist/chunk-KGZIORNL.cjs +43 -0
- package/dist/chunk-KR6CKSXT.cjs +15 -0
- package/dist/chunk-KROWKCUH.cjs +185 -0
- package/dist/chunk-KVFPGF2M.cjs +46 -0
- package/dist/{chunk-TNBAYAWO.mjs → chunk-L4DVIHOC.mjs} +1 -1
- package/dist/chunk-LCCBO7PJ.cjs +46 -0
- package/dist/chunk-LIUGYUX3.cjs +22 -0
- package/dist/chunk-LTNGXMQ6.cjs +55 -0
- package/dist/chunk-M2L4MYDQ.cjs +14 -0
- package/dist/chunk-MCJLA63J.cjs +1 -0
- package/dist/chunk-MKB2EGIR.cjs +148 -0
- package/dist/chunk-MQ3H6LT5.cjs +202 -0
- package/dist/chunk-MT763TDW.cjs +43 -0
- package/dist/{chunk-XWAYMDLB.mjs → chunk-MVUREHPN.mjs} +1 -1
- package/dist/chunk-MWSK6C4J.cjs +18 -0
- package/dist/chunk-MWWVKDW3.cjs +169 -0
- package/dist/{chunk-6VQIKZZO.mjs → chunk-N255VYFP.mjs} +1 -1
- package/dist/chunk-NBAHDVOJ.cjs +2040 -0
- package/dist/chunk-NO3WWW3N.cjs +192 -0
- package/dist/chunk-NSFC3LHB.cjs +10244 -0
- package/dist/chunk-NZKJGRB3.cjs +230 -0
- package/dist/chunk-OAVTUMJP.cjs +1496 -0
- package/dist/{chunk-SXHV42UQ.mjs → chunk-OFEY6KHO.mjs} +88 -13
- package/dist/chunk-OHY2ZWUG.cjs +25 -0
- package/dist/chunk-OI6CMLWX.cjs +47 -0
- package/dist/chunk-OWOUTKIJ.cjs +558 -0
- package/dist/chunk-OX6O6WVA.cjs +74 -0
- package/dist/chunk-OXSIH4D6.cjs +476 -0
- package/dist/chunk-OYDRPBBV.cjs +453 -0
- package/dist/chunk-OYEUREB6.cjs +35 -0
- package/dist/chunk-PCOTGFSM.cjs +139 -0
- package/dist/{chunk-76DG3LF3.mjs → chunk-PGQBL5DN.mjs} +1 -1
- package/dist/chunk-PZYCPSCC.cjs +35 -0
- package/dist/chunk-QBK2AA4U.cjs +445 -0
- package/dist/{chunk-UTBVHYS3.mjs → chunk-QBPKKQTD.mjs} +2 -2
- package/dist/chunk-QBPXNZGV.cjs +487 -0
- package/dist/chunk-QNPEUFHQ.cjs +27 -0
- package/dist/chunk-QZRVZSPN.cjs +236 -0
- package/dist/chunk-R5A5KNVX.cjs +20 -0
- package/dist/chunk-R5JIFR6B.cjs +42 -0
- package/dist/chunk-R6AIILII.cjs +193 -0
- package/dist/chunk-RFYO7QUD.cjs +9 -0
- package/dist/chunk-RG3ZOTG5.cjs +34 -0
- package/dist/chunk-ROUTX2E5.cjs +390 -0
- package/dist/chunk-RTHIVJ2G.cjs +54 -0
- package/dist/chunk-S27FMYAM.cjs +644 -0
- package/dist/chunk-S3A45T7F.cjs +166 -0
- package/dist/chunk-S3JO3N4H.cjs +17 -0
- package/dist/chunk-SK35NQKK.cjs +27 -0
- package/dist/chunk-SU7MH53P.cjs +180 -0
- package/dist/chunk-SVRTJOUF.cjs +113 -0
- package/dist/chunk-SWN467MP.cjs +18 -0
- package/dist/chunk-SYQ3MOWW.cjs +73 -0
- package/dist/chunk-T5CERMEH.cjs +417 -0
- package/dist/chunk-TFAXUHWX.cjs +206 -0
- package/dist/chunk-TIWHTW3Q.cjs +24 -0
- package/dist/chunk-TKJZFIML.cjs +20 -0
- package/dist/chunk-TKNSDBBN.cjs +193 -0
- package/dist/chunk-U4KT7QP3.cjs +23 -0
- package/dist/chunk-U5BMPGS3.cjs +862 -0
- package/dist/chunk-UJ2C4ICS.cjs +277 -0
- package/dist/chunk-UQZ4AYTH.cjs +168 -0
- package/dist/chunk-US2QVW3E.cjs +36 -0
- package/dist/{chunk-QGVJVSNX.mjs → chunk-V4AICMQA.mjs} +2 -2
- package/dist/chunk-VB6UCX3V.cjs +421 -0
- package/dist/chunk-VEKFLAQM.cjs +300 -0
- package/dist/chunk-VQDBNVOO.cjs +14 -0
- package/dist/chunk-W4E7WMXE.cjs +71 -0
- package/dist/chunk-WJ3HK3LJ.cjs +1102 -0
- package/dist/chunk-WMAPPDMM.cjs +28 -0
- package/dist/chunk-WMOGFOUJ.cjs +223 -0
- package/dist/chunk-WPYFSQKK.cjs +37 -0
- package/dist/{chunk-56DAX2BE.mjs → chunk-WZXN4R5Y.mjs} +24 -13
- package/dist/chunk-XDGMADQM.cjs +14225 -0
- package/dist/chunk-XGC343EY.cjs +443 -0
- package/dist/chunk-XSKZORAS.cjs +727 -0
- package/dist/chunk-XWAWFQFS.cjs +82 -0
- package/dist/chunk-Y4YMF2NQ.cjs +460 -0
- package/dist/chunk-Y4YWHNKU.cjs +250 -0
- package/dist/chunk-Y53ZSFN6.cjs +504 -0
- package/dist/chunk-YA6LLTIJ.cjs +411 -0
- package/dist/chunk-YFPGHF5F.cjs +202 -0
- package/dist/chunk-YJRZR7VU.cjs +28 -0
- package/dist/chunk-YTAABQEV.cjs +1 -0
- package/dist/chunk-YX3DBN4M.cjs +18 -0
- package/dist/chunk-YZTASLPQ.cjs +64 -0
- package/dist/chunk-Z5HIWVDP.cjs +2173 -0
- package/dist/chunk-ZEG3OPIB.cjs +93 -0
- package/dist/chunk-ZMN3H73H.cjs +155 -0
- package/dist/client/lifecycle.cjs +6 -35
- package/dist/client-plugins.cjs +7 -448
- package/dist/client.cjs +171 -9808
- package/dist/config.cjs +8 -36
- package/dist/cron.cjs +24 -491
- package/dist/deferred.cjs +26 -475
- package/dist/deployment.cjs +39 -210
- package/dist/devtools-5KGPDVKL.cjs +388 -0
- package/dist/{devtools-UFVTMQX5.mjs → devtools-FY5R7TQ4.mjs} +3 -3
- package/dist/devtools-client-4WAPJY5L.cjs +254 -0
- package/dist/devtools-ui-5GBDIGMK.cjs +1296 -0
- package/dist/docs.cjs +46 -5657
- package/dist/docs.mjs +5 -5
- package/dist/env-types.cjs +5 -226
- package/dist/env.cjs +21 -338
- package/dist/environment/vite.cjs +8 -372
- package/dist/environment.cjs +12 -94
- package/dist/font.cjs +13 -63
- package/dist/headers.cjs +7 -123
- package/dist/i18n/client.cjs +55 -294
- package/dist/i18n/index.cjs +22 -209
- package/dist/i18n/server.cjs +22 -745
- package/dist/image/server.cjs +13 -729
- package/dist/image/sharp.cjs +33 -171
- package/dist/image.cjs +41 -85
- package/dist/index.cjs +1151 -68080
- package/dist/index.mjs +14 -14
- package/dist/instrumentation.cjs +12 -138
- package/dist/integration-orm-55F7CII5.cjs +13 -0
- package/dist/integrations.cjs +55 -4090
- package/dist/internal/app-markdown-runtime.cjs +27 -224
- package/dist/internal/app-markdown-runtime.mjs +2 -2
- package/dist/internal/build-runtime.cjs +120 -52259
- package/dist/internal/build-runtime.mjs +13 -13
- package/dist/internal/cli-runtime.cjs +67 -13811
- package/dist/internal/cli-runtime.mjs +7 -7
- package/dist/internal/client-error-overlay.cjs +80 -733
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/client-runtime.cjs +81 -913
- package/dist/internal/compression-runtime.cjs +8 -214
- package/dist/internal/config-runtime.cjs +42 -6547
- package/dist/internal/config-runtime.mjs +3 -3
- package/dist/internal/docs-precompiled-runtime.cjs +26 -46
- package/dist/internal/infra-analytics-runtime.cjs +10 -536
- package/dist/internal/isolated-boundary.cjs +14 -414
- package/dist/internal/metadata-image-runtime.cjs +7 -285
- package/dist/internal/product-telemetry-runtime.cjs +42 -97
- package/dist/internal/product-telemetry-runtime.mjs +1 -1
- package/dist/internal/production-node-env.cjs +6 -63
- package/dist/internal/production-runtime.cjs +418 -7133
- package/dist/internal/production-runtime.mjs +3 -3
- package/dist/internal/request-cookies.cjs +6 -54
- package/dist/json-ld.cjs +24 -50
- package/dist/layers-E4WPJNY5.cjs +17 -0
- package/dist/manager-G4B2IPYE.cjs +14 -0
- package/dist/markdown.cjs +21 -547
- package/dist/markdown.mjs +1 -1
- package/dist/middleware.cjs +36 -2995
- package/dist/navigation.cjs +22 -2588
- package/dist/nitro-4I2MYLY2.cjs +652 -0
- package/dist/observability.cjs +22 -614
- package/dist/og.cjs +5 -28
- package/dist/plugin.cjs +106 -37442
- package/dist/plugin.mjs +9 -9
- package/dist/query/client.cjs +113 -449
- package/dist/query/index.cjs +26 -288
- package/dist/query/parsers.cjs +23 -247
- package/dist/query/server.cjs +36 -298
- package/dist/renderer/react/client.cjs +9 -43
- package/dist/renderer/react/server.cjs +40 -103
- package/dist/renderer/react/vite.cjs +7 -29
- package/dist/renderer-client.cjs +126 -4295
- package/dist/renderer.cjs +31 -249
- package/dist/request.cjs +5 -68
- package/dist/router.cjs +11 -474
- package/dist/routes.cjs +42 -2461
- package/dist/{schema-dev-notice-2IE2F2XI.mjs → schema-dev-notice-O67CPXJ6.mjs} +1 -1
- package/dist/schema-dev-notice-Y7MQEFGN.cjs +56 -0
- package/dist/schema.cjs +6 -33
- package/dist/search-client-G3RICOFU.cjs +13 -0
- package/dist/server-action-security.cjs +25 -541
- package/dist/server-fn-client.cjs +6 -337
- package/dist/server-fn.cjs +32 -1841
- package/dist/server-plugins.cjs +15 -884
- package/dist/server-query-client.cjs +15 -1883
- package/dist/server-query.cjs +16 -1838
- package/dist/server.cjs +296 -44681
- package/dist/server.mjs +11 -11
- package/dist/storage.cjs +57 -576
- package/dist/testing.cjs +89 -3186
- package/dist/theme/client.cjs +13 -108
- package/dist/theme/index.cjs +6 -68
- package/dist/theme/runtime.cjs +13 -78
- package/dist/theme/server.cjs +10 -179
- package/dist/version.cjs +4 -32
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +119 -37773
- package/dist/vite.mjs +9 -9
- package/dist/workflows.cjs +19 -1040
- package/package.json +1 -1
package/dist/routes.cjs
CHANGED
|
@@ -1,2472 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
20
2
|
|
|
21
|
-
// src/routes.ts
|
|
22
|
-
var routes_exports = {};
|
|
23
|
-
__export(routes_exports, {
|
|
24
|
-
PROGRAMMATIC_ROUTE_FILE_NAMES: () => PROGRAMMATIC_ROUTE_FILE_NAMES,
|
|
25
|
-
api: () => api,
|
|
26
|
-
createLayoutModuleFromProgrammaticLayout: () => createLayoutModuleFromProgrammaticLayout,
|
|
27
|
-
createProgrammaticRouteModuleId: () => createProgrammaticRouteModuleId,
|
|
28
|
-
createRoute: () => createRoute,
|
|
29
|
-
createRouteModuleFromProgrammaticPage: () => createRouteModuleFromProgrammaticPage,
|
|
30
|
-
defineRoutes: () => defineRoutes,
|
|
31
|
-
getProgrammaticRouteManifest: () => getProgrammaticRouteManifest,
|
|
32
|
-
getProgrammaticRouteSearchClientOptions: () => getProgrammaticRouteSearchClientOptions,
|
|
33
|
-
getProgrammaticRouteSearchSchema: () => getProgrammaticRouteSearchSchema,
|
|
34
|
-
isProgrammaticRouteDefinition: () => isProgrammaticRouteDefinition,
|
|
35
|
-
isProgrammaticRouteManifest: () => isProgrammaticRouteManifest,
|
|
36
|
-
isProgrammaticRoutesFileName: () => isProgrammaticRoutesFileName,
|
|
37
|
-
layout: () => layout,
|
|
38
|
-
page: () => page,
|
|
39
|
-
parseProgrammaticRouteModuleId: () => parseProgrammaticRouteModuleId,
|
|
40
|
-
parseProgrammaticRoutePath: () => parseProgrammaticRoutePath2,
|
|
41
|
-
redirect: () => redirect,
|
|
42
|
-
routesBuilder: () => routesBuilder,
|
|
43
|
-
scanProgrammaticPagePaths: () => scanProgrammaticPagePaths
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(routes_exports);
|
|
46
3
|
|
|
47
|
-
// src/tracing.ts
|
|
48
|
-
var import_api = require("@opentelemetry/api");
|
|
49
|
-
var FARM_TRACER_NAME = "@farm.js/core";
|
|
50
|
-
var ALL_SPAN_KINDS = [
|
|
51
|
-
"request",
|
|
52
|
-
"render",
|
|
53
|
-
"middleware",
|
|
54
|
-
"api",
|
|
55
|
-
"integration",
|
|
56
|
-
"storage",
|
|
57
|
-
"ppr",
|
|
58
|
-
"build",
|
|
59
|
-
"plugin"
|
|
60
|
-
];
|
|
61
|
-
var DEFAULT_IGNORED_PATHS = [
|
|
62
|
-
"/@vite/",
|
|
63
|
-
"/@fs/",
|
|
64
|
-
"/@id/",
|
|
65
|
-
"/@react-refresh",
|
|
66
|
-
"/node_modules/",
|
|
67
|
-
"/__vite",
|
|
68
|
-
"/.well-known/appspecific/"
|
|
69
|
-
];
|
|
70
|
-
var FARM_REQUEST_METHOD_CONTEXT_KEY = (0, import_api.createContextKey)("@farm.js/core/request-method");
|
|
71
|
-
var TRACING_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/tracing-runtime/v1");
|
|
72
|
-
var runtime = globalThis;
|
|
73
|
-
var tracingState = runtime[TRACING_RUNTIME] ?? (runtime[TRACING_RUNTIME] = normalizeFarmTracingConfig(false));
|
|
74
|
-
function normalizeFarmTracingConfig(config) {
|
|
75
|
-
if (!config) {
|
|
76
|
-
return {
|
|
77
|
-
enabled: false,
|
|
78
|
-
spans: new Set(ALL_SPAN_KINDS),
|
|
79
|
-
recordEvents: true,
|
|
80
|
-
attributes: {},
|
|
81
|
-
ignorePaths: DEFAULT_IGNORED_PATHS
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
if (config === true) {
|
|
85
|
-
return {
|
|
86
|
-
enabled: true,
|
|
87
|
-
spans: new Set(ALL_SPAN_KINDS),
|
|
88
|
-
recordEvents: true,
|
|
89
|
-
attributes: {},
|
|
90
|
-
ignorePaths: DEFAULT_IGNORED_PATHS
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
enabled: config.enabled ?? true,
|
|
95
|
-
spans: new Set(config.spans ?? ALL_SPAN_KINDS),
|
|
96
|
-
recordEvents: config.recordEvents ?? true,
|
|
97
|
-
attributes: { ...config.attributes },
|
|
98
|
-
ignorePaths: [...DEFAULT_IGNORED_PATHS, ...config.ignorePaths ?? []]
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
__name(normalizeFarmTracingConfig, "normalizeFarmTracingConfig");
|
|
102
|
-
function recordFarmEventTrace(event) {
|
|
103
|
-
if (!tracingState.enabled) return void 0;
|
|
104
|
-
const activeContext = import_api.context.active();
|
|
105
|
-
const activeSpan = import_api.trace.getSpan(activeContext);
|
|
106
|
-
const traceContext = getSpanTraceContext(activeSpan);
|
|
107
|
-
if (activeSpan && traceContext) {
|
|
108
|
-
if (event.type === "route.matched") {
|
|
109
|
-
const method = activeContext.getValue(FARM_REQUEST_METHOD_CONTEXT_KEY) ?? "HTTP";
|
|
110
|
-
activeSpan.updateName(`${method} ${event.route}`);
|
|
111
|
-
activeSpan.setAttribute("http.route", event.route);
|
|
112
|
-
activeSpan.setAttribute("farm.route", event.route);
|
|
113
|
-
}
|
|
114
|
-
if (tracingState.recordEvents) {
|
|
115
|
-
activeSpan.addEvent(event.type, toEventAttributes(event), event.timestamp);
|
|
116
|
-
}
|
|
117
|
-
const error = event.type === "request.error" ? void 0 : getEventError(event);
|
|
118
|
-
if (error !== void 0) {
|
|
119
|
-
if (event.type === "render.error") {
|
|
120
|
-
recordSpanException(activeSpan, error);
|
|
121
|
-
} else {
|
|
122
|
-
recordSpanError(activeSpan, error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const completedTraceContext = recordCompletedEventSpan(event, activeContext);
|
|
127
|
-
return traceContext ?? completedTraceContext;
|
|
128
|
-
}
|
|
129
|
-
__name(recordFarmEventTrace, "recordFarmEventTrace");
|
|
130
|
-
function recordCompletedEventSpan(event, parentContext) {
|
|
131
|
-
const descriptor = getCompletedSpanDescriptor(event);
|
|
132
|
-
if (!descriptor || !tracingState.spans.has(descriptor.kind)) return void 0;
|
|
133
|
-
const tracer = import_api.trace.getTracer(FARM_TRACER_NAME);
|
|
134
|
-
const span = tracer.startSpan(
|
|
135
|
-
descriptor.name,
|
|
136
|
-
{
|
|
137
|
-
kind: import_api.SpanKind.INTERNAL,
|
|
138
|
-
startTime: event.timestamp - descriptor.durationMs,
|
|
139
|
-
attributes: {
|
|
140
|
-
...tracingState.attributes,
|
|
141
|
-
...toEventAttributes(event),
|
|
142
|
-
"farm.event.type": event.type
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
parentContext
|
|
146
|
-
);
|
|
147
|
-
const status = "status" in event && typeof event.status === "number" ? event.status : void 0;
|
|
148
|
-
if (status !== void 0) setResponseStatus(span, status);
|
|
149
|
-
const error = getEventError(event);
|
|
150
|
-
if (error !== void 0) recordSpanError(span, error);
|
|
151
|
-
const traceContext = getSpanTraceContext(span);
|
|
152
|
-
span.end(event.timestamp);
|
|
153
|
-
return traceContext;
|
|
154
|
-
}
|
|
155
|
-
__name(recordCompletedEventSpan, "recordCompletedEventSpan");
|
|
156
|
-
function getCompletedSpanDescriptor(event) {
|
|
157
|
-
if (!("durationMs" in event) || typeof event.durationMs !== "number") return void 0;
|
|
158
|
-
switch (event.type) {
|
|
159
|
-
case "render.complete":
|
|
160
|
-
return { kind: "render", name: `farm.render ${event.route}`, durationMs: event.durationMs };
|
|
161
|
-
case "render.stream.shellReady":
|
|
162
|
-
return {
|
|
163
|
-
kind: "render",
|
|
164
|
-
name: `farm.render.shell ${event.route}`,
|
|
165
|
-
durationMs: event.durationMs
|
|
166
|
-
};
|
|
167
|
-
case "render.stream.complete":
|
|
168
|
-
return {
|
|
169
|
-
kind: "render",
|
|
170
|
-
name: `farm.render.stream ${event.route}`,
|
|
171
|
-
durationMs: event.durationMs
|
|
172
|
-
};
|
|
173
|
-
case "middleware.complete":
|
|
174
|
-
return {
|
|
175
|
-
kind: "middleware",
|
|
176
|
-
name: `farm.middleware ${event.name ?? event.route ?? "anonymous"}`,
|
|
177
|
-
durationMs: event.durationMs
|
|
178
|
-
};
|
|
179
|
-
case "api.request.complete":
|
|
180
|
-
case "api.error":
|
|
181
|
-
return {
|
|
182
|
-
kind: "api",
|
|
183
|
-
name: `farm.api ${event.method} ${event.route}`,
|
|
184
|
-
durationMs: event.durationMs
|
|
185
|
-
};
|
|
186
|
-
case "integration.api.call.complete":
|
|
187
|
-
return {
|
|
188
|
-
kind: "integration",
|
|
189
|
-
name: `farm.integration ${event.integration}.${event.operation}`,
|
|
190
|
-
durationMs: event.durationMs
|
|
191
|
-
};
|
|
192
|
-
case "storage.query.complete":
|
|
193
|
-
return {
|
|
194
|
-
kind: "storage",
|
|
195
|
-
name: `farm.storage ${event.operation}`,
|
|
196
|
-
durationMs: event.durationMs
|
|
197
|
-
};
|
|
198
|
-
case "ppr.refresh.complete":
|
|
199
|
-
return {
|
|
200
|
-
kind: "ppr",
|
|
201
|
-
name: `farm.ppr.refresh ${event.route}`,
|
|
202
|
-
durationMs: event.durationMs
|
|
203
|
-
};
|
|
204
|
-
case "build.complete":
|
|
205
|
-
return {
|
|
206
|
-
kind: "build",
|
|
207
|
-
name: `farm.build${event.target ? ` ${event.target}` : ""}`,
|
|
208
|
-
durationMs: event.durationMs
|
|
209
|
-
};
|
|
210
|
-
case "plugin.hook.complete":
|
|
211
|
-
return {
|
|
212
|
-
kind: "plugin",
|
|
213
|
-
name: `farm.plugin ${event.plugin}.${event.hook}`,
|
|
214
|
-
durationMs: event.durationMs
|
|
215
|
-
};
|
|
216
|
-
default:
|
|
217
|
-
return void 0;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
__name(getCompletedSpanDescriptor, "getCompletedSpanDescriptor");
|
|
221
|
-
function hashFarmCacheKey(value) {
|
|
222
|
-
let hash = 2166136261;
|
|
223
|
-
for (let index = 0; index < value.length; index++) {
|
|
224
|
-
hash ^= value.charCodeAt(index);
|
|
225
|
-
hash = Math.imul(hash, 16777619);
|
|
226
|
-
}
|
|
227
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
228
|
-
}
|
|
229
|
-
__name(hashFarmCacheKey, "hashFarmCacheKey");
|
|
230
|
-
function toEventAttributes(event) {
|
|
231
|
-
const attributes = {};
|
|
232
|
-
const redactKey = typeof event.type === "string" && event.type.startsWith("cache.");
|
|
233
|
-
for (const [key, value] of Object.entries(event)) {
|
|
234
|
-
if (key === "timestamp" || key === "level" || key === "error" || key === "traceId" || key === "spanId" || key === "traceSampled" || value === void 0) {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
if (redactKey && key === "key" && typeof value === "string") {
|
|
238
|
-
attributes["farm.key_hash"] = hashFarmCacheKey(value);
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
242
|
-
attributes[`farm.${key}`] = value;
|
|
243
|
-
} else if (Array.isArray(value)) {
|
|
244
|
-
if (value.every((entry) => typeof entry === "string")) {
|
|
245
|
-
attributes[`farm.${key}`] = value;
|
|
246
|
-
} else if (value.every((entry) => typeof entry === "number")) {
|
|
247
|
-
attributes[`farm.${key}`] = value;
|
|
248
|
-
} else if (value.every((entry) => typeof entry === "boolean")) {
|
|
249
|
-
attributes[`farm.${key}`] = value;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return attributes;
|
|
254
|
-
}
|
|
255
|
-
__name(toEventAttributes, "toEventAttributes");
|
|
256
|
-
function getEventError(event) {
|
|
257
|
-
return "error" in event ? event.error : void 0;
|
|
258
|
-
}
|
|
259
|
-
__name(getEventError, "getEventError");
|
|
260
|
-
function recordSpanException(span, error) {
|
|
261
|
-
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
262
|
-
span.recordException(normalized);
|
|
263
|
-
return normalized;
|
|
264
|
-
}
|
|
265
|
-
__name(recordSpanException, "recordSpanException");
|
|
266
|
-
function recordSpanError(span, error) {
|
|
267
|
-
const normalized = recordSpanException(span, error);
|
|
268
|
-
span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: normalized.message });
|
|
269
|
-
}
|
|
270
|
-
__name(recordSpanError, "recordSpanError");
|
|
271
|
-
function setResponseStatus(span, status) {
|
|
272
|
-
span.setAttribute("http.response.status_code", status);
|
|
273
|
-
if (status >= 500) {
|
|
274
|
-
span.setStatus({ code: import_api.SpanStatusCode.ERROR });
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
__name(setResponseStatus, "setResponseStatus");
|
|
278
|
-
function getSpanTraceContext(span) {
|
|
279
|
-
if (!span) return void 0;
|
|
280
|
-
const spanContext = span.spanContext();
|
|
281
|
-
if (!(0, import_api.isSpanContextValid)(spanContext)) return void 0;
|
|
282
|
-
return {
|
|
283
|
-
traceId: spanContext.traceId,
|
|
284
|
-
spanId: spanContext.spanId,
|
|
285
|
-
traceSampled: (spanContext.traceFlags & 1) === 1
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
__name(getSpanTraceContext, "getSpanTraceContext");
|
|
289
4
|
|
|
290
|
-
// src/observability.ts
|
|
291
|
-
var OBSERVABILITY_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/observability-runtime/v1");
|
|
292
|
-
var runtime2 = globalThis;
|
|
293
|
-
var shared = runtime2[OBSERVABILITY_RUNTIME] ?? (runtime2[OBSERVABILITY_RUNTIME] = {
|
|
294
|
-
handlers: /* @__PURE__ */ new Set(),
|
|
295
|
-
unfilteredHandlers: /* @__PURE__ */ new Set(),
|
|
296
|
-
config: { logs: false, handlers: [], tracing: normalizeFarmTracingConfig(false) }
|
|
297
|
-
});
|
|
298
|
-
var runtimeHandlers = shared.handlers;
|
|
299
|
-
var unfilteredRuntimeHandlers = shared.unfilteredHandlers;
|
|
300
|
-
var observabilityState = shared.config;
|
|
301
|
-
function emitFarmEvent(input) {
|
|
302
|
-
const event = {
|
|
303
|
-
timestamp: Date.now(),
|
|
304
|
-
level: inferFarmEventLevel(input.type),
|
|
305
|
-
...input
|
|
306
|
-
};
|
|
307
|
-
const traceContext = recordFarmEventTrace(event);
|
|
308
|
-
if (traceContext) {
|
|
309
|
-
event.traceId = traceContext.traceId;
|
|
310
|
-
event.spanId = traceContext.spanId;
|
|
311
|
-
event.traceSampled = traceContext.traceSampled;
|
|
312
|
-
}
|
|
313
|
-
notifyFarmEventHandlers(event, unfilteredRuntimeHandlers);
|
|
314
|
-
if (!shouldEmitFarmEvent(event)) return event;
|
|
315
|
-
if (observabilityState.logs) {
|
|
316
|
-
logFarmEvent(event);
|
|
317
|
-
}
|
|
318
|
-
notifyFarmEventHandlers(event, [...observabilityState.handlers, ...runtimeHandlers]);
|
|
319
|
-
return event;
|
|
320
|
-
}
|
|
321
|
-
__name(emitFarmEvent, "emitFarmEvent");
|
|
322
|
-
function notifyFarmEventHandlers(event, handlers) {
|
|
323
|
-
for (const handler of handlers) {
|
|
324
|
-
try {
|
|
325
|
-
Promise.resolve(handler(event)).catch((error) => {
|
|
326
|
-
console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
|
|
327
|
-
});
|
|
328
|
-
} catch (error) {
|
|
329
|
-
console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
__name(notifyFarmEventHandlers, "notifyFarmEventHandlers");
|
|
334
|
-
function shouldEmitFarmEvent(event) {
|
|
335
|
-
if (!observabilityState.logs && observabilityState.handlers.length === 0 && runtimeHandlers.size === 0) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
if (observabilityState.events && !observabilityState.events.has(event.type)) {
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
|
-
return true;
|
|
342
|
-
}
|
|
343
|
-
__name(shouldEmitFarmEvent, "shouldEmitFarmEvent");
|
|
344
|
-
function inferFarmEventLevel(type) {
|
|
345
|
-
if (type === "error" || type.endsWith(".error") || type.endsWith(".failed")) {
|
|
346
|
-
return "error";
|
|
347
|
-
}
|
|
348
|
-
if (type.endsWith(".bypass") || type.endsWith(".invalidated") || type.endsWith(".stale") || type.endsWith(".notFound")) {
|
|
349
|
-
return "warn";
|
|
350
|
-
}
|
|
351
|
-
if (type.endsWith(".hit") || type.endsWith(".miss") || type.endsWith(".start") || type.endsWith(".shellReady")) {
|
|
352
|
-
return "debug";
|
|
353
|
-
}
|
|
354
|
-
return "info";
|
|
355
|
-
}
|
|
356
|
-
__name(inferFarmEventLevel, "inferFarmEventLevel");
|
|
357
|
-
function logFarmEvent(event) {
|
|
358
|
-
const message = `[farm:${event.level}] ${event.type}${formatFarmEventDetails(event)}`;
|
|
359
|
-
switch (event.level) {
|
|
360
|
-
case "error":
|
|
361
|
-
console.error(message);
|
|
362
|
-
break;
|
|
363
|
-
case "warn":
|
|
364
|
-
console.warn(message);
|
|
365
|
-
break;
|
|
366
|
-
default:
|
|
367
|
-
console.log(message);
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
__name(logFarmEvent, "logFarmEvent");
|
|
372
|
-
function formatFarmEventDetails(event) {
|
|
373
|
-
const details = [];
|
|
374
|
-
const record = event;
|
|
375
|
-
for (const key of [
|
|
376
|
-
"route",
|
|
377
|
-
"pathname",
|
|
378
|
-
"method",
|
|
379
|
-
"status",
|
|
380
|
-
"key",
|
|
381
|
-
"tag",
|
|
382
|
-
"path",
|
|
383
|
-
"reason",
|
|
384
|
-
"durationMs",
|
|
385
|
-
"integration",
|
|
386
|
-
"server",
|
|
387
|
-
"tool",
|
|
388
|
-
"outcome",
|
|
389
|
-
"operation",
|
|
390
|
-
"plugin",
|
|
391
|
-
"hook",
|
|
392
|
-
"target",
|
|
393
|
-
"count"
|
|
394
|
-
]) {
|
|
395
|
-
const value = record[key];
|
|
396
|
-
if (value !== void 0) {
|
|
397
|
-
details.push(`${key}=${formatDetailValue(value)}`);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
return details.length > 0 ? ` ${details.join(" ")}` : "";
|
|
401
|
-
}
|
|
402
|
-
__name(formatFarmEventDetails, "formatFarmEventDetails");
|
|
403
|
-
function formatDetailValue(value) {
|
|
404
|
-
if (typeof value === "string") {
|
|
405
|
-
return value;
|
|
406
|
-
}
|
|
407
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
408
|
-
return String(value);
|
|
409
|
-
}
|
|
410
|
-
try {
|
|
411
|
-
return JSON.stringify(value);
|
|
412
|
-
} catch {
|
|
413
|
-
return String(value);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
__name(formatDetailValue, "formatDetailValue");
|
|
417
|
-
function formatError(error) {
|
|
418
|
-
return error instanceof Error ? error.message : String(error);
|
|
419
|
-
}
|
|
420
|
-
__name(formatError, "formatError");
|
|
421
5
|
|
|
422
|
-
// src/cache-invalidation-stream.ts
|
|
423
|
-
var MAX_BUFFERED_BYTES = 64 * 1024;
|
|
424
|
-
var textEncoder = new TextEncoder();
|
|
425
6
|
|
|
426
|
-
// src/cache.ts
|
|
427
|
-
var _FarmDataCache = class _FarmDataCache {
|
|
428
|
-
constructor(config = {}) {
|
|
429
|
-
this.entries = /* @__PURE__ */ new Map();
|
|
430
|
-
this.inflight = /* @__PURE__ */ new Map();
|
|
431
|
-
/** Local entries by tag, so tag counts and pruning never scan unrelated entries. */
|
|
432
|
-
this.entriesByTag = /* @__PURE__ */ new Map();
|
|
433
|
-
this.invalidatedTagVersions = /* @__PURE__ */ new Map();
|
|
434
|
-
this.activeGenerations = /* @__PURE__ */ new Set();
|
|
435
|
-
this.version = 0;
|
|
436
|
-
this.generation = 0;
|
|
437
|
-
this.namespace = "farm";
|
|
438
|
-
this.local = true;
|
|
439
|
-
this.maxEntries = 1024;
|
|
440
|
-
this.lease = {
|
|
441
|
-
enabled: true,
|
|
442
|
-
ttlMs: 1e4,
|
|
443
|
-
waitTimeoutMs: 1e4,
|
|
444
|
-
pollIntervalMs: 25
|
|
445
|
-
};
|
|
446
|
-
this.configure(config);
|
|
447
|
-
}
|
|
448
|
-
configure(config = {}) {
|
|
449
|
-
this.generation++;
|
|
450
|
-
this.entries.clear();
|
|
451
|
-
this.entriesByTag.clear();
|
|
452
|
-
this.inflight.clear();
|
|
453
|
-
this.invalidatedTagVersions.clear();
|
|
454
|
-
this.activeGenerations.clear();
|
|
455
|
-
this.version = 0;
|
|
456
|
-
this.adapter = config.adapter;
|
|
457
|
-
this.namespace = normalizeCacheNamespace(config.namespace || "farm");
|
|
458
|
-
this.local = !config.adapter;
|
|
459
|
-
this.maxEntries = normalizePositiveInteger(config.maxEntries, 1024, "cache.maxEntries");
|
|
460
|
-
this.lease = config.lease === false ? { ...this.lease, enabled: false } : {
|
|
461
|
-
enabled: true,
|
|
462
|
-
ttlMs: normalizePositiveDuration(config.lease?.ttlMs, 1e4, "cache.lease.ttlMs"),
|
|
463
|
-
waitTimeoutMs: normalizePositiveDuration(
|
|
464
|
-
config.lease?.waitTimeoutMs,
|
|
465
|
-
1e4,
|
|
466
|
-
"cache.lease.waitTimeoutMs"
|
|
467
|
-
),
|
|
468
|
-
pollIntervalMs: normalizePositiveDuration(
|
|
469
|
-
config.lease?.pollIntervalMs,
|
|
470
|
-
25,
|
|
471
|
-
"cache.lease.pollIntervalMs"
|
|
472
|
-
)
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
get adapterName() {
|
|
476
|
-
return this.adapter?.name || (this.adapter ? "custom" : "memory");
|
|
477
|
-
}
|
|
478
|
-
get hasAdapter() {
|
|
479
|
-
return this.adapter !== void 0;
|
|
480
|
-
}
|
|
481
|
-
get size() {
|
|
482
|
-
return this.entries.size;
|
|
483
|
-
}
|
|
484
|
-
get(key, options = {}) {
|
|
485
|
-
return this.getEntry(key, options)?.value;
|
|
486
|
-
}
|
|
487
|
-
getEntry(key, options = {}) {
|
|
488
|
-
const entry = this.entries.get(key);
|
|
489
|
-
if (!entry) {
|
|
490
|
-
emitFarmEvent({ type: "cache.miss", key });
|
|
491
|
-
return void 0;
|
|
492
|
-
}
|
|
493
|
-
const stale = this.isStale(entry, options.now);
|
|
494
|
-
if (stale) {
|
|
495
|
-
emitFarmEvent({
|
|
496
|
-
type: "cache.stale",
|
|
497
|
-
key,
|
|
498
|
-
tags: Array.from(entry.tags),
|
|
499
|
-
revalidate: entry.revalidate
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
if (!options.allowStale && stale) {
|
|
503
|
-
emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
|
|
504
|
-
return void 0;
|
|
505
|
-
}
|
|
506
|
-
this.touchEntry(key, entry);
|
|
507
|
-
emitFarmEvent({
|
|
508
|
-
type: "cache.hit",
|
|
509
|
-
key,
|
|
510
|
-
tags: Array.from(entry.tags),
|
|
511
|
-
revalidate: entry.revalidate,
|
|
512
|
-
stale
|
|
513
|
-
});
|
|
514
|
-
return this.toPublicEntry(entry);
|
|
515
|
-
}
|
|
516
|
-
async getEntryAsync(key, options = {}) {
|
|
517
|
-
if (this.local) {
|
|
518
|
-
const localEntry = this.getEntry(key, options);
|
|
519
|
-
if (localEntry) return localEntry;
|
|
520
|
-
}
|
|
521
|
-
if (!this.adapter) {
|
|
522
|
-
return this.local ? void 0 : this.getEntry(key, options);
|
|
523
|
-
}
|
|
524
|
-
const generation = this.generation;
|
|
525
|
-
const adapter = this.adapter;
|
|
526
|
-
const namespace = this.namespace;
|
|
527
|
-
const entry = await adapter.get(`${namespace}:entry:${key}`);
|
|
528
|
-
if (generation !== this.generation) return void 0;
|
|
529
|
-
if (!entry) {
|
|
530
|
-
emitFarmEvent({ type: "cache.miss", key });
|
|
531
|
-
return void 0;
|
|
532
|
-
}
|
|
533
|
-
assertFarmCacheEntry(entry, key);
|
|
534
|
-
const stale = await this.isAdapterEntryStale(entry, options.now, adapter, namespace);
|
|
535
|
-
if (generation !== this.generation) return void 0;
|
|
536
|
-
if (stale) {
|
|
537
|
-
emitFarmEvent({
|
|
538
|
-
type: "cache.stale",
|
|
539
|
-
key,
|
|
540
|
-
tags: [...entry.tags],
|
|
541
|
-
revalidate: entry.revalidate
|
|
542
|
-
});
|
|
543
|
-
if (!options.allowStale) {
|
|
544
|
-
emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
|
|
545
|
-
return void 0;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
emitFarmEvent({
|
|
549
|
-
type: "cache.hit",
|
|
550
|
-
key,
|
|
551
|
-
tags: [...entry.tags],
|
|
552
|
-
revalidate: entry.revalidate,
|
|
553
|
-
stale
|
|
554
|
-
});
|
|
555
|
-
if (this.local && !stale) {
|
|
556
|
-
this.hydrateLocalEntry(entry);
|
|
557
|
-
}
|
|
558
|
-
return { ...entry, key };
|
|
559
|
-
}
|
|
560
|
-
set(key, value, options = {}) {
|
|
561
|
-
const revalidate = normalizeRevalidate(options.revalidate);
|
|
562
|
-
const tags = /* @__PURE__ */ new Set();
|
|
563
|
-
for (const tag of options.tags ?? []) {
|
|
564
|
-
tags.add(normalizeCacheTag(tag));
|
|
565
|
-
}
|
|
566
|
-
for (const routePath of options.paths ?? []) {
|
|
567
|
-
tags.add(createPathCacheTag(routePath));
|
|
568
|
-
}
|
|
569
|
-
const entry = {
|
|
570
|
-
key,
|
|
571
|
-
value,
|
|
572
|
-
tags,
|
|
573
|
-
tagVersions: void 0,
|
|
574
|
-
createdAt: options.createdAt ?? Date.now(),
|
|
575
|
-
createdVersion: ++this.version,
|
|
576
|
-
revalidate
|
|
577
|
-
};
|
|
578
|
-
this.storeLocalEntry(entry);
|
|
579
|
-
emitFarmEvent({
|
|
580
|
-
type: "cache.set",
|
|
581
|
-
key,
|
|
582
|
-
tags: Array.from(tags),
|
|
583
|
-
revalidate: entry.revalidate
|
|
584
|
-
});
|
|
585
|
-
return this.toPublicEntry(entry);
|
|
586
|
-
}
|
|
587
|
-
async setAsync(key, value, options = {}, tagVersions) {
|
|
588
|
-
return this.writeAsync(key, value, options, tagVersions);
|
|
589
|
-
}
|
|
590
|
-
async writeAsync(key, value, options, tagVersions, createdVersion) {
|
|
591
|
-
const revalidate = normalizeRevalidate(options.revalidate);
|
|
592
|
-
const tags = normalizeCacheOptionsTags(options);
|
|
593
|
-
const capturedVersions = tagVersions ?? await this.getAdapterTagVersions(Array.from(tags.values()));
|
|
594
|
-
const entry = {
|
|
595
|
-
key,
|
|
596
|
-
value,
|
|
597
|
-
tags: Array.from(tags),
|
|
598
|
-
tagVersions: capturedVersions,
|
|
599
|
-
createdAt: options.createdAt ?? Date.now(),
|
|
600
|
-
createdVersion: createdVersion ?? ++this.version,
|
|
601
|
-
revalidate
|
|
602
|
-
};
|
|
603
|
-
if (this.local) {
|
|
604
|
-
this.hydrateLocalEntry(entry);
|
|
605
|
-
}
|
|
606
|
-
if (this.adapter) {
|
|
607
|
-
await this.adapter.set(this.createAdapterKey(key), entry);
|
|
608
|
-
}
|
|
609
|
-
emitFarmEvent({
|
|
610
|
-
type: "cache.set",
|
|
611
|
-
key,
|
|
612
|
-
tags: [...entry.tags],
|
|
613
|
-
revalidate: entry.revalidate
|
|
614
|
-
});
|
|
615
|
-
return entry;
|
|
616
|
-
}
|
|
617
|
-
delete(key) {
|
|
618
|
-
const deleted = this.deleteLocalEntry(key);
|
|
619
|
-
emitFarmEvent({ type: "cache.delete", key, deleted });
|
|
620
|
-
return deleted;
|
|
621
|
-
}
|
|
622
|
-
async deleteAsync(key) {
|
|
623
|
-
const deleted = this.deleteLocalEntry(key);
|
|
624
|
-
if (this.adapter) {
|
|
625
|
-
await this.adapter.delete(this.createAdapterKey(key));
|
|
626
|
-
}
|
|
627
|
-
emitFarmEvent({ type: "cache.delete", key, deleted: this.adapter ? true : deleted });
|
|
628
|
-
return this.adapter ? true : deleted;
|
|
629
|
-
}
|
|
630
|
-
clear() {
|
|
631
|
-
const count = this.entries.size;
|
|
632
|
-
this.generation++;
|
|
633
|
-
this.entries.clear();
|
|
634
|
-
this.entriesByTag.clear();
|
|
635
|
-
this.inflight.clear();
|
|
636
|
-
this.invalidatedTagVersions.clear();
|
|
637
|
-
this.activeGenerations.clear();
|
|
638
|
-
this.version = 0;
|
|
639
|
-
emitFarmEvent({ type: "cache.clear", count });
|
|
640
|
-
}
|
|
641
|
-
async clearAsync() {
|
|
642
|
-
this.clear();
|
|
643
|
-
await this.adapter?.clear?.();
|
|
644
|
-
}
|
|
645
|
-
isStale(entry, now = Date.now()) {
|
|
646
|
-
if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
|
|
647
|
-
return true;
|
|
648
|
-
}
|
|
649
|
-
for (const tag of entry.tags) {
|
|
650
|
-
const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
|
|
651
|
-
if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
|
|
652
|
-
return true;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
async isStaleAsync(entry, now = Date.now()) {
|
|
658
|
-
if (this.adapter) {
|
|
659
|
-
return this.isAdapterEntryStale(entry, now);
|
|
660
|
-
}
|
|
661
|
-
return this.isStale(entry, now);
|
|
662
|
-
}
|
|
663
|
-
revalidateTag(tag, options = {}) {
|
|
664
|
-
const normalized = normalizeCacheTag(tag);
|
|
665
|
-
const count = this.invalidateTag(normalized);
|
|
666
|
-
emitFarmEvent(
|
|
667
|
-
options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
|
|
668
|
-
);
|
|
669
|
-
return count;
|
|
670
|
-
}
|
|
671
|
-
async revalidateTagAsync(tag, options = {}) {
|
|
672
|
-
const normalized = normalizeCacheTag(tag);
|
|
673
|
-
const count = this.invalidateTag(normalized);
|
|
674
|
-
await this.adapter?.invalidateTags?.([this.createAdapterTag(normalized)]);
|
|
675
|
-
emitFarmEvent(
|
|
676
|
-
options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
|
|
677
|
-
);
|
|
678
|
-
return count;
|
|
679
|
-
}
|
|
680
|
-
revalidatePath(routePath) {
|
|
681
|
-
const normalizedPath = normalizeRevalidatePath(routePath);
|
|
682
|
-
const pathTag = createPathCacheTag(normalizedPath);
|
|
683
|
-
const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
|
|
684
|
-
const count = this.invalidateTag(pathTag);
|
|
685
|
-
emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
|
|
686
|
-
if (pprCount > 0) {
|
|
687
|
-
emitFarmEvent({
|
|
688
|
-
type: "ppr.shell.invalidated",
|
|
689
|
-
route: normalizedPath,
|
|
690
|
-
reason: "revalidatePath",
|
|
691
|
-
count: pprCount
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
return count;
|
|
695
|
-
}
|
|
696
|
-
async revalidatePathAsync(routePath) {
|
|
697
|
-
const normalizedPath = normalizeRevalidatePath(routePath);
|
|
698
|
-
const pathTag = createPathCacheTag(normalizedPath);
|
|
699
|
-
const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
|
|
700
|
-
const count = this.invalidateTag(pathTag);
|
|
701
|
-
await this.adapter?.invalidateTags?.([this.createAdapterTag(pathTag)]);
|
|
702
|
-
emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
|
|
703
|
-
if (pprCount > 0) {
|
|
704
|
-
emitFarmEvent({
|
|
705
|
-
type: "ppr.shell.invalidated",
|
|
706
|
-
route: normalizedPath,
|
|
707
|
-
reason: "revalidatePath",
|
|
708
|
-
count: pprCount
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
return count;
|
|
712
|
-
}
|
|
713
|
-
async getOrSet(key, producer, options = {}) {
|
|
714
|
-
normalizeRevalidate(options.revalidate);
|
|
715
|
-
const cached = await this.getEntryAsync(key);
|
|
716
|
-
if (cached) {
|
|
717
|
-
return cached.value;
|
|
718
|
-
}
|
|
719
|
-
const inflight = this.inflight.get(key);
|
|
720
|
-
if (inflight && !this.wasInvalidatedSince(inflight.tags, inflight.startVersion)) {
|
|
721
|
-
emitFarmEvent({ type: "cache.dedupe", key });
|
|
722
|
-
return inflight.promise;
|
|
723
|
-
}
|
|
724
|
-
const tags = Array.from(normalizeCacheOptionsTags(options));
|
|
725
|
-
const generation = this.generation;
|
|
726
|
-
const startVersion = this.version;
|
|
727
|
-
const promise = this.fillCacheEntry(key, producer, options, tags, generation).catch((error) => {
|
|
728
|
-
emitFarmEvent({ type: "cache.error", key, operation: "set", error });
|
|
729
|
-
throw error;
|
|
730
|
-
}).finally(() => {
|
|
731
|
-
if (this.inflight.get(key)?.promise === promise) {
|
|
732
|
-
this.inflight.delete(key);
|
|
733
|
-
}
|
|
734
|
-
});
|
|
735
|
-
this.inflight.set(key, { promise, tags, startVersion });
|
|
736
|
-
return promise;
|
|
737
|
-
}
|
|
738
|
-
/** A fill that started before one of its tags was invalidated cannot satisfy later readers. */
|
|
739
|
-
wasInvalidatedSince(tags, version) {
|
|
740
|
-
for (const tag of tags) {
|
|
741
|
-
const invalidatedVersion = this.invalidatedTagVersions.get(tag);
|
|
742
|
-
if (invalidatedVersion !== void 0 && invalidatedVersion > version) return true;
|
|
743
|
-
}
|
|
744
|
-
return false;
|
|
745
|
-
}
|
|
746
|
-
async fillCacheEntry(key, producer, options, tags, generation) {
|
|
747
|
-
const adapter = this.adapter;
|
|
748
|
-
const namespace = this.namespace;
|
|
749
|
-
const lease = { ...this.lease };
|
|
750
|
-
const leaseKey = `${namespace}:lease:${key}`;
|
|
751
|
-
let leaseToken;
|
|
752
|
-
if (adapter?.acquireLease && adapter.releaseLease && lease.enabled) {
|
|
753
|
-
leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
|
|
754
|
-
if (!leaseToken) {
|
|
755
|
-
const shared2 = await this.waitForAdapterEntry(
|
|
756
|
-
key,
|
|
757
|
-
adapter,
|
|
758
|
-
namespace,
|
|
759
|
-
lease,
|
|
760
|
-
generation
|
|
761
|
-
);
|
|
762
|
-
if (shared2) {
|
|
763
|
-
emitFarmEvent({ type: "cache.dedupe", key });
|
|
764
|
-
return shared2.value;
|
|
765
|
-
}
|
|
766
|
-
if (generation === this.generation) {
|
|
767
|
-
leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
const initialCreatedVersion = this.version;
|
|
772
|
-
const activeGeneration = {
|
|
773
|
-
tags: new Set(tags),
|
|
774
|
-
createdVersion: initialCreatedVersion
|
|
775
|
-
};
|
|
776
|
-
this.activeGenerations.add(activeGeneration);
|
|
777
|
-
try {
|
|
778
|
-
const initialTagVersions = await this.getAdapterTagVersions(tags, adapter, namespace);
|
|
779
|
-
const value = await producer();
|
|
780
|
-
if (generation === this.generation) {
|
|
781
|
-
await this.writeAsync(key, value, options, initialTagVersions, initialCreatedVersion);
|
|
782
|
-
}
|
|
783
|
-
return value;
|
|
784
|
-
} finally {
|
|
785
|
-
this.activeGenerations.delete(activeGeneration);
|
|
786
|
-
this.pruneInvalidatedTagVersions(activeGeneration.tags);
|
|
787
|
-
if (leaseToken && adapter?.releaseLease) {
|
|
788
|
-
try {
|
|
789
|
-
await adapter.releaseLease(leaseKey, leaseToken);
|
|
790
|
-
} catch (error) {
|
|
791
|
-
emitFarmEvent({ type: "cache.error", key, operation: "set", error });
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
async waitForAdapterEntry(key, adapter, namespace, lease, generation) {
|
|
797
|
-
const deadline = Date.now() + lease.waitTimeoutMs;
|
|
798
|
-
while (Date.now() < deadline) {
|
|
799
|
-
await delay(lease.pollIntervalMs);
|
|
800
|
-
if (generation !== this.generation) return void 0;
|
|
801
|
-
const entry = await adapter.get(`${namespace}:entry:${key}`);
|
|
802
|
-
if (generation !== this.generation) return void 0;
|
|
803
|
-
if (!entry) {
|
|
804
|
-
emitFarmEvent({ type: "cache.miss", key });
|
|
805
|
-
continue;
|
|
806
|
-
}
|
|
807
|
-
assertFarmCacheEntry(entry, key);
|
|
808
|
-
const stale = await this.isAdapterEntryStale(entry, Date.now(), adapter, namespace);
|
|
809
|
-
if (generation !== this.generation) return void 0;
|
|
810
|
-
if (stale) {
|
|
811
|
-
emitFarmEvent({
|
|
812
|
-
type: "cache.stale",
|
|
813
|
-
key,
|
|
814
|
-
tags: [...entry.tags],
|
|
815
|
-
revalidate: entry.revalidate
|
|
816
|
-
});
|
|
817
|
-
emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
|
|
818
|
-
} else {
|
|
819
|
-
emitFarmEvent({
|
|
820
|
-
type: "cache.hit",
|
|
821
|
-
key,
|
|
822
|
-
tags: [...entry.tags],
|
|
823
|
-
revalidate: entry.revalidate,
|
|
824
|
-
stale: false
|
|
825
|
-
});
|
|
826
|
-
return { ...entry, key };
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
return void 0;
|
|
830
|
-
}
|
|
831
|
-
countEntriesForTags(tags) {
|
|
832
|
-
let count = 0;
|
|
833
|
-
for (const entry of this.entriesByTag.get(tags[0]) ?? []) {
|
|
834
|
-
if (tags.every((tag) => entry.tags.has(tag))) {
|
|
835
|
-
count++;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
return count;
|
|
839
|
-
}
|
|
840
|
-
invalidateTag(normalizedTag) {
|
|
841
|
-
const count = this.entriesByTag.get(normalizedTag)?.size ?? 0;
|
|
842
|
-
this.invalidatedTagVersions.delete(normalizedTag);
|
|
843
|
-
this.invalidatedTagVersions.set(normalizedTag, ++this.version);
|
|
844
|
-
this.pruneInvalidatedTagVersions([normalizedTag]);
|
|
845
|
-
return count;
|
|
846
|
-
}
|
|
847
|
-
toPublicEntry(entry) {
|
|
848
|
-
return {
|
|
849
|
-
key: entry.key,
|
|
850
|
-
value: entry.value,
|
|
851
|
-
tags: Array.from(entry.tags),
|
|
852
|
-
tagVersions: entry.tagVersions,
|
|
853
|
-
createdAt: entry.createdAt,
|
|
854
|
-
createdVersion: entry.createdVersion,
|
|
855
|
-
revalidate: entry.revalidate
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
hydrateLocalEntry(entry) {
|
|
859
|
-
this.storeLocalEntry({
|
|
860
|
-
key: entry.key,
|
|
861
|
-
value: entry.value,
|
|
862
|
-
tags: new Set(entry.tags.map(normalizeCacheTag)),
|
|
863
|
-
tagVersions: entry.tagVersions,
|
|
864
|
-
createdAt: entry.createdAt,
|
|
865
|
-
createdVersion: entry.createdVersion ?? ++this.version,
|
|
866
|
-
revalidate: normalizeRevalidate(entry.revalidate)
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
touchEntry(key, entry) {
|
|
870
|
-
this.entries.delete(key);
|
|
871
|
-
this.entries.set(key, entry);
|
|
872
|
-
}
|
|
873
|
-
storeLocalEntry(entry) {
|
|
874
|
-
const removed = [];
|
|
875
|
-
const replaced = this.detachLocalEntry(entry.key);
|
|
876
|
-
if (replaced) removed.push(replaced);
|
|
877
|
-
this.entries.set(entry.key, entry);
|
|
878
|
-
for (const tag of entry.tags) {
|
|
879
|
-
let tagged = this.entriesByTag.get(tag);
|
|
880
|
-
if (!tagged) this.entriesByTag.set(tag, tagged = /* @__PURE__ */ new Set());
|
|
881
|
-
tagged.add(entry);
|
|
882
|
-
}
|
|
883
|
-
while (this.entries.size > this.maxEntries) {
|
|
884
|
-
const oldestKey = this.entries.keys().next().value;
|
|
885
|
-
if (oldestKey === void 0) break;
|
|
886
|
-
removed.push(this.detachLocalEntry(oldestKey));
|
|
887
|
-
}
|
|
888
|
-
for (const removedEntry of removed) this.pruneInvalidatedTagVersions(removedEntry.tags);
|
|
889
|
-
}
|
|
890
|
-
deleteLocalEntry(key) {
|
|
891
|
-
const entry = this.detachLocalEntry(key);
|
|
892
|
-
if (!entry) return false;
|
|
893
|
-
this.pruneInvalidatedTagVersions(entry.tags);
|
|
894
|
-
return true;
|
|
895
|
-
}
|
|
896
|
-
detachLocalEntry(key) {
|
|
897
|
-
const entry = this.entries.get(key);
|
|
898
|
-
if (!entry) return void 0;
|
|
899
|
-
this.entries.delete(key);
|
|
900
|
-
for (const tag of entry.tags) {
|
|
901
|
-
const tagged = this.entriesByTag.get(tag);
|
|
902
|
-
if (!tagged) continue;
|
|
903
|
-
tagged.delete(entry);
|
|
904
|
-
if (tagged.size === 0) this.entriesByTag.delete(tag);
|
|
905
|
-
}
|
|
906
|
-
return entry;
|
|
907
|
-
}
|
|
908
|
-
/**
|
|
909
|
-
* Drop invalidation versions that no local entry or active fill can be stale against.
|
|
910
|
-
* Callers pass only the tags whose dependents just changed, so the cost is bounded by
|
|
911
|
-
* the entries sharing those tags rather than by the whole cache.
|
|
912
|
-
*/
|
|
913
|
-
pruneInvalidatedTagVersions(tags) {
|
|
914
|
-
tags: for (const tag of tags) {
|
|
915
|
-
const invalidatedVersion = this.invalidatedTagVersions.get(tag);
|
|
916
|
-
if (invalidatedVersion === void 0) continue;
|
|
917
|
-
for (const entry of this.entriesByTag.get(tag) ?? []) {
|
|
918
|
-
if (entry.createdVersion < invalidatedVersion) continue tags;
|
|
919
|
-
}
|
|
920
|
-
for (const generation of this.activeGenerations) {
|
|
921
|
-
if (generation.tags.has(tag) && generation.createdVersion < invalidatedVersion)
|
|
922
|
-
continue tags;
|
|
923
|
-
}
|
|
924
|
-
this.invalidatedTagVersions.delete(tag);
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
createAdapterKey(key) {
|
|
928
|
-
return `${this.namespace}:entry:${key}`;
|
|
929
|
-
}
|
|
930
|
-
createAdapterTag(tag) {
|
|
931
|
-
return `${this.namespace}:tag:${tag}`;
|
|
932
|
-
}
|
|
933
|
-
async getAdapterTagVersions(tags, adapter = this.adapter, namespace = this.namespace) {
|
|
934
|
-
if (!adapter?.getTagVersions || tags.length === 0) return {};
|
|
935
|
-
const normalized = tags.map(normalizeCacheTag);
|
|
936
|
-
const physicalTags = normalized.map((tag) => `${namespace}:tag:${tag}`);
|
|
937
|
-
const versions = await adapter.getTagVersions(physicalTags);
|
|
938
|
-
return Object.fromEntries(
|
|
939
|
-
normalized.map((tag, index) => [
|
|
940
|
-
tag,
|
|
941
|
-
normalizeAdapterVersion(versions[physicalTags[index]])
|
|
942
|
-
])
|
|
943
|
-
);
|
|
944
|
-
}
|
|
945
|
-
async isAdapterEntryStale(entry, now = Date.now(), adapter = this.adapter, namespace = this.namespace) {
|
|
946
|
-
if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
|
|
947
|
-
return true;
|
|
948
|
-
}
|
|
949
|
-
const currentVersions = await this.getAdapterTagVersions(entry.tags, adapter, namespace);
|
|
950
|
-
for (const tag of entry.tags) {
|
|
951
|
-
if (normalizeAdapterVersion(currentVersions[tag]) > normalizeAdapterVersion(entry.tagVersions?.[tag])) {
|
|
952
|
-
return true;
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
return false;
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
__name(_FarmDataCache, "FarmDataCache");
|
|
959
|
-
var FarmDataCache = _FarmDataCache;
|
|
960
|
-
var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
|
|
961
|
-
var farmDataCacheGlobal = globalThis;
|
|
962
|
-
var sharedFarmDataCache = farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] ?? (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache());
|
|
963
|
-
function getFarmDataCache() {
|
|
964
|
-
return sharedFarmDataCache;
|
|
965
|
-
}
|
|
966
|
-
__name(getFarmDataCache, "getFarmDataCache");
|
|
967
|
-
function createPathCacheTag(routePath) {
|
|
968
|
-
return `path:${normalizeRevalidatePath(routePath)}`;
|
|
969
|
-
}
|
|
970
|
-
__name(createPathCacheTag, "createPathCacheTag");
|
|
971
|
-
function createRouteDataCacheTag(key) {
|
|
972
|
-
return `route-data:${createRouteDataCacheKey(key)}`;
|
|
973
|
-
}
|
|
974
|
-
__name(createRouteDataCacheTag, "createRouteDataCacheTag");
|
|
975
|
-
function createRouteDataCacheKey(key) {
|
|
976
|
-
return createFarmCacheKey(Array.isArray(key) ? key : [key]);
|
|
977
|
-
}
|
|
978
|
-
__name(createRouteDataCacheKey, "createRouteDataCacheKey");
|
|
979
|
-
function normalizeRevalidatePath(routePath) {
|
|
980
|
-
if (typeof routePath !== "string") {
|
|
981
|
-
throw new TypeError("revalidatePath expects a path string.");
|
|
982
|
-
}
|
|
983
|
-
let normalized = routePath.trim();
|
|
984
|
-
if (!normalized) {
|
|
985
|
-
throw new Error("revalidatePath expects a non-empty path.");
|
|
986
|
-
}
|
|
987
|
-
try {
|
|
988
|
-
if (/^https?:\/\//i.test(normalized)) {
|
|
989
|
-
normalized = new URL(normalized).pathname;
|
|
990
|
-
}
|
|
991
|
-
} catch {
|
|
992
|
-
}
|
|
993
|
-
normalized = normalized.split(/[?#]/, 1)[0] ?? normalized;
|
|
994
|
-
normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
995
|
-
normalized = normalized.replace(/\/{2,}/g, "/");
|
|
996
|
-
normalized = new URL(normalized, "http://farm.invalid").pathname;
|
|
997
|
-
if (normalized.length > 1) {
|
|
998
|
-
normalized = normalized.replace(/\/+$/, "");
|
|
999
|
-
}
|
|
1000
|
-
return normalized || "/";
|
|
1001
|
-
}
|
|
1002
|
-
__name(normalizeRevalidatePath, "normalizeRevalidatePath");
|
|
1003
|
-
function createFarmCacheKey(parts) {
|
|
1004
|
-
return stableSerialize(parts);
|
|
1005
|
-
}
|
|
1006
|
-
__name(createFarmCacheKey, "createFarmCacheKey");
|
|
1007
|
-
function normalizeRevalidate(revalidate) {
|
|
1008
|
-
if (revalidate === false || revalidate === void 0) {
|
|
1009
|
-
return revalidate;
|
|
1010
|
-
}
|
|
1011
|
-
if (!Number.isFinite(revalidate) || revalidate < 0) {
|
|
1012
|
-
throw new TypeError("Cache revalidate must be false or a finite, non-negative number.");
|
|
1013
|
-
}
|
|
1014
|
-
return revalidate;
|
|
1015
|
-
}
|
|
1016
|
-
__name(normalizeRevalidate, "normalizeRevalidate");
|
|
1017
|
-
function normalizeCacheTag(tag) {
|
|
1018
|
-
if (typeof tag !== "string") {
|
|
1019
|
-
throw new TypeError("Cache tags must be strings.");
|
|
1020
|
-
}
|
|
1021
|
-
const normalized = tag.trim();
|
|
1022
|
-
if (!normalized) {
|
|
1023
|
-
throw new Error("Cache tags cannot be empty.");
|
|
1024
|
-
}
|
|
1025
|
-
return normalized;
|
|
1026
|
-
}
|
|
1027
|
-
__name(normalizeCacheTag, "normalizeCacheTag");
|
|
1028
|
-
function normalizeCacheNamespace(namespace) {
|
|
1029
|
-
if (typeof namespace !== "string") {
|
|
1030
|
-
throw new TypeError("Cache namespace must be a string.");
|
|
1031
|
-
}
|
|
1032
|
-
const normalized = namespace.trim().replace(/:+$/g, "");
|
|
1033
|
-
if (!normalized) {
|
|
1034
|
-
throw new Error("Cache namespace cannot be empty.");
|
|
1035
|
-
}
|
|
1036
|
-
return normalized;
|
|
1037
|
-
}
|
|
1038
|
-
__name(normalizeCacheNamespace, "normalizeCacheNamespace");
|
|
1039
|
-
function normalizeAdapterVersion(value) {
|
|
1040
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
|
1041
|
-
}
|
|
1042
|
-
__name(normalizeAdapterVersion, "normalizeAdapterVersion");
|
|
1043
|
-
function normalizePositiveDuration(value, fallback, name) {
|
|
1044
|
-
if (value === void 0) return fallback;
|
|
1045
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
1046
|
-
throw new TypeError(`${name} must be a positive number of milliseconds.`);
|
|
1047
|
-
}
|
|
1048
|
-
return Math.floor(value);
|
|
1049
|
-
}
|
|
1050
|
-
__name(normalizePositiveDuration, "normalizePositiveDuration");
|
|
1051
|
-
function normalizePositiveInteger(value, fallback, name) {
|
|
1052
|
-
if (value === void 0) return fallback;
|
|
1053
|
-
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
1054
|
-
throw new TypeError(`${name} must be a positive integer.`);
|
|
1055
|
-
}
|
|
1056
|
-
return value;
|
|
1057
|
-
}
|
|
1058
|
-
__name(normalizePositiveInteger, "normalizePositiveInteger");
|
|
1059
|
-
function delay(ms) {
|
|
1060
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1061
|
-
}
|
|
1062
|
-
__name(delay, "delay");
|
|
1063
|
-
function normalizeCacheOptionsTags(options) {
|
|
1064
|
-
const tags = /* @__PURE__ */ new Set();
|
|
1065
|
-
for (const tag of options.tags ?? []) {
|
|
1066
|
-
tags.add(normalizeCacheTag(tag));
|
|
1067
|
-
}
|
|
1068
|
-
for (const routePath of options.paths ?? []) {
|
|
1069
|
-
tags.add(createPathCacheTag(routePath));
|
|
1070
|
-
}
|
|
1071
|
-
return tags;
|
|
1072
|
-
}
|
|
1073
|
-
__name(normalizeCacheOptionsTags, "normalizeCacheOptionsTags");
|
|
1074
|
-
function assertFarmCacheEntry(entry, expectedKey) {
|
|
1075
|
-
if (!entry || typeof entry !== "object" || entry.key !== expectedKey || !Array.isArray(entry.tags) || typeof entry.createdAt !== "number") {
|
|
1076
|
-
throw new TypeError(
|
|
1077
|
-
`Cache adapter returned an invalid entry for ${JSON.stringify(expectedKey)}.`
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
__name(assertFarmCacheEntry, "assertFarmCacheEntry");
|
|
1082
|
-
function getFunctionCacheIdentity(fn) {
|
|
1083
|
-
const name = fn.name || "anonymous";
|
|
1084
|
-
return `${name}:${hashFunctionSource(String(fn))}`;
|
|
1085
|
-
}
|
|
1086
|
-
__name(getFunctionCacheIdentity, "getFunctionCacheIdentity");
|
|
1087
|
-
function hashFunctionSource(source) {
|
|
1088
|
-
let hash = 2166136261;
|
|
1089
|
-
for (let index = 0; index < source.length; index++) {
|
|
1090
|
-
hash ^= source.charCodeAt(index);
|
|
1091
|
-
hash = Math.imul(hash, 16777619);
|
|
1092
|
-
}
|
|
1093
|
-
return (hash >>> 0).toString(36);
|
|
1094
|
-
}
|
|
1095
|
-
__name(hashFunctionSource, "hashFunctionSource");
|
|
1096
|
-
function compareCodepoint(a, b) {
|
|
1097
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
1098
|
-
}
|
|
1099
|
-
__name(compareCodepoint, "compareCodepoint");
|
|
1100
|
-
function serializeBinaryBytes(bytes) {
|
|
1101
|
-
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1102
|
-
}
|
|
1103
|
-
__name(serializeBinaryBytes, "serializeBinaryBytes");
|
|
1104
|
-
function serializeCanonicalStringEntries(entries, seen) {
|
|
1105
|
-
const valuesByKey = /* @__PURE__ */ new Map();
|
|
1106
|
-
for (const [key, item] of entries) {
|
|
1107
|
-
const values = valuesByKey.get(key);
|
|
1108
|
-
if (values) values.push(item);
|
|
1109
|
-
else valuesByKey.set(key, [item]);
|
|
1110
|
-
}
|
|
1111
|
-
return Array.from(valuesByKey.keys()).sort(compareCodepoint).flatMap(
|
|
1112
|
-
(key) => valuesByKey.get(key).map((item) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`)
|
|
1113
|
-
).join(",");
|
|
1114
|
-
}
|
|
1115
|
-
__name(serializeCanonicalStringEntries, "serializeCanonicalStringEntries");
|
|
1116
|
-
function isPlainCacheKeyObject(value) {
|
|
1117
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1118
|
-
if (prototype === null) return true;
|
|
1119
|
-
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
1120
|
-
return Object.getPrototypeOf(prototype) === null && typeof constructor === "function" && constructor.name === "Object";
|
|
1121
|
-
}
|
|
1122
|
-
__name(isPlainCacheKeyObject, "isPlainCacheKeyObject");
|
|
1123
|
-
function getCacheKeyValueType(value) {
|
|
1124
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1125
|
-
const constructor = prototype ? Object.getOwnPropertyDescriptor(prototype, "constructor")?.value : void 0;
|
|
1126
|
-
if (typeof constructor === "function" && constructor.name) {
|
|
1127
|
-
return constructor.name;
|
|
1128
|
-
}
|
|
1129
|
-
return Object.prototype.toString.call(value).slice(8, -1) || "object";
|
|
1130
|
-
}
|
|
1131
|
-
__name(getCacheKeyValueType, "getCacheKeyValueType");
|
|
1132
|
-
function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
1133
|
-
if (value === null) return "null";
|
|
1134
|
-
if (value === void 0) return "undefined";
|
|
1135
|
-
const valueType = typeof value;
|
|
1136
|
-
if (valueType === "string") return JSON.stringify(value);
|
|
1137
|
-
if (valueType === "number" || valueType === "boolean" || valueType === "bigint") {
|
|
1138
|
-
return `${valueType}:${String(value)}`;
|
|
1139
|
-
}
|
|
1140
|
-
if (valueType === "symbol") {
|
|
1141
|
-
return `symbol:${String(value)}`;
|
|
1142
|
-
}
|
|
1143
|
-
if (valueType === "function") {
|
|
1144
|
-
return `function:${getFunctionCacheIdentity(value)}`;
|
|
1145
|
-
}
|
|
1146
|
-
if (value instanceof Date) {
|
|
1147
|
-
return Number.isNaN(value.getTime()) ? "date:invalid" : `date:${value.toISOString()}`;
|
|
1148
|
-
}
|
|
1149
|
-
if (value instanceof URL) {
|
|
1150
|
-
return `url:${value.toString()}`;
|
|
1151
|
-
}
|
|
1152
|
-
if (value instanceof RegExp) {
|
|
1153
|
-
return `regexp:${value.toString()}`;
|
|
1154
|
-
}
|
|
1155
|
-
if (value instanceof ArrayBuffer) {
|
|
1156
|
-
return `arraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
|
|
1157
|
-
}
|
|
1158
|
-
if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) {
|
|
1159
|
-
return `sharedarraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
|
|
1160
|
-
}
|
|
1161
|
-
if (ArrayBuffer.isView(value)) {
|
|
1162
|
-
const viewType = Object.prototype.toString.call(value).slice(8, -1);
|
|
1163
|
-
const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
1164
|
-
return `binary:${viewType}:${serializeBinaryBytes(bytes)}`;
|
|
1165
|
-
}
|
|
1166
|
-
if (value && typeof value === "object") {
|
|
1167
|
-
if (seen.has(value)) {
|
|
1168
|
-
return "[Circular]";
|
|
1169
|
-
}
|
|
1170
|
-
seen.add(value);
|
|
1171
|
-
if (Array.isArray(value)) {
|
|
1172
|
-
const items = [];
|
|
1173
|
-
for (let index = 0; index < value.length; index++) {
|
|
1174
|
-
items.push(
|
|
1175
|
-
Object.prototype.hasOwnProperty.call(value, index) ? stableSerialize(value[index], seen) : "[Hole]"
|
|
1176
|
-
);
|
|
1177
|
-
}
|
|
1178
|
-
seen.delete(value);
|
|
1179
|
-
return `[${items.join(",")}]`;
|
|
1180
|
-
}
|
|
1181
|
-
if (value instanceof Set) {
|
|
1182
|
-
const items = Array.from(value, (item) => stableSerialize(item, seen)).sort(compareCodepoint);
|
|
1183
|
-
seen.delete(value);
|
|
1184
|
-
return `set:[${items.join(",")}]`;
|
|
1185
|
-
}
|
|
1186
|
-
if (value instanceof Map) {
|
|
1187
|
-
const items = Array.from(
|
|
1188
|
-
value,
|
|
1189
|
-
([key, item]) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`
|
|
1190
|
-
).sort(compareCodepoint);
|
|
1191
|
-
seen.delete(value);
|
|
1192
|
-
return `map:[${items.join(",")}]`;
|
|
1193
|
-
}
|
|
1194
|
-
if (value instanceof URLSearchParams) {
|
|
1195
|
-
const serialized2 = serializeCanonicalStringEntries(value, seen);
|
|
1196
|
-
seen.delete(value);
|
|
1197
|
-
return `urlsearchparams:[${serialized2}]`;
|
|
1198
|
-
}
|
|
1199
|
-
if (value instanceof Headers) {
|
|
1200
|
-
const serialized2 = serializeCanonicalStringEntries(value, seen);
|
|
1201
|
-
seen.delete(value);
|
|
1202
|
-
return `headers:[${serialized2}]`;
|
|
1203
|
-
}
|
|
1204
|
-
if (!isPlainCacheKeyObject(value)) {
|
|
1205
|
-
throw new TypeError(
|
|
1206
|
-
`Cache keys do not support ${getCacheKeyValueType(value)} values. Convert the value to an explicit stable string or structured key before caching.`
|
|
1207
|
-
);
|
|
1208
|
-
}
|
|
1209
|
-
const entries = Object.entries(value).sort(
|
|
1210
|
-
([a], [b]) => compareCodepoint(a, b)
|
|
1211
|
-
);
|
|
1212
|
-
const serialized = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item, seen)}`).join(",");
|
|
1213
|
-
seen.delete(value);
|
|
1214
|
-
return `{${serialized}}`;
|
|
1215
|
-
}
|
|
1216
|
-
return String(value);
|
|
1217
|
-
}
|
|
1218
|
-
__name(stableSerialize, "stableSerialize");
|
|
1219
7
|
|
|
1220
|
-
// src/route-context.ts
|
|
1221
|
-
var FARM_ROUTE_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("farm.routeContext");
|
|
1222
|
-
function getFarmRouteContext(props) {
|
|
1223
|
-
if (!props || typeof props !== "object") {
|
|
1224
|
-
return void 0;
|
|
1225
|
-
}
|
|
1226
|
-
return props[FARM_ROUTE_CONTEXT_SYMBOL];
|
|
1227
|
-
}
|
|
1228
|
-
__name(getFarmRouteContext, "getFarmRouteContext");
|
|
1229
8
|
|
|
1230
|
-
// src/route-runtime.ts
|
|
1231
|
-
function normalizeFarmRouteRuntimeConfig(value, source = "Route configuration") {
|
|
1232
|
-
if (!value) return {};
|
|
1233
|
-
const normalized = {};
|
|
1234
|
-
if (value.runtime !== void 0) {
|
|
1235
|
-
if (value.runtime !== "auto" && value.runtime !== "node" && value.runtime !== "edge") {
|
|
1236
|
-
throw new TypeError(`${source} runtime must be "auto", "node", or "edge"`);
|
|
1237
|
-
}
|
|
1238
|
-
normalized.runtime = value.runtime;
|
|
1239
|
-
}
|
|
1240
|
-
if (value.regions !== void 0) {
|
|
1241
|
-
if (value.regions === "auto") {
|
|
1242
|
-
normalized.regions = "auto";
|
|
1243
|
-
} else {
|
|
1244
|
-
if (!Array.isArray(value.regions) || value.regions.length === 0) {
|
|
1245
|
-
throw new TypeError(`${source} regions must be "auto" or a non-empty string array`);
|
|
1246
|
-
}
|
|
1247
|
-
const regions = Array.from(
|
|
1248
|
-
new Set(
|
|
1249
|
-
value.regions.map((region) => {
|
|
1250
|
-
if (typeof region !== "string" || !region.trim() || /[\u0000-\u001f\u007f]/.test(region)) {
|
|
1251
|
-
throw new TypeError(`${source} regions must contain non-empty region identifiers`);
|
|
1252
|
-
}
|
|
1253
|
-
return region.trim();
|
|
1254
|
-
})
|
|
1255
|
-
)
|
|
1256
|
-
);
|
|
1257
|
-
normalized.regions = regions;
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
if (value.maxDuration !== void 0) {
|
|
1261
|
-
if (value.maxDuration === "auto") {
|
|
1262
|
-
normalized.maxDuration = "auto";
|
|
1263
|
-
} else if (typeof value.maxDuration !== "number" || !Number.isInteger(value.maxDuration) || value.maxDuration <= 0) {
|
|
1264
|
-
throw new TypeError(`${source} maxDuration must be "auto" or a positive integer in seconds`);
|
|
1265
|
-
} else {
|
|
1266
|
-
normalized.maxDuration = value.maxDuration;
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
return normalized;
|
|
1270
|
-
}
|
|
1271
|
-
__name(normalizeFarmRouteRuntimeConfig, "normalizeFarmRouteRuntimeConfig");
|
|
1272
9
|
|
|
1273
|
-
// src/routing/specificity.ts
|
|
1274
|
-
var _AmbiguousRouteError = class _AmbiguousRouteError extends Error {
|
|
1275
|
-
constructor(message) {
|
|
1276
|
-
super(message);
|
|
1277
|
-
this.name = "AmbiguousRouteError";
|
|
1278
|
-
}
|
|
1279
|
-
};
|
|
1280
|
-
__name(_AmbiguousRouteError, "AmbiguousRouteError");
|
|
1281
|
-
var AmbiguousRouteError = _AmbiguousRouteError;
|
|
1282
|
-
var _NonTerminalCatchAllRouteError = class _NonTerminalCatchAllRouteError extends TypeError {
|
|
1283
|
-
constructor(message) {
|
|
1284
|
-
super(message);
|
|
1285
|
-
this.name = "NonTerminalCatchAllRouteError";
|
|
1286
|
-
}
|
|
1287
|
-
};
|
|
1288
|
-
__name(_NonTerminalCatchAllRouteError, "NonTerminalCatchAllRouteError");
|
|
1289
|
-
var NonTerminalCatchAllRouteError = _NonTerminalCatchAllRouteError;
|
|
1290
|
-
var _DuplicateRouteParameterError = class _DuplicateRouteParameterError extends AmbiguousRouteError {
|
|
1291
|
-
constructor(message) {
|
|
1292
|
-
super(message);
|
|
1293
|
-
this.name = "DuplicateRouteParameterError";
|
|
1294
|
-
}
|
|
1295
|
-
};
|
|
1296
|
-
__name(_DuplicateRouteParameterError, "DuplicateRouteParameterError");
|
|
1297
|
-
var DuplicateRouteParameterError = _DuplicateRouteParameterError;
|
|
1298
|
-
var _ReservedRouteParameterError = class _ReservedRouteParameterError extends AmbiguousRouteError {
|
|
1299
|
-
constructor(message) {
|
|
1300
|
-
super(message);
|
|
1301
|
-
this.name = "ReservedRouteParameterError";
|
|
1302
|
-
}
|
|
1303
|
-
};
|
|
1304
|
-
__name(_ReservedRouteParameterError, "ReservedRouteParameterError");
|
|
1305
|
-
var ReservedRouteParameterError = _ReservedRouteParameterError;
|
|
1306
|
-
var _BrowserUnstableRouteError = class _BrowserUnstableRouteError extends TypeError {
|
|
1307
|
-
constructor(message) {
|
|
1308
|
-
super(message);
|
|
1309
|
-
this.name = "BrowserUnstableRouteError";
|
|
1310
|
-
}
|
|
1311
|
-
};
|
|
1312
|
-
__name(_BrowserUnstableRouteError, "BrowserUnstableRouteError");
|
|
1313
|
-
var BrowserUnstableRouteError = _BrowserUnstableRouteError;
|
|
1314
|
-
var ROUTER_PARAMETER_NAME = "[A-Za-z0-9_$-]+";
|
|
1315
|
-
var PAGE_PARAMETER_PATTERN = /^(?:\[\[\.\.\.(.+)\]\]|\[\.\.\.(.+)\]|\[(.+)\])$/;
|
|
1316
|
-
var ROUTER_PARAMETER_PATTERN = /^(?:\[\[\.\.\.([A-Za-z0-9_$-]+)\]\]|\[\.\.\.([A-Za-z0-9_$-]+)\]|\[([A-Za-z0-9_$-]+)\]|:([A-Za-z0-9_$-]+)|\*([A-Za-z0-9_$-]+)\??)$/;
|
|
1317
|
-
var RESERVED_PARAMETER_NAMES = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1318
|
-
function assertBrowserStableRoutePath(pattern) {
|
|
1319
|
-
if (pattern.includes("\\") || hasControlCharacter(pattern)) {
|
|
1320
|
-
throw new BrowserUnstableRouteError(
|
|
1321
|
-
`Route path "${pattern}" cannot contain backslashes or control characters.`
|
|
1322
|
-
);
|
|
1323
|
-
}
|
|
1324
|
-
for (const segment of pattern.split("/").filter(Boolean)) {
|
|
1325
|
-
if (segment.startsWith("(") && segment.endsWith(")") || segment.startsWith("[") && segment.endsWith("]")) {
|
|
1326
|
-
continue;
|
|
1327
|
-
}
|
|
1328
|
-
let decoded = segment;
|
|
1329
|
-
try {
|
|
1330
|
-
decoded = decodeURIComponent(segment);
|
|
1331
|
-
} catch {
|
|
1332
|
-
}
|
|
1333
|
-
if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || hasControlCharacter(decoded)) {
|
|
1334
|
-
throw new BrowserUnstableRouteError(
|
|
1335
|
-
`Route path "${pattern}" contains browser-unstable segment "${segment}".`
|
|
1336
|
-
);
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
__name(assertBrowserStableRoutePath, "assertBrowserStableRoutePath");
|
|
1341
|
-
function hasControlCharacter(value) {
|
|
1342
|
-
return Array.from(value).some((character) => {
|
|
1343
|
-
const code = character.charCodeAt(0);
|
|
1344
|
-
return code <= 31 || code >= 127 && code <= 159;
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
__name(hasControlCharacter, "hasControlCharacter");
|
|
1348
|
-
function assertUniqueRouteParameters(pattern, syntax = "page") {
|
|
1349
|
-
const parameterPattern = syntax === "router" ? ROUTER_PARAMETER_PATTERN : PAGE_PARAMETER_PATTERN;
|
|
1350
|
-
const names = /* @__PURE__ */ new Set();
|
|
1351
|
-
for (const segment of splitRoutePattern(pattern, syntax)) {
|
|
1352
|
-
const match = parameterPattern.exec(segment);
|
|
1353
|
-
const name = match?.slice(1).find(Boolean);
|
|
1354
|
-
if (!name) continue;
|
|
1355
|
-
if (RESERVED_PARAMETER_NAMES.has(name)) {
|
|
1356
|
-
throw new ReservedRouteParameterError(
|
|
1357
|
-
`Route parameter "${name}" in route "${pattern}" is reserved. Use a different parameter name.`
|
|
1358
|
-
);
|
|
1359
|
-
}
|
|
1360
|
-
if (names.has(name)) {
|
|
1361
|
-
throw new DuplicateRouteParameterError(
|
|
1362
|
-
`Duplicate route parameter "${name}" in route "${pattern}". Each dynamic segment must use a unique name.`
|
|
1363
|
-
);
|
|
1364
|
-
}
|
|
1365
|
-
names.add(name);
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
__name(assertUniqueRouteParameters, "assertUniqueRouteParameters");
|
|
1369
|
-
function splitRoutePattern(pattern, syntax) {
|
|
1370
|
-
return pattern.replace(/\\/g, "/").split("/").filter(Boolean).filter(
|
|
1371
|
-
(segment) => syntax === "api" ? true : !(segment.startsWith("(") && segment.endsWith(")"))
|
|
1372
|
-
);
|
|
1373
|
-
}
|
|
1374
|
-
__name(splitRoutePattern, "splitRoutePattern");
|
|
1375
|
-
function assertTerminalCatchAll(pattern, syntax = "page") {
|
|
1376
|
-
const segments = splitRoutePattern(pattern, syntax);
|
|
1377
|
-
const parameterName = syntax === "router" ? ROUTER_PARAMETER_NAME : ".+";
|
|
1378
|
-
const catchAllPattern = new RegExp(
|
|
1379
|
-
syntax === "router" ? `^(?:\\[\\[\\.\\.\\.${parameterName}\\]\\]|\\[\\.\\.\\.${parameterName}\\]|\\*${parameterName}\\??)$` : `^(?:\\[\\[\\.\\.\\.${parameterName}\\]\\]|\\[\\.\\.\\.${parameterName}\\])$`
|
|
1380
|
-
);
|
|
1381
|
-
const catchAllIndex = segments.findIndex((segment) => catchAllPattern.test(segment));
|
|
1382
|
-
if (catchAllIndex >= 0 && catchAllIndex !== segments.length - 1) {
|
|
1383
|
-
throw new NonTerminalCatchAllRouteError(
|
|
1384
|
-
`Catch-all segment "${segments[catchAllIndex]}" must be the final segment in route "${pattern}".`
|
|
1385
|
-
);
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
__name(assertTerminalCatchAll, "assertTerminalCatchAll");
|
|
1389
10
|
|
|
1390
|
-
// src/route-call-scanner.ts
|
|
1391
|
-
function extractProgrammaticPageCallPathLiterals(source) {
|
|
1392
|
-
const results = /* @__PURE__ */ new Set();
|
|
1393
|
-
const length = source.length;
|
|
1394
|
-
let cursor = 0;
|
|
1395
|
-
const controlParentheses = [];
|
|
1396
|
-
let nextParenthesisIsControl = false;
|
|
1397
|
-
let prev = "none";
|
|
1398
|
-
const isWhitespace = /* @__PURE__ */ __name((char) => char === " " || char === " " || char === "\n" || char === "\r" || char === "\f" || char === "\v", "isWhitespace");
|
|
1399
|
-
const isIdentifierStart = /* @__PURE__ */ __name((char) => /[A-Za-z_$]/.test(char), "isIdentifierStart");
|
|
1400
|
-
const isIdentifierPart = /* @__PURE__ */ __name((char) => /[A-Za-z0-9_$]/.test(char), "isIdentifierPart");
|
|
1401
|
-
const isDigit = /* @__PURE__ */ __name((char) => char >= "0" && char <= "9", "isDigit");
|
|
1402
|
-
const EXPRESSION_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1403
|
-
"return",
|
|
1404
|
-
"typeof",
|
|
1405
|
-
"delete",
|
|
1406
|
-
"void",
|
|
1407
|
-
"new",
|
|
1408
|
-
"throw",
|
|
1409
|
-
"instanceof",
|
|
1410
|
-
"in",
|
|
1411
|
-
"of",
|
|
1412
|
-
"await",
|
|
1413
|
-
"yield",
|
|
1414
|
-
"else",
|
|
1415
|
-
"do",
|
|
1416
|
-
"case"
|
|
1417
|
-
]);
|
|
1418
|
-
const VALUE_KEYWORDS = /* @__PURE__ */ new Set(["true", "false", "null", "this", "super", "undefined"]);
|
|
1419
|
-
const CONTROL_PAREN_KEYWORDS = /* @__PURE__ */ new Set(["if", "for", "while", "switch", "with", "catch"]);
|
|
1420
|
-
const REGEX_CONTEXT = /* @__PURE__ */ new Set([
|
|
1421
|
-
"none",
|
|
1422
|
-
"open",
|
|
1423
|
-
"operator",
|
|
1424
|
-
"keyword",
|
|
1425
|
-
"spread"
|
|
1426
|
-
]);
|
|
1427
|
-
function readIdentifier(start) {
|
|
1428
|
-
let end = start;
|
|
1429
|
-
while (end < length && isIdentifierPart(source[end])) end++;
|
|
1430
|
-
return { end, text: source.slice(start, end) };
|
|
1431
|
-
}
|
|
1432
|
-
__name(readIdentifier, "readIdentifier");
|
|
1433
|
-
function readStringLiteral(start, quote) {
|
|
1434
|
-
let end = start + 1;
|
|
1435
|
-
while (end < length) {
|
|
1436
|
-
const char = source[end];
|
|
1437
|
-
if (char === "\\") {
|
|
1438
|
-
end += 2;
|
|
1439
|
-
continue;
|
|
1440
|
-
}
|
|
1441
|
-
if (char === quote) {
|
|
1442
|
-
return { end: end + 1, content: source.slice(start + 1, end) };
|
|
1443
|
-
}
|
|
1444
|
-
end++;
|
|
1445
|
-
}
|
|
1446
|
-
return null;
|
|
1447
|
-
}
|
|
1448
|
-
__name(readStringLiteral, "readStringLiteral");
|
|
1449
|
-
function readTemplateLiteral(start) {
|
|
1450
|
-
let end = start + 1;
|
|
1451
|
-
let dynamic = false;
|
|
1452
|
-
while (end < length) {
|
|
1453
|
-
const char = source[end];
|
|
1454
|
-
if (char === "\\") {
|
|
1455
|
-
end += 2;
|
|
1456
|
-
continue;
|
|
1457
|
-
}
|
|
1458
|
-
if (char === "`") {
|
|
1459
|
-
return { end: end + 1, content: source.slice(start + 1, end), dynamic };
|
|
1460
|
-
}
|
|
1461
|
-
if (char === "$" && source[end + 1] === "{") {
|
|
1462
|
-
dynamic = true;
|
|
1463
|
-
const after = skipTemplateInterpolation(end + 2);
|
|
1464
|
-
if (after === -1) return null;
|
|
1465
|
-
end = after;
|
|
1466
|
-
continue;
|
|
1467
|
-
}
|
|
1468
|
-
end++;
|
|
1469
|
-
}
|
|
1470
|
-
return null;
|
|
1471
|
-
}
|
|
1472
|
-
__name(readTemplateLiteral, "readTemplateLiteral");
|
|
1473
|
-
function skipTemplateInterpolation(start) {
|
|
1474
|
-
let end = start;
|
|
1475
|
-
let depth = 1;
|
|
1476
|
-
while (end < length && depth > 0) {
|
|
1477
|
-
const char = source[end];
|
|
1478
|
-
if (char === "\\") {
|
|
1479
|
-
end += 2;
|
|
1480
|
-
continue;
|
|
1481
|
-
}
|
|
1482
|
-
if (char === "{") {
|
|
1483
|
-
depth++;
|
|
1484
|
-
end++;
|
|
1485
|
-
continue;
|
|
1486
|
-
}
|
|
1487
|
-
if (char === "}") {
|
|
1488
|
-
depth--;
|
|
1489
|
-
end++;
|
|
1490
|
-
continue;
|
|
1491
|
-
}
|
|
1492
|
-
if (char === '"' || char === "'") {
|
|
1493
|
-
const result = readStringLiteral(end, char);
|
|
1494
|
-
if (!result) return -1;
|
|
1495
|
-
end = result.end;
|
|
1496
|
-
continue;
|
|
1497
|
-
}
|
|
1498
|
-
if (char === "`") {
|
|
1499
|
-
const result = readTemplateLiteral(end);
|
|
1500
|
-
if (!result) return -1;
|
|
1501
|
-
end = result.end;
|
|
1502
|
-
continue;
|
|
1503
|
-
}
|
|
1504
|
-
end++;
|
|
1505
|
-
}
|
|
1506
|
-
return depth === 0 ? end : -1;
|
|
1507
|
-
}
|
|
1508
|
-
__name(skipTemplateInterpolation, "skipTemplateInterpolation");
|
|
1509
|
-
function readRegexLiteral(start) {
|
|
1510
|
-
let end = start + 1;
|
|
1511
|
-
let inClass = false;
|
|
1512
|
-
while (end < length) {
|
|
1513
|
-
const char = source[end];
|
|
1514
|
-
if (char === "\\") {
|
|
1515
|
-
end += 2;
|
|
1516
|
-
continue;
|
|
1517
|
-
}
|
|
1518
|
-
if (char === "[") {
|
|
1519
|
-
inClass = true;
|
|
1520
|
-
end++;
|
|
1521
|
-
continue;
|
|
1522
|
-
}
|
|
1523
|
-
if (char === "]") {
|
|
1524
|
-
inClass = false;
|
|
1525
|
-
end++;
|
|
1526
|
-
continue;
|
|
1527
|
-
}
|
|
1528
|
-
if (char === "/" && !inClass) {
|
|
1529
|
-
end++;
|
|
1530
|
-
while (end < length && source[end] >= "a" && source[end] <= "z") end++;
|
|
1531
|
-
return end;
|
|
1532
|
-
}
|
|
1533
|
-
if (char === "\n") return null;
|
|
1534
|
-
end++;
|
|
1535
|
-
}
|
|
1536
|
-
return null;
|
|
1537
|
-
}
|
|
1538
|
-
__name(readRegexLiteral, "readRegexLiteral");
|
|
1539
|
-
function skipLineComment(start) {
|
|
1540
|
-
let end = start + 2;
|
|
1541
|
-
while (end < length && source[end] !== "\n") end++;
|
|
1542
|
-
return end;
|
|
1543
|
-
}
|
|
1544
|
-
__name(skipLineComment, "skipLineComment");
|
|
1545
|
-
function skipBlockComment(start) {
|
|
1546
|
-
let end = start + 2;
|
|
1547
|
-
while (end < length) {
|
|
1548
|
-
if (source[end] === "*" && source[end + 1] === "/") return end + 2;
|
|
1549
|
-
end++;
|
|
1550
|
-
}
|
|
1551
|
-
return end;
|
|
1552
|
-
}
|
|
1553
|
-
__name(skipBlockComment, "skipBlockComment");
|
|
1554
|
-
function readNumber(start) {
|
|
1555
|
-
const first = source[start];
|
|
1556
|
-
let end = start;
|
|
1557
|
-
if (first === "0") {
|
|
1558
|
-
const prefix = source[start + 1];
|
|
1559
|
-
if (prefix === "x" || prefix === "X" || prefix === "o" || prefix === "O" || prefix === "b" || prefix === "B") {
|
|
1560
|
-
end = start + 2;
|
|
1561
|
-
while (end < length && /[0-9a-fA-F_]/.test(source[end])) end++;
|
|
1562
|
-
if (source[end] === "n") end++;
|
|
1563
|
-
return end;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
while (end < length && (isDigit(source[end]) || source[end] === "_")) end++;
|
|
1567
|
-
if (source[end] === ".") {
|
|
1568
|
-
end++;
|
|
1569
|
-
while (end < length && (isDigit(source[end]) || source[end] === "_")) end++;
|
|
1570
|
-
}
|
|
1571
|
-
if (source[end] === "e" || source[end] === "E") {
|
|
1572
|
-
end++;
|
|
1573
|
-
if (source[end] === "+" || source[end] === "-") end++;
|
|
1574
|
-
while (end < length && (isDigit(source[end]) || source[end] === "_")) end++;
|
|
1575
|
-
}
|
|
1576
|
-
if (source[end] === "n") end++;
|
|
1577
|
-
return end;
|
|
1578
|
-
}
|
|
1579
|
-
__name(readNumber, "readNumber");
|
|
1580
|
-
function classifyWord(text) {
|
|
1581
|
-
if (VALUE_KEYWORDS.has(text)) return "value";
|
|
1582
|
-
if (EXPRESSION_KEYWORDS.has(text)) return "keyword";
|
|
1583
|
-
return "identifier";
|
|
1584
|
-
}
|
|
1585
|
-
__name(classifyWord, "classifyWord");
|
|
1586
|
-
while (cursor < length) {
|
|
1587
|
-
const char = source[cursor];
|
|
1588
|
-
if (isWhitespace(char)) {
|
|
1589
|
-
cursor++;
|
|
1590
|
-
continue;
|
|
1591
|
-
}
|
|
1592
|
-
if (char === "/" && source[cursor + 1] === "/") {
|
|
1593
|
-
cursor = skipLineComment(cursor);
|
|
1594
|
-
continue;
|
|
1595
|
-
}
|
|
1596
|
-
if (char === "/" && source[cursor + 1] === "*") {
|
|
1597
|
-
cursor = skipBlockComment(cursor);
|
|
1598
|
-
continue;
|
|
1599
|
-
}
|
|
1600
|
-
if (char === '"' || char === "'") {
|
|
1601
|
-
const result = readStringLiteral(cursor, char);
|
|
1602
|
-
prev = "value";
|
|
1603
|
-
nextParenthesisIsControl = false;
|
|
1604
|
-
cursor = result ? result.end : length;
|
|
1605
|
-
continue;
|
|
1606
|
-
}
|
|
1607
|
-
if (char === "`") {
|
|
1608
|
-
const result = readTemplateLiteral(cursor);
|
|
1609
|
-
prev = "value";
|
|
1610
|
-
nextParenthesisIsControl = false;
|
|
1611
|
-
cursor = result ? result.end : length;
|
|
1612
|
-
continue;
|
|
1613
|
-
}
|
|
1614
|
-
if (char === "/" && REGEX_CONTEXT.has(prev)) {
|
|
1615
|
-
const end = readRegexLiteral(cursor);
|
|
1616
|
-
if (end !== null) {
|
|
1617
|
-
prev = "value";
|
|
1618
|
-
nextParenthesisIsControl = false;
|
|
1619
|
-
cursor = end;
|
|
1620
|
-
continue;
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
if (isIdentifierStart(char)) {
|
|
1624
|
-
const { end: idEnd, text } = readIdentifier(cursor);
|
|
1625
|
-
const isMemberAccess = prev === "dot" || prev === "questionDot";
|
|
1626
|
-
let next = idEnd;
|
|
1627
|
-
while (next < length && isWhitespace(source[next])) next++;
|
|
1628
|
-
if (!isMemberAccess && (text === "page" || text === "createRoute") && source[next] === "(") {
|
|
1629
|
-
let argStart = next + 1;
|
|
1630
|
-
while (argStart < length && isWhitespace(source[argStart])) argStart++;
|
|
1631
|
-
const quote = source[argStart];
|
|
1632
|
-
if (quote === '"' || quote === "'") {
|
|
1633
|
-
const arg = readStringLiteral(argStart, quote);
|
|
1634
|
-
if (arg) {
|
|
1635
|
-
results.add(arg.content);
|
|
1636
|
-
prev = "value";
|
|
1637
|
-
nextParenthesisIsControl = false;
|
|
1638
|
-
cursor = arg.end;
|
|
1639
|
-
continue;
|
|
1640
|
-
}
|
|
1641
|
-
} else if (quote === "`") {
|
|
1642
|
-
const arg = readTemplateLiteral(argStart);
|
|
1643
|
-
if (arg) {
|
|
1644
|
-
if (!arg.dynamic) results.add(arg.content);
|
|
1645
|
-
prev = "value";
|
|
1646
|
-
nextParenthesisIsControl = false;
|
|
1647
|
-
cursor = arg.end;
|
|
1648
|
-
continue;
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
prev = classifyWord(text);
|
|
1653
|
-
nextParenthesisIsControl = CONTROL_PAREN_KEYWORDS.has(text);
|
|
1654
|
-
cursor = idEnd;
|
|
1655
|
-
continue;
|
|
1656
|
-
}
|
|
1657
|
-
if (isDigit(char) || char === "." && isDigit(source[cursor + 1] || "")) {
|
|
1658
|
-
prev = "value";
|
|
1659
|
-
nextParenthesisIsControl = false;
|
|
1660
|
-
cursor = readNumber(cursor);
|
|
1661
|
-
continue;
|
|
1662
|
-
}
|
|
1663
|
-
if (char === "?" && source[cursor + 1] === ".") {
|
|
1664
|
-
prev = "questionDot";
|
|
1665
|
-
nextParenthesisIsControl = false;
|
|
1666
|
-
cursor += 2;
|
|
1667
|
-
continue;
|
|
1668
|
-
}
|
|
1669
|
-
if (char === "." && source[cursor + 1] === "." && source[cursor + 2] === ".") {
|
|
1670
|
-
prev = "spread";
|
|
1671
|
-
nextParenthesisIsControl = false;
|
|
1672
|
-
cursor += 3;
|
|
1673
|
-
continue;
|
|
1674
|
-
}
|
|
1675
|
-
if (char === "." && source[cursor + 1] === ".") {
|
|
1676
|
-
prev = "operator";
|
|
1677
|
-
nextParenthesisIsControl = false;
|
|
1678
|
-
cursor += 2;
|
|
1679
|
-
continue;
|
|
1680
|
-
}
|
|
1681
|
-
if (char === ".") {
|
|
1682
|
-
prev = "dot";
|
|
1683
|
-
nextParenthesisIsControl = false;
|
|
1684
|
-
cursor += 1;
|
|
1685
|
-
continue;
|
|
1686
|
-
}
|
|
1687
|
-
if (char === "(") {
|
|
1688
|
-
controlParentheses.push(nextParenthesisIsControl);
|
|
1689
|
-
nextParenthesisIsControl = false;
|
|
1690
|
-
prev = "open";
|
|
1691
|
-
cursor++;
|
|
1692
|
-
continue;
|
|
1693
|
-
}
|
|
1694
|
-
if (char === "[" || char === "{") {
|
|
1695
|
-
nextParenthesisIsControl = false;
|
|
1696
|
-
prev = "open";
|
|
1697
|
-
cursor++;
|
|
1698
|
-
continue;
|
|
1699
|
-
}
|
|
1700
|
-
if (char === ")") {
|
|
1701
|
-
prev = controlParentheses.pop() ? "keyword" : "close";
|
|
1702
|
-
nextParenthesisIsControl = false;
|
|
1703
|
-
cursor++;
|
|
1704
|
-
continue;
|
|
1705
|
-
}
|
|
1706
|
-
if (char === "]" || char === "}") {
|
|
1707
|
-
prev = "close";
|
|
1708
|
-
nextParenthesisIsControl = false;
|
|
1709
|
-
cursor++;
|
|
1710
|
-
continue;
|
|
1711
|
-
}
|
|
1712
|
-
prev = "operator";
|
|
1713
|
-
nextParenthesisIsControl = false;
|
|
1714
|
-
cursor++;
|
|
1715
|
-
}
|
|
1716
|
-
return results.size > 0 ? Array.from(results) : [];
|
|
1717
|
-
}
|
|
1718
|
-
__name(extractProgrammaticPageCallPathLiterals, "extractProgrammaticPageCallPathLiterals");
|
|
1719
11
|
|
|
1720
|
-
// src/routes-shared.ts
|
|
1721
|
-
function parseProgrammaticRoutePath(routePath, type = "page") {
|
|
1722
|
-
const fileName = type === "layout" ? "layout.tsx" : "page.tsx";
|
|
1723
|
-
const normalized = normalizeProgrammaticRoutePath(routePath);
|
|
1724
|
-
assertTerminalCatchAll(normalized);
|
|
1725
|
-
assertUniqueRouteParameters(normalized);
|
|
1726
|
-
const filePath = normalized === "/" ? fileName : `${normalized.slice(1).replace(/\/+$/, "")}/${fileName}`;
|
|
1727
|
-
return {
|
|
1728
|
-
filePath,
|
|
1729
|
-
segments: normalized.split("/").filter(Boolean).filter((segment) => !(segment.startsWith("(") && segment.endsWith(")"))).map(parseRouteSegment),
|
|
1730
|
-
type
|
|
1731
|
-
};
|
|
1732
|
-
}
|
|
1733
|
-
__name(parseProgrammaticRoutePath, "parseProgrammaticRoutePath");
|
|
1734
|
-
function normalizeProgrammaticRoutePath(routePath) {
|
|
1735
|
-
if (routePath.includes("?") || routePath.includes("#")) {
|
|
1736
|
-
throw new TypeError(
|
|
1737
|
-
`Programmatic route path "${routePath}" must be a pathname without a query string or hash.`
|
|
1738
|
-
);
|
|
1739
|
-
}
|
|
1740
|
-
const withSlash = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
1741
|
-
const withoutTrailing = withSlash.length > 1 ? withSlash.replace(/\/+$/, "") : withSlash;
|
|
1742
|
-
assertBrowserStableRoutePath(withoutTrailing);
|
|
1743
|
-
return withoutTrailing || "/";
|
|
1744
|
-
}
|
|
1745
|
-
__name(normalizeProgrammaticRoutePath, "normalizeProgrammaticRoutePath");
|
|
1746
|
-
function parseRouteSegment(segment) {
|
|
1747
|
-
if (segment.startsWith("[") && segment.endsWith("]")) {
|
|
1748
|
-
let name = segment.slice(1, -1);
|
|
1749
|
-
let isOptional = false;
|
|
1750
|
-
let isCatchAll = false;
|
|
1751
|
-
if (name.startsWith("[") && name.endsWith("]")) {
|
|
1752
|
-
isOptional = true;
|
|
1753
|
-
name = name.slice(1, -1);
|
|
1754
|
-
}
|
|
1755
|
-
if (name.startsWith("...")) {
|
|
1756
|
-
isCatchAll = true;
|
|
1757
|
-
name = name.slice(3);
|
|
1758
|
-
}
|
|
1759
|
-
return { segment: name, isDynamic: true, isOptional, isCatchAll };
|
|
1760
|
-
}
|
|
1761
|
-
return { segment, isDynamic: false, isOptional: false, isCatchAll: false };
|
|
1762
|
-
}
|
|
1763
|
-
__name(parseRouteSegment, "parseRouteSegment");
|
|
1764
12
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
...options
|
|
1807
|
-
});
|
|
1808
|
-
},
|
|
1809
|
-
api(path, options) {
|
|
1810
|
-
const { render, runtime: runtime3, regions, maxDuration, ...methods } = options;
|
|
1811
|
-
return normalizeProgrammaticRoute({
|
|
1812
|
-
kind: "api",
|
|
1813
|
-
path,
|
|
1814
|
-
render,
|
|
1815
|
-
runtime: runtime3,
|
|
1816
|
-
regions,
|
|
1817
|
-
maxDuration,
|
|
1818
|
-
methods: normalizeApiMethods(methods)
|
|
1819
|
-
});
|
|
1820
|
-
},
|
|
1821
|
-
redirect(source, destination, options = {}) {
|
|
1822
|
-
return normalizeProgrammaticRoute({
|
|
1823
|
-
kind: "redirect",
|
|
1824
|
-
source,
|
|
1825
|
-
destination,
|
|
1826
|
-
...options
|
|
1827
|
-
});
|
|
1828
|
-
}
|
|
1829
|
-
};
|
|
1830
|
-
var page = routesBuilder.page;
|
|
1831
|
-
var layout = routesBuilder.layout;
|
|
1832
|
-
var api = routesBuilder.api;
|
|
1833
|
-
var redirect = routesBuilder.redirect;
|
|
1834
|
-
function getProgrammaticRouteSearchSchema(search) {
|
|
1835
|
-
if (!search) return void 0;
|
|
1836
|
-
if (isProgrammaticRouteSchema(search)) return search;
|
|
1837
|
-
return search.schema;
|
|
1838
|
-
}
|
|
1839
|
-
__name(getProgrammaticRouteSearchSchema, "getProgrammaticRouteSearchSchema");
|
|
1840
|
-
function getProgrammaticRouteSearchClientOptions(search) {
|
|
1841
|
-
if (!search || isProgrammaticRouteSchema(search)) return void 0;
|
|
1842
|
-
const options = {};
|
|
1843
|
-
if (typeof search.stripDefaults !== "undefined") options.stripDefaults = search.stripDefaults;
|
|
1844
|
-
if (search.preserve?.length) options.preserve = [...search.preserve];
|
|
1845
|
-
if (search.temporary?.length) options.temporary = [...search.temporary];
|
|
1846
|
-
return Object.keys(options).length > 0 ? options : void 0;
|
|
1847
|
-
}
|
|
1848
|
-
__name(getProgrammaticRouteSearchClientOptions, "getProgrammaticRouteSearchClientOptions");
|
|
1849
|
-
function resolveProgrammaticRouteSearch(searchConfig, rawSearch, path, routePath) {
|
|
1850
|
-
const schema = getProgrammaticRouteSearchSchema(searchConfig);
|
|
1851
|
-
const search = parseProgrammaticSchema(schema, rawSearch, "search", routePath);
|
|
1852
|
-
const options = getProgrammaticRouteSearchOptions(searchConfig);
|
|
1853
|
-
const canonicalPath = resolveProgrammaticRouteCanonicalPath({
|
|
1854
|
-
options,
|
|
1855
|
-
schema,
|
|
1856
|
-
rawSearch,
|
|
1857
|
-
parsedSearch: search,
|
|
1858
|
-
path
|
|
1859
|
-
});
|
|
1860
|
-
return { search, canonicalPath };
|
|
1861
|
-
}
|
|
1862
|
-
__name(resolveProgrammaticRouteSearch, "resolveProgrammaticRouteSearch");
|
|
1863
|
-
function getProgrammaticRouteSearchOptions(search) {
|
|
1864
|
-
if (!search || isProgrammaticRouteSchema(search)) return void 0;
|
|
1865
|
-
return search;
|
|
1866
|
-
}
|
|
1867
|
-
__name(getProgrammaticRouteSearchOptions, "getProgrammaticRouteSearchOptions");
|
|
1868
|
-
function isProgrammaticRouteSchema(value) {
|
|
1869
|
-
return !!value && typeof value === "object" && typeof value.parse === "function";
|
|
1870
|
-
}
|
|
1871
|
-
__name(isProgrammaticRouteSchema, "isProgrammaticRouteSchema");
|
|
1872
|
-
function resolveProgrammaticRouteCanonicalPath(input) {
|
|
1873
|
-
const options = input.options;
|
|
1874
|
-
if (!options?.temporary?.length && !options?.stripDefaults) {
|
|
1875
|
-
return void 0;
|
|
1876
|
-
}
|
|
1877
|
-
const params = createSearchParams(input.rawSearch);
|
|
1878
|
-
const original = params.toString();
|
|
1879
|
-
for (const key of options.temporary || []) {
|
|
1880
|
-
params.delete(key);
|
|
1881
|
-
}
|
|
1882
|
-
if (options.stripDefaults) {
|
|
1883
|
-
const defaultSearch = parseDefaultSearch(input.schema);
|
|
1884
|
-
if (defaultSearch !== void 0) {
|
|
1885
|
-
const keys = options.stripDefaults === true ? Array.from(new Set(Array.from(params.keys()))) : [...options.stripDefaults];
|
|
1886
|
-
for (const key of keys) {
|
|
1887
|
-
if (params.has(key) && searchValuesEqual(
|
|
1888
|
-
readSearchValue(input.parsedSearch, key),
|
|
1889
|
-
readSearchValue(defaultSearch, key)
|
|
1890
|
-
)) {
|
|
1891
|
-
params.delete(key);
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
const next = params.toString();
|
|
1897
|
-
if (next === original) {
|
|
1898
|
-
return void 0;
|
|
1899
|
-
}
|
|
1900
|
-
return next ? `${input.path}?${next}` : input.path;
|
|
1901
|
-
}
|
|
1902
|
-
__name(resolveProgrammaticRouteCanonicalPath, "resolveProgrammaticRouteCanonicalPath");
|
|
1903
|
-
function createSearchParams(value) {
|
|
1904
|
-
const params = new URLSearchParams();
|
|
1905
|
-
for (const [key, item] of Object.entries(value)) {
|
|
1906
|
-
if (item == null) continue;
|
|
1907
|
-
const values = Array.isArray(item) ? item : [item];
|
|
1908
|
-
for (const entry of values) {
|
|
1909
|
-
if (entry != null) params.append(key, String(entry));
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
return params;
|
|
1913
|
-
}
|
|
1914
|
-
__name(createSearchParams, "createSearchParams");
|
|
1915
|
-
function parseDefaultSearch(schema) {
|
|
1916
|
-
if (!schema) return void 0;
|
|
1917
|
-
try {
|
|
1918
|
-
const value = schema.parse({});
|
|
1919
|
-
return value && typeof value === "object" ? value : void 0;
|
|
1920
|
-
} catch {
|
|
1921
|
-
return void 0;
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
__name(parseDefaultSearch, "parseDefaultSearch");
|
|
1925
|
-
function readSearchValue(value, key) {
|
|
1926
|
-
return value && typeof value === "object" ? value[key] : void 0;
|
|
1927
|
-
}
|
|
1928
|
-
__name(readSearchValue, "readSearchValue");
|
|
1929
|
-
function searchValuesEqual(left, right) {
|
|
1930
|
-
return JSON.stringify(normalizeComparableValue(left)) === JSON.stringify(normalizeComparableValue(right));
|
|
1931
|
-
}
|
|
1932
|
-
__name(searchValuesEqual, "searchValuesEqual");
|
|
1933
|
-
function normalizeComparableValue(value) {
|
|
1934
|
-
if (Array.isArray(value)) {
|
|
1935
|
-
return value.map(normalizeComparableValue);
|
|
1936
|
-
}
|
|
1937
|
-
if (value && typeof value === "object") {
|
|
1938
|
-
return Object.keys(value).sort().reduce((output, key) => {
|
|
1939
|
-
output[key] = normalizeComparableValue(value[key]);
|
|
1940
|
-
return output;
|
|
1941
|
-
}, {});
|
|
1942
|
-
}
|
|
1943
|
-
return value;
|
|
1944
|
-
}
|
|
1945
|
-
__name(normalizeComparableValue, "normalizeComparableValue");
|
|
1946
|
-
function createRoute(path, options) {
|
|
1947
|
-
return routesBuilder.page(path, options);
|
|
1948
|
-
}
|
|
1949
|
-
__name(createRoute, "createRoute");
|
|
1950
|
-
function isProgrammaticRoutesFileName(fileName) {
|
|
1951
|
-
const normalized = fileName.replace(/\\/g, "/");
|
|
1952
|
-
const baseName = normalized.split("/").pop() || normalized;
|
|
1953
|
-
return PROGRAMMATIC_ROUTE_FILE_NAMES.includes(baseName);
|
|
1954
|
-
}
|
|
1955
|
-
__name(isProgrammaticRoutesFileName, "isProgrammaticRoutesFileName");
|
|
1956
|
-
function getProgrammaticRouteManifest(mod) {
|
|
1957
|
-
if (!mod) return null;
|
|
1958
|
-
const candidates = [mod.default, mod.routes, mod.Route];
|
|
1959
|
-
for (const candidate of candidates) {
|
|
1960
|
-
if (isProgrammaticRouteManifest(candidate)) {
|
|
1961
|
-
return candidate;
|
|
1962
|
-
}
|
|
1963
|
-
if (isProgrammaticRouteDefinition(candidate)) {
|
|
1964
|
-
return defineRoutes([candidate]);
|
|
1965
|
-
}
|
|
1966
|
-
if (Array.isArray(candidate)) {
|
|
1967
|
-
return defineRoutes(candidate);
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
const routeDefinitions = Object.values(mod).filter(isProgrammaticRouteDefinition);
|
|
1971
|
-
if (routeDefinitions.length > 0) {
|
|
1972
|
-
return defineRoutes(routeDefinitions);
|
|
1973
|
-
}
|
|
1974
|
-
return null;
|
|
1975
|
-
}
|
|
1976
|
-
__name(getProgrammaticRouteManifest, "getProgrammaticRouteManifest");
|
|
1977
|
-
function isProgrammaticRouteManifest(value) {
|
|
1978
|
-
return !!value && typeof value === "object" && value.__farmRoutes === true && Array.isArray(value.routes);
|
|
1979
|
-
}
|
|
1980
|
-
__name(isProgrammaticRouteManifest, "isProgrammaticRouteManifest");
|
|
1981
|
-
function isProgrammaticRouteDefinition(value) {
|
|
1982
|
-
if (!value || typeof value !== "object") {
|
|
1983
|
-
return false;
|
|
1984
|
-
}
|
|
1985
|
-
const kind = value.kind;
|
|
1986
|
-
return kind === "page" || kind === "layout" || kind === "api" || kind === "redirect";
|
|
1987
|
-
}
|
|
1988
|
-
__name(isProgrammaticRouteDefinition, "isProgrammaticRouteDefinition");
|
|
1989
|
-
function createProgrammaticRouteModuleId(filePath, kind, routePath) {
|
|
1990
|
-
return `${filePath}?farm-route=${kind}:${encodeURIComponent(normalizeRoutePath(routePath))}&lang.js`;
|
|
1991
|
-
}
|
|
1992
|
-
__name(createProgrammaticRouteModuleId, "createProgrammaticRouteModuleId");
|
|
1993
|
-
function parseProgrammaticRouteModuleId(moduleId) {
|
|
1994
|
-
const queryIndex = moduleId.indexOf("?");
|
|
1995
|
-
if (queryIndex === -1) {
|
|
1996
|
-
return null;
|
|
1997
|
-
}
|
|
1998
|
-
const filePath = moduleId.slice(0, queryIndex);
|
|
1999
|
-
const params = new URLSearchParams(moduleId.slice(queryIndex + 1));
|
|
2000
|
-
const value = params.get("farm-route");
|
|
2001
|
-
if (!value) {
|
|
2002
|
-
return null;
|
|
2003
|
-
}
|
|
2004
|
-
const separator = value.indexOf(":");
|
|
2005
|
-
if (separator === -1) {
|
|
2006
|
-
return null;
|
|
2007
|
-
}
|
|
2008
|
-
const kind = value.slice(0, separator);
|
|
2009
|
-
if (kind !== "page" && kind !== "layout" && kind !== "api") {
|
|
2010
|
-
return null;
|
|
2011
|
-
}
|
|
2012
|
-
return {
|
|
2013
|
-
filePath,
|
|
2014
|
-
kind,
|
|
2015
|
-
routePath: normalizeRoutePath(value.slice(separator + 1))
|
|
2016
|
-
};
|
|
2017
|
-
}
|
|
2018
|
-
__name(parseProgrammaticRouteModuleId, "parseProgrammaticRouteModuleId");
|
|
2019
|
-
function parseProgrammaticRoutePath2(routePath, type = "page") {
|
|
2020
|
-
return parseProgrammaticRoutePath(routePath, type);
|
|
2021
|
-
}
|
|
2022
|
-
__name(parseProgrammaticRoutePath2, "parseProgrammaticRoutePath");
|
|
2023
|
-
function createRouteModuleFromProgrammaticPage(route, rendererRuntime) {
|
|
2024
|
-
const mod = {
|
|
2025
|
-
default: createProgrammaticPageComponent(route, rendererRuntime),
|
|
2026
|
-
...normalizeFarmRouteRuntimeConfig(route, `Route "${route.path}"`)
|
|
2027
|
-
};
|
|
2028
|
-
if (route.params || route.search || route.guard || route.data) {
|
|
2029
|
-
mod.__farmRouteSchemas = {
|
|
2030
|
-
params: route.params,
|
|
2031
|
-
search: getProgrammaticRouteSearchSchema(route.search)
|
|
2032
|
-
};
|
|
2033
|
-
mod.__farmRouteSearch = getProgrammaticRouteSearchClientOptions(route.search);
|
|
2034
|
-
mod.__farmRouteGuard = route.guard;
|
|
2035
|
-
mod.__farmRouteData = route.data;
|
|
2036
|
-
mod.__farmRouteParsesProps = true;
|
|
2037
|
-
mod.__farmResolveRouteProps = (props) => resolveProgrammaticRouteProps(route, props);
|
|
2038
|
-
mod.__farmResolveRouteCanonicalPath = (rawSearch, path) => resolveProgrammaticRouteSearch(route.search, rawSearch, path, route.path).canonicalPath;
|
|
2039
|
-
}
|
|
2040
|
-
if (route.pending || route.error || route.notFound) {
|
|
2041
|
-
mod.__farmRouteComponents = {
|
|
2042
|
-
pending: route.pending,
|
|
2043
|
-
error: route.error,
|
|
2044
|
-
notFound: route.notFound
|
|
2045
|
-
};
|
|
2046
|
-
}
|
|
2047
|
-
if (route.render === "static" || route.staticPaths) {
|
|
2048
|
-
mod.ssg = true;
|
|
2049
|
-
mod.dynamic = "force-static";
|
|
2050
|
-
} else if (route.render === "dynamic") {
|
|
2051
|
-
mod.ssg = false;
|
|
2052
|
-
mod.dynamic = "force-dynamic";
|
|
2053
|
-
}
|
|
2054
|
-
if (typeof route.revalidate !== "undefined") {
|
|
2055
|
-
mod.revalidate = route.revalidate;
|
|
2056
|
-
}
|
|
2057
|
-
if (route.ppr) {
|
|
2058
|
-
mod.ppr = true;
|
|
2059
|
-
}
|
|
2060
|
-
if (route.metadata) {
|
|
2061
|
-
mod.metadata = route.metadata;
|
|
2062
|
-
}
|
|
2063
|
-
if (route.generateMetadata) {
|
|
2064
|
-
mod.generateMetadata = route.generateMetadata;
|
|
2065
|
-
}
|
|
2066
|
-
if (route.staticPaths) {
|
|
2067
|
-
mod.getStaticPaths = async () => normalizeStaticPaths(route.path, await route.staticPaths());
|
|
2068
|
-
}
|
|
2069
|
-
return mod;
|
|
2070
|
-
}
|
|
2071
|
-
__name(createRouteModuleFromProgrammaticPage, "createRouteModuleFromProgrammaticPage");
|
|
2072
|
-
function createLayoutModuleFromProgrammaticLayout(route) {
|
|
2073
|
-
return {
|
|
2074
|
-
default: route.component,
|
|
2075
|
-
...normalizeFarmRouteRuntimeConfig(route, `Layout "${route.path}"`),
|
|
2076
|
-
metadata: route.metadata,
|
|
2077
|
-
generateMetadata: route.generateMetadata
|
|
2078
|
-
};
|
|
2079
|
-
}
|
|
2080
|
-
__name(createLayoutModuleFromProgrammaticLayout, "createLayoutModuleFromProgrammaticLayout");
|
|
2081
|
-
function scanProgrammaticPagePaths(source) {
|
|
2082
|
-
const paths = /* @__PURE__ */ new Set();
|
|
2083
|
-
for (const routePath of extractProgrammaticPageCallPathLiterals(source)) {
|
|
2084
|
-
if (routePath) {
|
|
2085
|
-
paths.add(normalizeRoutePath(routePath));
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
return Array.from(paths);
|
|
2089
|
-
}
|
|
2090
|
-
__name(scanProgrammaticPagePaths, "scanProgrammaticPagePaths");
|
|
2091
|
-
function createProgrammaticPageComponent(route, rendererRuntime) {
|
|
2092
|
-
if (!route.params && !route.search && !route.guard && !route.data && !route.pending && !route.error && !route.notFound) {
|
|
2093
|
-
return route.component;
|
|
2094
|
-
}
|
|
2095
|
-
const createElement = /* @__PURE__ */ __name((...args) => {
|
|
2096
|
-
if (!rendererRuntime) {
|
|
2097
|
-
throw new Error(
|
|
2098
|
-
`Programmatic route "${route.path}" requires a FARMJS renderer runtime before it can render.`
|
|
2099
|
-
);
|
|
2100
|
-
}
|
|
2101
|
-
return rendererRuntime.createElement(...args);
|
|
2102
|
-
}, "createElement");
|
|
2103
|
-
const markFunctionComponent = /* @__PURE__ */ __name((component) => rendererRuntime?.markFunctionComponent?.(component) ?? component, "markFunctionComponent");
|
|
2104
|
-
const Component = route.component;
|
|
2105
|
-
if (route.pending) {
|
|
2106
|
-
const PendingComponent = route.pending;
|
|
2107
|
-
const routePropsResources = /* @__PURE__ */ new WeakMap();
|
|
2108
|
-
const FarmProgrammaticPageContent2 = /* @__PURE__ */ __name(function FarmProgrammaticPageContent3(props) {
|
|
2109
|
-
try {
|
|
2110
|
-
const resolvedProps = readProgrammaticRouteProps(route, props, routePropsResources);
|
|
2111
|
-
return createElement(Component, stripProgrammaticRoutePropsMarker(resolvedProps));
|
|
2112
|
-
} catch (error) {
|
|
2113
|
-
if (isPromiseLike(error) || isProgrammaticRedirectSignal(error)) {
|
|
2114
|
-
throw error;
|
|
2115
|
-
}
|
|
2116
|
-
if (isProgrammaticNotFoundSignal(error) && route.notFound) {
|
|
2117
|
-
return createElement(route.notFound, createProgrammaticRouteErrorProps(error, props));
|
|
2118
|
-
}
|
|
2119
|
-
if (route.error) {
|
|
2120
|
-
return createElement(route.error, createProgrammaticRouteErrorProps(error, props));
|
|
2121
|
-
}
|
|
2122
|
-
throw error;
|
|
2123
|
-
}
|
|
2124
|
-
}, "FarmProgrammaticPageContent");
|
|
2125
|
-
const PageContent = markFunctionComponent(
|
|
2126
|
-
FarmProgrammaticPageContent2
|
|
2127
|
-
);
|
|
2128
|
-
const FarmProgrammaticPage = /* @__PURE__ */ __name(function FarmProgrammaticPage2(props) {
|
|
2129
|
-
return createElement(
|
|
2130
|
-
rendererRuntime.Suspense,
|
|
2131
|
-
{
|
|
2132
|
-
fallback: createElement(PendingComponent, createProgrammaticRoutePendingProps(props))
|
|
2133
|
-
},
|
|
2134
|
-
createElement(PageContent, props)
|
|
2135
|
-
);
|
|
2136
|
-
}, "FarmProgrammaticPage");
|
|
2137
|
-
return markFunctionComponent(FarmProgrammaticPage);
|
|
2138
|
-
}
|
|
2139
|
-
const FarmProgrammaticPageContent = /* @__PURE__ */ __name(async function FarmProgrammaticPageContent2(props) {
|
|
2140
|
-
try {
|
|
2141
|
-
const resolvedProps = isProgrammaticRoutePropsResolved(props) ? props : await resolveProgrammaticRouteProps(route, props);
|
|
2142
|
-
return createElement(Component, stripProgrammaticRoutePropsMarker(resolvedProps));
|
|
2143
|
-
} catch (error) {
|
|
2144
|
-
if (isProgrammaticRedirectSignal(error)) {
|
|
2145
|
-
throw error;
|
|
2146
|
-
}
|
|
2147
|
-
if (isProgrammaticNotFoundSignal(error) && route.notFound) {
|
|
2148
|
-
return createElement(route.notFound, createProgrammaticRouteErrorProps(error, props));
|
|
2149
|
-
}
|
|
2150
|
-
if (route.error) {
|
|
2151
|
-
return createElement(route.error, createProgrammaticRouteErrorProps(error, props));
|
|
2152
|
-
}
|
|
2153
|
-
throw error;
|
|
2154
|
-
}
|
|
2155
|
-
}, "FarmProgrammaticPageContent");
|
|
2156
|
-
return markFunctionComponent(FarmProgrammaticPageContent);
|
|
2157
|
-
}
|
|
2158
|
-
__name(createProgrammaticPageComponent, "createProgrammaticPageComponent");
|
|
2159
|
-
function readProgrammaticRouteProps(route, props, resources) {
|
|
2160
|
-
if (isProgrammaticRoutePropsResolved(props)) {
|
|
2161
|
-
return props;
|
|
2162
|
-
}
|
|
2163
|
-
let resource = resources.get(props);
|
|
2164
|
-
if (!resource) {
|
|
2165
|
-
const deferredRouteProps = props.__farmRoutePropsPromise;
|
|
2166
|
-
const promise = Promise.resolve(
|
|
2167
|
-
isPromiseLike(deferredRouteProps) ? deferredRouteProps : resolveProgrammaticRouteProps(route, props)
|
|
2168
|
-
);
|
|
2169
|
-
resource = { status: "pending", promise };
|
|
2170
|
-
resources.set(props, resource);
|
|
2171
|
-
promise.then(
|
|
2172
|
-
(value) => resources.set(props, { status: "resolved", value }),
|
|
2173
|
-
(error) => resources.set(props, { status: "rejected", error })
|
|
2174
|
-
);
|
|
2175
|
-
}
|
|
2176
|
-
if (resource.status === "pending") throw resource.promise;
|
|
2177
|
-
if (resource.status === "rejected") throw resource.error;
|
|
2178
|
-
return resource.value;
|
|
2179
|
-
}
|
|
2180
|
-
__name(readProgrammaticRouteProps, "readProgrammaticRouteProps");
|
|
2181
|
-
function isPromiseLike(value) {
|
|
2182
|
-
return Boolean(
|
|
2183
|
-
value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function"
|
|
2184
|
-
);
|
|
2185
|
-
}
|
|
2186
|
-
__name(isPromiseLike, "isPromiseLike");
|
|
2187
|
-
function createProgrammaticRoutePendingProps(props) {
|
|
2188
|
-
return {
|
|
2189
|
-
params: props.params,
|
|
2190
|
-
searchParams: props.searchParams,
|
|
2191
|
-
path: props.path
|
|
2192
|
-
};
|
|
2193
|
-
}
|
|
2194
|
-
__name(createProgrammaticRoutePendingProps, "createProgrammaticRoutePendingProps");
|
|
2195
|
-
function createProgrammaticRouteErrorProps(error, props) {
|
|
2196
|
-
return {
|
|
2197
|
-
error,
|
|
2198
|
-
params: props.params,
|
|
2199
|
-
searchParams: props.searchParams,
|
|
2200
|
-
path: props.path
|
|
2201
|
-
};
|
|
2202
|
-
}
|
|
2203
|
-
__name(createProgrammaticRouteErrorProps, "createProgrammaticRouteErrorProps");
|
|
2204
|
-
function isProgrammaticRedirectSignal(error) {
|
|
2205
|
-
if (!error || typeof error !== "object") return false;
|
|
2206
|
-
const digest = error.digest;
|
|
2207
|
-
return typeof digest === "string" && digest.startsWith("FARM_REDIRECT;");
|
|
2208
|
-
}
|
|
2209
|
-
__name(isProgrammaticRedirectSignal, "isProgrammaticRedirectSignal");
|
|
2210
|
-
function isProgrammaticNotFoundSignal(error) {
|
|
2211
|
-
if (!error || typeof error !== "object") return false;
|
|
2212
|
-
const digest = error.digest;
|
|
2213
|
-
return digest === "FARM_NOT_FOUND";
|
|
2214
|
-
}
|
|
2215
|
-
__name(isProgrammaticNotFoundSignal, "isProgrammaticNotFoundSignal");
|
|
2216
|
-
async function resolveProgrammaticRouteProps(route, props) {
|
|
2217
|
-
const rawSearch = await props.searchParams;
|
|
2218
|
-
const params = parseProgrammaticSchema(route.params, props.params, "params", route.path);
|
|
2219
|
-
const { search, canonicalPath } = resolveProgrammaticRouteSearch(
|
|
2220
|
-
route.search,
|
|
2221
|
-
rawSearch,
|
|
2222
|
-
props.path,
|
|
2223
|
-
route.path
|
|
2224
|
-
);
|
|
2225
|
-
const routeContextValue = getFarmRouteContext(props);
|
|
2226
|
-
const pluginContext = props.context;
|
|
2227
|
-
const baseProps = {
|
|
2228
|
-
...props,
|
|
2229
|
-
params,
|
|
2230
|
-
search,
|
|
2231
|
-
searchParams: Promise.resolve(search)
|
|
2232
|
-
};
|
|
2233
|
-
const routeContextProps = {
|
|
2234
|
-
...baseProps,
|
|
2235
|
-
context: routeContextValue,
|
|
2236
|
-
pluginContext
|
|
2237
|
-
};
|
|
2238
|
-
if (route.guard) {
|
|
2239
|
-
await route.guard(routeContextProps);
|
|
2240
|
-
}
|
|
2241
|
-
if (!route.data) {
|
|
2242
|
-
return markProgrammaticRoutePropsResolved(addCanonicalPath(baseProps, canonicalPath));
|
|
2243
|
-
}
|
|
2244
|
-
const before = route.data.before ? await route.data.before(routeContextProps) : void 0;
|
|
2245
|
-
const dataContext = {
|
|
2246
|
-
...routeContextProps,
|
|
2247
|
-
before
|
|
2248
|
-
};
|
|
2249
|
-
const data = await resolveProgrammaticRouteData(route, route.data, dataContext);
|
|
2250
|
-
if (route.data.after) {
|
|
2251
|
-
await route.data.after({
|
|
2252
|
-
...routeContextProps,
|
|
2253
|
-
before,
|
|
2254
|
-
data
|
|
2255
|
-
});
|
|
2256
|
-
}
|
|
2257
|
-
return markProgrammaticRoutePropsResolved({
|
|
2258
|
-
...baseProps,
|
|
2259
|
-
data,
|
|
2260
|
-
...canonicalPath ? { __farmCanonicalPath: canonicalPath } : {}
|
|
2261
|
-
});
|
|
2262
|
-
}
|
|
2263
|
-
__name(resolveProgrammaticRouteProps, "resolveProgrammaticRouteProps");
|
|
2264
|
-
async function resolveProgrammaticRouteData(route, dataHooks, context2) {
|
|
2265
|
-
if (!dataHooks?.key) {
|
|
2266
|
-
return dataHooks.main(context2);
|
|
2267
|
-
}
|
|
2268
|
-
const routeDataKey = await dataHooks.key(context2);
|
|
2269
|
-
if (routeDataKey == null) {
|
|
2270
|
-
return dataHooks.main(context2);
|
|
2271
|
-
}
|
|
2272
|
-
const cacheKey = createFarmCacheKey(["route-data", routeDataKey]);
|
|
2273
|
-
const cacheOptions = {
|
|
2274
|
-
tags: [
|
|
2275
|
-
createRouteDataCacheTag(routeDataKey),
|
|
2276
|
-
...await resolveProgrammaticRouteDataKeys(dataHooks.tags, context2)
|
|
2277
|
-
],
|
|
2278
|
-
paths: [
|
|
2279
|
-
...typeof context2.path === "string" ? [context2.path] : [],
|
|
2280
|
-
...await resolveProgrammaticRouteDataKeys(dataHooks.paths, context2)
|
|
2281
|
-
],
|
|
2282
|
-
revalidate: normalizeProgrammaticRouteStaleTime(dataHooks.staleTime)
|
|
2283
|
-
};
|
|
2284
|
-
return getFarmDataCache().getOrSet(cacheKey, () => dataHooks.main(context2), cacheOptions);
|
|
2285
|
-
}
|
|
2286
|
-
__name(resolveProgrammaticRouteData, "resolveProgrammaticRouteData");
|
|
2287
|
-
async function resolveProgrammaticRouteDataKeys(input, context2) {
|
|
2288
|
-
if (!input) return [];
|
|
2289
|
-
const value = typeof input === "function" ? await input(context2) : input;
|
|
2290
|
-
return value.filter((item) => typeof item === "string" && item.trim().length > 0);
|
|
2291
|
-
}
|
|
2292
|
-
__name(resolveProgrammaticRouteDataKeys, "resolveProgrammaticRouteDataKeys");
|
|
2293
|
-
function normalizeProgrammaticRouteStaleTime(staleTime) {
|
|
2294
|
-
if (staleTime === void 0) return void 0;
|
|
2295
|
-
if (staleTime === false) return false;
|
|
2296
|
-
if (typeof staleTime === "number") {
|
|
2297
|
-
if (!Number.isFinite(staleTime) || staleTime <= 0) return void 0;
|
|
2298
|
-
return Math.max(1, Math.ceil(staleTime / 1e3));
|
|
2299
|
-
}
|
|
2300
|
-
const match = staleTime.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)$/);
|
|
2301
|
-
if (!match) return void 0;
|
|
2302
|
-
const value = Number(match[1]);
|
|
2303
|
-
if (!Number.isFinite(value) || value <= 0) return void 0;
|
|
2304
|
-
const unit = match[2];
|
|
2305
|
-
const milliseconds = unit === "ms" ? value : unit === "s" ? value * 1e3 : unit === "m" ? value * 6e4 : value * 36e5;
|
|
2306
|
-
return Math.max(1, Math.ceil(milliseconds / 1e3));
|
|
2307
|
-
}
|
|
2308
|
-
__name(normalizeProgrammaticRouteStaleTime, "normalizeProgrammaticRouteStaleTime");
|
|
2309
|
-
function isProgrammaticRoutePropsResolved(value) {
|
|
2310
|
-
return !!value && typeof value === "object" && value.__farmRoutePropsResolved === true;
|
|
2311
|
-
}
|
|
2312
|
-
__name(isProgrammaticRoutePropsResolved, "isProgrammaticRoutePropsResolved");
|
|
2313
|
-
function markProgrammaticRoutePropsResolved(props) {
|
|
2314
|
-
return {
|
|
2315
|
-
...props,
|
|
2316
|
-
__farmRoutePropsResolved: true
|
|
2317
|
-
};
|
|
2318
|
-
}
|
|
2319
|
-
__name(markProgrammaticRoutePropsResolved, "markProgrammaticRoutePropsResolved");
|
|
2320
|
-
function addCanonicalPath(props, canonicalPath) {
|
|
2321
|
-
return canonicalPath ? { ...props, __farmCanonicalPath: canonicalPath } : props;
|
|
2322
|
-
}
|
|
2323
|
-
__name(addCanonicalPath, "addCanonicalPath");
|
|
2324
|
-
function stripProgrammaticRoutePropsMarker(props) {
|
|
2325
|
-
if (!isProgrammaticRoutePropsResolved(props)) {
|
|
2326
|
-
return props;
|
|
2327
|
-
}
|
|
2328
|
-
const {
|
|
2329
|
-
__farmRoutePropsResolved,
|
|
2330
|
-
__farmCanonicalPath,
|
|
2331
|
-
__farmRoutePropsPromise,
|
|
2332
|
-
...componentProps
|
|
2333
|
-
} = props;
|
|
2334
|
-
return componentProps;
|
|
2335
|
-
}
|
|
2336
|
-
__name(stripProgrammaticRoutePropsMarker, "stripProgrammaticRoutePropsMarker");
|
|
2337
|
-
function parseProgrammaticSchema(schema, value, label, routePath) {
|
|
2338
|
-
if (!schema) {
|
|
2339
|
-
return value;
|
|
2340
|
-
}
|
|
2341
|
-
try {
|
|
2342
|
-
return schema.parse(value);
|
|
2343
|
-
} catch (error) {
|
|
2344
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2345
|
-
throw new Error(`Invalid ${label} for route "${routePath}": ${message}`);
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
__name(parseProgrammaticSchema, "parseProgrammaticSchema");
|
|
2349
|
-
function normalizeProgrammaticRoute(route) {
|
|
2350
|
-
if (route.kind === "redirect") {
|
|
2351
|
-
return {
|
|
2352
|
-
...route,
|
|
2353
|
-
source: normalizeRoutePath(route.source)
|
|
2354
|
-
};
|
|
2355
|
-
}
|
|
2356
|
-
if (route.kind === "api") {
|
|
2357
|
-
return {
|
|
2358
|
-
...route,
|
|
2359
|
-
...normalizeFarmRouteRuntimeConfig(route, `API route "${route.path}"`),
|
|
2360
|
-
path: normalizeRoutePath(route.path),
|
|
2361
|
-
methods: normalizeApiMethods(route.methods)
|
|
2362
|
-
};
|
|
2363
|
-
}
|
|
2364
|
-
const routeActions = route.kind === "page" ? normalizeProgrammaticRouteActions(route) : void 0;
|
|
2365
|
-
return {
|
|
2366
|
-
...route,
|
|
2367
|
-
...routeActions,
|
|
2368
|
-
...normalizeFarmRouteRuntimeConfig(
|
|
2369
|
-
route,
|
|
2370
|
-
`${route.kind === "layout" ? "Layout" : "Route"} "${route.path}"`
|
|
2371
|
-
),
|
|
2372
|
-
path: normalizeRoutePath(route.path)
|
|
2373
|
-
};
|
|
2374
|
-
}
|
|
2375
|
-
__name(normalizeProgrammaticRoute, "normalizeProgrammaticRoute");
|
|
2376
|
-
function normalizeProgrammaticRouteActions(route) {
|
|
2377
|
-
const entries = Object.entries(route.actions ?? {});
|
|
2378
|
-
if (entries.length === 0) {
|
|
2379
|
-
if (route.defaultAction !== void 0) {
|
|
2380
|
-
throw new TypeError(
|
|
2381
|
-
`Route "${route.path}" declares defaultAction without declaring any actions.`
|
|
2382
|
-
);
|
|
2383
|
-
}
|
|
2384
|
-
return {};
|
|
2385
|
-
}
|
|
2386
|
-
for (const [name, action2] of entries) {
|
|
2387
|
-
if (typeof action2 !== "function") {
|
|
2388
|
-
throw new TypeError(`Route "${route.path}" action "${name}" must be a server function.`);
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
const defaultAction = route.defaultAction ?? entries[0][0];
|
|
2392
|
-
const actions = Object.freeze({ ...route.actions });
|
|
2393
|
-
const action = actions[defaultAction];
|
|
2394
|
-
if (!action) {
|
|
2395
|
-
throw new TypeError(
|
|
2396
|
-
`Route "${route.path}" defaultAction "${defaultAction}" does not match a declared action.`
|
|
2397
|
-
);
|
|
2398
|
-
}
|
|
2399
|
-
return {
|
|
2400
|
-
actions,
|
|
2401
|
-
defaultAction,
|
|
2402
|
-
action
|
|
2403
|
-
};
|
|
2404
|
-
}
|
|
2405
|
-
__name(normalizeProgrammaticRouteActions, "normalizeProgrammaticRouteActions");
|
|
2406
|
-
function normalizeRoutePath(routePath) {
|
|
2407
|
-
const withSlash = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
2408
|
-
const withoutTrailing = withSlash.length > 1 ? withSlash.replace(/\/+$/, "") : withSlash;
|
|
2409
|
-
return withoutTrailing || "/";
|
|
2410
|
-
}
|
|
2411
|
-
__name(normalizeRoutePath, "normalizeRoutePath");
|
|
2412
|
-
function normalizeApiMethods(methods) {
|
|
2413
|
-
const normalized = {};
|
|
2414
|
-
for (const [method, handler] of Object.entries(methods)) {
|
|
2415
|
-
const normalizedMethod = method.toUpperCase();
|
|
2416
|
-
if (handler && isProgrammaticRouteMethod(normalizedMethod)) {
|
|
2417
|
-
normalized[normalizedMethod] = handler;
|
|
2418
|
-
}
|
|
2419
|
-
}
|
|
2420
|
-
return normalized;
|
|
2421
|
-
}
|
|
2422
|
-
__name(normalizeApiMethods, "normalizeApiMethods");
|
|
2423
|
-
function isProgrammaticRouteMethod(method) {
|
|
2424
|
-
return method === "GET" || method === "HEAD" || method === "QUERY" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "OPTIONS";
|
|
2425
|
-
}
|
|
2426
|
-
__name(isProgrammaticRouteMethod, "isProgrammaticRouteMethod");
|
|
2427
|
-
function normalizeStaticPaths(routePath, paths) {
|
|
2428
|
-
const dynamicSegments = parseProgrammaticRoutePath2(routePath).segments.filter(
|
|
2429
|
-
(segment) => segment.isDynamic
|
|
2430
|
-
);
|
|
2431
|
-
return paths.map((entry) => {
|
|
2432
|
-
if (typeof entry === "string" || Array.isArray(entry)) {
|
|
2433
|
-
if (dynamicSegments.length !== 1) {
|
|
2434
|
-
throw new Error(
|
|
2435
|
-
`staticPaths for "${routePath}" must return objects when the route has ${dynamicSegments.length} dynamic params.`
|
|
2436
|
-
);
|
|
2437
|
-
}
|
|
2438
|
-
const value = Array.isArray(entry) ? entry.join("/") : entry;
|
|
2439
|
-
return { [dynamicSegments[0].segment]: String(value) };
|
|
2440
|
-
}
|
|
2441
|
-
return Object.fromEntries(
|
|
2442
|
-
Object.entries(entry).map(([key, value]) => [
|
|
2443
|
-
key,
|
|
2444
|
-
Array.isArray(value) ? value.map(String).join("/") : String(value)
|
|
2445
|
-
])
|
|
2446
|
-
);
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
__name(normalizeStaticPaths, "normalizeStaticPaths");
|
|
2450
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2451
|
-
0 && (module.exports = {
|
|
2452
|
-
PROGRAMMATIC_ROUTE_FILE_NAMES,
|
|
2453
|
-
api,
|
|
2454
|
-
createLayoutModuleFromProgrammaticLayout,
|
|
2455
|
-
createProgrammaticRouteModuleId,
|
|
2456
|
-
createRoute,
|
|
2457
|
-
createRouteModuleFromProgrammaticPage,
|
|
2458
|
-
defineRoutes,
|
|
2459
|
-
getProgrammaticRouteManifest,
|
|
2460
|
-
getProgrammaticRouteSearchClientOptions,
|
|
2461
|
-
getProgrammaticRouteSearchSchema,
|
|
2462
|
-
isProgrammaticRouteDefinition,
|
|
2463
|
-
isProgrammaticRouteManifest,
|
|
2464
|
-
isProgrammaticRoutesFileName,
|
|
2465
|
-
layout,
|
|
2466
|
-
page,
|
|
2467
|
-
parseProgrammaticRouteModuleId,
|
|
2468
|
-
parseProgrammaticRoutePath,
|
|
2469
|
-
redirect,
|
|
2470
|
-
routesBuilder,
|
|
2471
|
-
scanProgrammaticPagePaths
|
|
2472
|
-
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var _chunkXSKZORAScjs = require('./chunk-XSKZORAS.cjs');
|
|
23
|
+
require('./chunk-6QQDAAAZ.cjs');
|
|
24
|
+
require('./chunk-6V4TDWEC.cjs');
|
|
25
|
+
require('./chunk-MKB2EGIR.cjs');
|
|
26
|
+
require('./chunk-H6G5INWM.cjs');
|
|
27
|
+
require('./chunk-ZEG3OPIB.cjs');
|
|
28
|
+
require('./chunk-LIUGYUX3.cjs');
|
|
29
|
+
require('./chunk-E3UK5IIB.cjs');
|
|
30
|
+
require('./chunk-NO3WWW3N.cjs');
|
|
31
|
+
require('./chunk-S3JO3N4H.cjs');
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
exports.PROGRAMMATIC_ROUTE_FILE_NAMES = _chunkXSKZORAScjs.PROGRAMMATIC_ROUTE_FILE_NAMES; exports.api = _chunkXSKZORAScjs.api; exports.createLayoutModuleFromProgrammaticLayout = _chunkXSKZORAScjs.createLayoutModuleFromProgrammaticLayout; exports.createProgrammaticRouteModuleId = _chunkXSKZORAScjs.createProgrammaticRouteModuleId; exports.createRoute = _chunkXSKZORAScjs.createRoute; exports.createRouteModuleFromProgrammaticPage = _chunkXSKZORAScjs.createRouteModuleFromProgrammaticPage; exports.defineRoutes = _chunkXSKZORAScjs.defineRoutes; exports.getProgrammaticRouteManifest = _chunkXSKZORAScjs.getProgrammaticRouteManifest; exports.getProgrammaticRouteSearchClientOptions = _chunkXSKZORAScjs.getProgrammaticRouteSearchClientOptions; exports.getProgrammaticRouteSearchSchema = _chunkXSKZORAScjs.getProgrammaticRouteSearchSchema; exports.isProgrammaticRouteDefinition = _chunkXSKZORAScjs.isProgrammaticRouteDefinition; exports.isProgrammaticRouteManifest = _chunkXSKZORAScjs.isProgrammaticRouteManifest; exports.isProgrammaticRoutesFileName = _chunkXSKZORAScjs.isProgrammaticRoutesFileName; exports.layout = _chunkXSKZORAScjs.layout; exports.page = _chunkXSKZORAScjs.page; exports.parseProgrammaticRouteModuleId = _chunkXSKZORAScjs.parseProgrammaticRouteModuleId; exports.parseProgrammaticRoutePath = _chunkXSKZORAScjs.parseProgrammaticRoutePath; exports.redirect = _chunkXSKZORAScjs.redirect; exports.routesBuilder = _chunkXSKZORAScjs.routesBuilder; exports.scanProgrammaticPagePaths = _chunkXSKZORAScjs.scanProgrammaticPagePaths;
|