@farm.js/core 0.1.0-beta.14 → 0.1.0-beta.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 (93) hide show
  1. package/dist/api/route-manager.cjs.map +1 -1
  2. package/dist/api/route-manager.mjs +2 -2
  3. package/dist/api/runtime.cjs.map +1 -1
  4. package/dist/api/runtime.mjs +1 -1
  5. package/dist/api.cjs +18 -10
  6. package/dist/api.cjs.map +1 -1
  7. package/dist/api.mjs +3 -3
  8. package/dist/{chunk-B232I2GP.mjs → chunk-3HIVDX7J.mjs} +12 -1
  9. package/dist/chunk-3HIVDX7J.mjs.map +1 -0
  10. package/dist/{chunk-JDEOUK5V.mjs → chunk-6YXKHAFU.mjs} +3 -3
  11. package/dist/{chunk-VUL55IAX.mjs → chunk-AN3PQVKH.mjs} +14 -16
  12. package/dist/{chunk-VUL55IAX.mjs.map → chunk-AN3PQVKH.mjs.map} +1 -1
  13. package/dist/{chunk-Z5CQMP54.mjs → chunk-ARRYKOI5.mjs} +2 -2
  14. package/dist/{chunk-KLA67WKG.mjs → chunk-B3FFOIWS.mjs} +2 -2
  15. package/dist/{chunk-ARCGE2VT.mjs → chunk-BWJC5ZOD.mjs} +2 -2
  16. package/dist/{chunk-ARCGE2VT.mjs.map → chunk-BWJC5ZOD.mjs.map} +1 -1
  17. package/dist/{chunk-PFE6GMNE.mjs → chunk-HMRFYJK6.mjs} +19 -11
  18. package/dist/chunk-HMRFYJK6.mjs.map +1 -0
  19. package/dist/{chunk-32W4QEJP.mjs → chunk-KFTGPFRD.mjs} +1 -1
  20. package/dist/chunk-KFTGPFRD.mjs.map +1 -0
  21. package/dist/{chunk-PNFQQSRA.mjs → chunk-OSWV5IJB.mjs} +114 -35
  22. package/dist/chunk-OSWV5IJB.mjs.map +1 -0
  23. package/dist/{chunk-OPHK6OJN.mjs → chunk-SLDBGSC3.mjs} +2 -2
  24. package/dist/{chunk-L2PE36GQ.mjs → chunk-T2KL7VEL.mjs} +3 -3
  25. package/dist/{chunk-WDU6QXNK.mjs → chunk-UCYWGN2P.mjs} +1 -1
  26. package/dist/chunk-UCYWGN2P.mjs.map +1 -0
  27. package/dist/{chunk-65A7QIKI.mjs → chunk-UMVLB3PN.mjs} +3 -3
  28. package/dist/chunk-UMVLB3PN.mjs.map +1 -0
  29. package/dist/{chunk-VY2UYN5R.mjs → chunk-VPCFICID.mjs} +82 -3
  30. package/dist/chunk-VPCFICID.mjs.map +1 -0
  31. package/dist/{chunk-H3TE3LOV.mjs → chunk-XMFTIVJH.mjs} +2 -2
  32. package/dist/{chunk-UB5UOSHB.mjs → chunk-ZVMV3THA.mjs} +71 -2
  33. package/dist/chunk-ZVMV3THA.mjs.map +1 -0
  34. package/dist/client.cjs.map +1 -1
  35. package/dist/client.mjs +3 -3
  36. package/dist/deployment.cjs +12 -0
  37. package/dist/deployment.cjs.map +1 -1
  38. package/dist/deployment.mjs +3 -1
  39. package/dist/{devtools-GAZ7F3KL.mjs → devtools-E4YNCY5J.mjs} +4 -4
  40. package/dist/docs.cjs.map +1 -1
  41. package/dist/docs.mjs +4 -4
  42. package/dist/index.cjs +306 -52
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.mjs +28 -16
  45. package/dist/index.mjs.map +1 -1
  46. package/dist/internal/build-runtime.cjs +133 -40
  47. package/dist/internal/build-runtime.cjs.map +1 -1
  48. package/dist/internal/build-runtime.mjs +11 -11
  49. package/dist/internal/config-runtime.cjs.map +1 -1
  50. package/dist/internal/config-runtime.mjs +3 -3
  51. package/dist/navigation.cjs.map +1 -1
  52. package/dist/navigation.mjs +3 -3
  53. package/dist/plugin.cjs +115 -28
  54. package/dist/plugin.cjs.map +1 -1
  55. package/dist/plugin.mjs +8 -8
  56. package/dist/server-action-security.cjs +23 -1
  57. package/dist/server-action-security.cjs.map +1 -1
  58. package/dist/server-action-security.mjs +1 -1
  59. package/dist/server-fn-client.cjs.map +1 -1
  60. package/dist/server-fn-client.mjs +1 -1
  61. package/dist/server-fn.cjs +140 -3
  62. package/dist/server-fn.cjs.map +1 -1
  63. package/dist/server-fn.mjs +14 -3
  64. package/dist/server-query.cjs +99 -1
  65. package/dist/server-query.cjs.map +1 -1
  66. package/dist/server-query.mjs +3 -3
  67. package/dist/server.cjs +234 -31
  68. package/dist/server.cjs.map +1 -1
  69. package/dist/server.mjs +11 -11
  70. package/dist/testing.cjs.map +1 -1
  71. package/dist/testing.mjs +3 -3
  72. package/dist/version.cjs +1 -1
  73. package/dist/version.cjs.map +1 -1
  74. package/dist/version.mjs +1 -1
  75. package/dist/vite.cjs +116 -29
  76. package/dist/vite.cjs.map +1 -1
  77. package/dist/vite.mjs +8 -8
  78. package/package.json +1 -1
  79. package/dist/chunk-32W4QEJP.mjs.map +0 -1
  80. package/dist/chunk-65A7QIKI.mjs.map +0 -1
  81. package/dist/chunk-B232I2GP.mjs.map +0 -1
  82. package/dist/chunk-PFE6GMNE.mjs.map +0 -1
  83. package/dist/chunk-PNFQQSRA.mjs.map +0 -1
  84. package/dist/chunk-UB5UOSHB.mjs.map +0 -1
  85. package/dist/chunk-VY2UYN5R.mjs.map +0 -1
  86. package/dist/chunk-WDU6QXNK.mjs.map +0 -1
  87. /package/dist/{chunk-JDEOUK5V.mjs.map → chunk-6YXKHAFU.mjs.map} +0 -0
  88. /package/dist/{chunk-Z5CQMP54.mjs.map → chunk-ARRYKOI5.mjs.map} +0 -0
  89. /package/dist/{chunk-KLA67WKG.mjs.map → chunk-B3FFOIWS.mjs.map} +0 -0
  90. /package/dist/{chunk-OPHK6OJN.mjs.map → chunk-SLDBGSC3.mjs.map} +0 -0
  91. /package/dist/{chunk-L2PE36GQ.mjs.map → chunk-T2KL7VEL.mjs.map} +0 -0
  92. /package/dist/{chunk-H3TE3LOV.mjs.map → chunk-XMFTIVJH.mjs.map} +0 -0
  93. /package/dist/{devtools-GAZ7F3KL.mjs.map → devtools-E4YNCY5J.mjs.map} +0 -0
