@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
@@ -59,7 +59,7 @@ import {
59
59
  } from "./chunk-GY2STC2S.mjs";
60
60
  import {
61
61
  resolveServerActionsConfig
62
- } from "./chunk-UB5UOSHB.mjs";
62
+ } from "./chunk-ZVMV3THA.mjs";
63
63
  import {
64
64
  createFarmMarkdownRouteModuleFromFile,
65
65
  createFarmMarkdownSourceResponse,
@@ -109,7 +109,7 @@ import {
109
109
  discoverProgrammaticRoutePaths,
110
110
  findProgrammaticRouteFiles,
111
111
  loadProgrammaticRouteManifests
112
- } from "./chunk-Z5CQMP54.mjs";
112
+ } from "./chunk-ARRYKOI5.mjs";
113
113
  import {
114
114
  _runWithFarmI18nRequest,
115
115
  _setDefaultFarmI18nRuntime,
@@ -160,13 +160,13 @@ import {
160
160
  } from "./chunk-RHIFZZUI.mjs";
161
161
  import {
162
162
  FARM_VERSION
163
- } from "./chunk-ARCGE2VT.mjs";
163
+ } from "./chunk-BWJC5ZOD.mjs";
164
164
  import {
165
165
  FARM_DEPLOYMENT_ID_HEADER,
166
166
  createFarmDeploymentCookie,
167
167
  createFarmDeploymentMismatchResponse,
168
168
  getFarmDeploymentMismatch
169
- } from "./chunk-B232I2GP.mjs";
169
+ } from "./chunk-3HIVDX7J.mjs";
170
170
  import {
171
171
  createDeferredDataResponse,
172
172
  prepareDeferredData,
@@ -5131,7 +5131,7 @@ var HMRManager = _HMRManager;
5131
5131
 
5132
5132
  // src/type-artifacts.ts
5133
5133
  import { existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync2, unlinkSync } from "fs";
5134
- import { dirname as dirname3, join as join4, resolve as resolve3 } from "path";
5134
+ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join4, resolve as resolve3 } from "path";
5135
5135
 
5136
5136
  // src/routing/generate-route-types.ts
5137
5137
  import * as path7 from "path";
@@ -5165,6 +5165,15 @@ function routePatternToRouteLiteral(pattern) {
5165
5165
  return JSON.stringify(pattern);
5166
5166
  }
5167
5167
  __name(routePatternToRouteLiteral, "routePatternToRouteLiteral");
