@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.
- package/dist/api/route-manager.cjs.map +1 -1
- package/dist/api/route-manager.mjs +2 -2
- package/dist/api/runtime.cjs.map +1 -1
- package/dist/api/runtime.mjs +1 -1
- package/dist/api.cjs +18 -10
- package/dist/api.cjs.map +1 -1
- package/dist/api.mjs +3 -3
- package/dist/{chunk-B232I2GP.mjs → chunk-3HIVDX7J.mjs} +12 -1
- package/dist/chunk-3HIVDX7J.mjs.map +1 -0
- package/dist/{chunk-JDEOUK5V.mjs → chunk-6YXKHAFU.mjs} +3 -3
- package/dist/{chunk-VUL55IAX.mjs → chunk-AN3PQVKH.mjs} +14 -16
- package/dist/{chunk-VUL55IAX.mjs.map → chunk-AN3PQVKH.mjs.map} +1 -1
- package/dist/{chunk-Z5CQMP54.mjs → chunk-ARRYKOI5.mjs} +2 -2
- package/dist/{chunk-KLA67WKG.mjs → chunk-B3FFOIWS.mjs} +2 -2
- package/dist/{chunk-ARCGE2VT.mjs → chunk-BWJC5ZOD.mjs} +2 -2
- package/dist/{chunk-ARCGE2VT.mjs.map → chunk-BWJC5ZOD.mjs.map} +1 -1
- package/dist/{chunk-PFE6GMNE.mjs → chunk-HMRFYJK6.mjs} +19 -11
- package/dist/chunk-HMRFYJK6.mjs.map +1 -0
- package/dist/{chunk-32W4QEJP.mjs → chunk-KFTGPFRD.mjs} +1 -1
- package/dist/chunk-KFTGPFRD.mjs.map +1 -0
- package/dist/{chunk-PNFQQSRA.mjs → chunk-OSWV5IJB.mjs} +114 -35
- package/dist/chunk-OSWV5IJB.mjs.map +1 -0
- package/dist/{chunk-OPHK6OJN.mjs → chunk-SLDBGSC3.mjs} +2 -2
- package/dist/{chunk-L2PE36GQ.mjs → chunk-T2KL7VEL.mjs} +3 -3
- package/dist/{chunk-WDU6QXNK.mjs → chunk-UCYWGN2P.mjs} +1 -1
- package/dist/chunk-UCYWGN2P.mjs.map +1 -0
- package/dist/{chunk-65A7QIKI.mjs → chunk-UMVLB3PN.mjs} +3 -3
- package/dist/chunk-UMVLB3PN.mjs.map +1 -0
- package/dist/{chunk-VY2UYN5R.mjs → chunk-VPCFICID.mjs} +82 -3
- package/dist/chunk-VPCFICID.mjs.map +1 -0
- package/dist/{chunk-H3TE3LOV.mjs → chunk-XMFTIVJH.mjs} +2 -2
- package/dist/{chunk-UB5UOSHB.mjs → chunk-ZVMV3THA.mjs} +71 -2
- package/dist/chunk-ZVMV3THA.mjs.map +1 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.mjs +3 -3
- package/dist/deployment.cjs +12 -0
- package/dist/deployment.cjs.map +1 -1
- package/dist/deployment.mjs +3 -1
- package/dist/{devtools-GAZ7F3KL.mjs → devtools-E4YNCY5J.mjs} +4 -4
- package/dist/docs.cjs.map +1 -1
- package/dist/docs.mjs +4 -4
- package/dist/index.cjs +306 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +28 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/build-runtime.cjs +133 -40
- package/dist/internal/build-runtime.cjs.map +1 -1
- package/dist/internal/build-runtime.mjs +11 -11
- package/dist/internal/config-runtime.cjs.map +1 -1
- package/dist/internal/config-runtime.mjs +3 -3
- package/dist/navigation.cjs.map +1 -1
- package/dist/navigation.mjs +3 -3
- package/dist/plugin.cjs +115 -28
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.mjs +8 -8
- package/dist/server-action-security.cjs +23 -1
- package/dist/server-action-security.cjs.map +1 -1
- package/dist/server-action-security.mjs +1 -1
- package/dist/server-fn-client.cjs.map +1 -1
- package/dist/server-fn-client.mjs +1 -1
- package/dist/server-fn.cjs +140 -3
- package/dist/server-fn.cjs.map +1 -1
- package/dist/server-fn.mjs +14 -3
- package/dist/server-query.cjs +99 -1
- package/dist/server-query.cjs.map +1 -1
- package/dist/server-query.mjs +3 -3
- package/dist/server.cjs +234 -31
- package/dist/server.cjs.map +1 -1
- package/dist/server.mjs +11 -11
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.mjs +3 -3
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +116 -29
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +8 -8
- package/package.json +1 -1
- package/dist/chunk-32W4QEJP.mjs.map +0 -1
- package/dist/chunk-65A7QIKI.mjs.map +0 -1
- package/dist/chunk-B232I2GP.mjs.map +0 -1
- package/dist/chunk-PFE6GMNE.mjs.map +0 -1
- package/dist/chunk-PNFQQSRA.mjs.map +0 -1
- package/dist/chunk-UB5UOSHB.mjs.map +0 -1
- package/dist/chunk-VY2UYN5R.mjs.map +0 -1
- package/dist/chunk-WDU6QXNK.mjs.map +0 -1
- /package/dist/{chunk-JDEOUK5V.mjs.map → chunk-6YXKHAFU.mjs.map} +0 -0
- /package/dist/{chunk-Z5CQMP54.mjs.map → chunk-ARRYKOI5.mjs.map} +0 -0
- /package/dist/{chunk-KLA67WKG.mjs.map → chunk-B3FFOIWS.mjs.map} +0 -0
- /package/dist/{chunk-OPHK6OJN.mjs.map → chunk-SLDBGSC3.mjs.map} +0 -0
- /package/dist/{chunk-L2PE36GQ.mjs.map → chunk-T2KL7VEL.mjs.map} +0 -0
- /package/dist/{chunk-H3TE3LOV.mjs.map → chunk-XMFTIVJH.mjs.map} +0 -0
- /package/dist/{devtools-GAZ7F3KL.mjs.map → devtools-E4YNCY5J.mjs.map} +0 -0
package/dist/server-query.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FARM_SERVER_QUERY_SYMBOL,
|
|
3
3
|
createServerQuery
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-UMVLB3PN.mjs";
|
|
5
|
+
import "./chunk-VPCFICID.mjs";
|
|
6
6
|
import "./chunk-SCFX4UTD.mjs";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-ZVMV3THA.mjs";
|
|
8
8
|
import "./chunk-LM2YNO4U.mjs";
|
|
9
9
|
import "./chunk-V3XURYJO.mjs";
|
|
10
10
|
import "./chunk-WZ5QFROO.mjs";
|
package/dist/server.cjs
CHANGED
|
@@ -1919,6 +1919,47 @@ var init_cache_invalidation = __esm({
|
|
|
1919
1919
|
}
|
|
1920
1920
|
});
|
|
1921
1921
|
|
|
1922
|
+
// src/server-fn-error.ts
|
|
1923
|
+
function isServerFnFailure(value) {
|
|
1924
|
+
if (!value || typeof value !== "object") return false;
|
|
1925
|
+
const candidate = value;
|
|
1926
|
+
return candidate[FARM_SERVER_FN_FAILURE_SYMBOL] === true && candidate.name === "ServerFnFailure" && typeof candidate.code === "string" && Number.isInteger(candidate.status) && (candidate.status ?? 0) >= 400 && (candidate.status ?? 0) <= 599;
|
|
1927
|
+
}
|
|
1928
|
+
function serializeServerFnFailure(value) {
|
|
1929
|
+
if (!isServerFnFailure(value)) return null;
|
|
1930
|
+
return {
|
|
1931
|
+
name: "ServerFnFailure",
|
|
1932
|
+
message: value.message,
|
|
1933
|
+
code: value.code,
|
|
1934
|
+
status: value.status,
|
|
1935
|
+
data: value.data
|
|
1936
|
+
};
|
|
1937
|
+
}
|
|
1938
|
+
var FARM_SERVER_FN_FAILURE_SYMBOL, _ServerFnFailure, ServerFnFailure;
|
|
1939
|
+
var init_server_fn_error = __esm({
|
|
1940
|
+
"src/server-fn-error.ts"() {
|
|
1941
|
+
"use strict";
|
|
1942
|
+
FARM_SERVER_FN_FAILURE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn.failure");
|
|
1943
|
+
_ServerFnFailure = class _ServerFnFailure extends Error {
|
|
1944
|
+
constructor(code, data, options) {
|
|
1945
|
+
super(options.message);
|
|
1946
|
+
this.name = "ServerFnFailure";
|
|
1947
|
+
this.code = code;
|
|
1948
|
+
this.data = data;
|
|
1949
|
+
this.status = options.status;
|
|
1950
|
+
Object.defineProperty(this, FARM_SERVER_FN_FAILURE_SYMBOL, {
|
|
1951
|
+
value: true,
|
|
1952
|
+
enumerable: false
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
__name(_ServerFnFailure, "ServerFnFailure");
|
|
1957
|
+
ServerFnFailure = _ServerFnFailure;
|
|
1958
|
+
__name(isServerFnFailure, "isServerFnFailure");
|
|
1959
|
+
__name(serializeServerFnFailure, "serializeServerFnFailure");
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
|
|
1922
1963
|
// src/server-action-security.ts
|
|
1923
1964
|
function resolveServerActionsConfig(config) {
|
|
1924
1965
|
const allowedOrigins = (config?.allowedOrigins ?? []).map(normalizeAllowedOriginPattern);
|
|
@@ -2005,7 +2046,9 @@ function createServerActionRequestErrorResponse(error) {
|
|
|
2005
2046
|
headers
|
|
2006
2047
|
});
|
|
2007
2048
|
}
|
|
2008
|
-
function sanitizeServerActionError(
|
|
2049
|
+
function sanitizeServerActionError(error) {
|
|
2050
|
+
const declaredFailure = serializeServerFnFailure(error);
|
|
2051
|
+
if (declaredFailure) return declaredFailure;
|
|
2009
2052
|
return {
|
|
2010
2053
|
name: "ServerActionError",
|
|
2011
2054
|
message: "Server function failed"
|
|
@@ -2304,6 +2347,7 @@ var init_server_action_security = __esm({
|
|
|
2304
2347
|
"use strict";
|
|
2305
2348
|
import_node_async_hooks = require("async_hooks");
|
|
2306
2349
|
init_cache_invalidation();
|
|
2350
|
+
init_server_fn_error();
|
|
2307
2351
|
DEFAULT_SERVER_ACTION_BODY_SIZE_LIMIT = 1e6;
|
|
2308
2352
|
_ServerActionRequestError = class _ServerActionRequestError extends Error {
|
|
2309
2353
|
constructor(code, status, message) {
|
|
@@ -22961,6 +23005,15 @@ function routePatternToRouteLiteral(pattern) {
|
|
|
22961
23005
|
return JSON.stringify(pattern);
|
|
22962
23006
|
}
|
|
22963
23007
|
__name(routePatternToRouteLiteral, "routePatternToRouteLiteral");
|
|
23008
|
+
function renderTypeUnion(values) {
|
|
23009
|
+
return values.length <= 1 ? values[0] || "never" : `
|
|
23010
|
+
| ${values.join("\n | ")}`;
|
|
23011
|
+
}
|
|
23012
|
+
__name(renderTypeUnion, "renderTypeUnion");
|
|
23013
|
+
function renderTypeAlias(name, value) {
|
|
23014
|
+
return `export type ${name} =${value.startsWith("\n") ? "" : " "}${value};`;
|
|
23015
|
+
}
|
|
23016
|
+
__name(renderTypeAlias, "renderTypeAlias");
|
|
22964
23017
|
function createRoutePattern(route) {
|
|
22965
23018
|
if (route.segments.length === 0) return "/";
|
|
22966
23019
|
return "/" + route.segments.map((seg) => {
|
|
@@ -23023,9 +23076,9 @@ async function createRouteTypeDeclarations(options, outPath) {
|
|
|
23023
23076
|
const typeLiterals = Array.from(new Set(sortedPatterns.flatMap(routePatternToTsTypeLiterals)));
|
|
23024
23077
|
const patternLiterals = sortedPatterns.map(routePatternToRouteLiteral);
|
|
23025
23078
|
const routeModulePatternLiterals = Array.from(routeModulePatterns).sort().map(routePatternToRouteLiteral);
|
|
23026
|
-
const routePathType = suppressLintOnLink ? "string" : typeLiterals
|
|
23027
|
-
const routePatternType = suppressLintOnLink ? "string" : patternLiterals
|
|
23028
|
-
const routeModulePatternType = routeModulePatternLiterals
|
|
23079
|
+
const routePathType = suppressLintOnLink ? "string" : renderTypeUnion(typeLiterals);
|
|
23080
|
+
const routePatternType = suppressLintOnLink ? "string" : renderTypeUnion(patternLiterals);
|
|
23081
|
+
const routeModulePatternType = renderTypeUnion(routeModulePatternLiterals);
|
|
23029
23082
|
const routeTypesImportPath = `./${path14.basename(outPath).replace(/\.d\.ts$/, "")}`;
|
|
23030
23083
|
const linkAugmentationBlock = suppressLintOnLink ? "" : `
|
|
23031
23084
|
declare module "@farm.js/core/client" {
|
|
@@ -23067,9 +23120,9 @@ declare global {
|
|
|
23067
23120
|
* Regenerated on dev start and when routes change.
|
|
23068
23121
|
* Set suppressLintOnLink: true in farm.config.ts to accept any string on Link href.
|
|
23069
23122
|
*/
|
|
23070
|
-
|
|
23071
|
-
|
|
23072
|
-
|
|
23123
|
+
${renderTypeAlias("RoutePath", routePathType)}
|
|
23124
|
+
${renderTypeAlias("RoutePattern", routePatternType)}
|
|
23125
|
+
${renderTypeAlias("RouteModulePattern", routeModulePatternType)}${linkAugmentationBlock}${routeModuleAugmentationBlock}
|
|
23073
23126
|
`;
|
|
23074
23127
|
return content;
|
|
23075
23128
|
}
|
|
@@ -23351,7 +23404,8 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
23351
23404
|
const sourceRoots = getFarmSourceRoots({ root, srcDir, layers: options.layers });
|
|
23352
23405
|
const appDirs = getFarmAppDirectories({ root, srcDir, layers: options.layers });
|
|
23353
23406
|
const result = {
|
|
23354
|
-
apiRoutes: []
|
|
23407
|
+
apiRoutes: [],
|
|
23408
|
+
stalePaths: []
|
|
23355
23409
|
};
|
|
23356
23410
|
const unifiedTypesPath = (0, import_path8.join)(root, srcDir, "farm.d.ts");
|
|
23357
23411
|
const shouldRefreshUnifiedTypes = shouldGenerateRoutes && !options.routeTypesOutFile || shouldGenerateEnv && !options.envTypesOutFile || shouldGenerateI18n && !options.i18nTypesOutFile;
|
|
@@ -23367,22 +23421,29 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
23367
23421
|
unifiedSections.push(await createRouteTypeDeclarations(routeOptions, unifiedTypesPath));
|
|
23368
23422
|
result.routeTypesPath = unifiedTypesPath;
|
|
23369
23423
|
} else if (shouldGenerateRoutes) {
|
|
23370
|
-
|
|
23424
|
+
const routeOptions = {
|
|
23371
23425
|
root,
|
|
23372
23426
|
srcDir,
|
|
23373
23427
|
outFile: options.routeTypesOutFile,
|
|
23374
23428
|
extraRoutes: options.extraRoutes || [],
|
|
23375
23429
|
suppressLintOnLink: options.suppressLintOnLink,
|
|
23376
23430
|
sourceRoots
|
|
23377
|
-
}
|
|
23431
|
+
};
|
|
23432
|
+
if (options.check) {
|
|
23433
|
+
const routeTypesPath = resolveGeneratedPath(root, srcDir, options.routeTypesOutFile);
|
|
23434
|
+
const content = await createRouteTypeDeclarations(routeOptions, routeTypesPath);
|
|
23435
|
+
checkGeneratedFile(routeTypesPath, content, result.stalePaths);
|
|
23436
|
+
result.routeTypesPath = routeTypesPath;
|
|
23437
|
+
} else {
|
|
23438
|
+
result.routeTypesPath = await generateRouteTypes(routeOptions);
|
|
23439
|
+
}
|
|
23378
23440
|
}
|
|
23379
23441
|
if (shouldGenerateApi) {
|
|
23380
23442
|
const generator = new APITypeGenerator(appDirs);
|
|
23381
23443
|
const apiRoutes = generator.scanAPIRoutes();
|
|
23382
23444
|
const apiTypesPath = options.apiTypesOutFile ? (0, import_path8.resolve)(root, options.apiTypesOutFile) : (0, import_path8.join)(root, srcDir, "lib", "api.generated.ts");
|
|
23383
23445
|
const content = generator.generateAPIRouter(apiRoutes, { outFile: apiTypesPath });
|
|
23384
|
-
(
|
|
23385
|
-
writeFileIfChanged(apiTypesPath, content);
|
|
23446
|
+
writeOrCheckGeneratedFile(apiTypesPath, content, options.check, result.stalePaths);
|
|
23386
23447
|
result.apiTypesPath = apiTypesPath;
|
|
23387
23448
|
result.apiRoutes = apiRoutes;
|
|
23388
23449
|
}
|
|
@@ -23400,36 +23461,63 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
23400
23461
|
);
|
|
23401
23462
|
result.envTypesPath = unifiedTypesPath;
|
|
23402
23463
|
} else if (shouldGenerateEnv) {
|
|
23403
|
-
|
|
23464
|
+
const envOptions = {
|
|
23404
23465
|
root,
|
|
23405
23466
|
srcDir,
|
|
23406
23467
|
outFile: options.envTypesOutFile,
|
|
23407
23468
|
configPath: options.configPath,
|
|
23408
23469
|
layerConfigPaths: (options.layers ?? []).map((layer) => layer.configFile).filter((configFile) => Boolean(configFile))
|
|
23409
|
-
}
|
|
23470
|
+
};
|
|
23471
|
+
if (options.check) {
|
|
23472
|
+
const envTypesPath = resolveGeneratedPath(root, srcDir, options.envTypesOutFile);
|
|
23473
|
+
checkGeneratedFile(
|
|
23474
|
+
envTypesPath,
|
|
23475
|
+
createEnvTypeDeclarations(envOptions, envTypesPath),
|
|
23476
|
+
result.stalePaths
|
|
23477
|
+
);
|
|
23478
|
+
result.envTypesPath = envTypesPath;
|
|
23479
|
+
} else {
|
|
23480
|
+
result.envTypesPath = await generateEnvTypes(envOptions);
|
|
23481
|
+
}
|
|
23410
23482
|
}
|
|
23411
23483
|
if (shouldGenerateImages && options.imageTypesOutFile) {
|
|
23412
|
-
|
|
23413
|
-
|
|
23414
|
-
|
|
23415
|
-
|
|
23416
|
-
}
|
|
23484
|
+
const imageTypesPath = resolveGeneratedPath(root, srcDir, options.imageTypesOutFile, false);
|
|
23485
|
+
if (options.check) {
|
|
23486
|
+
checkGeneratedFile(imageTypesPath, createFarmImageTypeDeclarations(), result.stalePaths);
|
|
23487
|
+
result.imageTypesPath = imageTypesPath;
|
|
23488
|
+
} else {
|
|
23489
|
+
result.imageTypesPath = generateFarmImageTypes({
|
|
23490
|
+
root,
|
|
23491
|
+
srcDir,
|
|
23492
|
+
outFile: options.imageTypesOutFile
|
|
23493
|
+
});
|
|
23494
|
+
}
|
|
23417
23495
|
}
|
|
23418
23496
|
if (shouldRefreshUnifiedTypes && options.i18nConfig?.enabled && !options.i18nTypesOutFile) {
|
|
23419
23497
|
const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
|
|
23420
23498
|
unifiedSections.push(renderFarmI18nTypes(options.i18nConfig.locales, signatures));
|
|
23421
23499
|
result.i18nTypesPath = unifiedTypesPath;
|
|
23422
23500
|
} else if (shouldGenerateI18n && options.i18nConfig) {
|
|
23423
|
-
|
|
23424
|
-
root,
|
|
23425
|
-
|
|
23426
|
-
|
|
23427
|
-
|
|
23428
|
-
|
|
23501
|
+
if (options.check) {
|
|
23502
|
+
const i18nTypesPath = resolveGeneratedPath(root, srcDir, options.i18nTypesOutFile, false);
|
|
23503
|
+
const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
|
|
23504
|
+
checkGeneratedFile(
|
|
23505
|
+
i18nTypesPath,
|
|
23506
|
+
renderFarmI18nTypes(options.i18nConfig.locales, signatures),
|
|
23507
|
+
result.stalePaths
|
|
23508
|
+
);
|
|
23509
|
+
result.i18nTypesPath = i18nTypesPath;
|
|
23510
|
+
} else {
|
|
23511
|
+
result.i18nTypesPath = await generateFarmI18nTypes({
|
|
23512
|
+
root,
|
|
23513
|
+
srcDir,
|
|
23514
|
+
config: options.i18nConfig,
|
|
23515
|
+
outFile: options.i18nTypesOutFile
|
|
23516
|
+
});
|
|
23517
|
+
}
|
|
23429
23518
|
}
|
|
23430
23519
|
if (shouldRefreshUnifiedTypes) {
|
|
23431
|
-
(
|
|
23432
|
-
writeFileIfChanged(
|
|
23520
|
+
writeOrCheckGeneratedFile(
|
|
23433
23521
|
unifiedTypesPath,
|
|
23434
23522
|
`/**
|
|
23435
23523
|
* Generated by Farm.js. Do not edit.
|
|
@@ -23438,14 +23526,41 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
23438
23526
|
|
|
23439
23527
|
import "@farm.js/core/image";
|
|
23440
23528
|
|
|
23441
|
-
${unifiedSections.join("\n")}
|
|
23529
|
+
${unifiedSections.map((section) => section.trimEnd()).join("\n\n")}
|
|
23530
|
+
`,
|
|
23531
|
+
options.check,
|
|
23532
|
+
result.stalePaths
|
|
23442
23533
|
);
|
|
23443
23534
|
result.typesPath = unifiedTypesPath;
|
|
23444
|
-
|
|
23535
|
+
if (options.check) {
|
|
23536
|
+
collectLegacyTypeArtifacts(root, srcDir, result.stalePaths);
|
|
23537
|
+
} else {
|
|
23538
|
+
removeLegacyTypeArtifacts(root, srcDir);
|
|
23539
|
+
}
|
|
23445
23540
|
}
|
|
23446
23541
|
return result;
|
|
23447
23542
|
}
|
|
23448
23543
|
__name(generateFarmTypeArtifacts, "generateFarmTypeArtifacts");
|
|
23544
|
+
function resolveGeneratedPath(root, srcDir, outFile, relativeToSrc = true) {
|
|
23545
|
+
if ((0, import_path8.isAbsolute)(outFile)) return (0, import_path8.resolve)(outFile);
|
|
23546
|
+
return (0, import_path8.resolve)(root, relativeToSrc ? (0, import_path8.join)(srcDir, outFile) : outFile);
|
|
23547
|
+
}
|
|
23548
|
+
__name(resolveGeneratedPath, "resolveGeneratedPath");
|
|
23549
|
+
function writeOrCheckGeneratedFile(filePath, content, check, stalePaths) {
|
|
23550
|
+
if (check) {
|
|
23551
|
+
checkGeneratedFile(filePath, content, stalePaths);
|
|
23552
|
+
return;
|
|
23553
|
+
}
|
|
23554
|
+
(0, import_fs4.mkdirSync)((0, import_path8.dirname)(filePath), { recursive: true });
|
|
23555
|
+
writeFileIfChanged(filePath, content);
|
|
23556
|
+
}
|
|
23557
|
+
__name(writeOrCheckGeneratedFile, "writeOrCheckGeneratedFile");
|
|
23558
|
+
function checkGeneratedFile(filePath, content, stalePaths) {
|
|
23559
|
+
if (!(0, import_fs4.existsSync)(filePath) || (0, import_fs4.readFileSync)(filePath, "utf8") !== content) {
|
|
23560
|
+
stalePaths.push(filePath);
|
|
23561
|
+
}
|
|
23562
|
+
}
|
|
23563
|
+
__name(checkGeneratedFile, "checkGeneratedFile");
|
|
23449
23564
|
var LEGACY_TYPE_ARTIFACTS = [
|
|
23450
23565
|
["farm-routes.d.ts", "Auto-generated route types"],
|
|
23451
23566
|
["farm-env.d.ts", "Auto-generated env types"],
|
|
@@ -23463,6 +23578,14 @@ function removeLegacyTypeArtifacts(root, srcDir) {
|
|
|
23463
23578
|
}
|
|
23464
23579
|
}
|
|
23465
23580
|
__name(removeLegacyTypeArtifacts, "removeLegacyTypeArtifacts");
|
|
23581
|
+
function collectLegacyTypeArtifacts(root, srcDir, stalePaths) {
|
|
23582
|
+
for (const [fileName, marker] of LEGACY_TYPE_ARTIFACTS) {
|
|
23583
|
+
const filePath = (0, import_path8.join)(root, srcDir, fileName);
|
|
23584
|
+
if (!(0, import_fs4.existsSync)(filePath)) continue;
|
|
23585
|
+
if ((0, import_fs4.readFileSync)(filePath, "utf8").includes(marker)) stalePaths.push(filePath);
|
|
23586
|
+
}
|
|
23587
|
+
}
|
|
23588
|
+
__name(collectLegacyTypeArtifacts, "collectLegacyTypeArtifacts");
|
|
23466
23589
|
|
|
23467
23590
|
// src/vite.ts
|
|
23468
23591
|
init_markdown();
|
|
@@ -23818,7 +23941,7 @@ function transformError(id, message) {
|
|
|
23818
23941
|
__name(transformError, "transformError");
|
|
23819
23942
|
|
|
23820
23943
|
// package.json
|
|
23821
|
-
var version = "0.1.0-beta.
|
|
23944
|
+
var version = "0.1.0-beta.16";
|
|
23822
23945
|
|
|
23823
23946
|
// src/version.ts
|
|
23824
23947
|
var FARM_VERSION = version;
|
|
@@ -27980,6 +28103,8 @@ init_server_action_security();
|
|
|
27980
28103
|
|
|
27981
28104
|
// src/server-fn.ts
|
|
27982
28105
|
init_server_action_security();
|
|
28106
|
+
init_server_fn_error();
|
|
28107
|
+
init_server_fn_error();
|
|
27983
28108
|
var FARM_SERVER_FN_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn");
|
|
27984
28109
|
var UNSAFE_FORM_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
27985
28110
|
function createServerFn(options) {
|
|
@@ -27987,6 +28112,8 @@ function createServerFn(options) {
|
|
|
27987
28112
|
throw new TypeError("createServerFn requires a handler function");
|
|
27988
28113
|
}
|
|
27989
28114
|
const middleware = resolveServerFnMiddleware(options.middleware);
|
|
28115
|
+
const errors = normalizeServerFnErrors(options.errors);
|
|
28116
|
+
const error = createServerFnErrorHandler(errors);
|
|
27990
28117
|
const serverFn = /* @__PURE__ */ __name(async (value) => {
|
|
27991
28118
|
const formData = isFormData(value) ? value : void 0;
|
|
27992
28119
|
const rawInput = formData ? formDataToObject2(formData) : value;
|
|
@@ -28004,7 +28131,7 @@ function createServerFn(options) {
|
|
|
28004
28131
|
let resolvedContext = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
28005
28132
|
const result = await runServerFnMiddleware(middleware, handlerContext, async (context) => {
|
|
28006
28133
|
resolvedContext = context.context;
|
|
28007
|
-
return options.handler(context);
|
|
28134
|
+
return options.handler({ ...context, error });
|
|
28008
28135
|
});
|
|
28009
28136
|
const parsedResult = await _parseServerFnSchema(options.output, result, "output");
|
|
28010
28137
|
if (options.invalidates) {
|
|
@@ -28034,6 +28161,10 @@ function createServerFn(options) {
|
|
|
28034
28161
|
value: options.output,
|
|
28035
28162
|
enumerable: false
|
|
28036
28163
|
},
|
|
28164
|
+
__farmServerFnError: {
|
|
28165
|
+
value: void 0,
|
|
28166
|
+
enumerable: false
|
|
28167
|
+
},
|
|
28037
28168
|
__farmServerFnMiddleware: {
|
|
28038
28169
|
value: middleware,
|
|
28039
28170
|
enumerable: false
|
|
@@ -28072,6 +28203,78 @@ async function runServerFnMiddleware(middleware, handlerContext, handler) {
|
|
|
28072
28203
|
return dispatch(0, Object.freeze(/* @__PURE__ */ Object.create(null)));
|
|
28073
28204
|
}
|
|
28074
28205
|
__name(runServerFnMiddleware, "runServerFnMiddleware");
|
|
28206
|
+
function normalizeServerFnErrors(definitions) {
|
|
28207
|
+
if (definitions === void 0) return Object.freeze({});
|
|
28208
|
+
if (!isPlainServerFnObject(definitions)) {
|
|
28209
|
+
throw new TypeError("createServerFn errors must be an object");
|
|
28210
|
+
}
|
|
28211
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
28212
|
+
for (const [code, definition] of Object.entries(definitions)) {
|
|
28213
|
+
if (!code.trim()) {
|
|
28214
|
+
throw new TypeError("Server function error codes cannot be empty");
|
|
28215
|
+
}
|
|
28216
|
+
if (!definition || typeof definition !== "object") {
|
|
28217
|
+
throw new TypeError(`Server function error "${code}" must be an object`);
|
|
28218
|
+
}
|
|
28219
|
+
if (!Number.isInteger(definition.status) || definition.status < 400 || definition.status > 599) {
|
|
28220
|
+
throw new TypeError(
|
|
28221
|
+
`Server function error "${code}" status must be an integer between 400 and 599`
|
|
28222
|
+
);
|
|
28223
|
+
}
|
|
28224
|
+
if (!definition.data || typeof definition.data.parse !== "function" && typeof definition.data.safeParse !== "function") {
|
|
28225
|
+
throw new TypeError(
|
|
28226
|
+
`Server function error "${code}" data must provide synchronous parse() or safeParse()`
|
|
28227
|
+
);
|
|
28228
|
+
}
|
|
28229
|
+
if (definition.message !== void 0 && typeof definition.message !== "string") {
|
|
28230
|
+
throw new TypeError(`Server function error "${code}" message must be a string`);
|
|
28231
|
+
}
|
|
28232
|
+
normalized[code] = Object.freeze({ ...definition });
|
|
28233
|
+
}
|
|
28234
|
+
return Object.freeze(normalized);
|
|
28235
|
+
}
|
|
28236
|
+
__name(normalizeServerFnErrors, "normalizeServerFnErrors");
|
|
28237
|
+
function createServerFnErrorHandler(definitions) {
|
|
28238
|
+
return ((code, data) => {
|
|
28239
|
+
const definition = definitions[code];
|
|
28240
|
+
if (!definition) {
|
|
28241
|
+
throw new TypeError(`Server function error "${code}" is not declared`);
|
|
28242
|
+
}
|
|
28243
|
+
const parsed = parseServerFnFailureData(code, definition.data, data);
|
|
28244
|
+
throw new ServerFnFailure(code, parsed, {
|
|
28245
|
+
status: definition.status,
|
|
28246
|
+
message: definition.message ?? "Server function failed"
|
|
28247
|
+
});
|
|
28248
|
+
});
|
|
28249
|
+
}
|
|
28250
|
+
__name(createServerFnErrorHandler, "createServerFnErrorHandler");
|
|
28251
|
+
function parseServerFnFailureData(code, schema, value) {
|
|
28252
|
+
if (typeof schema.safeParse === "function") {
|
|
28253
|
+
const result2 = schema.safeParse(value);
|
|
28254
|
+
if (isPromiseLike2(result2)) {
|
|
28255
|
+
throw new TypeError(`Server function error "${code}" data schema must parse synchronously`);
|
|
28256
|
+
}
|
|
28257
|
+
return unwrapSafeParseResult(result2);
|
|
28258
|
+
}
|
|
28259
|
+
const result = schema.parse(value);
|
|
28260
|
+
if (isPromiseLike2(result)) {
|
|
28261
|
+
throw new TypeError(`Server function error "${code}" data schema must parse synchronously`);
|
|
28262
|
+
}
|
|
28263
|
+
return result;
|
|
28264
|
+
}
|
|
28265
|
+
__name(parseServerFnFailureData, "parseServerFnFailureData");
|
|
28266
|
+
function isPlainServerFnObject(value) {
|
|
28267
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
28268
|
+
const prototype = Object.getPrototypeOf(value);
|
|
28269
|
+
return prototype === Object.prototype || prototype === null;
|
|
28270
|
+
}
|
|
28271
|
+
__name(isPlainServerFnObject, "isPlainServerFnObject");
|
|
28272
|
+
function isPromiseLike2(value) {
|
|
28273
|
+
return Boolean(
|
|
28274
|
+
value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function"
|
|
28275
|
+
);
|
|
28276
|
+
}
|
|
28277
|
+
__name(isPromiseLike2, "isPromiseLike");
|
|
28075
28278
|
function resolveServerFnMiddleware(middleware) {
|
|
28076
28279
|
const resolved = [];
|
|
28077
28280
|
const seen = /* @__PURE__ */ new Set();
|