@farm.js/core 0.1.14 → 0.1.16

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.
Files changed (123) hide show
  1. package/dist/agent-runtime.d.mts +5 -2
  2. package/dist/agent-runtime.d.ts +5 -2
  3. package/dist/api/client.d.mts +3 -2
  4. package/dist/api/client.d.ts +3 -2
  5. package/dist/api/route-manager.d.mts +5 -2
  6. package/dist/api/route-manager.d.ts +5 -2
  7. package/dist/api/runtime.d.mts +3 -2
  8. package/dist/api/runtime.d.ts +3 -2
  9. package/dist/{api-client-C8d7BZNp.d.mts → api-client-B-n3pm_Q.d.mts} +2 -1
  10. package/dist/{api-client-BWrEbxfO.d.ts → api-client-C0_NZEBl.d.ts} +2 -1
  11. package/dist/api.d.mts +7 -4
  12. package/dist/api.d.ts +7 -4
  13. package/dist/{app-wIYse61b.d.ts → app-AyjEsCBq.d.ts} +3 -3
  14. package/dist/{app-B3nVSjen.d.mts → app-CYPHeOo_.d.mts} +3 -3
  15. package/dist/app-markdown.d.mts +6 -3
  16. package/dist/app-markdown.d.ts +6 -3
  17. package/dist/{chunk-FOGLGRDS.mjs → chunk-7HDZYYS4.mjs} +100 -8
  18. package/dist/{chunk-DNCKVMSV.mjs → chunk-IL5RWYK7.mjs} +1 -1
  19. package/dist/{chunk-GNTPTTLA.mjs → chunk-IXTEENRS.mjs} +1 -1
  20. package/dist/{chunk-J2F5LFQ2.mjs → chunk-NHHKW2T6.mjs} +175 -8
  21. package/dist/{chunk-NJ47VORC.mjs → chunk-NUD6XBMO.mjs} +1 -1
  22. package/dist/{chunk-U6CRU23N.mjs → chunk-TYVVIQ5M.mjs} +10 -7
  23. package/dist/{chunk-W7IVHTOP.mjs → chunk-UQZPTIML.mjs} +15 -2
  24. package/dist/{chunk-S3QW3BIS.mjs → chunk-VVTREAG5.mjs} +89 -4
  25. package/dist/{client-plugins-C1EgdoJM.d.mts → client-plugins-CIPRtSsW.d.mts} +16 -4
  26. package/dist/{client-plugins-CslwYp3E.d.ts → client-plugins-CqVtZi5X.d.ts} +16 -4
  27. package/dist/client-plugins.d.mts +5 -2
  28. package/dist/client-plugins.d.ts +5 -2
  29. package/dist/client.d.mts +8 -7
  30. package/dist/client.d.ts +8 -7
  31. package/dist/config.d.mts +5 -2
  32. package/dist/config.d.ts +5 -2
  33. package/dist/{devtools-PCGEBRSC.mjs → devtools-IU7LKZOH.mjs} +2 -2
  34. package/dist/docs.cjs +74 -3
  35. package/dist/docs.mjs +3 -3
  36. package/dist/{route-C6UClI1z.d.mts → endpoint-Bu3XgeMK.d.mts} +3 -128
  37. package/dist/{route-CHBaW55F.d.ts → endpoint-kSAxE52R.d.ts} +3 -128
  38. package/dist/env.cjs +101 -8
  39. package/dist/env.d.mts +20 -2
  40. package/dist/env.d.ts +20 -2
  41. package/dist/env.mjs +3 -1
  42. package/dist/index.cjs +383 -24
  43. package/dist/index.d.mts +16 -15
  44. package/dist/index.d.ts +16 -15
  45. package/dist/index.mjs +20 -8
  46. package/dist/integrations.d.mts +5 -2
  47. package/dist/integrations.d.ts +5 -2
  48. package/dist/internal/app-markdown-runtime.d.mts +5 -2
  49. package/dist/internal/app-markdown-runtime.d.ts +5 -2
  50. package/dist/internal/build-runtime.cjs +435 -174
  51. package/dist/internal/build-runtime.d.mts +7 -4
  52. package/dist/internal/build-runtime.d.ts +7 -4
  53. package/dist/internal/build-runtime.mjs +6 -6
  54. package/dist/internal/cli-runtime.cjs +68 -4
  55. package/dist/internal/cli-runtime.mjs +2 -2
  56. package/dist/internal/client-error-overlay.cjs +1 -1
  57. package/dist/internal/client-error-overlay.mjs +1 -1
  58. package/dist/internal/compression-runtime.d.mts +5 -2
  59. package/dist/internal/compression-runtime.d.ts +5 -2
  60. package/dist/internal/config-runtime.cjs +68 -4
  61. package/dist/internal/config-runtime.d.mts +6 -3
  62. package/dist/internal/config-runtime.d.ts +6 -3
  63. package/dist/internal/config-runtime.mjs +2 -2
  64. package/dist/internal/product-telemetry-runtime.cjs +1 -1
  65. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  66. package/dist/internal/production-runtime.d.mts +11 -8
  67. package/dist/internal/production-runtime.d.ts +11 -8
  68. package/dist/{metadata-BsUcOEXg.d.ts → metadata-8g__AMPM.d.ts} +1 -1
  69. package/dist/{metadata-B1bxCPUY.d.mts → metadata-OMX6wFNf.d.mts} +1 -1
  70. package/dist/middleware.d.mts +7 -4
  71. package/dist/middleware.d.ts +7 -4
  72. package/dist/{nitro-ICBP5APY.mjs → nitro-3N4ZXRYM.mjs} +5 -2
  73. package/dist/plugin.cjs +278 -11
  74. package/dist/plugin.d.mts +5 -2
  75. package/dist/plugin.d.ts +5 -2
  76. package/dist/plugin.mjs +3 -3
  77. package/dist/{production-runtime-CsNn2-zx.d.ts → production-runtime-BJh7o6Cr.d.ts} +1 -1
  78. package/dist/{production-runtime-BDllolVh.d.mts → production-runtime-W3M0eNDV.d.mts} +1 -1
  79. package/dist/{render-plan-EG4hNFjy.d.ts → render-plan-Be4ZGTJP.d.ts} +1 -1
  80. package/dist/{render-plan-CNUlzylR.d.mts → render-plan-io7pvDNc.d.mts} +1 -1
  81. package/dist/renderer-client.d.mts +5 -4
  82. package/dist/renderer-client.d.ts +5 -4
  83. package/dist/{request-Blh_f7Z3.d.mts → request-DZkHYQ89.d.mts} +1 -1
  84. package/dist/{request-DsVSQVfD.d.ts → request-G8JhKr4F.d.ts} +1 -1
  85. package/dist/request.d.mts +6 -3
  86. package/dist/request.d.ts +6 -3
  87. package/dist/route-BxNJT447.d.ts +128 -0
  88. package/dist/route-C_eLaFTZ.d.mts +128 -0
  89. package/dist/{route-rendering-hUETRCbM.d.ts → route-rendering-BcLLPJgN.d.ts} +1 -1
  90. package/dist/{route-rendering-LT4XSoQK.d.mts → route-rendering-CbAKr1TY.d.mts} +1 -1
  91. package/dist/routes.d.mts +4 -2
  92. package/dist/routes.d.ts +4 -2
  93. package/dist/server-fn-client.d.mts +3 -2
  94. package/dist/server-fn-client.d.ts +3 -2
  95. package/dist/server-fn.cjs +141 -3
  96. package/dist/server-fn.d.mts +72 -1
  97. package/dist/server-fn.d.ts +72 -1
  98. package/dist/server-fn.mjs +12 -1
  99. package/dist/server-plugins.d.mts +6 -3
  100. package/dist/server-plugins.d.ts +6 -3
  101. package/dist/server-query-client.d.mts +1 -0
  102. package/dist/server-query-client.d.ts +1 -0
  103. package/dist/server-query.cjs +60 -3
  104. package/dist/server-query.d.mts +6 -1
  105. package/dist/server-query.d.ts +6 -1
  106. package/dist/server-query.mjs +3 -2
  107. package/dist/server.cjs +331 -15
  108. package/dist/server.d.mts +9 -8
  109. package/dist/server.d.ts +9 -8
  110. package/dist/server.mjs +6 -6
  111. package/dist/{spa-router-csKR9Ebj.d.mts → spa-router-BcS_4nqm.d.mts} +2 -2
  112. package/dist/{spa-router-Y_2FSJQK.d.ts → spa-router-BzFBUJkn.d.ts} +2 -2
  113. package/dist/testing.d.mts +5 -3
  114. package/dist/testing.d.ts +5 -3
  115. package/dist/{utils-DR2wfZAn.d.mts → utils-5kQP1mFR.d.mts} +1 -1
  116. package/dist/{utils-jISOE9SD.d.ts → utils-C4yrAhNc.d.ts} +1 -1
  117. package/dist/version.cjs +1 -1
  118. package/dist/version.mjs +1 -1
  119. package/dist/vite.cjs +416 -153
  120. package/dist/vite.d.mts +5 -2
  121. package/dist/vite.d.ts +5 -2
  122. package/dist/vite.mjs +3 -3
  123. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -14902,9 +14902,10 @@ function collectIsolatedClientBoundaries(ownerPath, root, options = {}) {
14902
14902
  const importedBindings = getStaticImportBindings(content);
14903
14903
  let estimatedBoundaryCount2 = 0;
14904
14904
  for (const specifier of new Set(getImportSpecifiers(content))) {
14905
- const importedPath = resolveImportedModuleSourcePath(moduleSourcePath, specifier, root);
14905
+ const imported = resolveImportedModule(moduleSourcePath, specifier, root);
14906
+ const importedPath = imported.path;
14906
14907
  if (!importedPath) continue;
14907
- if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
14908
+ if (!imported.local) {
14908
14909
  const packageMetadata = inspectPackageClientBoundary(importedPath, root, /* @__PURE__ */ new Set());
14909
14910
  if (packageMetadata.shouldHydrate) {
14910
14911
  if (options.staticPackageBoundaries) {
@@ -14972,8 +14973,8 @@ function inspectClientModuleMetadata(resolvedPath, root, visited, inspectIslandE
14972
14973
  let importsClientBoundary = false;
14973
14974
  let importedIslandStrategy = null;
14974
14975
  for (const specifier of getImportSpecifiers(content)) {
14975
- const importedPath = resolveImportedModuleSourcePath(resolvedPath, specifier, root);
14976
- const importedMetadata = !specifier.startsWith(".") && !specifier.startsWith("/") ? inspectPackageClientBoundary(importedPath, root, visited) : inspectClientModuleMetadata(importedPath, root, visited, false);
14976
+ const imported = resolveImportedModule(resolvedPath, specifier, root);
14977
+ const importedMetadata = imported.local ? inspectClientModuleMetadata(imported.path, root, visited, false) : inspectPackageClientBoundary(imported.path, root, visited);
14977
14978
  if (importedMetadata.isClientComponent || importedMetadata.shouldHydrate) {
14978
14979
  importsClientBoundary = true;
14979
14980
  if (importedIslandStrategy === null) {
@@ -15098,6 +15099,161 @@ function isTypeOnlyNamedClause(tokens, startIndex, endIndex) {
15098
15099
  }
15099
15100
  return true;
15100
15101
  }
15102
+ function resolveImportedModule(importerPath, specifier, root) {
15103
+ if (specifier.startsWith(".") || specifier.startsWith("/")) {
15104
+ return { path: resolveImportedModuleSourcePath(importerPath, specifier, root), local: true };
15105
+ }
15106
+ const aliased = resolveProjectAliasSourcePath(specifier, root);
15107
+ if (aliased !== void 0) return { path: aliased, local: true };
15108
+ return { path: resolvePackageModuleSourcePath(importerPath, specifier, root), local: false };
15109
+ }
15110
+ function resolveProjectAliasSourcePath(specifier, root) {
15111
+ if (!root) return void 0;
15112
+ const projectRoot = import_path4.default.resolve(root);
15113
+ let match;
15114
+ for (const alias of getProjectImportAliases(projectRoot)) {
15115
+ const captured = matchProjectImportAlias(alias, specifier);
15116
+ if (captured === null) continue;
15117
+ if (!match || alias.prefix.length > match.alias.prefix.length) match = { alias, captured };
15118
+ }
15119
+ if (!match) return void 0;
15120
+ return resolveSourceCandidate(
15121
+ match.alias.targets.map(
15122
+ (target) => import_path4.default.normalize(match.alias.wildcard ? target.replace("*", match.captured) : target)
15123
+ )
15124
+ );
15125
+ }
15126
+ function matchProjectImportAlias(alias, specifier) {
15127
+ if (!alias.wildcard) return specifier === alias.prefix ? "" : null;
15128
+ if (specifier.length < alias.prefix.length + alias.suffix.length || !specifier.startsWith(alias.prefix) || !specifier.endsWith(alias.suffix)) {
15129
+ return null;
15130
+ }
15131
+ return specifier.slice(alias.prefix.length, specifier.length - alias.suffix.length);
15132
+ }
15133
+ function getProjectImportAliases(projectRoot) {
15134
+ const stamp = PROJECT_ALIAS_FILES.map((file) => {
15135
+ try {
15136
+ return String(import_fs2.default.statSync(import_path4.default.join(projectRoot, file)).mtimeMs);
15137
+ } catch {
15138
+ return "-";
15139
+ }
15140
+ }).join(":");
15141
+ const cached = projectImportAliasCache.get(projectRoot);
15142
+ if (cached?.stamp === stamp) return cached.aliases;
15143
+ const aliases = [
15144
+ ...readTsconfigPathAliases(projectRoot),
15145
+ ...readPackageImportAliases(projectRoot)
15146
+ ];
15147
+ if (!aliases.some((alias) => alias.prefix === "@/")) {
15148
+ aliases.push({
15149
+ prefix: "@/",
15150
+ suffix: "",
15151
+ wildcard: true,
15152
+ targets: [import_path4.default.join(projectRoot, "src", "*")]
15153
+ });
15154
+ }
15155
+ projectImportAliasCache.set(projectRoot, { stamp, aliases });
15156
+ return aliases;
15157
+ }
15158
+ function readTsconfigPathAliases(projectRoot) {
15159
+ for (const name2 of ["tsconfig.json", "jsconfig.json"]) {
15160
+ const configPath = import_path4.default.join(projectRoot, name2);
15161
+ if (!import_fs2.default.existsSync(configPath)) continue;
15162
+ const resolved = readTsconfigPaths(configPath, /* @__PURE__ */ new Set());
15163
+ if (!resolved?.paths) return [];
15164
+ const base = resolved.baseUrl ?? resolved.pathsDirectory;
15165
+ return Object.entries(resolved.paths).flatMap(([pattern, targets]) => {
15166
+ if (!Array.isArray(targets)) return [];
15167
+ const wildcardIndex = pattern.indexOf("*");
15168
+ return [
15169
+ {
15170
+ prefix: wildcardIndex === -1 ? pattern : pattern.slice(0, wildcardIndex),
15171
+ suffix: wildcardIndex === -1 ? "" : pattern.slice(wildcardIndex + 1),
15172
+ wildcard: wildcardIndex !== -1,
15173
+ targets: targets.filter((target) => typeof target === "string").map((target) => import_path4.default.resolve(base, target))
15174
+ }
15175
+ ];
15176
+ });
15177
+ }
15178
+ return [];
15179
+ }
15180
+ function readTsconfigPaths(configPath, visited) {
15181
+ if (visited.has(configPath)) return null;
15182
+ visited.add(configPath);
15183
+ const config = readJsonWithComments(configPath);
15184
+ if (!config) return null;
15185
+ const directory = import_path4.default.dirname(configPath);
15186
+ const parents = (Array.isArray(config.extends) ? config.extends : [config.extends]).filter(
15187
+ (parent) => typeof parent === "string" && parent.startsWith(".")
15188
+ );
15189
+ let inherited = null;
15190
+ for (const parent of parents) {
15191
+ const parentPath = import_path4.default.resolve(
15192
+ directory,
15193
+ parent.endsWith(".json") ? parent : `${parent}.json`
15194
+ );
15195
+ inherited = readTsconfigPaths(parentPath, visited) ?? inherited;
15196
+ }
15197
+ const options = config.compilerOptions ?? {};
15198
+ const baseUrl = typeof options.baseUrl === "string" ? import_path4.default.resolve(directory, options.baseUrl) : inherited?.baseUrl;
15199
+ if (options.paths && typeof options.paths === "object") {
15200
+ return { paths: options.paths, pathsDirectory: directory, baseUrl };
15201
+ }
15202
+ return inherited ? { ...inherited, baseUrl } : { pathsDirectory: directory, baseUrl };
15203
+ }
15204
+ function readPackageImportAliases(projectRoot) {
15205
+ const imports = readPackageJson(import_path4.default.join(projectRoot, "package.json"))?.imports;
15206
+ if (!imports || typeof imports !== "object") return [];
15207
+ return Object.entries(imports).flatMap(([pattern, value]) => {
15208
+ const target = resolveConditionalExportTarget(value);
15209
+ if (!pattern.startsWith("#") || !target?.startsWith("./")) return [];
15210
+ const wildcardIndex = pattern.indexOf("*");
15211
+ return [
15212
+ {
15213
+ prefix: wildcardIndex === -1 ? pattern : pattern.slice(0, wildcardIndex),
15214
+ suffix: wildcardIndex === -1 ? "" : pattern.slice(wildcardIndex + 1),
15215
+ wildcard: wildcardIndex !== -1,
15216
+ targets: [import_path4.default.resolve(projectRoot, target)]
15217
+ }
15218
+ ];
15219
+ });
15220
+ }
15221
+ function readJsonWithComments(filePath) {
15222
+ let source;
15223
+ try {
15224
+ source = import_fs2.default.readFileSync(filePath, "utf8");
15225
+ } catch {
15226
+ return null;
15227
+ }
15228
+ let output = "";
15229
+ let inString = false;
15230
+ for (let index = 0; index < source.length; index++) {
15231
+ const char = source[index];
15232
+ if (inString) {
15233
+ output += char;
15234
+ if (char === "\\") output += source[++index] ?? "";
15235
+ else if (char === '"') inString = false;
15236
+ continue;
15237
+ }
15238
+ if (char === '"') {
15239
+ inString = true;
15240
+ output += char;
15241
+ } else if (char === "/" && source[index + 1] === "/") {
15242
+ while (index < source.length && source[index] !== "\n") index++;
15243
+ output += "\n";
15244
+ } else if (char === "/" && source[index + 1] === "*") {
15245
+ const end = source.indexOf("*/", index + 2);
15246
+ index = end === -1 ? source.length : end + 1;
15247
+ } else {
15248
+ output += char;
15249
+ }
15250
+ }
15251
+ try {
15252
+ return JSON.parse(output.replace(/,(\s*[}\]])/g, "$1"));
15253
+ } catch {
15254
+ return null;
15255
+ }
15256
+ }
15101
15257
  function resolveImportedModuleSourcePath(importerPath, specifier, root) {
15102
15258
  if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
15103
15259
  return resolvePackageModuleSourcePath(importerPath, specifier, root);
@@ -15228,7 +15384,7 @@ function resolveSourceCandidate(candidates) {
15228
15384
  }
15229
15385
  return null;
15230
15386
  }
15231
- var import_fs2, import_path4, import_url3, FARM_ISOLATED_HYDRATION_MAX_BOUNDARIES, RESOLVABLE_SOURCE_EXTENSIONS, REGEXP_PREFIX_PUNCTUATION, REGEXP_PREFIX_KEYWORDS, PARSER_SENSITIVE_JSX_CONTAINERS;
15387
+ var import_fs2, import_path4, import_url3, FARM_ISOLATED_HYDRATION_MAX_BOUNDARIES, RESOLVABLE_SOURCE_EXTENSIONS, REGEXP_PREFIX_PUNCTUATION, REGEXP_PREFIX_KEYWORDS, PARSER_SENSITIVE_JSX_CONTAINERS, projectImportAliasCache, PROJECT_ALIAS_FILES;
15232
15388
  var init_client_component = __esm({
15233
15389
  "src/utils/client-component.ts"() {
15234
15390
  "use strict";
@@ -15334,6 +15490,16 @@ var init_client_component = __esm({
15334
15490
  __name(inspectPackageClientBoundary, "inspectPackageClientBoundary");
15335
15491
  __name(getImportSpecifiers, "getImportSpecifiers");
15336
15492
  __name(isTypeOnlyNamedClause, "isTypeOnlyNamedClause");
15493
+ __name(resolveImportedModule, "resolveImportedModule");
15494
+ projectImportAliasCache = /* @__PURE__ */ new Map();
15495
+ PROJECT_ALIAS_FILES = ["tsconfig.json", "jsconfig.json", "package.json"];
15496
+ __name(resolveProjectAliasSourcePath, "resolveProjectAliasSourcePath");
15497
+ __name(matchProjectImportAlias, "matchProjectImportAlias");
15498
+ __name(getProjectImportAliases, "getProjectImportAliases");
15499
+ __name(readTsconfigPathAliases, "readTsconfigPathAliases");
15500
+ __name(readTsconfigPaths, "readTsconfigPaths");
15501
+ __name(readPackageImportAliases, "readPackageImportAliases");
15502
+ __name(readJsonWithComments, "readJsonWithComments");
15337
15503
  __name(resolveImportedModuleSourcePath, "resolveImportedModuleSourcePath");
15338
15504
  __name(resolvePackageModuleSourcePath, "resolvePackageModuleSourcePath");
15339
15505
  __name(findPackageDirectory, "findPackageDirectory");
@@ -21872,7 +22038,7 @@ var init_server3 = __esm({
21872
22038
  var version;
21873
22039
  var init_package = __esm({
21874
22040
  "package.json"() {
21875
- version = "0.1.14";
22041
+ version = "0.1.16";
21876
22042
  }
21877
22043
  });
21878
22044
 
@@ -26207,21 +26373,40 @@ function resolveEnv(config, source = getProcessEnv()) {
26207
26373
  };
26208
26374
  return resolved;
26209
26375
  }
26376
+ function createBundledEnv(env2, source = getProcessEnv()) {
26377
+ const resolved = normalizeResolvedEnv(env2 ?? {});
26378
+ const server = {};
26379
+ const runtime3 = {};
26380
+ for (const [key, value] of Object.entries(resolved.server)) {
26381
+ if (source[key] === void 0) {
26382
+ server[key] = value;
26383
+ } else {
26384
+ runtime3[key] = getRuntimeEnvType(value);
26385
+ }
26386
+ }
26387
+ return {
26388
+ server,
26389
+ public: resolved.public,
26390
+ ...Object.keys(runtime3).length > 0 ? { runtime: { server: runtime3 } } : {}
26391
+ };
26392
+ }
26210
26393
  function setEnv(env2) {
26211
- currentEnv = normalizeResolvedEnv(env2);
26394
+ currentEnv = prepareEnv(env2);
26212
26395
  if (typeof window === "undefined") {
26213
26396
  farmEnvGlobal[FARM_ENV_SYMBOL] = currentEnv;
26214
26397
  }
26215
26398
  }
26216
26399
  function getResolvedEnv() {
26217
- return getCurrentEnv();
26400
+ const env2 = getCurrentEnv();
26401
+ if (typeof window === "undefined") readRuntimeServerEnv(env2);
26402
+ return env2;
26218
26403
  }
26219
26404
  function getEnv(key) {
26220
- assertServerEnvAccess();
26405
+ const server = getEnvScope("server");
26221
26406
  if (key === void 0) {
26222
- return getCurrentEnv().server;
26407
+ return server;
26223
26408
  }
26224
- return getCurrentEnv().server[key];
26409
+ return readServerEnvKey(server, key);
26225
26410
  }
26226
26411
  function getPublicEnv(key) {
26227
26412
  if (key === void 0) {
@@ -26262,7 +26447,7 @@ function createEnvProxy(scope) {
26262
26447
  return void 0;
26263
26448
  }
26264
26449
  const env2 = getEnvScope(scope);
26265
- return env2[property];
26450
+ return scope === "server" ? readServerEnvKey(env2, property) : env2[property];
26266
26451
  },
26267
26452
  ownKeys() {
26268
26453
  return Reflect.ownKeys(getEnvScope(scope));
@@ -26285,10 +26470,75 @@ function createEnvProxy(scope) {
26285
26470
  );
26286
26471
  }
26287
26472
  function getEnvScope(scope) {
26473
+ const env2 = getCurrentEnv();
26288
26474
  if (scope === "server") {
26289
26475
  assertServerEnvAccess();
26476
+ readRuntimeServerEnv(env2);
26477
+ }
26478
+ return env2[scope] || {};
26479
+ }
26480
+ function readServerEnvKey(server, key) {
26481
+ const value = server[key];
26482
+ if (value === void 0) {
26483
+ const state = getCurrentEnv()[FARM_ENV_RUNTIME_SYMBOL];
26484
+ if (state && key in state.pending && !state.warned.has(key)) {
26485
+ state.warned.add(key);
26486
+ console.warn(
26487
+ `[Farm] Server env "${key}" was set when this app was built but is not set where the server runs, so it reads as undefined. Farm reads server env at runtime and does not store it in the build output; set "${key}" in the server's environment.`
26488
+ );
26489
+ }
26490
+ }
26491
+ return value;
26492
+ }
26493
+ function readRuntimeServerEnv(env2) {
26494
+ const state = env2[FARM_ENV_RUNTIME_SYMBOL];
26495
+ if (!state) return;
26496
+ const source = getProcessEnv();
26497
+ for (const [key, type] of Object.entries(state.pending)) {
26498
+ const raw = source[key];
26499
+ if (raw === void 0) continue;
26500
+ env2.server[key] = coerceRuntimeEnvValue(raw, type);
26501
+ delete state.pending[key];
26502
+ }
26503
+ }
26504
+ function getRuntimeEnvType(value) {
26505
+ if (typeof value === "number") return "number";
26506
+ if (typeof value === "boolean") return "boolean";
26507
+ if (value !== null && typeof value === "object" && !(value instanceof Date)) return "json";
26508
+ return "string";
26509
+ }
26510
+ function coerceRuntimeEnvValue(raw, type) {
26511
+ if (type === "number") {
26512
+ const value = Number(raw);
26513
+ return raw.trim() !== "" && Number.isFinite(value) ? value : raw;
26514
+ }
26515
+ if (type === "boolean") {
26516
+ if (/^(true|1)$/i.test(raw.trim())) return true;
26517
+ if (/^(false|0|)$/i.test(raw.trim())) return false;
26518
+ return raw;
26519
+ }
26520
+ if (type === "json") {
26521
+ try {
26522
+ return JSON.parse(raw);
26523
+ } catch {
26524
+ return raw;
26525
+ }
26290
26526
  }
26291
- return getCurrentEnv()[scope] || {};
26527
+ return raw;
26528
+ }
26529
+ function prepareEnv(env2) {
26530
+ const normalized = normalizeResolvedEnv(env2);
26531
+ const runtime3 = env2.runtime?.server;
26532
+ if (!isRecord4(runtime3) || Object.keys(runtime3).length === 0) return normalized;
26533
+ const prepared = { server: { ...normalized.server }, public: normalized.public };
26534
+ Object.defineProperty(prepared, FARM_ENV_RUNTIME_SYMBOL, {
26535
+ value: {
26536
+ pending: { ...runtime3 },
26537
+ warned: /* @__PURE__ */ new Set()
26538
+ },
26539
+ enumerable: false
26540
+ });
26541
+ return prepared;
26292
26542
  }
26293
26543
  function assertServerEnvAccess() {
26294
26544
  if (typeof window !== "undefined") {
@@ -26317,7 +26567,7 @@ function getCurrentEnv() {
26317
26567
  function getInjectedEnv() {
26318
26568
  try {
26319
26569
  if (typeof __FARM_ENV__ !== "undefined" && __FARM_ENV__) {
26320
- return normalizeResolvedEnv(__FARM_ENV__);
26570
+ return prepareEnv(__FARM_ENV__);
26321
26571
  }
26322
26572
  } catch {
26323
26573
  }
@@ -26347,14 +26597,16 @@ function getProcessEnv() {
26347
26597
  }
26348
26598
  return {};
26349
26599
  }
26350
- var FARM_ENV_SYMBOL, farmEnvGlobal, currentEnv, env, serverEnv, publicEnv;
26600
+ var FARM_ENV_SYMBOL, FARM_ENV_RUNTIME_SYMBOL, farmEnvGlobal, currentEnv, env, serverEnv, publicEnv;
26351
26601
  var init_env = __esm({
26352
26602
  "src/env.ts"() {
26353
26603
  "use strict";
26354
26604
  FARM_ENV_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env");
26605
+ FARM_ENV_RUNTIME_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env.runtime");
26355
26606
  farmEnvGlobal = globalThis;
26356
26607
  currentEnv = getInitialEnv();
26357
26608
  __name(resolveEnv, "resolveEnv");
26609
+ __name(createBundledEnv, "createBundledEnv");
26358
26610
  __name(setEnv, "setEnv");
26359
26611
  __name(getResolvedEnv, "getResolvedEnv");
26360
26612
  __name(getEnv, "getEnv");
@@ -26366,6 +26618,11 @@ var init_env = __esm({
26366
26618
  __name(parseEnvValue, "parseEnvValue");
26367
26619
  __name(createEnvProxy, "createEnvProxy");
26368
26620
  __name(getEnvScope, "getEnvScope");
26621
+ __name(readServerEnvKey, "readServerEnvKey");
26622
+ __name(readRuntimeServerEnv, "readRuntimeServerEnv");
26623
+ __name(getRuntimeEnvType, "getRuntimeEnvType");
26624
+ __name(coerceRuntimeEnvValue, "coerceRuntimeEnvValue");
26625
+ __name(prepareEnv, "prepareEnv");
26369
26626
  __name(assertServerEnvAccess, "assertServerEnvAccess");
26370
26627
  __name(getInitialEnv, "getInitialEnv");
26371
26628
  __name(getCurrentEnv, "getCurrentEnv");
@@ -39632,7 +39889,7 @@ function getEnvDefines(config, configEnv) {
39632
39889
  )
39633
39890
  };
39634
39891
  if (configEnv?.isSsrBuild) {
39635
- defines.__FARM_ENV__ = JSON.stringify(getFullEnvDefine(config));
39892
+ defines.__FARM_ENV__ = JSON.stringify(createBundledEnv(getFullEnvDefine(config)));
39636
39893
  }
39637
39894
  return defines;
39638
39895
  }
@@ -44027,6 +44284,7 @@ var fs14, path38, import_node_url11, ALL_TYPE_ARTIFACTS, createEmptyTypeArtifact
44027
44284
  var init_vite2 = __esm({
44028
44285
  "src/vite.ts"() {
44029
44286
  "use strict";
44287
+ init_env();
44030
44288
  init_app();
44031
44289
  init_utils();
44032
44290
  init_plugin();
@@ -45097,7 +45355,7 @@ export const farmRegistry: {
45097
45355
  clientManifest?: any;
45098
45356
  routePaths?: Record<string, string>;
45099
45357
  } = {
45100
- env: ${JSON.stringify(config.env || { server: {}, public: {} }, null, 2)},
45358
+ env: ${JSON.stringify(createBundledEnv(config.env), null, 2)},
45101
45359
  deploymentId: ${JSON.stringify(config.deploymentId)},
45102
45360
  basePath: ${JSON.stringify(config.basePath)},
45103
45361
  apiBasePath: ${JSON.stringify(apiBasePath)},
@@ -45601,7 +45859,7 @@ export default defineEventHandler(async (event: H3Event) => {
45601
45859
  farmRegistry.apiRouteManager = apiRouteManager;
45602
45860
  farmRegistry.routeManager = routeManager;
45603
45861
  farmRegistry.serverRenderer = serverRenderer;
45604
- farmRegistry.env = config.env || { server: {}, public: {} };
45862
+ farmRegistry.env = createBundledEnv(config.env);
45605
45863
  farmRegistry.deploymentId = config.deploymentId;
45606
45864
  farmRegistry.basePath = config.basePath;
45607
45865
  };
@@ -45666,6 +45924,7 @@ var import_path16;
45666
45924
  var init_nitro = __esm({
45667
45925
  "src/nitro/index.ts"() {
45668
45926
  "use strict";
45927
+ init_env();
45669
45928
  import_path16 = __toESM(require("path"));
45670
45929
  init_workflows();
45671
45930
  init_cron();
@@ -45748,7 +46007,11 @@ __export(src_exports, {
45748
46007
  ServerActionRequestError: () => ServerActionRequestError,
45749
46008
  ServerFnFailure: () => ServerFnFailure,
45750
46009
  UnsupportedRateLimitStorageError: () => UnsupportedRateLimitStorageError,
46010
+ _attachServerFunctionDescriptor: () => _attachServerFunctionDescriptor,
46011
+ _describeServerFunction: () => _describeServerFunction,
46012
+ _invokeServerFunction: () => _invokeServerFunction,
45751
46013
  _parseServerFnSchema: () => _parseServerFnSchema,
46014
+ _runServerFunctionForCaller: () => _runServerFunctionForCaller,
45752
46015
  _runWithAfterNodeResponse: () => _runWithAfterNodeResponse,
45753
46016
  _runWithAfterRequest: () => _runWithAfterRequest,
45754
46017
  _runWithMiddlewareContext: () => _runWithMiddlewareContext,
@@ -45794,6 +46057,7 @@ __export(src_exports, {
45794
46057
  cookies: () => cookies,
45795
46058
  createAPIClient: () => createAPIClient,
45796
46059
  createApiClients: () => createApiClients,
46060
+ createBundledEnv: () => createBundledEnv,
45797
46061
  createClientOnlyFn: () => createClientOnlyFn,
45798
46062
  createClientPluginManager: () => createClientPluginManager,
45799
46063
  createCompressionPlugin: () => createCompressionPlugin,
@@ -45856,6 +46120,7 @@ __export(src_exports, {
45856
46120
  createServerActionRequestErrorResponse: () => createServerActionRequestErrorResponse,
45857
46121
  createServerFn: () => createServerFn,
45858
46122
  createServerFnTransportError: () => createServerFnTransportError,
46123
+ createServerFunctionDescriptor: () => createServerFunctionDescriptor,
45859
46124
  createServerMiddleware: () => createServerMiddleware,
45860
46125
  createServerOnlyFn: () => createServerOnlyFn,
45861
46126
  createServerQuery: () => createServerQuery,
@@ -52627,8 +52892,74 @@ init_server_action_security();
52627
52892
  init_request_bridge();
52628
52893
  init_cache();
52629
52894
  init_server_fn_error();
52895
+ init_navigation_errors();
52630
52896
  init_server_fn_error();
52631
52897
  var FARM_SERVER_FN_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn");
52898
+ var FARM_SERVER_FUNCTION_DESCRIPTOR = /* @__PURE__ */ Symbol.for("farm.server-function.descriptor");
52899
+ var _ServerFnInputError = class _ServerFnInputError extends Error {
52900
+ constructor(cause) {
52901
+ super("Server function input is invalid");
52902
+ this.cause = cause;
52903
+ }
52904
+ };
52905
+ __name(_ServerFnInputError, "ServerFnInputError");
52906
+ var ServerFnInputError = _ServerFnInputError;
52907
+ function createServerFunctionDescriptor(kind, options, run) {
52908
+ return Object.freeze({
52909
+ kind,
52910
+ input: options.input,
52911
+ output: options.output,
52912
+ mcp: options.mcp === void 0 ? void 0 : Object.freeze({ ...options.mcp }),
52913
+ run
52914
+ });
52915
+ }
52916
+ __name(createServerFunctionDescriptor, "createServerFunctionDescriptor");
52917
+ function _attachServerFunctionDescriptor(target, descriptor) {
52918
+ Object.defineProperty(target, FARM_SERVER_FUNCTION_DESCRIPTOR, {
52919
+ value: descriptor,
52920
+ enumerable: false
52921
+ });
52922
+ }
52923
+ __name(_attachServerFunctionDescriptor, "_attachServerFunctionDescriptor");
52924
+ function getServerFunctionRunner(value) {
52925
+ if (typeof value !== "function") return void 0;
52926
+ return value[FARM_SERVER_FUNCTION_DESCRIPTOR];
52927
+ }
52928
+ __name(getServerFunctionRunner, "getServerFunctionRunner");
52929
+ function _runServerFunctionForCaller(value, input) {
52930
+ const runner = getServerFunctionRunner(value);
52931
+ if (!runner) throw new TypeError("Expected a function created with createServerFn");
52932
+ return runner.run(input);
52933
+ }
52934
+ __name(_runServerFunctionForCaller, "_runServerFunctionForCaller");
52935
+ function _describeServerFunction(value) {
52936
+ const runner = getServerFunctionRunner(value);
52937
+ if (!runner) return void 0;
52938
+ const { kind, input, output, mcp } = runner;
52939
+ return Object.freeze({ kind, input, output, mcp });
52940
+ }
52941
+ __name(_describeServerFunction, "_describeServerFunction");
52942
+ async function _invokeServerFunction(value, input, request2) {
52943
+ const runner = getServerFunctionRunner(value);
52944
+ if (!runner) {
52945
+ throw new TypeError("Expected a function created with createServerFn or createServerQuery");
52946
+ }
52947
+ try {
52948
+ const data = await runWithServerActionRequest(request2, () => runner.run(input));
52949
+ return { ok: true, data };
52950
+ } catch (error) {
52951
+ if (error instanceof ServerFnInputError) {
52952
+ return { ok: false, reason: "input", error: error.cause };
52953
+ }
52954
+ if (isServerFnFailure(error)) return { ok: false, reason: "failure", failure: error };
52955
+ const redirect3 = getFarmRedirectError(error);
52956
+ if (redirect3) {
52957
+ return { ok: false, reason: "redirect", url: redirect3.url, status: redirect3.status };
52958
+ }
52959
+ return { ok: false, reason: "error", error };
52960
+ }
52961
+ }
52962
+ __name(_invokeServerFunction, "_invokeServerFunction");
52632
52963
  var UNSAFE_FORM_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
52633
52964
  function createServerMiddleware(options) {
52634
52965
  if (!options || typeof options.handler !== "function") {
@@ -52652,10 +52983,15 @@ function createServerFn(options) {
52652
52983
  const middleware2 = resolveServerFnMiddleware(options.middleware);
52653
52984
  const errors = normalizeServerFnErrors(options.errors);
52654
52985
  const error = createServerFnErrorHandler(errors);
52655
- const serverFn = /* @__PURE__ */ __name(async (value) => {
52986
+ const run = /* @__PURE__ */ __name(async (value, labelInputErrors) => {
52656
52987
  const formData = isFormData2(value) ? value : void 0;
52657
52988
  const rawInput = formData ? formDataToObject2(formData) : value;
52658
- const input = await _parseServerFnSchema(options.input, rawInput, "input");
52989
+ let input;
52990
+ try {
52991
+ input = await _parseServerFnSchema(options.input, rawInput, "input");
52992
+ } catch (cause) {
52993
+ throw labelInputErrors ? new ServerFnInputError(cause) : cause;
52994
+ }
52659
52995
  const executionContext = getServerActionExecutionContext();
52660
52996
  const request2 = executionContext?.request ?? _resolveCurrentRequest();
52661
52997
  const signal = executionContext?.signal ?? request2?.signal ?? getServerActionSignal();
@@ -52681,7 +53017,8 @@ function createServerFn(options) {
52681
53017
  await applyFarmCacheInvalidationTargets(declaration);
52682
53018
  }
52683
53019
  return parsedResult;
52684
- }, "serverFn");
53020
+ }, "run");
53021
+ const serverFn = /* @__PURE__ */ __name((value) => run(value, false), "serverFn");
52685
53022
  Object.defineProperties(serverFn, {
52686
53023
  [FARM_SERVER_FN_SYMBOL]: {
52687
53024
  value: true,
@@ -52712,6 +53049,10 @@ function createServerFn(options) {
52712
53049
  enumerable: false
52713
53050
  }
52714
53051
  });
53052
+ _attachServerFunctionDescriptor(
53053
+ serverFn,
53054
+ createServerFunctionDescriptor("action", options, (value) => run(value, true))
53055
+ );
52715
53056
  return serverFn;
52716
53057
  }
52717
53058
  __name(createServerFn, "createServerFn");
@@ -53263,6 +53604,16 @@ function createServerQuery(options) {
53263
53604
  enumerable: false
53264
53605
  }
53265
53606
  });
53607
+ _attachServerFunctionDescriptor(
53608
+ query,
53609
+ createServerFunctionDescriptor("query", options, async (value) => {
53610
+ const result = await _runServerFunctionForCaller(
53611
+ execute,
53612
+ value
53613
+ );
53614
+ return result.data;
53615
+ })
53616
+ );
53266
53617
  return query;
53267
53618
  }
53268
53619
  __name(createServerQuery, "createServerQuery");
@@ -53620,6 +53971,7 @@ init_deployment();
53620
53971
  init_generate_route_types();
53621
53972
 
53622
53973
  // src/build/index.ts
53974
+ init_env();
53623
53975
  init_config4();
53624
53976
  var import_path17 = __toESM(require("path"));
53625
53977
  var import_node_fs15 = require("fs");
@@ -53630,6 +53982,7 @@ init_server_path();
53630
53982
  init_layers();
53631
53983
 
53632
53984
  // src/nitro/universal-build.ts
53985
+ init_env();
53633
53986
  init_config4();
53634
53987
 
53635
53988
  // src/nitro/client-css-href.ts
@@ -58314,7 +58667,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
58314
58667
  },
58315
58668
  define: {
58316
58669
  __FARM_API_BASE_URL__: JSON.stringify(config.api.baseURL),
58317
- __FARM_ENV__: JSON.stringify(config.env || { server: {}, public: {} }),
58670
+ __FARM_ENV__: JSON.stringify(createBundledEnv(config.env)),
58318
58671
  __FARM_PUBLIC_ENV__: JSON.stringify(config.env?.public || {})
58319
58672
  },
58320
58673
  plugins: [
@@ -63765,7 +64118,7 @@ async function buildSSR(viteBuild, config, root, srcDir, outputDir) {
63765
64118
  },
63766
64119
  define: {
63767
64120
  __FARM_API_BASE_URL__: JSON.stringify(config.api.baseURL),
63768
- __FARM_ENV__: JSON.stringify(config.env || { server: {}, public: {} }),
64121
+ __FARM_ENV__: JSON.stringify(createBundledEnv(config.env)),
63769
64122
  __FARM_PUBLIC_ENV__: JSON.stringify(config.env?.public || {})
63770
64123
  },
63771
64124
  plugins: [
@@ -63848,7 +64201,7 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
63848
64201
  farmRegistry.apiRouteManager = apiRouteManager;
63849
64202
  farmRegistry.routeManager = routeManager;
63850
64203
  farmRegistry.serverRenderer = serverRenderer;
63851
- farmRegistry.env = config.env || { server: {}, public: {} };
64204
+ farmRegistry.env = createBundledEnv(config.env);
63852
64205
  const routePaths = {};
63853
64206
  for (const [pattern, entry] of routeManager.getRoutes()) {
63854
64207
  const bundledPath = entry.modulePath.replace(/.*\/src\/app\//, "").replace(/\.(tsx?|jsx?)$/, ".js");
@@ -67391,7 +67744,11 @@ __name(cookies, "cookies");
67391
67744
  ServerActionRequestError,
67392
67745
  ServerFnFailure,
67393
67746
  UnsupportedRateLimitStorageError,
67747
+ _attachServerFunctionDescriptor,
67748
+ _describeServerFunction,
67749
+ _invokeServerFunction,
67394
67750
  _parseServerFnSchema,
67751
+ _runServerFunctionForCaller,
67395
67752
  _runWithAfterNodeResponse,
67396
67753
  _runWithAfterRequest,
67397
67754
  _runWithMiddlewareContext,
@@ -67437,6 +67794,7 @@ __name(cookies, "cookies");
67437
67794
  cookies,
67438
67795
  createAPIClient,
67439
67796
  createApiClients,
67797
+ createBundledEnv,
67440
67798
  createClientOnlyFn,
67441
67799
  createClientPluginManager,
67442
67800
  createCompressionPlugin,
@@ -67499,6 +67857,7 @@ __name(cookies, "cookies");
67499
67857
  createServerActionRequestErrorResponse,
67500
67858
  createServerFn,
67501
67859
  createServerFnTransportError,
67860
+ createServerFunctionDescriptor,
67502
67861
  createServerMiddleware,
67503
67862
  createServerOnlyFn,
67504
67863
  createServerQuery,