@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/cache.cjs
CHANGED
|
@@ -1,1569 +1,47 @@
|
|
|
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/cache.ts
|
|
22
|
-
var cache_exports = {};
|
|
23
|
-
__export(cache_exports, {
|
|
24
|
-
FarmDataCache: () => FarmDataCache,
|
|
25
|
-
applyFarmCacheInvalidationTargets: () => applyFarmCacheInvalidationTargets,
|
|
26
|
-
applyFarmCacheInvalidations: () => applyFarmCacheInvalidations,
|
|
27
|
-
configureFarmCache: () => configureFarmCache,
|
|
28
|
-
createFarmCacheInvalidationStream: () => createFarmCacheInvalidationStream,
|
|
29
|
-
createFarmCacheKey: () => createFarmCacheKey,
|
|
30
|
-
createPathCacheTag: () => createPathCacheTag,
|
|
31
|
-
createRouteDataCacheKey: () => createRouteDataCacheKey,
|
|
32
|
-
createRouteDataCacheTag: () => createRouteDataCacheTag,
|
|
33
|
-
defineCacheKey: () => defineCacheKey,
|
|
34
|
-
getFarmDataCache: () => getFarmDataCache,
|
|
35
|
-
invalidate: () => invalidate,
|
|
36
|
-
invalidateRouteData: () => invalidateRouteData,
|
|
37
|
-
normalizeRevalidatePath: () => normalizeRevalidatePath,
|
|
38
|
-
revalidatePath: () => revalidatePath,
|
|
39
|
-
revalidateTag: () => revalidateTag,
|
|
40
|
-
storageCacheAdapter: () => storageCacheAdapter,
|
|
41
|
-
unstable_cache: () => unstable_cache,
|
|
42
|
-
updateTag: () => updateTag
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(cache_exports);
|
|
45
3
|
|
|
46
|
-
// src/tracing.ts
|
|
47
|
-
var import_api = require("@opentelemetry/api");
|
|
48
|
-
var FARM_TRACER_NAME = "@farm.js/core";
|
|
49
|
-
var ALL_SPAN_KINDS = [
|
|
50
|
-
"request",
|
|
51
|
-
"render",
|
|
52
|
-
"middleware",
|
|
53
|
-
"api",
|
|
54
|
-
"integration",
|
|
55
|
-
"storage",
|
|
56
|
-
"ppr",
|
|
57
|
-
"build",
|
|
58
|
-
"plugin"
|
|
59
|
-
];
|
|
60
|
-
var DEFAULT_IGNORED_PATHS = [
|
|
61
|
-
"/@vite/",
|
|
62
|
-
"/@fs/",
|
|
63
|
-
"/@id/",
|
|
64
|
-
"/@react-refresh",
|
|
65
|
-
"/node_modules/",
|
|
66
|
-
"/__vite",
|
|
67
|
-
"/.well-known/appspecific/"
|
|
68
|
-
];
|
|
69
|
-
var FARM_REQUEST_METHOD_CONTEXT_KEY = (0, import_api.createContextKey)("@farm.js/core/request-method");
|
|
70
|
-
var TRACING_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/tracing-runtime/v1");
|
|
71
|
-
var runtime = globalThis;
|
|
72
|
-
var tracingState = runtime[TRACING_RUNTIME] ?? (runtime[TRACING_RUNTIME] = normalizeFarmTracingConfig(false));
|
|
73
|
-
function normalizeFarmTracingConfig(config) {
|
|
74
|
-
if (!config) {
|
|
75
|
-
return {
|
|
76
|
-
enabled: false,
|
|
77
|
-
spans: new Set(ALL_SPAN_KINDS),
|
|
78
|
-
recordEvents: true,
|
|
79
|
-
attributes: {},
|
|
80
|
-
ignorePaths: DEFAULT_IGNORED_PATHS
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (config === true) {
|
|
84
|
-
return {
|
|
85
|
-
enabled: true,
|
|
86
|
-
spans: new Set(ALL_SPAN_KINDS),
|
|
87
|
-
recordEvents: true,
|
|
88
|
-
attributes: {},
|
|
89
|
-
ignorePaths: DEFAULT_IGNORED_PATHS
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
enabled: config.enabled ?? true,
|
|
94
|
-
spans: new Set(config.spans ?? ALL_SPAN_KINDS),
|
|
95
|
-
recordEvents: config.recordEvents ?? true,
|
|
96
|
-
attributes: { ...config.attributes },
|
|
97
|
-
ignorePaths: [...DEFAULT_IGNORED_PATHS, ...config.ignorePaths ?? []]
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
__name(normalizeFarmTracingConfig, "normalizeFarmTracingConfig");
|
|
101
|
-
function recordFarmEventTrace(event) {
|
|
102
|
-
if (!tracingState.enabled) return void 0;
|
|
103
|
-
const activeContext = import_api.context.active();
|
|
104
|
-
const activeSpan = import_api.trace.getSpan(activeContext);
|
|
105
|
-
const traceContext = getSpanTraceContext(activeSpan);
|
|
106
|
-
if (activeSpan && traceContext) {
|
|
107
|
-
if (event.type === "route.matched") {
|
|
108
|
-
const method = activeContext.getValue(FARM_REQUEST_METHOD_CONTEXT_KEY) ?? "HTTP";
|
|
109
|
-
activeSpan.updateName(`${method} ${event.route}`);
|
|
110
|
-
activeSpan.setAttribute("http.route", event.route);
|
|
111
|
-
activeSpan.setAttribute("farm.route", event.route);
|
|
112
|
-
}
|
|
113
|
-
if (tracingState.recordEvents) {
|
|
114
|
-
activeSpan.addEvent(event.type, toEventAttributes(event), event.timestamp);
|
|
115
|
-
}
|
|
116
|
-
const error = event.type === "request.error" ? void 0 : getEventError(event);
|
|
117
|
-
if (error !== void 0) {
|
|
118
|
-
if (event.type === "render.error") {
|
|
119
|
-
recordSpanException(activeSpan, error);
|
|
120
|
-
} else {
|
|
121
|
-
recordSpanError(activeSpan, error);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const completedTraceContext = recordCompletedEventSpan(event, activeContext);
|
|
126
|
-
return traceContext ?? completedTraceContext;
|
|
127
|
-
}
|
|
128
|
-
__name(recordFarmEventTrace, "recordFarmEventTrace");
|
|
129
|
-
function recordCompletedEventSpan(event, parentContext) {
|
|
130
|
-
const descriptor = getCompletedSpanDescriptor(event);
|
|
131
|
-
if (!descriptor || !tracingState.spans.has(descriptor.kind)) return void 0;
|
|
132
|
-
const tracer = import_api.trace.getTracer(FARM_TRACER_NAME);
|
|
133
|
-
const span = tracer.startSpan(
|
|
134
|
-
descriptor.name,
|
|
135
|
-
{
|
|
136
|
-
kind: import_api.SpanKind.INTERNAL,
|
|
137
|
-
startTime: event.timestamp - descriptor.durationMs,
|
|
138
|
-
attributes: {
|
|
139
|
-
...tracingState.attributes,
|
|
140
|
-
...toEventAttributes(event),
|
|
141
|
-
"farm.event.type": event.type
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
parentContext
|
|
145
|
-
);
|
|
146
|
-
const status = "status" in event && typeof event.status === "number" ? event.status : void 0;
|
|
147
|
-
if (status !== void 0) setResponseStatus(span, status);
|
|
148
|
-
const error = getEventError(event);
|
|
149
|
-
if (error !== void 0) recordSpanError(span, error);
|
|
150
|
-
const traceContext = getSpanTraceContext(span);
|
|
151
|
-
span.end(event.timestamp);
|
|
152
|
-
return traceContext;
|
|
153
|
-
}
|
|
154
|
-
__name(recordCompletedEventSpan, "recordCompletedEventSpan");
|
|
155
|
-
function getCompletedSpanDescriptor(event) {
|
|
156
|
-
if (!("durationMs" in event) || typeof event.durationMs !== "number") return void 0;
|
|
157
|
-
switch (event.type) {
|
|
158
|
-
case "render.complete":
|
|
159
|
-
return { kind: "render", name: `farm.render ${event.route}`, durationMs: event.durationMs };
|
|
160
|
-
case "render.stream.shellReady":
|
|
161
|
-
return {
|
|
162
|
-
kind: "render",
|
|
163
|
-
name: `farm.render.shell ${event.route}`,
|
|
164
|
-
durationMs: event.durationMs
|
|
165
|
-
};
|
|
166
|
-
case "render.stream.complete":
|
|
167
|
-
return {
|
|
168
|
-
kind: "render",
|
|
169
|
-
name: `farm.render.stream ${event.route}`,
|
|
170
|
-
durationMs: event.durationMs
|
|
171
|
-
};
|
|
172
|
-
case "middleware.complete":
|
|
173
|
-
return {
|
|
174
|
-
kind: "middleware",
|
|
175
|
-
name: `farm.middleware ${event.name ?? event.route ?? "anonymous"}`,
|
|
176
|
-
durationMs: event.durationMs
|
|
177
|
-
};
|
|
178
|
-
case "api.request.complete":
|
|
179
|
-
case "api.error":
|
|
180
|
-
return {
|
|
181
|
-
kind: "api",
|
|
182
|
-
name: `farm.api ${event.method} ${event.route}`,
|
|
183
|
-
durationMs: event.durationMs
|
|
184
|
-
};
|
|
185
|
-
case "integration.api.call.complete":
|
|
186
|
-
return {
|
|
187
|
-
kind: "integration",
|
|
188
|
-
name: `farm.integration ${event.integration}.${event.operation}`,
|
|
189
|
-
durationMs: event.durationMs
|
|
190
|
-
};
|
|
191
|
-
case "storage.query.complete":
|
|
192
|
-
return {
|
|
193
|
-
kind: "storage",
|
|
194
|
-
name: `farm.storage ${event.operation}`,
|
|
195
|
-
durationMs: event.durationMs
|
|
196
|
-
};
|
|
197
|
-
case "ppr.refresh.complete":
|
|
198
|
-
return {
|
|
199
|
-
kind: "ppr",
|
|
200
|
-
name: `farm.ppr.refresh ${event.route}`,
|
|
201
|
-
durationMs: event.durationMs
|
|
202
|
-
};
|
|
203
|
-
case "build.complete":
|
|
204
|
-
return {
|
|
205
|
-
kind: "build",
|
|
206
|
-
name: `farm.build${event.target ? ` ${event.target}` : ""}`,
|
|
207
|
-
durationMs: event.durationMs
|
|
208
|
-
};
|
|
209
|
-
case "plugin.hook.complete":
|
|
210
|
-
return {
|
|
211
|
-
kind: "plugin",
|
|
212
|
-
name: `farm.plugin ${event.plugin}.${event.hook}`,
|
|
213
|
-
durationMs: event.durationMs
|
|
214
|
-
};
|
|
215
|
-
default:
|
|
216
|
-
return void 0;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
__name(getCompletedSpanDescriptor, "getCompletedSpanDescriptor");
|
|
220
|
-
function hashFarmCacheKey(value) {
|
|
221
|
-
let hash = 2166136261;
|
|
222
|
-
for (let index = 0; index < value.length; index++) {
|
|
223
|
-
hash ^= value.charCodeAt(index);
|
|
224
|
-
hash = Math.imul(hash, 16777619);
|
|
225
|
-
}
|
|
226
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
227
|
-
}
|
|
228
|
-
__name(hashFarmCacheKey, "hashFarmCacheKey");
|
|
229
|
-
function toEventAttributes(event) {
|
|
230
|
-
const attributes = {};
|
|
231
|
-
const redactKey = typeof event.type === "string" && event.type.startsWith("cache.");
|
|
232
|
-
for (const [key, value] of Object.entries(event)) {
|
|
233
|
-
if (key === "timestamp" || key === "level" || key === "error" || key === "traceId" || key === "spanId" || key === "traceSampled" || value === void 0) {
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
if (redactKey && key === "key" && typeof value === "string") {
|
|
237
|
-
attributes["farm.key_hash"] = hashFarmCacheKey(value);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
241
|
-
attributes[`farm.${key}`] = value;
|
|
242
|
-
} else if (Array.isArray(value)) {
|
|
243
|
-
if (value.every((entry) => typeof entry === "string")) {
|
|
244
|
-
attributes[`farm.${key}`] = value;
|
|
245
|
-
} else if (value.every((entry) => typeof entry === "number")) {
|
|
246
|
-
attributes[`farm.${key}`] = value;
|
|
247
|
-
} else if (value.every((entry) => typeof entry === "boolean")) {
|
|
248
|
-
attributes[`farm.${key}`] = value;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return attributes;
|
|
253
|
-
}
|
|
254
|
-
__name(toEventAttributes, "toEventAttributes");
|
|
255
|
-
function getEventError(event) {
|
|
256
|
-
return "error" in event ? event.error : void 0;
|
|
257
|
-
}
|
|
258
|
-
__name(getEventError, "getEventError");
|
|
259
|
-
function recordSpanException(span, error) {
|
|
260
|
-
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
261
|
-
span.recordException(normalized);
|
|
262
|
-
return normalized;
|
|
263
|
-
}
|
|
264
|
-
__name(recordSpanException, "recordSpanException");
|
|
265
|
-
function recordSpanError(span, error) {
|
|
266
|
-
const normalized = recordSpanException(span, error);
|
|
267
|
-
span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: normalized.message });
|
|
268
|
-
}
|
|
269
|
-
__name(recordSpanError, "recordSpanError");
|
|
270
|
-
function setResponseStatus(span, status) {
|
|
271
|
-
span.setAttribute("http.response.status_code", status);
|
|
272
|
-
if (status >= 500) {
|
|
273
|
-
span.setStatus({ code: import_api.SpanStatusCode.ERROR });
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
__name(setResponseStatus, "setResponseStatus");
|
|
277
|
-
function getSpanTraceContext(span) {
|
|
278
|
-
if (!span) return void 0;
|
|
279
|
-
const spanContext = span.spanContext();
|
|
280
|
-
if (!(0, import_api.isSpanContextValid)(spanContext)) return void 0;
|
|
281
|
-
return {
|
|
282
|
-
traceId: spanContext.traceId,
|
|
283
|
-
spanId: spanContext.spanId,
|
|
284
|
-
traceSampled: (spanContext.traceFlags & 1) === 1
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
__name(getSpanTraceContext, "getSpanTraceContext");
|
|
288
4
|
|
|
289
|
-
// src/observability.ts
|
|
290
|
-
var OBSERVABILITY_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/observability-runtime/v1");
|
|
291
|
-
var runtime2 = globalThis;
|
|
292
|
-
var shared = runtime2[OBSERVABILITY_RUNTIME] ?? (runtime2[OBSERVABILITY_RUNTIME] = {
|
|
293
|
-
handlers: /* @__PURE__ */ new Set(),
|
|
294
|
-
unfilteredHandlers: /* @__PURE__ */ new Set(),
|
|
295
|
-
config: { logs: false, handlers: [], tracing: normalizeFarmTracingConfig(false) }
|
|
296
|
-
});
|
|
297
|
-
var runtimeHandlers = shared.handlers;
|
|
298
|
-
var unfilteredRuntimeHandlers = shared.unfilteredHandlers;
|
|
299
|
-
var observabilityState = shared.config;
|
|
300
|
-
function emitFarmEvent(input) {
|
|
301
|
-
const event = {
|
|
302
|
-
timestamp: Date.now(),
|
|
303
|
-
level: inferFarmEventLevel(input.type),
|
|
304
|
-
...input
|
|
305
|
-
};
|
|
306
|
-
const traceContext = recordFarmEventTrace(event);
|
|
307
|
-
if (traceContext) {
|
|
308
|
-
event.traceId = traceContext.traceId;
|
|
309
|
-
event.spanId = traceContext.spanId;
|
|
310
|
-
event.traceSampled = traceContext.traceSampled;
|
|
311
|
-
}
|
|
312
|
-
notifyFarmEventHandlers(event, unfilteredRuntimeHandlers);
|
|
313
|
-
if (!shouldEmitFarmEvent(event)) return event;
|
|
314
|
-
if (observabilityState.logs) {
|
|
315
|
-
logFarmEvent(event);
|
|
316
|
-
}
|
|
317
|
-
notifyFarmEventHandlers(event, [...observabilityState.handlers, ...runtimeHandlers]);
|
|
318
|
-
return event;
|
|
319
|
-
}
|
|
320
|
-
__name(emitFarmEvent, "emitFarmEvent");
|
|
321
|
-
function notifyFarmEventHandlers(event, handlers) {
|
|
322
|
-
for (const handler of handlers) {
|
|
323
|
-
try {
|
|
324
|
-
Promise.resolve(handler(event)).catch((error) => {
|
|
325
|
-
console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
|
|
326
|
-
});
|
|
327
|
-
} catch (error) {
|
|
328
|
-
console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
__name(notifyFarmEventHandlers, "notifyFarmEventHandlers");
|
|
333
|
-
function shouldEmitFarmEvent(event) {
|
|
334
|
-
if (!observabilityState.logs && observabilityState.handlers.length === 0 && runtimeHandlers.size === 0) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
if (observabilityState.events && !observabilityState.events.has(event.type)) {
|
|
338
|
-
return false;
|
|
339
|
-
}
|
|
340
|
-
return true;
|
|
341
|
-
}
|
|
342
|
-
__name(shouldEmitFarmEvent, "shouldEmitFarmEvent");
|
|
343
|
-
function inferFarmEventLevel(type) {
|
|
344
|
-
if (type === "error" || type.endsWith(".error") || type.endsWith(".failed")) {
|
|
345
|
-
return "error";
|
|
346
|
-
}
|
|
347
|
-
if (type.endsWith(".bypass") || type.endsWith(".invalidated") || type.endsWith(".stale") || type.endsWith(".notFound")) {
|
|
348
|
-
return "warn";
|
|
349
|
-
}
|
|
350
|
-
if (type.endsWith(".hit") || type.endsWith(".miss") || type.endsWith(".start") || type.endsWith(".shellReady")) {
|
|
351
|
-
return "debug";
|
|
352
|
-
}
|
|
353
|
-
return "info";
|
|
354
|
-
}
|
|
355
|
-
__name(inferFarmEventLevel, "inferFarmEventLevel");
|
|
356
|
-
function logFarmEvent(event) {
|
|
357
|
-
const message = `[farm:${event.level}] ${event.type}${formatFarmEventDetails(event)}`;
|
|
358
|
-
switch (event.level) {
|
|
359
|
-
case "error":
|
|
360
|
-
console.error(message);
|
|
361
|
-
break;
|
|
362
|
-
case "warn":
|
|
363
|
-
console.warn(message);
|
|
364
|
-
break;
|
|
365
|
-
default:
|
|
366
|
-
console.log(message);
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
__name(logFarmEvent, "logFarmEvent");
|
|
371
|
-
function formatFarmEventDetails(event) {
|
|
372
|
-
const details = [];
|
|
373
|
-
const record = event;
|
|
374
|
-
for (const key of [
|
|
375
|
-
"route",
|
|
376
|
-
"pathname",
|
|
377
|
-
"method",
|
|
378
|
-
"status",
|
|
379
|
-
"key",
|
|
380
|
-
"tag",
|
|
381
|
-
"path",
|
|
382
|
-
"reason",
|
|
383
|
-
"durationMs",
|
|
384
|
-
"integration",
|
|
385
|
-
"server",
|
|
386
|
-
"tool",
|
|
387
|
-
"outcome",
|
|
388
|
-
"operation",
|
|
389
|
-
"plugin",
|
|
390
|
-
"hook",
|
|
391
|
-
"target",
|
|
392
|
-
"count"
|
|
393
|
-
]) {
|
|
394
|
-
const value = record[key];
|
|
395
|
-
if (value !== void 0) {
|
|
396
|
-
details.push(`${key}=${formatDetailValue(value)}`);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return details.length > 0 ? ` ${details.join(" ")}` : "";
|
|
400
|
-
}
|
|
401
|
-
__name(formatFarmEventDetails, "formatFarmEventDetails");
|
|
402
|
-
function formatDetailValue(value) {
|
|
403
|
-
if (typeof value === "string") {
|
|
404
|
-
return value;
|
|
405
|
-
}
|
|
406
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
407
|
-
return String(value);
|
|
408
|
-
}
|
|
409
|
-
try {
|
|
410
|
-
return JSON.stringify(value);
|
|
411
|
-
} catch {
|
|
412
|
-
return String(value);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
__name(formatDetailValue, "formatDetailValue");
|
|
416
|
-
function formatError(error) {
|
|
417
|
-
return error instanceof Error ? error.message : String(error);
|
|
418
|
-
}
|
|
419
|
-
__name(formatError, "formatError");
|
|
420
5
|
|
|
421
|
-
// src/cache-invalidation.ts
|
|
422
|
-
var FARM_CACHE_INVALIDATION_STATE = /* @__PURE__ */ Symbol.for("farm.cacheInvalidationState");
|
|
423
|
-
var globalState = globalThis;
|
|
424
|
-
function getFarmCacheInvalidationState() {
|
|
425
|
-
return globalState[FARM_CACHE_INVALIDATION_STATE] ?? (globalState[FARM_CACHE_INVALIDATION_STATE] = {
|
|
426
|
-
listeners: /* @__PURE__ */ new Set(),
|
|
427
|
-
taskListeners: /* @__PURE__ */ new Set()
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
__name(getFarmCacheInvalidationState, "getFarmCacheInvalidationState");
|
|
431
|
-
function warnFarmCacheListenerError(scope, error) {
|
|
432
|
-
const detail = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
433
|
-
console.warn(`[farm:cache] ${scope} listener failed: ${detail}`);
|
|
434
|
-
}
|
|
435
|
-
__name(warnFarmCacheListenerError, "warnFarmCacheListenerError");
|
|
436
|
-
function notifyFarmCacheInvalidation(key, source = "local") {
|
|
437
|
-
if (typeof key !== "string" || key.length === 0) return;
|
|
438
|
-
for (const listener of getFarmCacheInvalidationState().listeners) {
|
|
439
|
-
try {
|
|
440
|
-
listener(key, source);
|
|
441
|
-
} catch (error) {
|
|
442
|
-
warnFarmCacheListenerError("invalidation", error);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
__name(notifyFarmCacheInvalidation, "notifyFarmCacheInvalidation");
|
|
447
|
-
function notifyFarmCacheTask(task) {
|
|
448
|
-
for (const listener of getFarmCacheInvalidationState().taskListeners) {
|
|
449
|
-
try {
|
|
450
|
-
listener(task);
|
|
451
|
-
} catch (error) {
|
|
452
|
-
warnFarmCacheListenerError("task", error);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
__name(notifyFarmCacheTask, "notifyFarmCacheTask");
|
|
457
|
-
function applyFarmCacheInvalidations(keys, source = "local") {
|
|
458
|
-
if (!Array.isArray(keys)) return;
|
|
459
|
-
for (const key of keys) {
|
|
460
|
-
if (typeof key === "string") {
|
|
461
|
-
notifyFarmCacheInvalidation(key, source);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
__name(applyFarmCacheInvalidations, "applyFarmCacheInvalidations");
|
|
466
|
-
function encodeFarmCacheInvalidations(keys) {
|
|
467
|
-
const normalized = Array.from(
|
|
468
|
-
new Set(keys.filter((key) => typeof key === "string" && key.length > 0))
|
|
469
|
-
);
|
|
470
|
-
if (normalized.length === 0) return null;
|
|
471
|
-
return encodeURIComponent(JSON.stringify(normalized));
|
|
472
|
-
}
|
|
473
|
-
__name(encodeFarmCacheInvalidations, "encodeFarmCacheInvalidations");
|
|
474
|
-
function subscribeFarmCacheInvalidation(listener) {
|
|
475
|
-
const state = getFarmCacheInvalidationState();
|
|
476
|
-
state.listeners.add(listener);
|
|
477
|
-
return () => state.listeners.delete(listener);
|
|
478
|
-
}
|
|
479
|
-
__name(subscribeFarmCacheInvalidation, "subscribeFarmCacheInvalidation");
|
|
480
6
|
|
|
481
|
-
// src/i18n/bridge.ts
|
|
482
|
-
var FARM_I18N_SNAPSHOT_RESOLVER = /* @__PURE__ */ Symbol.for("farm.i18n.snapshotResolver");
|
|
483
|
-
function getActiveFarmI18nSnapshot() {
|
|
484
|
-
if (typeof window !== "undefined" && window.__FARM_I18N__) {
|
|
485
|
-
return window.__FARM_I18N__;
|
|
486
|
-
}
|
|
487
|
-
return globalThis[FARM_I18N_SNAPSHOT_RESOLVER]?.();
|
|
488
|
-
}
|
|
489
|
-
__name(getActiveFarmI18nSnapshot, "getActiveFarmI18nSnapshot");
|
|
490
7
|
|
|
491
|
-
// src/cache-invalidation-stream.ts
|
|
492
|
-
var DEFAULT_HEARTBEAT_INTERVAL_MS = 15e3;
|
|
493
|
-
var DEFAULT_RETRY_MS = 3e3;
|
|
494
|
-
var MAX_BUFFERED_BYTES = 64 * 1024;
|
|
495
|
-
var MAX_PENDING_KEYS = 1024;
|
|
496
|
-
var textEncoder = new TextEncoder();
|
|
497
|
-
function positiveDuration(value, fallback) {
|
|
498
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
499
|
-
}
|
|
500
|
-
__name(positiveDuration, "positiveDuration");
|
|
501
|
-
function createFarmCacheInvalidationStream(options = {}) {
|
|
502
|
-
const heartbeatIntervalMs = options.heartbeatIntervalMs === false ? false : positiveDuration(options.heartbeatIntervalMs, DEFAULT_HEARTBEAT_INTERVAL_MS);
|
|
503
|
-
const retryMs = positiveDuration(options.retryMs, DEFAULT_RETRY_MS);
|
|
504
|
-
let unsubscribe;
|
|
505
|
-
let heartbeat;
|
|
506
|
-
let controller;
|
|
507
|
-
let closed = false;
|
|
508
|
-
let flushScheduled = false;
|
|
509
|
-
const pending = /* @__PURE__ */ new Set();
|
|
510
|
-
let pendingBytes = 0;
|
|
511
|
-
const enqueue = /* @__PURE__ */ __name((value) => {
|
|
512
|
-
if (closed || !controller) return;
|
|
513
|
-
const chunk = textEncoder.encode(value);
|
|
514
|
-
if (chunk.byteLength > (controller.desiredSize ?? 0)) {
|
|
515
|
-
overflow();
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
controller.enqueue(chunk);
|
|
519
|
-
}, "enqueue");
|
|
520
|
-
const cleanup = /* @__PURE__ */ __name(() => {
|
|
521
|
-
unsubscribe?.();
|
|
522
|
-
unsubscribe = void 0;
|
|
523
|
-
if (heartbeat !== void 0) clearInterval(heartbeat);
|
|
524
|
-
heartbeat = void 0;
|
|
525
|
-
options.signal?.removeEventListener("abort", abort);
|
|
526
|
-
pending.clear();
|
|
527
|
-
pendingBytes = 0;
|
|
528
|
-
}, "cleanup");
|
|
529
|
-
const stop = /* @__PURE__ */ __name((closeController) => {
|
|
530
|
-
if (closed) return;
|
|
531
|
-
closed = true;
|
|
532
|
-
cleanup();
|
|
533
|
-
if (closeController) controller?.close();
|
|
534
|
-
}, "stop");
|
|
535
|
-
const abort = /* @__PURE__ */ __name(() => stop(true), "abort");
|
|
536
|
-
const overflow = /* @__PURE__ */ __name(() => {
|
|
537
|
-
if (closed) return;
|
|
538
|
-
stop(false);
|
|
539
|
-
controller?.error(new Error("Farm cache invalidation stream exceeded its buffer limit."));
|
|
540
|
-
}, "overflow");
|
|
541
|
-
const flush = /* @__PURE__ */ __name(() => {
|
|
542
|
-
flushScheduled = false;
|
|
543
|
-
if (closed || pending.size === 0) return;
|
|
544
|
-
const encoded = encodeFarmCacheInvalidations([...pending]);
|
|
545
|
-
pending.clear();
|
|
546
|
-
pendingBytes = 0;
|
|
547
|
-
if (encoded !== null) enqueue(`data: ${encoded}
|
|
548
8
|
|
|
549
|
-
`);
|
|
550
|
-
}, "flush");
|
|
551
|
-
const stream = new ReadableStream(
|
|
552
|
-
{
|
|
553
|
-
start(nextController) {
|
|
554
|
-
controller = nextController;
|
|
555
|
-
if (options.signal?.aborted) {
|
|
556
|
-
stop(true);
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
enqueue(`: connected
|
|
560
|
-
retry: ${retryMs}
|
|
561
9
|
|
|
562
|
-
`);
|
|
563
|
-
unsubscribe = subscribeFarmCacheInvalidation((key) => {
|
|
564
|
-
if (closed || options.filter?.(key) === false) return;
|
|
565
|
-
if (closed || pending.has(key)) return;
|
|
566
|
-
if (pending.size >= MAX_PENDING_KEYS || pendingBytes + key.length * 2 > MAX_BUFFERED_BYTES) {
|
|
567
|
-
overflow();
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
pending.add(key);
|
|
571
|
-
pendingBytes += key.length * 2;
|
|
572
|
-
if (!flushScheduled) {
|
|
573
|
-
flushScheduled = true;
|
|
574
|
-
queueMicrotask(flush);
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
options.signal?.addEventListener("abort", abort, { once: true });
|
|
578
|
-
if (heartbeatIntervalMs !== false) {
|
|
579
|
-
heartbeat = setInterval(() => {
|
|
580
|
-
if (controller?.desiredSize === MAX_BUFFERED_BYTES) enqueue(": heartbeat\n\n");
|
|
581
|
-
}, heartbeatIntervalMs);
|
|
582
|
-
}
|
|
583
|
-
},
|
|
584
|
-
cancel() {
|
|
585
|
-
stop(false);
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
|
-
{ highWaterMark: MAX_BUFFERED_BYTES, size: /* @__PURE__ */ __name((chunk) => chunk.byteLength, "size") }
|
|
589
|
-
);
|
|
590
|
-
return new Response(stream, {
|
|
591
|
-
headers: {
|
|
592
|
-
"Cache-Control": "no-cache, no-transform",
|
|
593
|
-
"Content-Type": "text/event-stream; charset=utf-8"
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
__name(createFarmCacheInvalidationStream, "createFarmCacheInvalidationStream");
|
|
598
10
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
getTagVersions: /* @__PURE__ */ __name(async (tags) => {
|
|
637
|
-
const versions = await Promise.all(
|
|
638
|
-
tags.map(async (tag) => {
|
|
639
|
-
const value = await storage.getItem(tagKey(tag));
|
|
640
|
-
return [tag, normalizeAdapterVersion(value)];
|
|
641
|
-
})
|
|
642
|
-
);
|
|
643
|
-
return Object.fromEntries(versions);
|
|
644
|
-
}, "getTagVersions"),
|
|
645
|
-
invalidateTags: /* @__PURE__ */ __name(async (tags) => {
|
|
646
|
-
await Promise.all(
|
|
647
|
-
tags.map(async (tag) => {
|
|
648
|
-
const key = tagKey(tag);
|
|
649
|
-
const current = normalizeAdapterVersion(await storage.getItem(key));
|
|
650
|
-
await storage.setItem(key, Math.max(Date.now(), current + 1));
|
|
651
|
-
})
|
|
652
|
-
);
|
|
653
|
-
}, "invalidateTags")
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
__name(storageCacheAdapter, "storageCacheAdapter");
|
|
657
|
-
var _FarmDataCache = class _FarmDataCache {
|
|
658
|
-
constructor(config = {}) {
|
|
659
|
-
this.entries = /* @__PURE__ */ new Map();
|
|
660
|
-
this.inflight = /* @__PURE__ */ new Map();
|
|
661
|
-
/** Local entries by tag, so tag counts and pruning never scan unrelated entries. */
|
|
662
|
-
this.entriesByTag = /* @__PURE__ */ new Map();
|
|
663
|
-
this.invalidatedTagVersions = /* @__PURE__ */ new Map();
|
|
664
|
-
this.activeGenerations = /* @__PURE__ */ new Set();
|
|
665
|
-
this.version = 0;
|
|
666
|
-
this.generation = 0;
|
|
667
|
-
this.namespace = "farm";
|
|
668
|
-
this.local = true;
|
|
669
|
-
this.maxEntries = 1024;
|
|
670
|
-
this.lease = {
|
|
671
|
-
enabled: true,
|
|
672
|
-
ttlMs: 1e4,
|
|
673
|
-
waitTimeoutMs: 1e4,
|
|
674
|
-
pollIntervalMs: 25
|
|
675
|
-
};
|
|
676
|
-
this.configure(config);
|
|
677
|
-
}
|
|
678
|
-
configure(config = {}) {
|
|
679
|
-
this.generation++;
|
|
680
|
-
this.entries.clear();
|
|
681
|
-
this.entriesByTag.clear();
|
|
682
|
-
this.inflight.clear();
|
|
683
|
-
this.invalidatedTagVersions.clear();
|
|
684
|
-
this.activeGenerations.clear();
|
|
685
|
-
this.version = 0;
|
|
686
|
-
this.adapter = config.adapter;
|
|
687
|
-
this.namespace = normalizeCacheNamespace(config.namespace || "farm");
|
|
688
|
-
this.local = !config.adapter;
|
|
689
|
-
this.maxEntries = normalizePositiveInteger(config.maxEntries, 1024, "cache.maxEntries");
|
|
690
|
-
this.lease = config.lease === false ? { ...this.lease, enabled: false } : {
|
|
691
|
-
enabled: true,
|
|
692
|
-
ttlMs: normalizePositiveDuration(config.lease?.ttlMs, 1e4, "cache.lease.ttlMs"),
|
|
693
|
-
waitTimeoutMs: normalizePositiveDuration(
|
|
694
|
-
config.lease?.waitTimeoutMs,
|
|
695
|
-
1e4,
|
|
696
|
-
"cache.lease.waitTimeoutMs"
|
|
697
|
-
),
|
|
698
|
-
pollIntervalMs: normalizePositiveDuration(
|
|
699
|
-
config.lease?.pollIntervalMs,
|
|
700
|
-
25,
|
|
701
|
-
"cache.lease.pollIntervalMs"
|
|
702
|
-
)
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
get adapterName() {
|
|
706
|
-
return this.adapter?.name || (this.adapter ? "custom" : "memory");
|
|
707
|
-
}
|
|
708
|
-
get hasAdapter() {
|
|
709
|
-
return this.adapter !== void 0;
|
|
710
|
-
}
|
|
711
|
-
get size() {
|
|
712
|
-
return this.entries.size;
|
|
713
|
-
}
|
|
714
|
-
get(key, options = {}) {
|
|
715
|
-
return this.getEntry(key, options)?.value;
|
|
716
|
-
}
|
|
717
|
-
getEntry(key, options = {}) {
|
|
718
|
-
const entry = this.entries.get(key);
|
|
719
|
-
if (!entry) {
|
|
720
|
-
emitFarmEvent({ type: "cache.miss", key });
|
|
721
|
-
return void 0;
|
|
722
|
-
}
|
|
723
|
-
const stale = this.isStale(entry, options.now);
|
|
724
|
-
if (stale) {
|
|
725
|
-
emitFarmEvent({
|
|
726
|
-
type: "cache.stale",
|
|
727
|
-
key,
|
|
728
|
-
tags: Array.from(entry.tags),
|
|
729
|
-
revalidate: entry.revalidate
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
if (!options.allowStale && stale) {
|
|
733
|
-
emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
|
|
734
|
-
return void 0;
|
|
735
|
-
}
|
|
736
|
-
this.touchEntry(key, entry);
|
|
737
|
-
emitFarmEvent({
|
|
738
|
-
type: "cache.hit",
|
|
739
|
-
key,
|
|
740
|
-
tags: Array.from(entry.tags),
|
|
741
|
-
revalidate: entry.revalidate,
|
|
742
|
-
stale
|
|
743
|
-
});
|
|
744
|
-
return this.toPublicEntry(entry);
|
|
745
|
-
}
|
|
746
|
-
async getEntryAsync(key, options = {}) {
|
|
747
|
-
if (this.local) {
|
|
748
|
-
const localEntry = this.getEntry(key, options);
|
|
749
|
-
if (localEntry) return localEntry;
|
|
750
|
-
}
|
|
751
|
-
if (!this.adapter) {
|
|
752
|
-
return this.local ? void 0 : this.getEntry(key, options);
|
|
753
|
-
}
|
|
754
|
-
const generation = this.generation;
|
|
755
|
-
const adapter = this.adapter;
|
|
756
|
-
const namespace = this.namespace;
|
|
757
|
-
const entry = await adapter.get(`${namespace}:entry:${key}`);
|
|
758
|
-
if (generation !== this.generation) return void 0;
|
|
759
|
-
if (!entry) {
|
|
760
|
-
emitFarmEvent({ type: "cache.miss", key });
|
|
761
|
-
return void 0;
|
|
762
|
-
}
|
|
763
|
-
assertFarmCacheEntry(entry, key);
|
|
764
|
-
const stale = await this.isAdapterEntryStale(entry, options.now, adapter, namespace);
|
|
765
|
-
if (generation !== this.generation) return void 0;
|
|
766
|
-
if (stale) {
|
|
767
|
-
emitFarmEvent({
|
|
768
|
-
type: "cache.stale",
|
|
769
|
-
key,
|
|
770
|
-
tags: [...entry.tags],
|
|
771
|
-
revalidate: entry.revalidate
|
|
772
|
-
});
|
|
773
|
-
if (!options.allowStale) {
|
|
774
|
-
emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
|
|
775
|
-
return void 0;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
emitFarmEvent({
|
|
779
|
-
type: "cache.hit",
|
|
780
|
-
key,
|
|
781
|
-
tags: [...entry.tags],
|
|
782
|
-
revalidate: entry.revalidate,
|
|
783
|
-
stale
|
|
784
|
-
});
|
|
785
|
-
if (this.local && !stale) {
|
|
786
|
-
this.hydrateLocalEntry(entry);
|
|
787
|
-
}
|
|
788
|
-
return { ...entry, key };
|
|
789
|
-
}
|
|
790
|
-
set(key, value, options = {}) {
|
|
791
|
-
const revalidate = normalizeRevalidate(options.revalidate);
|
|
792
|
-
const tags = /* @__PURE__ */ new Set();
|
|
793
|
-
for (const tag of options.tags ?? []) {
|
|
794
|
-
tags.add(normalizeCacheTag(tag));
|
|
795
|
-
}
|
|
796
|
-
for (const routePath of options.paths ?? []) {
|
|
797
|
-
tags.add(createPathCacheTag(routePath));
|
|
798
|
-
}
|
|
799
|
-
const entry = {
|
|
800
|
-
key,
|
|
801
|
-
value,
|
|
802
|
-
tags,
|
|
803
|
-
tagVersions: void 0,
|
|
804
|
-
createdAt: options.createdAt ?? Date.now(),
|
|
805
|
-
createdVersion: ++this.version,
|
|
806
|
-
revalidate
|
|
807
|
-
};
|
|
808
|
-
this.storeLocalEntry(entry);
|
|
809
|
-
emitFarmEvent({
|
|
810
|
-
type: "cache.set",
|
|
811
|
-
key,
|
|
812
|
-
tags: Array.from(tags),
|
|
813
|
-
revalidate: entry.revalidate
|
|
814
|
-
});
|
|
815
|
-
return this.toPublicEntry(entry);
|
|
816
|
-
}
|
|
817
|
-
async setAsync(key, value, options = {}, tagVersions) {
|
|
818
|
-
return this.writeAsync(key, value, options, tagVersions);
|
|
819
|
-
}
|
|
820
|
-
async writeAsync(key, value, options, tagVersions, createdVersion) {
|
|
821
|
-
const revalidate = normalizeRevalidate(options.revalidate);
|
|
822
|
-
const tags = normalizeCacheOptionsTags(options);
|
|
823
|
-
const capturedVersions = tagVersions ?? await this.getAdapterTagVersions(Array.from(tags.values()));
|
|
824
|
-
const entry = {
|
|
825
|
-
key,
|
|
826
|
-
value,
|
|
827
|
-
tags: Array.from(tags),
|
|
828
|
-
tagVersions: capturedVersions,
|
|
829
|
-
createdAt: options.createdAt ?? Date.now(),
|
|
830
|
-
createdVersion: createdVersion ?? ++this.version,
|
|
831
|
-
revalidate
|
|
832
|
-
};
|
|
833
|
-
if (this.local) {
|
|
834
|
-
this.hydrateLocalEntry(entry);
|
|
835
|
-
}
|
|
836
|
-
if (this.adapter) {
|
|
837
|
-
await this.adapter.set(this.createAdapterKey(key), entry);
|
|
838
|
-
}
|
|
839
|
-
emitFarmEvent({
|
|
840
|
-
type: "cache.set",
|
|
841
|
-
key,
|
|
842
|
-
tags: [...entry.tags],
|
|
843
|
-
revalidate: entry.revalidate
|
|
844
|
-
});
|
|
845
|
-
return entry;
|
|
846
|
-
}
|
|
847
|
-
delete(key) {
|
|
848
|
-
const deleted = this.deleteLocalEntry(key);
|
|
849
|
-
emitFarmEvent({ type: "cache.delete", key, deleted });
|
|
850
|
-
return deleted;
|
|
851
|
-
}
|
|
852
|
-
async deleteAsync(key) {
|
|
853
|
-
const deleted = this.deleteLocalEntry(key);
|
|
854
|
-
if (this.adapter) {
|
|
855
|
-
await this.adapter.delete(this.createAdapterKey(key));
|
|
856
|
-
}
|
|
857
|
-
emitFarmEvent({ type: "cache.delete", key, deleted: this.adapter ? true : deleted });
|
|
858
|
-
return this.adapter ? true : deleted;
|
|
859
|
-
}
|
|
860
|
-
clear() {
|
|
861
|
-
const count = this.entries.size;
|
|
862
|
-
this.generation++;
|
|
863
|
-
this.entries.clear();
|
|
864
|
-
this.entriesByTag.clear();
|
|
865
|
-
this.inflight.clear();
|
|
866
|
-
this.invalidatedTagVersions.clear();
|
|
867
|
-
this.activeGenerations.clear();
|
|
868
|
-
this.version = 0;
|
|
869
|
-
emitFarmEvent({ type: "cache.clear", count });
|
|
870
|
-
}
|
|
871
|
-
async clearAsync() {
|
|
872
|
-
this.clear();
|
|
873
|
-
await this.adapter?.clear?.();
|
|
874
|
-
}
|
|
875
|
-
isStale(entry, now = Date.now()) {
|
|
876
|
-
if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
|
|
877
|
-
return true;
|
|
878
|
-
}
|
|
879
|
-
for (const tag of entry.tags) {
|
|
880
|
-
const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
|
|
881
|
-
if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
|
|
882
|
-
return true;
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
return false;
|
|
886
|
-
}
|
|
887
|
-
async isStaleAsync(entry, now = Date.now()) {
|
|
888
|
-
if (this.adapter) {
|
|
889
|
-
return this.isAdapterEntryStale(entry, now);
|
|
890
|
-
}
|
|
891
|
-
return this.isStale(entry, now);
|
|
892
|
-
}
|
|
893
|
-
revalidateTag(tag, options = {}) {
|
|
894
|
-
const normalized = normalizeCacheTag(tag);
|
|
895
|
-
const count = this.invalidateTag(normalized);
|
|
896
|
-
emitFarmEvent(
|
|
897
|
-
options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
|
|
898
|
-
);
|
|
899
|
-
return count;
|
|
900
|
-
}
|
|
901
|
-
async revalidateTagAsync(tag, options = {}) {
|
|
902
|
-
const normalized = normalizeCacheTag(tag);
|
|
903
|
-
const count = this.invalidateTag(normalized);
|
|
904
|
-
await this.adapter?.invalidateTags?.([this.createAdapterTag(normalized)]);
|
|
905
|
-
emitFarmEvent(
|
|
906
|
-
options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
|
|
907
|
-
);
|
|
908
|
-
return count;
|
|
909
|
-
}
|
|
910
|
-
revalidatePath(routePath) {
|
|
911
|
-
const normalizedPath = normalizeRevalidatePath(routePath);
|
|
912
|
-
const pathTag = createPathCacheTag(normalizedPath);
|
|
913
|
-
const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
|
|
914
|
-
const count = this.invalidateTag(pathTag);
|
|
915
|
-
emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
|
|
916
|
-
if (pprCount > 0) {
|
|
917
|
-
emitFarmEvent({
|
|
918
|
-
type: "ppr.shell.invalidated",
|
|
919
|
-
route: normalizedPath,
|
|
920
|
-
reason: "revalidatePath",
|
|
921
|
-
count: pprCount
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
return count;
|
|
925
|
-
}
|
|
926
|
-
async revalidatePathAsync(routePath) {
|
|
927
|
-
const normalizedPath = normalizeRevalidatePath(routePath);
|
|
928
|
-
const pathTag = createPathCacheTag(normalizedPath);
|
|
929
|
-
const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
|
|
930
|
-
const count = this.invalidateTag(pathTag);
|
|
931
|
-
await this.adapter?.invalidateTags?.([this.createAdapterTag(pathTag)]);
|
|
932
|
-
emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
|
|
933
|
-
if (pprCount > 0) {
|
|
934
|
-
emitFarmEvent({
|
|
935
|
-
type: "ppr.shell.invalidated",
|
|
936
|
-
route: normalizedPath,
|
|
937
|
-
reason: "revalidatePath",
|
|
938
|
-
count: pprCount
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
return count;
|
|
942
|
-
}
|
|
943
|
-
async getOrSet(key, producer, options = {}) {
|
|
944
|
-
normalizeRevalidate(options.revalidate);
|
|
945
|
-
const cached = await this.getEntryAsync(key);
|
|
946
|
-
if (cached) {
|
|
947
|
-
return cached.value;
|
|
948
|
-
}
|
|
949
|
-
const inflight = this.inflight.get(key);
|
|
950
|
-
if (inflight && !this.wasInvalidatedSince(inflight.tags, inflight.startVersion)) {
|
|
951
|
-
emitFarmEvent({ type: "cache.dedupe", key });
|
|
952
|
-
return inflight.promise;
|
|
953
|
-
}
|
|
954
|
-
const tags = Array.from(normalizeCacheOptionsTags(options));
|
|
955
|
-
const generation = this.generation;
|
|
956
|
-
const startVersion = this.version;
|
|
957
|
-
const promise = this.fillCacheEntry(key, producer, options, tags, generation).catch((error) => {
|
|
958
|
-
emitFarmEvent({ type: "cache.error", key, operation: "set", error });
|
|
959
|
-
throw error;
|
|
960
|
-
}).finally(() => {
|
|
961
|
-
if (this.inflight.get(key)?.promise === promise) {
|
|
962
|
-
this.inflight.delete(key);
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
this.inflight.set(key, { promise, tags, startVersion });
|
|
966
|
-
return promise;
|
|
967
|
-
}
|
|
968
|
-
/** A fill that started before one of its tags was invalidated cannot satisfy later readers. */
|
|
969
|
-
wasInvalidatedSince(tags, version) {
|
|
970
|
-
for (const tag of tags) {
|
|
971
|
-
const invalidatedVersion = this.invalidatedTagVersions.get(tag);
|
|
972
|
-
if (invalidatedVersion !== void 0 && invalidatedVersion > version) return true;
|
|
973
|
-
}
|
|
974
|
-
return false;
|
|
975
|
-
}
|
|
976
|
-
async fillCacheEntry(key, producer, options, tags, generation) {
|
|
977
|
-
const adapter = this.adapter;
|
|
978
|
-
const namespace = this.namespace;
|
|
979
|
-
const lease = { ...this.lease };
|
|
980
|
-
const leaseKey = `${namespace}:lease:${key}`;
|
|
981
|
-
let leaseToken;
|
|
982
|
-
if (adapter?.acquireLease && adapter.releaseLease && lease.enabled) {
|
|
983
|
-
leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
|
|
984
|
-
if (!leaseToken) {
|
|
985
|
-
const shared2 = await this.waitForAdapterEntry(
|
|
986
|
-
key,
|
|
987
|
-
adapter,
|
|
988
|
-
namespace,
|
|
989
|
-
lease,
|
|
990
|
-
generation
|
|
991
|
-
);
|
|
992
|
-
if (shared2) {
|
|
993
|
-
emitFarmEvent({ type: "cache.dedupe", key });
|
|
994
|
-
return shared2.value;
|
|
995
|
-
}
|
|
996
|
-
if (generation === this.generation) {
|
|
997
|
-
leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
const initialCreatedVersion = this.version;
|
|
1002
|
-
const activeGeneration = {
|
|
1003
|
-
tags: new Set(tags),
|
|
1004
|
-
createdVersion: initialCreatedVersion
|
|
1005
|
-
};
|
|
1006
|
-
this.activeGenerations.add(activeGeneration);
|
|
1007
|
-
try {
|
|
1008
|
-
const initialTagVersions = await this.getAdapterTagVersions(tags, adapter, namespace);
|
|
1009
|
-
const value = await producer();
|
|
1010
|
-
if (generation === this.generation) {
|
|
1011
|
-
await this.writeAsync(key, value, options, initialTagVersions, initialCreatedVersion);
|
|
1012
|
-
}
|
|
1013
|
-
return value;
|
|
1014
|
-
} finally {
|
|
1015
|
-
this.activeGenerations.delete(activeGeneration);
|
|
1016
|
-
this.pruneInvalidatedTagVersions(activeGeneration.tags);
|
|
1017
|
-
if (leaseToken && adapter?.releaseLease) {
|
|
1018
|
-
try {
|
|
1019
|
-
await adapter.releaseLease(leaseKey, leaseToken);
|
|
1020
|
-
} catch (error) {
|
|
1021
|
-
emitFarmEvent({ type: "cache.error", key, operation: "set", error });
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
async waitForAdapterEntry(key, adapter, namespace, lease, generation) {
|
|
1027
|
-
const deadline = Date.now() + lease.waitTimeoutMs;
|
|
1028
|
-
while (Date.now() < deadline) {
|
|
1029
|
-
await delay(lease.pollIntervalMs);
|
|
1030
|
-
if (generation !== this.generation) return void 0;
|
|
1031
|
-
const entry = await adapter.get(`${namespace}:entry:${key}`);
|
|
1032
|
-
if (generation !== this.generation) return void 0;
|
|
1033
|
-
if (!entry) {
|
|
1034
|
-
emitFarmEvent({ type: "cache.miss", key });
|
|
1035
|
-
continue;
|
|
1036
|
-
}
|
|
1037
|
-
assertFarmCacheEntry(entry, key);
|
|
1038
|
-
const stale = await this.isAdapterEntryStale(entry, Date.now(), adapter, namespace);
|
|
1039
|
-
if (generation !== this.generation) return void 0;
|
|
1040
|
-
if (stale) {
|
|
1041
|
-
emitFarmEvent({
|
|
1042
|
-
type: "cache.stale",
|
|
1043
|
-
key,
|
|
1044
|
-
tags: [...entry.tags],
|
|
1045
|
-
revalidate: entry.revalidate
|
|
1046
|
-
});
|
|
1047
|
-
emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
|
|
1048
|
-
} else {
|
|
1049
|
-
emitFarmEvent({
|
|
1050
|
-
type: "cache.hit",
|
|
1051
|
-
key,
|
|
1052
|
-
tags: [...entry.tags],
|
|
1053
|
-
revalidate: entry.revalidate,
|
|
1054
|
-
stale: false
|
|
1055
|
-
});
|
|
1056
|
-
return { ...entry, key };
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
return void 0;
|
|
1060
|
-
}
|
|
1061
|
-
countEntriesForTags(tags) {
|
|
1062
|
-
let count = 0;
|
|
1063
|
-
for (const entry of this.entriesByTag.get(tags[0]) ?? []) {
|
|
1064
|
-
if (tags.every((tag) => entry.tags.has(tag))) {
|
|
1065
|
-
count++;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
return count;
|
|
1069
|
-
}
|
|
1070
|
-
invalidateTag(normalizedTag) {
|
|
1071
|
-
const count = this.entriesByTag.get(normalizedTag)?.size ?? 0;
|
|
1072
|
-
this.invalidatedTagVersions.delete(normalizedTag);
|
|
1073
|
-
this.invalidatedTagVersions.set(normalizedTag, ++this.version);
|
|
1074
|
-
this.pruneInvalidatedTagVersions([normalizedTag]);
|
|
1075
|
-
return count;
|
|
1076
|
-
}
|
|
1077
|
-
toPublicEntry(entry) {
|
|
1078
|
-
return {
|
|
1079
|
-
key: entry.key,
|
|
1080
|
-
value: entry.value,
|
|
1081
|
-
tags: Array.from(entry.tags),
|
|
1082
|
-
tagVersions: entry.tagVersions,
|
|
1083
|
-
createdAt: entry.createdAt,
|
|
1084
|
-
createdVersion: entry.createdVersion,
|
|
1085
|
-
revalidate: entry.revalidate
|
|
1086
|
-
};
|
|
1087
|
-
}
|
|
1088
|
-
hydrateLocalEntry(entry) {
|
|
1089
|
-
this.storeLocalEntry({
|
|
1090
|
-
key: entry.key,
|
|
1091
|
-
value: entry.value,
|
|
1092
|
-
tags: new Set(entry.tags.map(normalizeCacheTag)),
|
|
1093
|
-
tagVersions: entry.tagVersions,
|
|
1094
|
-
createdAt: entry.createdAt,
|
|
1095
|
-
createdVersion: entry.createdVersion ?? ++this.version,
|
|
1096
|
-
revalidate: normalizeRevalidate(entry.revalidate)
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
touchEntry(key, entry) {
|
|
1100
|
-
this.entries.delete(key);
|
|
1101
|
-
this.entries.set(key, entry);
|
|
1102
|
-
}
|
|
1103
|
-
storeLocalEntry(entry) {
|
|
1104
|
-
const removed = [];
|
|
1105
|
-
const replaced = this.detachLocalEntry(entry.key);
|
|
1106
|
-
if (replaced) removed.push(replaced);
|
|
1107
|
-
this.entries.set(entry.key, entry);
|
|
1108
|
-
for (const tag of entry.tags) {
|
|
1109
|
-
let tagged = this.entriesByTag.get(tag);
|
|
1110
|
-
if (!tagged) this.entriesByTag.set(tag, tagged = /* @__PURE__ */ new Set());
|
|
1111
|
-
tagged.add(entry);
|
|
1112
|
-
}
|
|
1113
|
-
while (this.entries.size > this.maxEntries) {
|
|
1114
|
-
const oldestKey = this.entries.keys().next().value;
|
|
1115
|
-
if (oldestKey === void 0) break;
|
|
1116
|
-
removed.push(this.detachLocalEntry(oldestKey));
|
|
1117
|
-
}
|
|
1118
|
-
for (const removedEntry of removed) this.pruneInvalidatedTagVersions(removedEntry.tags);
|
|
1119
|
-
}
|
|
1120
|
-
deleteLocalEntry(key) {
|
|
1121
|
-
const entry = this.detachLocalEntry(key);
|
|
1122
|
-
if (!entry) return false;
|
|
1123
|
-
this.pruneInvalidatedTagVersions(entry.tags);
|
|
1124
|
-
return true;
|
|
1125
|
-
}
|
|
1126
|
-
detachLocalEntry(key) {
|
|
1127
|
-
const entry = this.entries.get(key);
|
|
1128
|
-
if (!entry) return void 0;
|
|
1129
|
-
this.entries.delete(key);
|
|
1130
|
-
for (const tag of entry.tags) {
|
|
1131
|
-
const tagged = this.entriesByTag.get(tag);
|
|
1132
|
-
if (!tagged) continue;
|
|
1133
|
-
tagged.delete(entry);
|
|
1134
|
-
if (tagged.size === 0) this.entriesByTag.delete(tag);
|
|
1135
|
-
}
|
|
1136
|
-
return entry;
|
|
1137
|
-
}
|
|
1138
|
-
/**
|
|
1139
|
-
* Drop invalidation versions that no local entry or active fill can be stale against.
|
|
1140
|
-
* Callers pass only the tags whose dependents just changed, so the cost is bounded by
|
|
1141
|
-
* the entries sharing those tags rather than by the whole cache.
|
|
1142
|
-
*/
|
|
1143
|
-
pruneInvalidatedTagVersions(tags) {
|
|
1144
|
-
tags: for (const tag of tags) {
|
|
1145
|
-
const invalidatedVersion = this.invalidatedTagVersions.get(tag);
|
|
1146
|
-
if (invalidatedVersion === void 0) continue;
|
|
1147
|
-
for (const entry of this.entriesByTag.get(tag) ?? []) {
|
|
1148
|
-
if (entry.createdVersion < invalidatedVersion) continue tags;
|
|
1149
|
-
}
|
|
1150
|
-
for (const generation of this.activeGenerations) {
|
|
1151
|
-
if (generation.tags.has(tag) && generation.createdVersion < invalidatedVersion)
|
|
1152
|
-
continue tags;
|
|
1153
|
-
}
|
|
1154
|
-
this.invalidatedTagVersions.delete(tag);
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
createAdapterKey(key) {
|
|
1158
|
-
return `${this.namespace}:entry:${key}`;
|
|
1159
|
-
}
|
|
1160
|
-
createAdapterTag(tag) {
|
|
1161
|
-
return `${this.namespace}:tag:${tag}`;
|
|
1162
|
-
}
|
|
1163
|
-
async getAdapterTagVersions(tags, adapter = this.adapter, namespace = this.namespace) {
|
|
1164
|
-
if (!adapter?.getTagVersions || tags.length === 0) return {};
|
|
1165
|
-
const normalized = tags.map(normalizeCacheTag);
|
|
1166
|
-
const physicalTags = normalized.map((tag) => `${namespace}:tag:${tag}`);
|
|
1167
|
-
const versions = await adapter.getTagVersions(physicalTags);
|
|
1168
|
-
return Object.fromEntries(
|
|
1169
|
-
normalized.map((tag, index) => [
|
|
1170
|
-
tag,
|
|
1171
|
-
normalizeAdapterVersion(versions[physicalTags[index]])
|
|
1172
|
-
])
|
|
1173
|
-
);
|
|
1174
|
-
}
|
|
1175
|
-
async isAdapterEntryStale(entry, now = Date.now(), adapter = this.adapter, namespace = this.namespace) {
|
|
1176
|
-
if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
|
|
1177
|
-
return true;
|
|
1178
|
-
}
|
|
1179
|
-
const currentVersions = await this.getAdapterTagVersions(entry.tags, adapter, namespace);
|
|
1180
|
-
for (const tag of entry.tags) {
|
|
1181
|
-
if (normalizeAdapterVersion(currentVersions[tag]) > normalizeAdapterVersion(entry.tagVersions?.[tag])) {
|
|
1182
|
-
return true;
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
return false;
|
|
1186
|
-
}
|
|
1187
|
-
};
|
|
1188
|
-
__name(_FarmDataCache, "FarmDataCache");
|
|
1189
|
-
var FarmDataCache = _FarmDataCache;
|
|
1190
|
-
var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
|
|
1191
|
-
var farmDataCacheGlobal = globalThis;
|
|
1192
|
-
var sharedFarmDataCache = farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] ?? (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache());
|
|
1193
|
-
function getFarmDataCache() {
|
|
1194
|
-
return sharedFarmDataCache;
|
|
1195
|
-
}
|
|
1196
|
-
__name(getFarmDataCache, "getFarmDataCache");
|
|
1197
|
-
function configureFarmCache(config) {
|
|
1198
|
-
sharedFarmDataCache.configure(config);
|
|
1199
|
-
}
|
|
1200
|
-
__name(configureFarmCache, "configureFarmCache");
|
|
1201
|
-
function unstable_cache(fn, keyParts = [], options = {}) {
|
|
1202
|
-
return async (...args) => {
|
|
1203
|
-
const locale = getActiveFarmI18nSnapshot()?.locale;
|
|
1204
|
-
const key = createFarmCacheKey([
|
|
1205
|
-
"unstable_cache",
|
|
1206
|
-
getFunctionCacheIdentity(fn),
|
|
1207
|
-
locale ? ["locale", locale] : null,
|
|
1208
|
-
keyParts,
|
|
1209
|
-
args
|
|
1210
|
-
]);
|
|
1211
|
-
return getFarmDataCache().getOrSet(key, () => fn(...args), options);
|
|
1212
|
-
};
|
|
1213
|
-
}
|
|
1214
|
-
__name(unstable_cache, "unstable_cache");
|
|
1215
|
-
function revalidateTag(_tag, _profile) {
|
|
1216
|
-
const cache = getFarmDataCache();
|
|
1217
|
-
if (cache.hasAdapter) {
|
|
1218
|
-
const task = cache.revalidateTagAsync(_tag, {
|
|
1219
|
-
source: "revalidateTag",
|
|
1220
|
-
profile: _profile
|
|
1221
|
-
}).then(() => void 0);
|
|
1222
|
-
notifyFarmCacheTask(task);
|
|
1223
|
-
return task;
|
|
1224
|
-
}
|
|
1225
|
-
cache.revalidateTag(_tag, {
|
|
1226
|
-
source: "revalidateTag",
|
|
1227
|
-
profile: _profile
|
|
1228
|
-
});
|
|
1229
|
-
}
|
|
1230
|
-
__name(revalidateTag, "revalidateTag");
|
|
1231
|
-
function updateTag(tag) {
|
|
1232
|
-
const cache = getFarmDataCache();
|
|
1233
|
-
if (cache.hasAdapter) {
|
|
1234
|
-
const task = cache.revalidateTagAsync(tag, { source: "updateTag" }).then(() => void 0);
|
|
1235
|
-
notifyFarmCacheTask(task);
|
|
1236
|
-
return task;
|
|
1237
|
-
}
|
|
1238
|
-
cache.revalidateTag(tag, { source: "updateTag" });
|
|
1239
|
-
}
|
|
1240
|
-
__name(updateTag, "updateTag");
|
|
1241
|
-
function revalidatePath(routePath) {
|
|
1242
|
-
const cache = getFarmDataCache();
|
|
1243
|
-
if (cache.hasAdapter) {
|
|
1244
|
-
const task = cache.revalidatePathAsync(routePath).then(() => void 0);
|
|
1245
|
-
notifyFarmCacheTask(task);
|
|
1246
|
-
return task;
|
|
1247
|
-
}
|
|
1248
|
-
cache.revalidatePath(routePath);
|
|
1249
|
-
}
|
|
1250
|
-
__name(revalidatePath, "revalidatePath");
|
|
1251
|
-
function invalidate(key) {
|
|
1252
|
-
const clientKey = createRouteDataCacheKey(key);
|
|
1253
|
-
const task = updateTag(createRouteDataCacheTag(key));
|
|
1254
|
-
notifyFarmCacheInvalidation(clientKey);
|
|
1255
|
-
return task;
|
|
1256
|
-
}
|
|
1257
|
-
__name(invalidate, "invalidate");
|
|
1258
|
-
function invalidateRouteData(key) {
|
|
1259
|
-
return invalidate(key);
|
|
1260
|
-
}
|
|
1261
|
-
__name(invalidateRouteData, "invalidateRouteData");
|
|
1262
|
-
async function applyFarmCacheInvalidationTargets(targets) {
|
|
1263
|
-
if (!Array.isArray(targets)) {
|
|
1264
|
-
throw new TypeError("Cache invalidations must resolve to an array of targets.");
|
|
1265
|
-
}
|
|
1266
|
-
const clientKeys = [];
|
|
1267
|
-
for (const target of targets) {
|
|
1268
|
-
assertFarmCacheInvalidationTarget(target);
|
|
1269
|
-
if ("key" in target) {
|
|
1270
|
-
await invalidate(target.key);
|
|
1271
|
-
clientKeys.push(createRouteDataCacheKey(target.key));
|
|
1272
|
-
} else if ("path" in target) {
|
|
1273
|
-
await revalidatePath(target.path);
|
|
1274
|
-
} else {
|
|
1275
|
-
await updateTag(target.tag);
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
return Array.from(new Set(clientKeys));
|
|
1279
|
-
}
|
|
1280
|
-
__name(applyFarmCacheInvalidationTargets, "applyFarmCacheInvalidationTargets");
|
|
1281
|
-
function createPathCacheTag(routePath) {
|
|
1282
|
-
return `path:${normalizeRevalidatePath(routePath)}`;
|
|
1283
|
-
}
|
|
1284
|
-
__name(createPathCacheTag, "createPathCacheTag");
|
|
1285
|
-
function createRouteDataCacheTag(key) {
|
|
1286
|
-
return `route-data:${createRouteDataCacheKey(key)}`;
|
|
1287
|
-
}
|
|
1288
|
-
__name(createRouteDataCacheTag, "createRouteDataCacheTag");
|
|
1289
|
-
function createRouteDataCacheKey(key) {
|
|
1290
|
-
return createFarmCacheKey(Array.isArray(key) ? key : [key]);
|
|
1291
|
-
}
|
|
1292
|
-
__name(createRouteDataCacheKey, "createRouteDataCacheKey");
|
|
1293
|
-
function normalizeRevalidatePath(routePath) {
|
|
1294
|
-
if (typeof routePath !== "string") {
|
|
1295
|
-
throw new TypeError("revalidatePath expects a path string.");
|
|
1296
|
-
}
|
|
1297
|
-
let normalized = routePath.trim();
|
|
1298
|
-
if (!normalized) {
|
|
1299
|
-
throw new Error("revalidatePath expects a non-empty path.");
|
|
1300
|
-
}
|
|
1301
|
-
try {
|
|
1302
|
-
if (/^https?:\/\//i.test(normalized)) {
|
|
1303
|
-
normalized = new URL(normalized).pathname;
|
|
1304
|
-
}
|
|
1305
|
-
} catch {
|
|
1306
|
-
}
|
|
1307
|
-
normalized = normalized.split(/[?#]/, 1)[0] ?? normalized;
|
|
1308
|
-
normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
1309
|
-
normalized = normalized.replace(/\/{2,}/g, "/");
|
|
1310
|
-
normalized = new URL(normalized, "http://farm.invalid").pathname;
|
|
1311
|
-
if (normalized.length > 1) {
|
|
1312
|
-
normalized = normalized.replace(/\/+$/, "");
|
|
1313
|
-
}
|
|
1314
|
-
return normalized || "/";
|
|
1315
|
-
}
|
|
1316
|
-
__name(normalizeRevalidatePath, "normalizeRevalidatePath");
|
|
1317
|
-
function createFarmCacheKey(parts) {
|
|
1318
|
-
return stableSerialize(parts);
|
|
1319
|
-
}
|
|
1320
|
-
__name(createFarmCacheKey, "createFarmCacheKey");
|
|
1321
|
-
function normalizeRevalidate(revalidate) {
|
|
1322
|
-
if (revalidate === false || revalidate === void 0) {
|
|
1323
|
-
return revalidate;
|
|
1324
|
-
}
|
|
1325
|
-
if (!Number.isFinite(revalidate) || revalidate < 0) {
|
|
1326
|
-
throw new TypeError("Cache revalidate must be false or a finite, non-negative number.");
|
|
1327
|
-
}
|
|
1328
|
-
return revalidate;
|
|
1329
|
-
}
|
|
1330
|
-
__name(normalizeRevalidate, "normalizeRevalidate");
|
|
1331
|
-
function normalizeCacheTag(tag) {
|
|
1332
|
-
if (typeof tag !== "string") {
|
|
1333
|
-
throw new TypeError("Cache tags must be strings.");
|
|
1334
|
-
}
|
|
1335
|
-
const normalized = tag.trim();
|
|
1336
|
-
if (!normalized) {
|
|
1337
|
-
throw new Error("Cache tags cannot be empty.");
|
|
1338
|
-
}
|
|
1339
|
-
return normalized;
|
|
1340
|
-
}
|
|
1341
|
-
__name(normalizeCacheTag, "normalizeCacheTag");
|
|
1342
|
-
function normalizeCacheNamespace(namespace) {
|
|
1343
|
-
if (typeof namespace !== "string") {
|
|
1344
|
-
throw new TypeError("Cache namespace must be a string.");
|
|
1345
|
-
}
|
|
1346
|
-
const normalized = namespace.trim().replace(/:+$/g, "");
|
|
1347
|
-
if (!normalized) {
|
|
1348
|
-
throw new Error("Cache namespace cannot be empty.");
|
|
1349
|
-
}
|
|
1350
|
-
return normalized;
|
|
1351
|
-
}
|
|
1352
|
-
__name(normalizeCacheNamespace, "normalizeCacheNamespace");
|
|
1353
|
-
function normalizeAdapterVersion(value) {
|
|
1354
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
|
1355
|
-
}
|
|
1356
|
-
__name(normalizeAdapterVersion, "normalizeAdapterVersion");
|
|
1357
|
-
function normalizePositiveDuration(value, fallback, name) {
|
|
1358
|
-
if (value === void 0) return fallback;
|
|
1359
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
1360
|
-
throw new TypeError(`${name} must be a positive number of milliseconds.`);
|
|
1361
|
-
}
|
|
1362
|
-
return Math.floor(value);
|
|
1363
|
-
}
|
|
1364
|
-
__name(normalizePositiveDuration, "normalizePositiveDuration");
|
|
1365
|
-
function normalizePositiveInteger(value, fallback, name) {
|
|
1366
|
-
if (value === void 0) return fallback;
|
|
1367
|
-
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
1368
|
-
throw new TypeError(`${name} must be a positive integer.`);
|
|
1369
|
-
}
|
|
1370
|
-
return value;
|
|
1371
|
-
}
|
|
1372
|
-
__name(normalizePositiveInteger, "normalizePositiveInteger");
|
|
1373
|
-
function delay(ms) {
|
|
1374
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1375
|
-
}
|
|
1376
|
-
__name(delay, "delay");
|
|
1377
|
-
function normalizeCacheOptionsTags(options) {
|
|
1378
|
-
const tags = /* @__PURE__ */ new Set();
|
|
1379
|
-
for (const tag of options.tags ?? []) {
|
|
1380
|
-
tags.add(normalizeCacheTag(tag));
|
|
1381
|
-
}
|
|
1382
|
-
for (const routePath of options.paths ?? []) {
|
|
1383
|
-
tags.add(createPathCacheTag(routePath));
|
|
1384
|
-
}
|
|
1385
|
-
return tags;
|
|
1386
|
-
}
|
|
1387
|
-
__name(normalizeCacheOptionsTags, "normalizeCacheOptionsTags");
|
|
1388
|
-
function assertFarmCacheEntry(entry, expectedKey) {
|
|
1389
|
-
if (!entry || typeof entry !== "object" || entry.key !== expectedKey || !Array.isArray(entry.tags) || typeof entry.createdAt !== "number") {
|
|
1390
|
-
throw new TypeError(
|
|
1391
|
-
`Cache adapter returned an invalid entry for ${JSON.stringify(expectedKey)}.`
|
|
1392
|
-
);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
__name(assertFarmCacheEntry, "assertFarmCacheEntry");
|
|
1396
|
-
function assertFarmCacheInvalidationTarget(target) {
|
|
1397
|
-
if (!target || typeof target !== "object") {
|
|
1398
|
-
throw new TypeError("Cache invalidation targets must be { key }, { path }, or { tag }.");
|
|
1399
|
-
}
|
|
1400
|
-
if ("key" in target) {
|
|
1401
|
-
const key = target.key;
|
|
1402
|
-
if (typeof key === "string" || Array.isArray(key)) return;
|
|
1403
|
-
} else if ("path" in target && typeof target.path === "string") {
|
|
1404
|
-
return;
|
|
1405
|
-
} else if ("tag" in target && typeof target.tag === "string") {
|
|
1406
|
-
return;
|
|
1407
|
-
}
|
|
1408
|
-
throw new TypeError("Cache invalidation targets must contain a string/array key, path, or tag.");
|
|
1409
|
-
}
|
|
1410
|
-
__name(assertFarmCacheInvalidationTarget, "assertFarmCacheInvalidationTarget");
|
|
1411
|
-
function getFunctionCacheIdentity(fn) {
|
|
1412
|
-
const name = fn.name || "anonymous";
|
|
1413
|
-
return `${name}:${hashFunctionSource(String(fn))}`;
|
|
1414
|
-
}
|
|
1415
|
-
__name(getFunctionCacheIdentity, "getFunctionCacheIdentity");
|
|
1416
|
-
function hashFunctionSource(source) {
|
|
1417
|
-
let hash = 2166136261;
|
|
1418
|
-
for (let index = 0; index < source.length; index++) {
|
|
1419
|
-
hash ^= source.charCodeAt(index);
|
|
1420
|
-
hash = Math.imul(hash, 16777619);
|
|
1421
|
-
}
|
|
1422
|
-
return (hash >>> 0).toString(36);
|
|
1423
|
-
}
|
|
1424
|
-
__name(hashFunctionSource, "hashFunctionSource");
|
|
1425
|
-
function compareCodepoint(a, b) {
|
|
1426
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
1427
|
-
}
|
|
1428
|
-
__name(compareCodepoint, "compareCodepoint");
|
|
1429
|
-
function serializeBinaryBytes(bytes) {
|
|
1430
|
-
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1431
|
-
}
|
|
1432
|
-
__name(serializeBinaryBytes, "serializeBinaryBytes");
|
|
1433
|
-
function serializeCanonicalStringEntries(entries, seen) {
|
|
1434
|
-
const valuesByKey = /* @__PURE__ */ new Map();
|
|
1435
|
-
for (const [key, item] of entries) {
|
|
1436
|
-
const values = valuesByKey.get(key);
|
|
1437
|
-
if (values) values.push(item);
|
|
1438
|
-
else valuesByKey.set(key, [item]);
|
|
1439
|
-
}
|
|
1440
|
-
return Array.from(valuesByKey.keys()).sort(compareCodepoint).flatMap(
|
|
1441
|
-
(key) => valuesByKey.get(key).map((item) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`)
|
|
1442
|
-
).join(",");
|
|
1443
|
-
}
|
|
1444
|
-
__name(serializeCanonicalStringEntries, "serializeCanonicalStringEntries");
|
|
1445
|
-
function isPlainCacheKeyObject(value) {
|
|
1446
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1447
|
-
if (prototype === null) return true;
|
|
1448
|
-
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
1449
|
-
return Object.getPrototypeOf(prototype) === null && typeof constructor === "function" && constructor.name === "Object";
|
|
1450
|
-
}
|
|
1451
|
-
__name(isPlainCacheKeyObject, "isPlainCacheKeyObject");
|
|
1452
|
-
function getCacheKeyValueType(value) {
|
|
1453
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1454
|
-
const constructor = prototype ? Object.getOwnPropertyDescriptor(prototype, "constructor")?.value : void 0;
|
|
1455
|
-
if (typeof constructor === "function" && constructor.name) {
|
|
1456
|
-
return constructor.name;
|
|
1457
|
-
}
|
|
1458
|
-
return Object.prototype.toString.call(value).slice(8, -1) || "object";
|
|
1459
|
-
}
|
|
1460
|
-
__name(getCacheKeyValueType, "getCacheKeyValueType");
|
|
1461
|
-
function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
1462
|
-
if (value === null) return "null";
|
|
1463
|
-
if (value === void 0) return "undefined";
|
|
1464
|
-
const valueType = typeof value;
|
|
1465
|
-
if (valueType === "string") return JSON.stringify(value);
|
|
1466
|
-
if (valueType === "number" || valueType === "boolean" || valueType === "bigint") {
|
|
1467
|
-
return `${valueType}:${String(value)}`;
|
|
1468
|
-
}
|
|
1469
|
-
if (valueType === "symbol") {
|
|
1470
|
-
return `symbol:${String(value)}`;
|
|
1471
|
-
}
|
|
1472
|
-
if (valueType === "function") {
|
|
1473
|
-
return `function:${getFunctionCacheIdentity(value)}`;
|
|
1474
|
-
}
|
|
1475
|
-
if (value instanceof Date) {
|
|
1476
|
-
return Number.isNaN(value.getTime()) ? "date:invalid" : `date:${value.toISOString()}`;
|
|
1477
|
-
}
|
|
1478
|
-
if (value instanceof URL) {
|
|
1479
|
-
return `url:${value.toString()}`;
|
|
1480
|
-
}
|
|
1481
|
-
if (value instanceof RegExp) {
|
|
1482
|
-
return `regexp:${value.toString()}`;
|
|
1483
|
-
}
|
|
1484
|
-
if (value instanceof ArrayBuffer) {
|
|
1485
|
-
return `arraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
|
|
1486
|
-
}
|
|
1487
|
-
if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) {
|
|
1488
|
-
return `sharedarraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
|
|
1489
|
-
}
|
|
1490
|
-
if (ArrayBuffer.isView(value)) {
|
|
1491
|
-
const viewType = Object.prototype.toString.call(value).slice(8, -1);
|
|
1492
|
-
const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
1493
|
-
return `binary:${viewType}:${serializeBinaryBytes(bytes)}`;
|
|
1494
|
-
}
|
|
1495
|
-
if (value && typeof value === "object") {
|
|
1496
|
-
if (seen.has(value)) {
|
|
1497
|
-
return "[Circular]";
|
|
1498
|
-
}
|
|
1499
|
-
seen.add(value);
|
|
1500
|
-
if (Array.isArray(value)) {
|
|
1501
|
-
const items = [];
|
|
1502
|
-
for (let index = 0; index < value.length; index++) {
|
|
1503
|
-
items.push(
|
|
1504
|
-
Object.prototype.hasOwnProperty.call(value, index) ? stableSerialize(value[index], seen) : "[Hole]"
|
|
1505
|
-
);
|
|
1506
|
-
}
|
|
1507
|
-
seen.delete(value);
|
|
1508
|
-
return `[${items.join(",")}]`;
|
|
1509
|
-
}
|
|
1510
|
-
if (value instanceof Set) {
|
|
1511
|
-
const items = Array.from(value, (item) => stableSerialize(item, seen)).sort(compareCodepoint);
|
|
1512
|
-
seen.delete(value);
|
|
1513
|
-
return `set:[${items.join(",")}]`;
|
|
1514
|
-
}
|
|
1515
|
-
if (value instanceof Map) {
|
|
1516
|
-
const items = Array.from(
|
|
1517
|
-
value,
|
|
1518
|
-
([key, item]) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`
|
|
1519
|
-
).sort(compareCodepoint);
|
|
1520
|
-
seen.delete(value);
|
|
1521
|
-
return `map:[${items.join(",")}]`;
|
|
1522
|
-
}
|
|
1523
|
-
if (value instanceof URLSearchParams) {
|
|
1524
|
-
const serialized2 = serializeCanonicalStringEntries(value, seen);
|
|
1525
|
-
seen.delete(value);
|
|
1526
|
-
return `urlsearchparams:[${serialized2}]`;
|
|
1527
|
-
}
|
|
1528
|
-
if (value instanceof Headers) {
|
|
1529
|
-
const serialized2 = serializeCanonicalStringEntries(value, seen);
|
|
1530
|
-
seen.delete(value);
|
|
1531
|
-
return `headers:[${serialized2}]`;
|
|
1532
|
-
}
|
|
1533
|
-
if (!isPlainCacheKeyObject(value)) {
|
|
1534
|
-
throw new TypeError(
|
|
1535
|
-
`Cache keys do not support ${getCacheKeyValueType(value)} values. Convert the value to an explicit stable string or structured key before caching.`
|
|
1536
|
-
);
|
|
1537
|
-
}
|
|
1538
|
-
const entries = Object.entries(value).sort(
|
|
1539
|
-
([a], [b]) => compareCodepoint(a, b)
|
|
1540
|
-
);
|
|
1541
|
-
const serialized = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item, seen)}`).join(",");
|
|
1542
|
-
seen.delete(value);
|
|
1543
|
-
return `{${serialized}}`;
|
|
1544
|
-
}
|
|
1545
|
-
return String(value);
|
|
1546
|
-
}
|
|
1547
|
-
__name(stableSerialize, "stableSerialize");
|
|
1548
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1549
|
-
0 && (module.exports = {
|
|
1550
|
-
FarmDataCache,
|
|
1551
|
-
applyFarmCacheInvalidationTargets,
|
|
1552
|
-
applyFarmCacheInvalidations,
|
|
1553
|
-
configureFarmCache,
|
|
1554
|
-
createFarmCacheInvalidationStream,
|
|
1555
|
-
createFarmCacheKey,
|
|
1556
|
-
createPathCacheTag,
|
|
1557
|
-
createRouteDataCacheKey,
|
|
1558
|
-
createRouteDataCacheTag,
|
|
1559
|
-
defineCacheKey,
|
|
1560
|
-
getFarmDataCache,
|
|
1561
|
-
invalidate,
|
|
1562
|
-
invalidateRouteData,
|
|
1563
|
-
normalizeRevalidatePath,
|
|
1564
|
-
revalidatePath,
|
|
1565
|
-
revalidateTag,
|
|
1566
|
-
storageCacheAdapter,
|
|
1567
|
-
unstable_cache,
|
|
1568
|
-
updateTag
|
|
1569
|
-
});
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunkH6G5INWMcjs = require('./chunk-H6G5INWM.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _chunkZEG3OPIBcjs = require('./chunk-ZEG3OPIB.cjs');
|
|
24
|
+
require('./chunk-LIUGYUX3.cjs');
|
|
25
|
+
require('./chunk-E3UK5IIB.cjs');
|
|
26
|
+
require('./chunk-S3JO3N4H.cjs');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
exports.FarmDataCache = _chunkH6G5INWMcjs.FarmDataCache; exports.applyFarmCacheInvalidationTargets = _chunkH6G5INWMcjs.applyFarmCacheInvalidationTargets; exports.applyFarmCacheInvalidations = _chunkZEG3OPIBcjs.applyFarmCacheInvalidations; exports.configureFarmCache = _chunkH6G5INWMcjs.configureFarmCache; exports.createFarmCacheInvalidationStream = _chunkH6G5INWMcjs.createFarmCacheInvalidationStream; exports.createFarmCacheKey = _chunkH6G5INWMcjs.createFarmCacheKey; exports.createPathCacheTag = _chunkH6G5INWMcjs.createPathCacheTag; exports.createRouteDataCacheKey = _chunkH6G5INWMcjs.createRouteDataCacheKey; exports.createRouteDataCacheTag = _chunkH6G5INWMcjs.createRouteDataCacheTag; exports.defineCacheKey = _chunkH6G5INWMcjs.defineCacheKey; exports.getFarmDataCache = _chunkH6G5INWMcjs.getFarmDataCache; exports.invalidate = _chunkH6G5INWMcjs.invalidate; exports.invalidateRouteData = _chunkH6G5INWMcjs.invalidateRouteData; exports.normalizeRevalidatePath = _chunkH6G5INWMcjs.normalizeRevalidatePath; exports.revalidatePath = _chunkH6G5INWMcjs.revalidatePath; exports.revalidateTag = _chunkH6G5INWMcjs.revalidateTag; exports.storageCacheAdapter = _chunkH6G5INWMcjs.storageCacheAdapter; exports.unstable_cache = _chunkH6G5INWMcjs.unstable_cache; exports.updateTag = _chunkH6G5INWMcjs.updateTag;
|