5168
+ function renderTypeUnion(values) {
5169
+ return values.length <= 1 ? values[0] || "never" : `
5170
+ | ${values.join("\n | ")}`;
5171
+ }
5172
+ __name(renderTypeUnion, "renderTypeUnion");
5173
+ function renderTypeAlias(name, value) {
5174
+ return `export type ${name} =${value.startsWith("\n") ? "" : " "}${value};`;
5175
+ }
5176
+ __name(renderTypeAlias, "renderTypeAlias");
5168
5177
  function createRoutePattern(route) {
5169
5178
  if (route.segments.length === 0) return "/";
5170
5179
  return "/" + route.segments.map((seg) => {
@@ -5227,9 +5236,9 @@ async function createRouteTypeDeclarations(options, outPath) {
5227
5236
  const typeLiterals = Array.from(new Set(sortedPatterns.flatMap(routePatternToTsTypeLiterals)));
5228
5237
  const patternLiterals = sortedPatterns.map(routePatternToRouteLiteral);
5229
5238
  const routeModulePatternLiterals = Array.from(routeModulePatterns).sort().map(routePatternToRouteLiteral);
5230
- const routePathType = suppressLintOnLink ? "string" : typeLiterals.length ? typeLiterals.join(" | ") : "never";
5231
- const routePatternType = suppressLintOnLink ? "string" : patternLiterals.length ? patternLiterals.join(" | ") : "never";
5232
- const routeModulePatternType = routeModulePatternLiterals.length ? routeModulePatternLiterals.join(" | ") : "never";
5239
+ const routePathType = suppressLintOnLink ? "string" : renderTypeUnion(typeLiterals);
5240
+ const routePatternType = suppressLintOnLink ? "string" : renderTypeUnion(patternLiterals);
5241
+ const routeModulePatternType = renderTypeUnion(routeModulePatternLiterals);
5233
5242
  const routeTypesImportPath = `./${path7.basename(outPath).replace(/\.d\.ts$/, "")}`;
5234
5243
  const linkAugmentationBlock = suppressLintOnLink ? "" : `
5235
5244
  declare module "@farm.js/core/client" {
@@ -5271,9 +5280,9 @@ declare global {
5271
5280
  * Regenerated on dev start and when routes change.
5272
5281
  * Set suppressLintOnLink: true in farm.config.ts to accept any string on Link href.
5273
5282
  */
5274
- export type RoutePath = ${routePathType};
5275
- export type RoutePattern = ${routePatternType};
5276
- export type RouteModulePattern = ${routeModulePatternType};${linkAugmentationBlock}${routeModuleAugmentationBlock}
5283
+ ${renderTypeAlias("RoutePath", routePathType)}
5284
+ ${renderTypeAlias("RoutePattern", routePatternType)}
5285
+ ${renderTypeAlias("RouteModulePattern", routeModulePatternType)}${linkAugmentationBlock}${routeModuleAugmentationBlock}
5277
5286
  `;
5278
5287
  return content;
5279
5288
  }
@@ -5378,7 +5387,8 @@ async function generateFarmTypeArtifacts(options) {
5378
5387
  const sourceRoots = getFarmSourceRoots({ root, srcDir, layers: options.layers });
5379
5388
  const appDirs = getFarmAppDirectories({ root, srcDir, layers: options.layers });
5380
5389
  const result = {
5381
- apiRoutes: []
5390
+ apiRoutes: [],
5391
+ stalePaths: []
5382
5392
  };
5383
5393
  const unifiedTypesPath = join4(root, srcDir, "farm.d.ts");
5384
5394
  const shouldRefreshUnifiedTypes = shouldGenerateRoutes && !options.routeTypesOutFile || shouldGenerateEnv && !options.envTypesOutFile || shouldGenerateI18n && !options.i18nTypesOutFile;
@@ -5394,22 +5404,29 @@ async function generateFarmTypeArtifacts(options) {
5394
5404
  unifiedSections.push(await createRouteTypeDeclarations(routeOptions, unifiedTypesPath));
5395
5405
  result.routeTypesPath = unifiedTypesPath;
5396
5406
  } else if (shouldGenerateRoutes) {
5397
- result.routeTypesPath = await generateRouteTypes({
5407
+ const routeOptions = {
5398
5408
  root,
5399
5409
  srcDir,
5400
5410
  outFile: options.routeTypesOutFile,
5401
5411
  extraRoutes: options.extraRoutes || [],
5402
5412
  suppressLintOnLink: options.suppressLintOnLink,
5403
5413
  sourceRoots
5404
- });
5414
+ };
5415
+ if (options.check) {
5416
+ const routeTypesPath = resolveGeneratedPath(root, srcDir, options.routeTypesOutFile);
5417
+ const content = await createRouteTypeDeclarations(routeOptions, routeTypesPath);
5418
+ checkGeneratedFile(routeTypesPath, content, result.stalePaths);
5419
+ result.routeTypesPath = routeTypesPath;
5420
+ } else {
5421
+ result.routeTypesPath = await generateRouteTypes(routeOptions);
5422
+ }
5405
5423
  }
5406
5424
  if (shouldGenerateApi) {
5407
5425
  const generator = new APITypeGenerator(appDirs);
5408
5426
  const apiRoutes = generator.scanAPIRoutes();
5409
5427
  const apiTypesPath = options.apiTypesOutFile ? resolve3(root, options.apiTypesOutFile) : join4(root, srcDir, "lib", "api.generated.ts");
5410
5428
  const content = generator.generateAPIRouter(apiRoutes, { outFile: apiTypesPath });
5411
- mkdirSync4(dirname3(apiTypesPath), { recursive: true });
5412
- writeFileIfChanged(apiTypesPath, content);
5429
+ writeOrCheckGeneratedFile(apiTypesPath, content, options.check, result.stalePaths);
5413
5430
  result.apiTypesPath = apiTypesPath;
5414
5431
  result.apiRoutes = apiRoutes;
5415
5432
  }
@@ -5427,36 +5444,63 @@ async function generateFarmTypeArtifacts(options) {
5427
5444
  );
5428
5445
  result.envTypesPath = unifiedTypesPath;
5429
5446
  } else if (shouldGenerateEnv) {
5430
- result.envTypesPath = await generateEnvTypes({
5447
+ const envOptions = {
5431
5448
  root,
5432
5449
  srcDir,
5433
5450
  outFile: options.envTypesOutFile,
5434
5451
  configPath: options.configPath,
5435
5452
  layerConfigPaths: (options.layers ?? []).map((layer) => layer.configFile).filter((configFile) => Boolean(configFile))
5436
- });
5453
+ };
5454
+ if (options.check) {
5455
+ const envTypesPath = resolveGeneratedPath(root, srcDir, options.envTypesOutFile);
5456
+ checkGeneratedFile(
5457
+ envTypesPath,
5458
+ createEnvTypeDeclarations(envOptions, envTypesPath),
5459
+ result.stalePaths
5460
+ );
5461
+ result.envTypesPath = envTypesPath;
5462
+ } else {
5463
+ result.envTypesPath = await generateEnvTypes(envOptions);
5464
+ }
5437
5465
  }
5438
5466
  if (shouldGenerateImages && options.imageTypesOutFile) {
5439
- result.imageTypesPath = generateFarmImageTypes({
5440
- root,
5441
- srcDir,
5442
- outFile: options.imageTypesOutFile
5443
- });
5467
+ const imageTypesPath = resolveGeneratedPath(root, srcDir, options.imageTypesOutFile, false);
5468
+ if (options.check) {
5469
+ checkGeneratedFile(imageTypesPath, createFarmImageTypeDeclarations(), result.stalePaths);
5470
+ result.imageTypesPath = imageTypesPath;
5471
+ } else {
5472
+ result.imageTypesPath = generateFarmImageTypes({
5473
+ root,
5474
+ srcDir,
5475
+ outFile: options.imageTypesOutFile
5476
+ });
5477
+ }
5444
5478
  }
5445
5479
  if (shouldRefreshUnifiedTypes && options.i18nConfig?.enabled && !options.i18nTypesOutFile) {
5446
5480
  const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
5447
5481
  unifiedSections.push(renderFarmI18nTypes(options.i18nConfig.locales, signatures));
5448
5482
  result.i18nTypesPath = unifiedTypesPath;
5449
5483
  } else if (shouldGenerateI18n && options.i18nConfig) {
5450
- result.i18nTypesPath = await generateFarmI18nTypes({
5451
- root,
5452
- srcDir,
5453
- config: options.i18nConfig,
5454
- outFile: options.i18nTypesOutFile
5455
- });
5484
+ if (options.check) {
5485
+ const i18nTypesPath = resolveGeneratedPath(root, srcDir, options.i18nTypesOutFile, false);
5486
+ const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
5487
+ checkGeneratedFile(
5488
+ i18nTypesPath,
5489
+ renderFarmI18nTypes(options.i18nConfig.locales, signatures),
5490
+ result.stalePaths
5491
+ );
5492
+ result.i18nTypesPath = i18nTypesPath;
5493
+ } else {
5494
+ result.i18nTypesPath = await generateFarmI18nTypes({
5495
+ root,
5496
+ srcDir,
5497
+ config: options.i18nConfig,
5498
+ outFile: options.i18nTypesOutFile
5499
+ });
5500
+ }
5456
5501
  }
5457
5502
  if (shouldRefreshUnifiedTypes) {
5458
- mkdirSync4(dirname3(unifiedTypesPath), { recursive: true });
5459
- writeFileIfChanged(
5503
+ writeOrCheckGeneratedFile(
5460
5504
  unifiedTypesPath,
5461
5505
  `/**
5462
5506
  * Generated by Farm.js. Do not edit.
@@ -5465,14 +5509,41 @@ async function generateFarmTypeArtifacts(options) {
5465
5509
 
5466
5510
  import "@farm.js/core/image";
5467
5511
 
5468
- ${unifiedSections.join("\n")}`
5512
+ ${unifiedSections.map((section) => section.trimEnd()).join("\n\n")}
5513
+ `,
5514
+ options.check,
5515
+ result.stalePaths
5469
5516
  );
5470
5517
  result.typesPath = unifiedTypesPath;
5471
- removeLegacyTypeArtifacts(root, srcDir);
5518
+ if (options.check) {
5519
+ collectLegacyTypeArtifacts(root, srcDir, result.stalePaths);
5520
+ } else {
5521
+ removeLegacyTypeArtifacts(root, srcDir);
5522
+ }
5472
5523
  }
5473
5524
  return result;
5474
5525
  }
5475
5526
  __name(generateFarmTypeArtifacts, "generateFarmTypeArtifacts");
5527
+ function resolveGeneratedPath(root, srcDir, outFile, relativeToSrc = true) {
5528
+ if (isAbsolute2(outFile)) return resolve3(outFile);
5529
+ return resolve3(root, relativeToSrc ? join4(srcDir, outFile) : outFile);
5530
+ }
5531
+ __name(resolveGeneratedPath, "resolveGeneratedPath");
5532
+ function writeOrCheckGeneratedFile(filePath, content, check, stalePaths) {
5533
+ if (check) {
5534
+ checkGeneratedFile(filePath, content, stalePaths);
5535
+ return;
5536
+ }
5537
+ mkdirSync4(dirname3(filePath), { recursive: true });
5538
+ writeFileIfChanged(filePath, content);
5539
+ }
5540
+ __name(writeOrCheckGeneratedFile, "writeOrCheckGeneratedFile");
5541
+ function checkGeneratedFile(filePath, content, stalePaths) {
5542
+ if (!existsSync4(filePath) || readFileSync2(filePath, "utf8") !== content) {
5543
+ stalePaths.push(filePath);
5544
+ }
5545
+ }
5546
+ __name(checkGeneratedFile, "checkGeneratedFile");
5476
5547
  var LEGACY_TYPE_ARTIFACTS = [
5477
5548
  ["farm-routes.d.ts", "Auto-generated route types"],
5478
5549
  ["farm-env.d.ts", "Auto-generated env types"],
@@ -5490,6 +5561,14 @@ function removeLegacyTypeArtifacts(root, srcDir) {
5490
5561
  }
5491
5562
  }
5492
5563
  __name(removeLegacyTypeArtifacts, "removeLegacyTypeArtifacts");
5564
+ function collectLegacyTypeArtifacts(root, srcDir, stalePaths) {
5565
+ for (const [fileName, marker] of LEGACY_TYPE_ARTIFACTS) {
5566
+ const filePath = join4(root, srcDir, fileName);
5567
+ if (!existsSync4(filePath)) continue;
5568
+ if (readFileSync2(filePath, "utf8").includes(marker)) stalePaths.push(filePath);
5569
+ }
5570
+ }
5571
+ __name(collectLegacyTypeArtifacts, "collectLegacyTypeArtifacts");
5493
5572
 
5494
5573
  // src/vite.ts
5495
5574
  import * as fs4 from "fs";
@@ -5700,7 +5779,7 @@ function loadFarmWorkflowsDevRuntime() {
5700
5779
  }
5701
5780
  __name(loadFarmWorkflowsDevRuntime, "loadFarmWorkflowsDevRuntime");
5702
5781
  function loadFarmDevtoolsSnapshotRuntime() {
5703
- return import("./devtools-GAZ7F3KL.mjs");
5782
+ return import("./devtools-E4YNCY5J.mjs");
5704
5783
  }
5705
5784
  __name(loadFarmDevtoolsSnapshotRuntime, "loadFarmDevtoolsSnapshotRuntime");
5706
5785
  function loadFarmDevtoolsUIRuntime() {
@@ -9467,4 +9546,4 @@ export {
9467
9546
  farmPlugin,
9468
9547
  defineConfig
9469
9548
  };
9470
- //# sourceMappingURL=chunk-PNFQQSRA.mjs.map
9549
+ //# sourceMappingURL=chunk-OSWV5IJB.mjs.map