package/dist/plugin.cjs CHANGED
@@ -2036,6 +2036,13 @@ var init_cache_invalidation = __esm({
2036
2036
  }
2037
2037
  });
2038
2038
 
2039
+ // src/server-fn-error.ts
2040
+ var init_server_fn_error = __esm({
2041
+ "src/server-fn-error.ts"() {
2042
+ "use strict";
2043
+ }
2044
+ });
2045
+
2039
2046
  // src/server-action-security.ts
2040
2047
  function resolveServerActionsConfig(config) {
2041
2048
  const allowedOrigins = (config?.allowedOrigins ?? []).map(normalizeAllowedOriginPattern);
@@ -2129,6 +2136,7 @@ var init_server_action_security = __esm({
2129
2136
  "use strict";
2130
2137
  import_node_async_hooks = require("async_hooks");
2131
2138
  init_cache_invalidation();
2139
+ init_server_fn_error();
2132
2140
  DEFAULT_SERVER_ACTION_BODY_SIZE_LIMIT = 1e6;
2133
2141
  SERVER_ACTION_STORAGE_KEY = /* @__PURE__ */ Symbol.for("farm.serverActionStorage");
2134
2142
  __name(resolveServerActionsConfig, "resolveServerActionsConfig");
@@ -20913,6 +20921,15 @@ function routePatternToRouteLiteral(pattern) {
20913
20921
  return JSON.stringify(pattern);
20914
20922
  }
20915
20923
  __name(routePatternToRouteLiteral, "routePatternToRouteLiteral");
20924
+ function renderTypeUnion(values) {
20925
+ return values.length <= 1 ? values[0] || "never" : `
20926
+ | ${values.join("\n | ")}`;
20927
+ }
20928
+ __name(renderTypeUnion, "renderTypeUnion");
20929
+ function renderTypeAlias(name, value) {
20930
+ return `export type ${name} =${value.startsWith("\n") ? "" : " "}${value};`;
20931
+ }
20932
+ __name(renderTypeAlias, "renderTypeAlias");
20916
20933
  function createRoutePattern(route) {
20917
20934
  if (route.segments.length === 0) return "/";
20918
20935
  return "/" + route.segments.map((seg) => {
@@ -20975,9 +20992,9 @@ async function createRouteTypeDeclarations(options, outPath) {
20975
20992
  const typeLiterals = Array.from(new Set(sortedPatterns.flatMap(routePatternToTsTypeLiterals)));
20976
20993
  const patternLiterals = sortedPatterns.map(routePatternToRouteLiteral);
20977
20994
  const routeModulePatternLiterals = Array.from(routeModulePatterns).sort().map(routePatternToRouteLiteral);
20978
- const routePathType = suppressLintOnLink ? "string" : typeLiterals.length ? typeLiterals.join(" | ") : "never";
20979
- const routePatternType = suppressLintOnLink ? "string" : patternLiterals.length ? patternLiterals.join(" | ") : "never";
20980
- const routeModulePatternType = routeModulePatternLiterals.length ? routeModulePatternLiterals.join(" | ") : "never";
20995
+ const routePathType = suppressLintOnLink ? "string" : renderTypeUnion(typeLiterals);
20996
+ const routePatternType = suppressLintOnLink ? "string" : renderTypeUnion(patternLiterals);
20997
+ const routeModulePatternType = renderTypeUnion(routeModulePatternLiterals);
20981
20998
  const routeTypesImportPath = `./${path14.basename(outPath).replace(/\.d\.ts$/, "")}`;
20982
20999
  const linkAugmentationBlock = suppressLintOnLink ? "" : `
20983
21000
  declare module "@farm.js/core/client" {
@@ -21019,9 +21036,9 @@ declare global {
21019
21036
  * Regenerated on dev start and when routes change.
21020
21037
  * Set suppressLintOnLink: true in farm.config.ts to accept any string on Link href.
21021
21038
  */
21022
- export type RoutePath = ${routePathType};
21023
- export type RoutePattern = ${routePatternType};
21024
- export type RouteModulePattern = ${routeModulePatternType};${linkAugmentationBlock}${routeModuleAugmentationBlock}
21039
+ ${renderTypeAlias("RoutePath", routePathType)}
21040
+ ${renderTypeAlias("RoutePattern", routePatternType)}
21041
+ ${renderTypeAlias("RouteModulePattern", routeModulePatternType)}${linkAugmentationBlock}${routeModuleAugmentationBlock}
21025
21042
  `;
21026
21043
  return content;
21027
21044
  }
@@ -21303,7 +21320,8 @@ async function generateFarmTypeArtifacts(options) {
21303
21320
  const sourceRoots = getFarmSourceRoots({ root, srcDir, layers: options.layers });
21304
21321
  const appDirs = getFarmAppDirectories({ root, srcDir, layers: options.layers });
21305
21322
  const result = {
21306
- apiRoutes: []
21323
+ apiRoutes: [],
21324
+ stalePaths: []
21307
21325
  };
21308
21326
  const unifiedTypesPath = (0, import_path8.join)(root, srcDir, "farm.d.ts");
21309
21327
  const shouldRefreshUnifiedTypes = shouldGenerateRoutes && !options.routeTypesOutFile || shouldGenerateEnv && !options.envTypesOutFile || shouldGenerateI18n && !options.i18nTypesOutFile;
@@ -21319,22 +21337,29 @@ async function generateFarmTypeArtifacts(options) {
21319
21337
  unifiedSections.push(await createRouteTypeDeclarations(routeOptions, unifiedTypesPath));
21320
21338
  result.routeTypesPath = unifiedTypesPath;
21321
21339
  } else if (shouldGenerateRoutes) {
21322
- result.routeTypesPath = await generateRouteTypes({
21340
+ const routeOptions = {
21323
21341
  root,
21324
21342
  srcDir,
21325
21343
  outFile: options.routeTypesOutFile,
21326
21344
  extraRoutes: options.extraRoutes || [],
21327
21345
  suppressLintOnLink: options.suppressLintOnLink,
21328
21346
  sourceRoots
21329
- });
21347
+ };
21348
+ if (options.check) {
21349
+ const routeTypesPath = resolveGeneratedPath(root, srcDir, options.routeTypesOutFile);
21350
+ const content = await createRouteTypeDeclarations(routeOptions, routeTypesPath);
21351
+ checkGeneratedFile(routeTypesPath, content, result.stalePaths);
21352
+ result.routeTypesPath = routeTypesPath;
21353
+ } else {
21354
+ result.routeTypesPath = await generateRouteTypes(routeOptions);
21355
+ }
21330
21356
  }
21331
21357
  if (shouldGenerateApi) {
21332
21358
  const generator = new APITypeGenerator(appDirs);
21333
21359
  const apiRoutes = generator.scanAPIRoutes();
21334
21360
  const apiTypesPath = options.apiTypesOutFile ? (0, import_path8.resolve)(root, options.apiTypesOutFile) : (0, import_path8.join)(root, srcDir, "lib", "api.generated.ts");
21335
21361
  const content = generator.generateAPIRouter(apiRoutes, { outFile: apiTypesPath });
21336
- (0, import_fs4.mkdirSync)((0, import_path8.dirname)(apiTypesPath), { recursive: true });
21337
- writeFileIfChanged(apiTypesPath, content);
21362
+ writeOrCheckGeneratedFile(apiTypesPath, content, options.check, result.stalePaths);
21338
21363
  result.apiTypesPath = apiTypesPath;
21339
21364
  result.apiRoutes = apiRoutes;
21340
21365
  }
@@ -21352,36 +21377,63 @@ async function generateFarmTypeArtifacts(options) {
21352
21377
  );
21353
21378
  result.envTypesPath = unifiedTypesPath;
21354
21379
  } else if (shouldGenerateEnv) {
21355
- result.envTypesPath = await generateEnvTypes({
21380
+ const envOptions = {
21356
21381
  root,
21357
21382
  srcDir,
21358
21383
  outFile: options.envTypesOutFile,
21359
21384
  configPath: options.configPath,
21360
21385
  layerConfigPaths: (options.layers ?? []).map((layer) => layer.configFile).filter((configFile) => Boolean(configFile))
21361
- });
21386
+ };
21387
+ if (options.check) {
21388
+ const envTypesPath = resolveGeneratedPath(root, srcDir, options.envTypesOutFile);
21389
+ checkGeneratedFile(
21390
+ envTypesPath,
21391
+ createEnvTypeDeclarations(envOptions, envTypesPath),
21392
+ result.stalePaths
21393
+ );
21394
+ result.envTypesPath = envTypesPath;
21395
+ } else {
21396
+ result.envTypesPath = await generateEnvTypes(envOptions);
21397
+ }
21362
21398
  }
21363
21399
  if (shouldGenerateImages && options.imageTypesOutFile) {
21364
- result.imageTypesPath = generateFarmImageTypes({
21365
- root,
21366
- srcDir,
21367
- outFile: options.imageTypesOutFile
21368
- });
21400
+ const imageTypesPath = resolveGeneratedPath(root, srcDir, options.imageTypesOutFile, false);
21401
+ if (options.check) {
21402
+ checkGeneratedFile(imageTypesPath, createFarmImageTypeDeclarations(), result.stalePaths);
21403
+ result.imageTypesPath = imageTypesPath;
21404
+ } else {
21405
+ result.imageTypesPath = generateFarmImageTypes({
21406
+ root,
21407
+ srcDir,
21408
+ outFile: options.imageTypesOutFile
21409
+ });
21410
+ }
21369
21411
  }
21370
21412
  if (shouldRefreshUnifiedTypes && options.i18nConfig?.enabled && !options.i18nTypesOutFile) {
21371
21413
  const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
21372
21414
  unifiedSections.push(renderFarmI18nTypes(options.i18nConfig.locales, signatures));
21373
21415
  result.i18nTypesPath = unifiedTypesPath;
21374
21416
  } else if (shouldGenerateI18n && options.i18nConfig) {
21375
- result.i18nTypesPath = await generateFarmI18nTypes({
21376
- root,
21377
- srcDir,
21378
- config: options.i18nConfig,
21379
- outFile: options.i18nTypesOutFile
21380
- });
21417
+ if (options.check) {
21418
+ const i18nTypesPath = resolveGeneratedPath(root, srcDir, options.i18nTypesOutFile, false);
21419
+ const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
21420
+ checkGeneratedFile(
21421
+ i18nTypesPath,
21422
+ renderFarmI18nTypes(options.i18nConfig.locales, signatures),
21423
+ result.stalePaths
21424
+ );
21425
+ result.i18nTypesPath = i18nTypesPath;
21426
+ } else {
21427
+ result.i18nTypesPath = await generateFarmI18nTypes({
21428
+ root,
21429
+ srcDir,
21430
+ config: options.i18nConfig,
21431
+ outFile: options.i18nTypesOutFile
21432
+ });
21433
+ }
21381
21434
  }
21382
21435
  if (shouldRefreshUnifiedTypes) {
21383
- (0, import_fs4.mkdirSync)((0, import_path8.dirname)(unifiedTypesPath), { recursive: true });
21384
- writeFileIfChanged(
21436
+ writeOrCheckGeneratedFile(
21385
21437
  unifiedTypesPath,
21386
21438
  `/**
21387
21439
  * Generated by Farm.js. Do not edit.
@@ -21390,14 +21442,41 @@ async function generateFarmTypeArtifacts(options) {
21390
21442
 
21391
21443
  import "@farm.js/core/image";
21392
21444
 
21393
- ${unifiedSections.join("\n")}`
21445
+ ${unifiedSections.map((section) => section.trimEnd()).join("\n\n")}
21446
+ `,
21447
+ options.check,
21448
+ result.stalePaths
21394
21449
  );
21395
21450
  result.typesPath = unifiedTypesPath;
21396
- removeLegacyTypeArtifacts(root, srcDir);
21451
+ if (options.check) {
21452
+ collectLegacyTypeArtifacts(root, srcDir, result.stalePaths);
21453
+ } else {
21454
+ removeLegacyTypeArtifacts(root, srcDir);
21455
+ }
21397
21456
  }
21398
21457
  return result;
21399
21458
  }
21400
21459
  __name(generateFarmTypeArtifacts, "generateFarmTypeArtifacts");
21460
+ function resolveGeneratedPath(root, srcDir, outFile, relativeToSrc = true) {
21461
+ if ((0, import_path8.isAbsolute)(outFile)) return (0, import_path8.resolve)(outFile);
21462
+ return (0, import_path8.resolve)(root, relativeToSrc ? (0, import_path8.join)(srcDir, outFile) : outFile);
21463
+ }
21464
+ __name(resolveGeneratedPath, "resolveGeneratedPath");
21465
+ function writeOrCheckGeneratedFile(filePath, content, check, stalePaths) {
21466
+ if (check) {
21467
+ checkGeneratedFile(filePath, content, stalePaths);
21468
+ return;
21469
+ }
21470
+ (0, import_fs4.mkdirSync)((0, import_path8.dirname)(filePath), { recursive: true });
21471
+ writeFileIfChanged(filePath, content);
21472
+ }
21473
+ __name(writeOrCheckGeneratedFile, "writeOrCheckGeneratedFile");
21474
+ function checkGeneratedFile(filePath, content, stalePaths) {
21475
+ if (!(0, import_fs4.existsSync)(filePath) || (0, import_fs4.readFileSync)(filePath, "utf8") !== content) {
21476
+ stalePaths.push(filePath);
21477
+ }
21478
+ }
21479
+ __name(checkGeneratedFile, "checkGeneratedFile");
21401
21480
  var LEGACY_TYPE_ARTIFACTS = [
21402
21481
  ["farm-routes.d.ts", "Auto-generated route types"],
21403
21482
  ["farm-env.d.ts", "Auto-generated env types"],
@@ -21415,6 +21494,14 @@ function removeLegacyTypeArtifacts(root, srcDir) {
21415
21494
  }
21416
21495
  }
21417
21496
  __name(removeLegacyTypeArtifacts, "removeLegacyTypeArtifacts");
21497
+ function collectLegacyTypeArtifacts(root, srcDir, stalePaths) {
21498
+ for (const [fileName, marker] of LEGACY_TYPE_ARTIFACTS) {
21499
+ const filePath = (0, import_path8.join)(root, srcDir, fileName);
21500
+ if (!(0, import_fs4.existsSync)(filePath)) continue;
21501
+ if ((0, import_fs4.readFileSync)(filePath, "utf8").includes(marker)) stalePaths.push(filePath);
21502
+ }
21503
+ }
21504
+ __name(collectLegacyTypeArtifacts, "collectLegacyTypeArtifacts");
21418
21505
 
21419
21506
  // src/vite.ts
21420
21507
  init_markdown();