@farm.js/core 0.1.0-beta.13 → 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-VSDZEB5M.mjs → chunk-AN3PQVKH.mjs} +14 -16
- package/dist/{chunk-VSDZEB5M.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-3WIRO3N7.mjs → chunk-BWJC5ZOD.mjs} +2 -2
- package/dist/{chunk-3WIRO3N7.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-Z3YG4OZT.mjs → chunk-OSWV5IJB.mjs} +140 -41
- 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 +332 -58
- 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 +159 -46
- 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 +141 -34
- 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 +260 -37
- 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 +142 -35
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +8 -8
- package/package.json +1 -1
- package/types/client.d.ts +115 -4
- 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-UB5UOSHB.mjs.map +0 -1
- package/dist/chunk-VY2UYN5R.mjs.map +0 -1
- package/dist/chunk-WDU6QXNK.mjs.map +0 -1
- package/dist/chunk-Z3YG4OZT.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/index.cjs
CHANGED
|
@@ -4842,6 +4842,72 @@ var init_cache_invalidation = __esm({
|
|
|
4842
4842
|
}
|
|
4843
4843
|
});
|
|
4844
4844
|
|
|
4845
|
+
// src/server-fn-error.ts
|
|
4846
|
+
function isServerFnFailure(value) {
|
|
4847
|
+
if (!value || typeof value !== "object") return false;
|
|
4848
|
+
const candidate = value;
|
|
4849
|
+
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;
|
|
4850
|
+
}
|
|
4851
|
+
function serializeServerFnFailure(value) {
|
|
4852
|
+
if (!isServerFnFailure(value)) return null;
|
|
4853
|
+
return {
|
|
4854
|
+
name: "ServerFnFailure",
|
|
4855
|
+
message: value.message,
|
|
4856
|
+
code: value.code,
|
|
4857
|
+
status: value.status,
|
|
4858
|
+
data: value.data
|
|
4859
|
+
};
|
|
4860
|
+
}
|
|
4861
|
+
function createServerFnTransportError(value) {
|
|
4862
|
+
if (isSerializedServerFnFailure(value)) {
|
|
4863
|
+
return new ServerFnFailure(value.code, value.data, {
|
|
4864
|
+
status: value.status,
|
|
4865
|
+
message: value.message
|
|
4866
|
+
});
|
|
4867
|
+
}
|
|
4868
|
+
const message = value && typeof value === "object" && "message" in value && typeof value.message === "string" ? value.message : "Server function failed";
|
|
4869
|
+
return new ServerActionError(message);
|
|
4870
|
+
}
|
|
4871
|
+
function isSerializedServerFnFailure(value) {
|
|
4872
|
+
if (!value || typeof value !== "object") return false;
|
|
4873
|
+
const candidate = value;
|
|
4874
|
+
return candidate.name === "ServerFnFailure" && typeof candidate.message === "string" && typeof candidate.code === "string" && Number.isInteger(candidate.status) && (candidate.status ?? 0) >= 400 && (candidate.status ?? 0) <= 599 && "data" in candidate;
|
|
4875
|
+
}
|
|
4876
|
+
var FARM_SERVER_FN_FAILURE_SYMBOL, _ServerFnFailure, ServerFnFailure, _ServerActionError, ServerActionError;
|
|
4877
|
+
var init_server_fn_error = __esm({
|
|
4878
|
+
"src/server-fn-error.ts"() {
|
|
4879
|
+
"use strict";
|
|
4880
|
+
FARM_SERVER_FN_FAILURE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn.failure");
|
|
4881
|
+
_ServerFnFailure = class _ServerFnFailure extends Error {
|
|
4882
|
+
constructor(code, data, options) {
|
|
4883
|
+
super(options.message);
|
|
4884
|
+
this.name = "ServerFnFailure";
|
|
4885
|
+
this.code = code;
|
|
4886
|
+
this.data = data;
|
|
4887
|
+
this.status = options.status;
|
|
4888
|
+
Object.defineProperty(this, FARM_SERVER_FN_FAILURE_SYMBOL, {
|
|
4889
|
+
value: true,
|
|
4890
|
+
enumerable: false
|
|
4891
|
+
});
|
|
4892
|
+
}
|
|
4893
|
+
};
|
|
4894
|
+
__name(_ServerFnFailure, "ServerFnFailure");
|
|
4895
|
+
ServerFnFailure = _ServerFnFailure;
|
|
4896
|
+
_ServerActionError = class _ServerActionError extends Error {
|
|
4897
|
+
constructor(message = "Server function failed") {
|
|
4898
|
+
super(message);
|
|
4899
|
+
this.name = "ServerActionError";
|
|
4900
|
+
}
|
|
4901
|
+
};
|
|
4902
|
+
__name(_ServerActionError, "ServerActionError");
|
|
4903
|
+
ServerActionError = _ServerActionError;
|
|
4904
|
+
__name(isServerFnFailure, "isServerFnFailure");
|
|
4905
|
+
__name(serializeServerFnFailure, "serializeServerFnFailure");
|
|
4906
|
+
__name(createServerFnTransportError, "createServerFnTransportError");
|
|
4907
|
+
__name(isSerializedServerFnFailure, "isSerializedServerFnFailure");
|
|
4908
|
+
}
|
|
4909
|
+
});
|
|
4910
|
+
|
|
4845
4911
|
// src/server-action-security.ts
|
|
4846
4912
|
function resolveServerActionsConfig(config) {
|
|
4847
4913
|
const allowedOrigins = (config?.allowedOrigins ?? []).map(normalizeAllowedOriginPattern);
|
|
@@ -4928,7 +4994,9 @@ function createServerActionRequestErrorResponse(error) {
|
|
|
4928
4994
|
headers: headers2
|
|
4929
4995
|
});
|
|
4930
4996
|
}
|
|
4931
|
-
function sanitizeServerActionError(
|
|
4997
|
+
function sanitizeServerActionError(error) {
|
|
4998
|
+
const declaredFailure = serializeServerFnFailure(error);
|
|
4999
|
+
if (declaredFailure) return declaredFailure;
|
|
4932
5000
|
return {
|
|
4933
5001
|
name: "ServerActionError",
|
|
4934
5002
|
message: "Server function failed"
|
|
@@ -5227,6 +5295,7 @@ var init_server_action_security = __esm({
|
|
|
5227
5295
|
"use strict";
|
|
5228
5296
|
import_node_async_hooks = require("async_hooks");
|
|
5229
5297
|
init_cache_invalidation();
|
|
5298
|
+
init_server_fn_error();
|
|
5230
5299
|
DEFAULT_SERVER_ACTION_BODY_SIZE_LIMIT = 1e6;
|
|
5231
5300
|
_ServerActionRequestError = class _ServerActionRequestError extends Error {
|
|
5232
5301
|
constructor(code, status, message) {
|
|
@@ -10252,6 +10321,15 @@ var init_deferred = __esm({
|
|
|
10252
10321
|
});
|
|
10253
10322
|
|
|
10254
10323
|
// src/deployment.ts
|
|
10324
|
+
function getFarmPresetRuntime(preset) {
|
|
10325
|
+
if (preset === "cloudflare" || preset === "cloudflare-pages" || preset === "cloudflare-module" || preset === "netlify-edge" || preset === "vercel-edge" || preset === "deno") {
|
|
10326
|
+
return "edge";
|
|
10327
|
+
}
|
|
10328
|
+
if (preset === "node-server" || preset === "vercel" || preset === "netlify" || preset === "aws-lambda" || preset === "azure" || preset === "firebase" || preset === "bun" || preset === "self-host" || preset === "farm") {
|
|
10329
|
+
return "node";
|
|
10330
|
+
}
|
|
10331
|
+
return "unknown";
|
|
10332
|
+
}
|
|
10255
10333
|
function normalizeFarmDeploymentId(value) {
|
|
10256
10334
|
if (typeof value !== "string" || value.trim() === "") {
|
|
10257
10335
|
throw new TypeError("Farm deploymentId must be a non-empty string");
|
|
@@ -10370,6 +10448,7 @@ var init_deployment = __esm({
|
|
|
10370
10448
|
FARM_DEPLOYMENT_COOKIE = "__farm_deployment";
|
|
10371
10449
|
FARM_DEPLOYMENT_MISMATCH_CODE = "FARM_DEPLOYMENT_MISMATCH";
|
|
10372
10450
|
FARM_DEPLOYMENT_MISMATCH_STATUS = 409;
|
|
10451
|
+
__name(getFarmPresetRuntime, "getFarmPresetRuntime");
|
|
10373
10452
|
_FarmDeploymentMismatchError = class _FarmDeploymentMismatchError extends Error {
|
|
10374
10453
|
constructor(clientDeploymentId, serverDeploymentId) {
|
|
10375
10454
|
super("The application was updated while this page was open. Refresh before trying again.");
|
|
@@ -15968,13 +16047,13 @@ function createEndpoint(pathOrOptions, optionsOrHandler, maybeHandler) {
|
|
|
15968
16047
|
}
|
|
15969
16048
|
const middleware2 = normalizeEndpointMiddleware(options.middleware);
|
|
15970
16049
|
const errors = normalizeEndpointErrors(options.errors);
|
|
15971
|
-
const
|
|
16050
|
+
const error = createEndpointErrorHandler(errors);
|
|
15972
16051
|
const wrappedHandler = /* @__PURE__ */ __name((async (ctx) => {
|
|
15973
16052
|
const execution = await runEndpointMiddleware(
|
|
15974
16053
|
middleware2,
|
|
15975
16054
|
ctx,
|
|
15976
16055
|
handler,
|
|
15977
|
-
|
|
16056
|
+
error,
|
|
15978
16057
|
options.invalidates
|
|
15979
16058
|
);
|
|
15980
16059
|
return execution.result;
|
|
@@ -15994,7 +16073,7 @@ function createEndpoint(pathOrOptions, optionsOrHandler, maybeHandler) {
|
|
|
15994
16073
|
endpoint2.__method = options.method || "GET";
|
|
15995
16074
|
endpoint2.__autoPath = !path32;
|
|
15996
16075
|
endpoint2.__handler = wrappedHandler;
|
|
15997
|
-
endpoint2.__farmInvoke = (ctx) => runEndpointMiddleware(middleware2, ctx, handler,
|
|
16076
|
+
endpoint2.__farmInvoke = (ctx) => runEndpointMiddleware(middleware2, ctx, handler, error, options.invalidates);
|
|
15998
16077
|
endpoint2.__middleware = middleware2;
|
|
15999
16078
|
endpoint2.__sourceHandler = handler;
|
|
16000
16079
|
endpoint2.__invalidates = options.invalidates;
|
|
@@ -16025,8 +16104,9 @@ function normalizeEndpointErrors(definitions) {
|
|
|
16025
16104
|
if (!Number.isInteger(definition.status) || definition.status < 400 || definition.status > 599) {
|
|
16026
16105
|
throw new TypeError(`Endpoint error "${code}" status must be an integer between 400 and 599`);
|
|
16027
16106
|
}
|
|
16028
|
-
|
|
16029
|
-
|
|
16107
|
+
const dataSchema = resolveEndpointErrorSchema(definition);
|
|
16108
|
+
if (!dataSchema || typeof dataSchema.parse !== "function") {
|
|
16109
|
+
throw new TypeError(`Endpoint error "${code}" requires a data schema with parse()`);
|
|
16030
16110
|
}
|
|
16031
16111
|
if (definition.message !== void 0 && typeof definition.message !== "string") {
|
|
16032
16112
|
throw new TypeError(`Endpoint error "${code}" message must be a string`);
|
|
@@ -16035,13 +16115,19 @@ function normalizeEndpointErrors(definitions) {
|
|
|
16035
16115
|
}
|
|
16036
16116
|
return Object.freeze(normalized);
|
|
16037
16117
|
}
|
|
16038
|
-
function
|
|
16118
|
+
function resolveEndpointErrorSchema(definition) {
|
|
16119
|
+
if (definition.data && definition.schema) {
|
|
16120
|
+
throw new TypeError("Endpoint errors cannot define both data and schema");
|
|
16121
|
+
}
|
|
16122
|
+
return definition.data ?? definition.schema;
|
|
16123
|
+
}
|
|
16124
|
+
function createEndpointErrorHandler(definitions) {
|
|
16039
16125
|
return ((code, data) => {
|
|
16040
16126
|
const definition = definitions[code];
|
|
16041
16127
|
if (!definition) {
|
|
16042
16128
|
throw new TypeError(`Endpoint error "${code}" is not declared`);
|
|
16043
16129
|
}
|
|
16044
|
-
const parsed = definition.
|
|
16130
|
+
const parsed = resolveEndpointErrorSchema(definition).parse(data);
|
|
16045
16131
|
throw new EndpointFailure(code, parsed, {
|
|
16046
16132
|
status: definition.status,
|
|
16047
16133
|
message: definition.message ?? "Request failed"
|
|
@@ -16061,7 +16147,7 @@ function normalizeEndpointMiddleware(middleware2) {
|
|
|
16061
16147
|
}
|
|
16062
16148
|
return Object.freeze(normalized);
|
|
16063
16149
|
}
|
|
16064
|
-
async function runEndpointMiddleware(middleware2, handlerContext, handler,
|
|
16150
|
+
async function runEndpointMiddleware(middleware2, handlerContext, handler, error, invalidations) {
|
|
16065
16151
|
let context = createInitialEndpointContext(handlerContext.context);
|
|
16066
16152
|
for (let index = 0; index < middleware2.length; index++) {
|
|
16067
16153
|
const result2 = await middleware2[index]({ ...handlerContext, context });
|
|
@@ -16089,7 +16175,7 @@ async function runEndpointMiddleware(middleware2, handlerContext, handler, fail,
|
|
|
16089
16175
|
}
|
|
16090
16176
|
context = mergeEndpointContext(context, result2, index);
|
|
16091
16177
|
}
|
|
16092
|
-
const result = await handler({ ...handlerContext, context, fail });
|
|
16178
|
+
const result = await handler({ ...handlerContext, context, error, fail: error });
|
|
16093
16179
|
return {
|
|
16094
16180
|
result,
|
|
16095
16181
|
context,
|
|
@@ -16219,7 +16305,8 @@ var init_endpoint = __esm({
|
|
|
16219
16305
|
EMPTY_ENDPOINT_CONTEXT = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
16220
16306
|
UNSAFE_ENDPOINT_CONTEXT_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
16221
16307
|
__name(normalizeEndpointErrors, "normalizeEndpointErrors");
|
|
16222
|
-
__name(
|
|
16308
|
+
__name(resolveEndpointErrorSchema, "resolveEndpointErrorSchema");
|
|
16309
|
+
__name(createEndpointErrorHandler, "createEndpointErrorHandler");
|
|
16223
16310
|
__name(normalizeEndpointMiddleware, "normalizeEndpointMiddleware");
|
|
16224
16311
|
__name(runEndpointMiddleware, "runEndpointMiddleware");
|
|
16225
16312
|
__name(applyEndpointInvalidations, "applyEndpointInvalidations");
|
|
@@ -17824,6 +17911,13 @@ function routePatternToTsTypeLiterals(pattern) {
|
|
|
17824
17911
|
function routePatternToRouteLiteral(pattern) {
|
|
17825
17912
|
return JSON.stringify(pattern);
|
|
17826
17913
|
}
|
|
17914
|
+
function renderTypeUnion(values) {
|
|
17915
|
+
return values.length <= 1 ? values[0] || "never" : `
|
|
17916
|
+
| ${values.join("\n | ")}`;
|
|
17917
|
+
}
|
|
17918
|
+
function renderTypeAlias(name, value) {
|
|
17919
|
+
return `export type ${name} =${value.startsWith("\n") ? "" : " "}${value};`;
|
|
17920
|
+
}
|
|
17827
17921
|
function createRoutePattern(route2) {
|
|
17828
17922
|
if (route2.segments.length === 0) return "/";
|
|
17829
17923
|
return "/" + route2.segments.map((seg) => {
|
|
@@ -17846,39 +17940,48 @@ async function createRouteTypeDeclarations(options, outPath) {
|
|
|
17846
17940
|
const { root, srcDir = "src", extraRoutes = [], suppressLintOnLink = false } = options;
|
|
17847
17941
|
const sourceRoots = options.sourceRoots ?? [{ name: "project", root, srcDir, layer: false }];
|
|
17848
17942
|
const patterns = /* @__PURE__ */ new Set();
|
|
17943
|
+
const routeModulePatterns = /* @__PURE__ */ new Set();
|
|
17849
17944
|
const glob = await import("fast-glob");
|
|
17850
17945
|
for (const source of sourceRoots) {
|
|
17851
17946
|
const appDir = path14.join(source.root, source.srcDir, "app");
|
|
17852
17947
|
if (fs5.existsSync(appDir)) {
|
|
17853
|
-
const
|
|
17854
|
-
|
|
17855
|
-
|
|
17856
|
-
|
|
17857
|
-
|
|
17948
|
+
const routeModuleFiles = await glob.default(
|
|
17949
|
+
"**/{page,layout,loading,error}.{ts,tsx,js,jsx,md,mdx}",
|
|
17950
|
+
{
|
|
17951
|
+
cwd: appDir,
|
|
17952
|
+
absolute: false
|
|
17953
|
+
}
|
|
17954
|
+
);
|
|
17955
|
+
for (const file of routeModuleFiles) {
|
|
17858
17956
|
if (parseRouteSlotFile(file)) continue;
|
|
17859
17957
|
const route2 = parseRoutePath(file);
|
|
17958
|
+
const pattern = createRoutePattern(route2);
|
|
17959
|
+
routeModulePatterns.add(pattern);
|
|
17860
17960
|
if (route2.type === "page") {
|
|
17861
|
-
const pattern = createRoutePattern(route2);
|
|
17862
17961
|
patterns.add(pattern);
|
|
17863
17962
|
}
|
|
17864
17963
|
}
|
|
17865
17964
|
}
|
|
17866
17965
|
for (const route2 of await discoverProgrammaticRoutePaths(source.root, source.srcDir)) {
|
|
17867
17966
|
patterns.add(route2);
|
|
17967
|
+
routeModulePatterns.add(route2);
|
|
17868
17968
|
}
|
|
17869
17969
|
}
|
|
17870
17970
|
for (const route2 of extraRoutes) {
|
|
17871
17971
|
if (route2.startsWith("/")) {
|
|
17872
17972
|
patterns.add(route2);
|
|
17973
|
+
routeModulePatterns.add(route2);
|
|
17873
17974
|
}
|
|
17874
17975
|
}
|
|
17875
17976
|
const sortedPatterns = Array.from(patterns).sort();
|
|
17876
17977
|
const typeLiterals = Array.from(new Set(sortedPatterns.flatMap(routePatternToTsTypeLiterals)));
|
|
17877
17978
|
const patternLiterals = sortedPatterns.map(routePatternToRouteLiteral);
|
|
17878
|
-
const
|
|
17879
|
-
const
|
|
17979
|
+
const routeModulePatternLiterals = Array.from(routeModulePatterns).sort().map(routePatternToRouteLiteral);
|
|
17980
|
+
const routePathType = suppressLintOnLink ? "string" : renderTypeUnion(typeLiterals);
|
|
17981
|
+
const routePatternType = suppressLintOnLink ? "string" : renderTypeUnion(patternLiterals);
|
|
17982
|
+
const routeModulePatternType = renderTypeUnion(routeModulePatternLiterals);
|
|
17880
17983
|
const routeTypesImportPath = `./${path14.basename(outPath).replace(/\.d\.ts$/, "")}`;
|
|
17881
|
-
const
|
|
17984
|
+
const linkAugmentationBlock = suppressLintOnLink ? "" : `
|
|
17882
17985
|
declare module "@farm.js/core/client" {
|
|
17883
17986
|
interface LinkDefaultRoute {
|
|
17884
17987
|
_: import(${JSON.stringify(routeTypesImportPath)}).RoutePath;
|
|
@@ -17902,14 +18005,25 @@ declare module "@farm.js/core/dist/client.js" {
|
|
|
17902
18005
|
pattern: import(${JSON.stringify(routeTypesImportPath)}).RoutePattern;
|
|
17903
18006
|
}
|
|
17904
18007
|
}
|
|
18008
|
+
`;
|
|
18009
|
+
const routeModuleAugmentationBlock = `
|
|
18010
|
+
declare global {
|
|
18011
|
+
namespace FarmJS {
|
|
18012
|
+
interface RouteRegistry {
|
|
18013
|
+
pattern: import(${JSON.stringify(routeTypesImportPath)}).RouteModulePattern;
|
|
18014
|
+
}
|
|
18015
|
+
}
|
|
18016
|
+
}
|
|
17905
18017
|
`;
|
|
17906
18018
|
const content = `/**
|
|
17907
18019
|
* Auto-generated route types from src/app.
|
|
17908
|
-
* Link href
|
|
18020
|
+
* Link href and route component props are typed automatically from generated declarations.
|
|
18021
|
+
* Regenerated on dev start and when routes change.
|
|
17909
18022
|
* Set suppressLintOnLink: true in farm.config.ts to accept any string on Link href.
|
|
17910
18023
|
*/
|
|
17911
|
-
|
|
17912
|
-
|
|
18024
|
+
${renderTypeAlias("RoutePath", routePathType)}
|
|
18025
|
+
${renderTypeAlias("RoutePattern", routePatternType)}
|
|
18026
|
+
${renderTypeAlias("RouteModulePattern", routeModulePatternType)}${linkAugmentationBlock}${routeModuleAugmentationBlock}
|
|
17913
18027
|
`;
|
|
17914
18028
|
return content;
|
|
17915
18029
|
}
|
|
@@ -17926,6 +18040,8 @@ var init_generate_route_types = __esm({
|
|
|
17926
18040
|
__name(routeSegmentsToTsTypeLiteral, "routeSegmentsToTsTypeLiteral");
|
|
17927
18041
|
__name(routePatternToTsTypeLiterals, "routePatternToTsTypeLiterals");
|
|
17928
18042
|
__name(routePatternToRouteLiteral, "routePatternToRouteLiteral");
|
|
18043
|
+
__name(renderTypeUnion, "renderTypeUnion");
|
|
18044
|
+
__name(renderTypeAlias, "renderTypeAlias");
|
|
17929
18045
|
__name(createRoutePattern, "createRoutePattern");
|
|
17930
18046
|
DEFAULT_OUT_FILE = "farm-routes.d.ts";
|
|
17931
18047
|
__name(generateRouteTypes, "generateRouteTypes");
|
|
@@ -18226,7 +18342,8 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
18226
18342
|
const sourceRoots = getFarmSourceRoots({ root, srcDir, layers: options.layers });
|
|
18227
18343
|
const appDirs = getFarmAppDirectories({ root, srcDir, layers: options.layers });
|
|
18228
18344
|
const result = {
|
|
18229
|
-
apiRoutes: []
|
|
18345
|
+
apiRoutes: [],
|
|
18346
|
+
stalePaths: []
|
|
18230
18347
|
};
|
|
18231
18348
|
const unifiedTypesPath = (0, import_path8.join)(root, srcDir, "farm.d.ts");
|
|
18232
18349
|
const shouldRefreshUnifiedTypes = shouldGenerateRoutes && !options.routeTypesOutFile || shouldGenerateEnv && !options.envTypesOutFile || shouldGenerateI18n && !options.i18nTypesOutFile;
|
|
@@ -18242,22 +18359,29 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
18242
18359
|
unifiedSections.push(await createRouteTypeDeclarations(routeOptions, unifiedTypesPath));
|
|
18243
18360
|
result.routeTypesPath = unifiedTypesPath;
|
|
18244
18361
|
} else if (shouldGenerateRoutes) {
|
|
18245
|
-
|
|
18362
|
+
const routeOptions = {
|
|
18246
18363
|
root,
|
|
18247
18364
|
srcDir,
|
|
18248
18365
|
outFile: options.routeTypesOutFile,
|
|
18249
18366
|
extraRoutes: options.extraRoutes || [],
|
|
18250
18367
|
suppressLintOnLink: options.suppressLintOnLink,
|
|
18251
18368
|
sourceRoots
|
|
18252
|
-
}
|
|
18369
|
+
};
|
|
18370
|
+
if (options.check) {
|
|
18371
|
+
const routeTypesPath = resolveGeneratedPath(root, srcDir, options.routeTypesOutFile);
|
|
18372
|
+
const content = await createRouteTypeDeclarations(routeOptions, routeTypesPath);
|
|
18373
|
+
checkGeneratedFile(routeTypesPath, content, result.stalePaths);
|
|
18374
|
+
result.routeTypesPath = routeTypesPath;
|
|
18375
|
+
} else {
|
|
18376
|
+
result.routeTypesPath = await generateRouteTypes(routeOptions);
|
|
18377
|
+
}
|
|
18253
18378
|
}
|
|
18254
18379
|
if (shouldGenerateApi) {
|
|
18255
18380
|
const generator = new APITypeGenerator(appDirs);
|
|
18256
18381
|
const apiRoutes = generator.scanAPIRoutes();
|
|
18257
18382
|
const apiTypesPath = options.apiTypesOutFile ? (0, import_path8.resolve)(root, options.apiTypesOutFile) : (0, import_path8.join)(root, srcDir, "lib", "api.generated.ts");
|
|
18258
18383
|
const content = generator.generateAPIRouter(apiRoutes, { outFile: apiTypesPath });
|
|
18259
|
-
(
|
|
18260
|
-
writeFileIfChanged(apiTypesPath, content);
|
|
18384
|
+
writeOrCheckGeneratedFile(apiTypesPath, content, options.check, result.stalePaths);
|
|
18261
18385
|
result.apiTypesPath = apiTypesPath;
|
|
18262
18386
|
result.apiRoutes = apiRoutes;
|
|
18263
18387
|
}
|
|
@@ -18275,36 +18399,63 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
18275
18399
|
);
|
|
18276
18400
|
result.envTypesPath = unifiedTypesPath;
|
|
18277
18401
|
} else if (shouldGenerateEnv) {
|
|
18278
|
-
|
|
18402
|
+
const envOptions = {
|
|
18279
18403
|
root,
|
|
18280
18404
|
srcDir,
|
|
18281
18405
|
outFile: options.envTypesOutFile,
|
|
18282
18406
|
configPath: options.configPath,
|
|
18283
18407
|
layerConfigPaths: (options.layers ?? []).map((layer) => layer.configFile).filter((configFile) => Boolean(configFile))
|
|
18284
|
-
}
|
|
18408
|
+
};
|
|
18409
|
+
if (options.check) {
|
|
18410
|
+
const envTypesPath = resolveGeneratedPath(root, srcDir, options.envTypesOutFile);
|
|
18411
|
+
checkGeneratedFile(
|
|
18412
|
+
envTypesPath,
|
|
18413
|
+
createEnvTypeDeclarations(envOptions, envTypesPath),
|
|
18414
|
+
result.stalePaths
|
|
18415
|
+
);
|
|
18416
|
+
result.envTypesPath = envTypesPath;
|
|
18417
|
+
} else {
|
|
18418
|
+
result.envTypesPath = await generateEnvTypes(envOptions);
|
|
18419
|
+
}
|
|
18285
18420
|
}
|
|
18286
18421
|
if (shouldGenerateImages && options.imageTypesOutFile) {
|
|
18287
|
-
|
|
18288
|
-
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
}
|
|
18422
|
+
const imageTypesPath = resolveGeneratedPath(root, srcDir, options.imageTypesOutFile, false);
|
|
18423
|
+
if (options.check) {
|
|
18424
|
+
checkGeneratedFile(imageTypesPath, createFarmImageTypeDeclarations(), result.stalePaths);
|
|
18425
|
+
result.imageTypesPath = imageTypesPath;
|
|
18426
|
+
} else {
|
|
18427
|
+
result.imageTypesPath = generateFarmImageTypes({
|
|
18428
|
+
root,
|
|
18429
|
+
srcDir,
|
|
18430
|
+
outFile: options.imageTypesOutFile
|
|
18431
|
+
});
|
|
18432
|
+
}
|
|
18292
18433
|
}
|
|
18293
18434
|
if (shouldRefreshUnifiedTypes && options.i18nConfig?.enabled && !options.i18nTypesOutFile) {
|
|
18294
18435
|
const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
|
|
18295
18436
|
unifiedSections.push(renderFarmI18nTypes(options.i18nConfig.locales, signatures));
|
|
18296
18437
|
result.i18nTypesPath = unifiedTypesPath;
|
|
18297
18438
|
} else if (shouldGenerateI18n && options.i18nConfig) {
|
|
18298
|
-
|
|
18299
|
-
root,
|
|
18300
|
-
|
|
18301
|
-
|
|
18302
|
-
|
|
18303
|
-
|
|
18439
|
+
if (options.check) {
|
|
18440
|
+
const i18nTypesPath = resolveGeneratedPath(root, srcDir, options.i18nTypesOutFile, false);
|
|
18441
|
+
const { signatures } = await readFarmI18nCatalogs(options.i18nConfig);
|
|
18442
|
+
checkGeneratedFile(
|
|
18443
|
+
i18nTypesPath,
|
|
18444
|
+
renderFarmI18nTypes(options.i18nConfig.locales, signatures),
|
|
18445
|
+
result.stalePaths
|
|
18446
|
+
);
|
|
18447
|
+
result.i18nTypesPath = i18nTypesPath;
|
|
18448
|
+
} else {
|
|
18449
|
+
result.i18nTypesPath = await generateFarmI18nTypes({
|
|
18450
|
+
root,
|
|
18451
|
+
srcDir,
|
|
18452
|
+
config: options.i18nConfig,
|
|
18453
|
+
outFile: options.i18nTypesOutFile
|
|
18454
|
+
});
|
|
18455
|
+
}
|
|
18304
18456
|
}
|
|
18305
18457
|
if (shouldRefreshUnifiedTypes) {
|
|
18306
|
-
(
|
|
18307
|
-
writeFileIfChanged(
|
|
18458
|
+
writeOrCheckGeneratedFile(
|
|
18308
18459
|
unifiedTypesPath,
|
|
18309
18460
|
`/**
|
|
18310
18461
|
* Generated by Farm.js. Do not edit.
|
|
@@ -18313,13 +18464,37 @@ async function generateFarmTypeArtifacts(options) {
|
|
|
18313
18464
|
|
|
18314
18465
|
import "@farm.js/core/image";
|
|
18315
18466
|
|
|
18316
|
-
${unifiedSections.join("\n")}
|
|
18467
|
+
${unifiedSections.map((section) => section.trimEnd()).join("\n\n")}
|
|
18468
|
+
`,
|
|
18469
|
+
options.check,
|
|
18470
|
+
result.stalePaths
|
|
18317
18471
|
);
|
|
18318
18472
|
result.typesPath = unifiedTypesPath;
|
|
18319
|
-
|
|
18473
|
+
if (options.check) {
|
|
18474
|
+
collectLegacyTypeArtifacts(root, srcDir, result.stalePaths);
|
|
18475
|
+
} else {
|
|
18476
|
+
removeLegacyTypeArtifacts(root, srcDir);
|
|
18477
|
+
}
|
|
18320
18478
|
}
|
|
18321
18479
|
return result;
|
|
18322
18480
|
}
|
|
18481
|
+
function resolveGeneratedPath(root, srcDir, outFile, relativeToSrc = true) {
|
|
18482
|
+
if ((0, import_path8.isAbsolute)(outFile)) return (0, import_path8.resolve)(outFile);
|
|
18483
|
+
return (0, import_path8.resolve)(root, relativeToSrc ? (0, import_path8.join)(srcDir, outFile) : outFile);
|
|
18484
|
+
}
|
|
18485
|
+
function writeOrCheckGeneratedFile(filePath, content, check, stalePaths) {
|
|
18486
|
+
if (check) {
|
|
18487
|
+
checkGeneratedFile(filePath, content, stalePaths);
|
|
18488
|
+
return;
|
|
18489
|
+
}
|
|
18490
|
+
(0, import_fs4.mkdirSync)((0, import_path8.dirname)(filePath), { recursive: true });
|
|
18491
|
+
writeFileIfChanged(filePath, content);
|
|
18492
|
+
}
|
|
18493
|
+
function checkGeneratedFile(filePath, content, stalePaths) {
|
|
18494
|
+
if (!(0, import_fs4.existsSync)(filePath) || (0, import_fs4.readFileSync)(filePath, "utf8") !== content) {
|
|
18495
|
+
stalePaths.push(filePath);
|
|
18496
|
+
}
|
|
18497
|
+
}
|
|
18323
18498
|
function removeLegacyTypeArtifacts(root, srcDir) {
|
|
18324
18499
|
for (const [fileName, marker] of LEGACY_TYPE_ARTIFACTS) {
|
|
18325
18500
|
const filePath = (0, import_path8.join)(root, srcDir, fileName);
|
|
@@ -18330,6 +18505,13 @@ function removeLegacyTypeArtifacts(root, srcDir) {
|
|
|
18330
18505
|
}
|
|
18331
18506
|
}
|
|
18332
18507
|
}
|
|
18508
|
+
function collectLegacyTypeArtifacts(root, srcDir, stalePaths) {
|
|
18509
|
+
for (const [fileName, marker] of LEGACY_TYPE_ARTIFACTS) {
|
|
18510
|
+
const filePath = (0, import_path8.join)(root, srcDir, fileName);
|
|
18511
|
+
if (!(0, import_fs4.existsSync)(filePath)) continue;
|
|
18512
|
+
if ((0, import_fs4.readFileSync)(filePath, "utf8").includes(marker)) stalePaths.push(filePath);
|
|
18513
|
+
}
|
|
18514
|
+
}
|
|
18333
18515
|
var import_fs4, import_path8, LEGACY_TYPE_ARTIFACTS;
|
|
18334
18516
|
var init_type_artifacts = __esm({
|
|
18335
18517
|
"src/type-artifacts.ts"() {
|
|
@@ -18345,6 +18527,9 @@ var init_type_artifacts = __esm({
|
|
|
18345
18527
|
init_layers();
|
|
18346
18528
|
init_write_file_if_changed();
|
|
18347
18529
|
__name(generateFarmTypeArtifacts, "generateFarmTypeArtifacts");
|
|
18530
|
+
__name(resolveGeneratedPath, "resolveGeneratedPath");
|
|
18531
|
+
__name(writeOrCheckGeneratedFile, "writeOrCheckGeneratedFile");
|
|
18532
|
+
__name(checkGeneratedFile, "checkGeneratedFile");
|
|
18348
18533
|
LEGACY_TYPE_ARTIFACTS = [
|
|
18349
18534
|
["farm-routes.d.ts", "Auto-generated route types"],
|
|
18350
18535
|
["farm-env.d.ts", "Auto-generated env types"],
|
|
@@ -18352,6 +18537,7 @@ var init_type_artifacts = __esm({
|
|
|
18352
18537
|
["farm-i18n.d.ts", "Generated by Farm.js"]
|
|
18353
18538
|
];
|
|
18354
18539
|
__name(removeLegacyTypeArtifacts, "removeLegacyTypeArtifacts");
|
|
18540
|
+
__name(collectLegacyTypeArtifacts, "collectLegacyTypeArtifacts");
|
|
18355
18541
|
}
|
|
18356
18542
|
});
|
|
18357
18543
|
|
|
@@ -18708,7 +18894,7 @@ var init_environment_vite = __esm({
|
|
|
18708
18894
|
var version;
|
|
18709
18895
|
var init_package = __esm({
|
|
18710
18896
|
"package.json"() {
|
|
18711
|
-
version = "0.1.0-beta.
|
|
18897
|
+
version = "0.1.0-beta.16";
|
|
18712
18898
|
}
|
|
18713
18899
|
});
|
|
18714
18900
|
|
|
@@ -31927,6 +32113,7 @@ __export(src_exports, {
|
|
|
31927
32113
|
FARM_DEVTOOLS_LAUNCH_PARAM: () => FARM_DEVTOOLS_LAUNCH_PARAM,
|
|
31928
32114
|
FARM_DEVTOOLS_PATH: () => FARM_DEVTOOLS_PATH,
|
|
31929
32115
|
FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY: () => FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY,
|
|
32116
|
+
FARM_SERVER_FN_FAILURE_SYMBOL: () => FARM_SERVER_FN_FAILURE_SYMBOL,
|
|
31930
32117
|
FARM_SERVER_FN_SYMBOL: () => FARM_SERVER_FN_SYMBOL,
|
|
31931
32118
|
FARM_SERVER_QUERY_SYMBOL: () => FARM_SERVER_QUERY_SYMBOL,
|
|
31932
32119
|
FarmClientPluginManager: () => FarmClientPluginManager,
|
|
@@ -31949,7 +32136,9 @@ __export(src_exports, {
|
|
|
31949
32136
|
PluginManager: () => PluginManager,
|
|
31950
32137
|
SPARouter: () => SPARouter,
|
|
31951
32138
|
ScalarAPIDocumentation: () => ScalarAPIDocumentation,
|
|
32139
|
+
ServerActionError: () => ServerActionError,
|
|
31952
32140
|
ServerActionRequestError: () => ServerActionRequestError,
|
|
32141
|
+
ServerFnFailure: () => ServerFnFailure,
|
|
31953
32142
|
_parseServerFnSchema: () => _parseServerFnSchema,
|
|
31954
32143
|
_runWithAfterNodeResponse: () => _runWithAfterNodeResponse,
|
|
31955
32144
|
_runWithAfterRequest: () => _runWithAfterRequest,
|
|
@@ -32038,6 +32227,7 @@ __export(src_exports, {
|
|
|
32038
32227
|
createServerAPIClient: () => createServerAPIClient,
|
|
32039
32228
|
createServerActionRequestErrorResponse: () => createServerActionRequestErrorResponse,
|
|
32040
32229
|
createServerFn: () => createServerFn,
|
|
32230
|
+
createServerFnTransportError: () => createServerFnTransportError,
|
|
32041
32231
|
createServerMiddleware: () => createServerMiddleware,
|
|
32042
32232
|
createServerOnlyFn: () => createServerOnlyFn,
|
|
32043
32233
|
createServerQuery: () => createServerQuery,
|
|
@@ -32091,6 +32281,7 @@ __export(src_exports, {
|
|
|
32091
32281
|
getFarmDocsRouteTypeEntries: () => getFarmDocsRouteTypeEntries,
|
|
32092
32282
|
getFarmIntegrationPluginServerRuntime: () => getFarmIntegrationPluginServerRuntime,
|
|
32093
32283
|
getFarmLayerAliases: () => getFarmLayerAliases,
|
|
32284
|
+
getFarmPresetRuntime: () => getFarmPresetRuntime,
|
|
32094
32285
|
getFarmRedirectError: () => getFarmRedirectError,
|
|
32095
32286
|
getFarmRequestDeploymentId: () => getFarmRequestDeploymentId,
|
|
32096
32287
|
getFarmResponseDeploymentId: () => getFarmResponseDeploymentId,
|
|
@@ -32154,6 +32345,7 @@ __export(src_exports, {
|
|
|
32154
32345
|
isProgrammaticRouteManifest: () => isProgrammaticRouteManifest,
|
|
32155
32346
|
isProgrammaticRoutesFileName: () => isProgrammaticRoutesFileName,
|
|
32156
32347
|
isSSGModule: () => isSSGModule,
|
|
32348
|
+
isServerFnFailure: () => isServerFnFailure,
|
|
32157
32349
|
isWebResponse: () => isWebResponse2,
|
|
32158
32350
|
jsonStream: () => jsonStream,
|
|
32159
32351
|
layout: () => layout,
|
|
@@ -35702,6 +35894,8 @@ init_image_types();
|
|
|
35702
35894
|
init_server_action_security();
|
|
35703
35895
|
init_request_bridge();
|
|
35704
35896
|
init_cache();
|
|
35897
|
+
init_server_fn_error();
|
|
35898
|
+
init_server_fn_error();
|
|
35705
35899
|
var FARM_SERVER_FN_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn");
|
|
35706
35900
|
var UNSAFE_FORM_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
35707
35901
|
function createServerMiddleware(options) {
|
|
@@ -35724,6 +35918,8 @@ function createServerFn(options) {
|
|
|
35724
35918
|
throw new TypeError("createServerFn requires a handler function");
|
|
35725
35919
|
}
|
|
35726
35920
|
const middleware2 = resolveServerFnMiddleware(options.middleware);
|
|
35921
|
+
const errors = normalizeServerFnErrors(options.errors);
|
|
35922
|
+
const error = createServerFnErrorHandler(errors);
|
|
35727
35923
|
const serverFn = /* @__PURE__ */ __name(async (value) => {
|
|
35728
35924
|
const formData = isFormData2(value) ? value : void 0;
|
|
35729
35925
|
const rawInput = formData ? formDataToObject2(formData) : value;
|
|
@@ -35741,7 +35937,7 @@ function createServerFn(options) {
|
|
|
35741
35937
|
let resolvedContext = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
35742
35938
|
const result = await runServerFnMiddleware(middleware2, handlerContext, async (context) => {
|
|
35743
35939
|
resolvedContext = context.context;
|
|
35744
|
-
return options.handler(context);
|
|
35940
|
+
return options.handler({ ...context, error });
|
|
35745
35941
|
});
|
|
35746
35942
|
const parsedResult = await _parseServerFnSchema(options.output, result, "output");
|
|
35747
35943
|
if (options.invalidates) {
|
|
@@ -35771,6 +35967,10 @@ function createServerFn(options) {
|
|
|
35771
35967
|
value: options.output,
|
|
35772
35968
|
enumerable: false
|
|
35773
35969
|
},
|
|
35970
|
+
__farmServerFnError: {
|
|
35971
|
+
value: void 0,
|
|
35972
|
+
enumerable: false
|
|
35973
|
+
},
|
|
35774
35974
|
__farmServerFnMiddleware: {
|
|
35775
35975
|
value: middleware2,
|
|
35776
35976
|
enumerable: false
|
|
@@ -35809,6 +36009,78 @@ async function runServerFnMiddleware(middleware2, handlerContext, handler) {
|
|
|
35809
36009
|
return dispatch(0, Object.freeze(/* @__PURE__ */ Object.create(null)));
|
|
35810
36010
|
}
|
|
35811
36011
|
__name(runServerFnMiddleware, "runServerFnMiddleware");
|
|
36012
|
+
function normalizeServerFnErrors(definitions) {
|
|
36013
|
+
if (definitions === void 0) return Object.freeze({});
|
|
36014
|
+
if (!isPlainServerFnObject(definitions)) {
|
|
36015
|
+
throw new TypeError("createServerFn errors must be an object");
|
|
36016
|
+
}
|
|
36017
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
36018
|
+
for (const [code, definition] of Object.entries(definitions)) {
|
|
36019
|
+
if (!code.trim()) {
|
|
36020
|
+
throw new TypeError("Server function error codes cannot be empty");
|
|
36021
|
+
}
|
|
36022
|
+
if (!definition || typeof definition !== "object") {
|
|
36023
|
+
throw new TypeError(`Server function error "${code}" must be an object`);
|
|
36024
|
+
}
|
|
36025
|
+
if (!Number.isInteger(definition.status) || definition.status < 400 || definition.status > 599) {
|
|
36026
|
+
throw new TypeError(
|
|
36027
|
+
`Server function error "${code}" status must be an integer between 400 and 599`
|
|
36028
|
+
);
|
|
36029
|
+
}
|
|
36030
|
+
if (!definition.data || typeof definition.data.parse !== "function" && typeof definition.data.safeParse !== "function") {
|
|
36031
|
+
throw new TypeError(
|
|
36032
|
+
`Server function error "${code}" data must provide synchronous parse() or safeParse()`
|
|
36033
|
+
);
|
|
36034
|
+
}
|
|
36035
|
+
if (definition.message !== void 0 && typeof definition.message !== "string") {
|
|
36036
|
+
throw new TypeError(`Server function error "${code}" message must be a string`);
|
|
36037
|
+
}
|
|
36038
|
+
normalized[code] = Object.freeze({ ...definition });
|
|
36039
|
+
}
|
|
36040
|
+
return Object.freeze(normalized);
|
|
36041
|
+
}
|
|
36042
|
+
__name(normalizeServerFnErrors, "normalizeServerFnErrors");
|
|
36043
|
+
function createServerFnErrorHandler(definitions) {
|
|
36044
|
+
return ((code, data) => {
|
|
36045
|
+
const definition = definitions[code];
|
|
36046
|
+
if (!definition) {
|
|
36047
|
+
throw new TypeError(`Server function error "${code}" is not declared`);
|
|
36048
|
+
}
|
|
36049
|
+
const parsed = parseServerFnFailureData(code, definition.data, data);
|
|
36050
|
+
throw new ServerFnFailure(code, parsed, {
|
|
36051
|
+
status: definition.status,
|
|
36052
|
+
message: definition.message ?? "Server function failed"
|
|
36053
|
+
});
|
|
36054
|
+
});
|
|
36055
|
+
}
|
|
36056
|
+
__name(createServerFnErrorHandler, "createServerFnErrorHandler");
|
|
36057
|
+
function parseServerFnFailureData(code, schema, value) {
|
|
36058
|
+
if (typeof schema.safeParse === "function") {
|
|
36059
|
+
const result2 = schema.safeParse(value);
|
|
36060
|
+
if (isPromiseLike2(result2)) {
|
|
36061
|
+
throw new TypeError(`Server function error "${code}" data schema must parse synchronously`);
|
|
36062
|
+
}
|
|
36063
|
+
return unwrapSafeParseResult(result2);
|
|
36064
|
+
}
|
|
36065
|
+
const result = schema.parse(value);
|
|
36066
|
+
if (isPromiseLike2(result)) {
|
|
36067
|
+
throw new TypeError(`Server function error "${code}" data schema must parse synchronously`);
|
|
36068
|
+
}
|
|
36069
|
+
return result;
|
|
36070
|
+
}
|
|
36071
|
+
__name(parseServerFnFailureData, "parseServerFnFailureData");
|
|
36072
|
+
function isPlainServerFnObject(value) {
|
|
36073
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
36074
|
+
const prototype = Object.getPrototypeOf(value);
|
|
36075
|
+
return prototype === Object.prototype || prototype === null;
|
|
36076
|
+
}
|
|
36077
|
+
__name(isPlainServerFnObject, "isPlainServerFnObject");
|
|
36078
|
+
function isPromiseLike2(value) {
|
|
36079
|
+
return Boolean(
|
|
36080
|
+
value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function"
|
|
36081
|
+
);
|
|
36082
|
+
}
|
|
36083
|
+
__name(isPromiseLike2, "isPromiseLike");
|
|
35812
36084
|
function resolveServerFnMiddleware(middleware2) {
|
|
35813
36085
|
const resolved = [];
|
|
35814
36086
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -36421,6 +36693,7 @@ init_fonts();
|
|
|
36421
36693
|
|
|
36422
36694
|
// src/route-runtime-manifest.ts
|
|
36423
36695
|
var import_path10 = __toESM(require("path"));
|
|
36696
|
+
init_deployment();
|
|
36424
36697
|
init_route_runtime();
|
|
36425
36698
|
init_ssg();
|
|
36426
36699
|
var FARM_ROUTE_RUNTIME_MANIFEST = "route-runtime-manifest.json";
|
|
@@ -36481,10 +36754,15 @@ async function writeFarmRouteRuntimeManifest(directory, manifest) {
|
|
|
36481
36754
|
}
|
|
36482
36755
|
__name(writeFarmRouteRuntimeManifest, "writeFarmRouteRuntimeManifest");
|
|
36483
36756
|
function validateFarmRouteRuntimeDeployment(manifest, preset) {
|
|
36484
|
-
const runtime =
|
|
36757
|
+
const runtime = getFarmPresetRuntime(preset);
|
|
36485
36758
|
const warnings = /* @__PURE__ */ new Set();
|
|
36486
36759
|
for (const route2 of manifest.routes) {
|
|
36487
36760
|
if (route2.rendering === "static") continue;
|
|
36761
|
+
if (runtime === "unknown" && route2.runtime !== "auto") {
|
|
36762
|
+
warnings.add(
|
|
36763
|
+
`Preset "${preset}" has an unknown runtime, so Farm could not verify routes that explicitly require node or edge.`
|
|
36764
|
+
);
|
|
36765
|
+
}
|
|
36488
36766
|
if (runtime !== "unknown" && route2.runtime !== "auto" && route2.runtime !== runtime) {
|
|
36489
36767
|
throw new Error(
|
|
36490
36768
|
`Route "${route2.pattern}" requires the ${route2.runtime} runtime, but preset "${preset}" emits ${runtime} functions. Choose a compatible preset or change the route runtime.`
|
|
@@ -36504,16 +36782,6 @@ function validateFarmRouteRuntimeDeployment(manifest, preset) {
|
|
|
36504
36782
|
return { runtime, warnings: Array.from(warnings) };
|
|
36505
36783
|
}
|
|
36506
36784
|
__name(validateFarmRouteRuntimeDeployment, "validateFarmRouteRuntimeDeployment");
|
|
36507
|
-
function getPresetRuntime(preset) {
|
|
36508
|
-
if (preset === "cloudflare" || preset === "cloudflare-pages" || preset === "cloudflare-module" || preset === "netlify-edge" || preset === "vercel-edge" || preset === "deno") {
|
|
36509
|
-
return "edge";
|
|
36510
|
-
}
|
|
36511
|
-
if (preset === "node-server" || preset === "vercel" || preset === "netlify" || preset === "aws-lambda" || preset === "azure" || preset === "firebase" || preset === "bun") {
|
|
36512
|
-
return "node";
|
|
36513
|
-
}
|
|
36514
|
-
return "unknown";
|
|
36515
|
-
}
|
|
36516
|
-
__name(getPresetRuntime, "getPresetRuntime");
|
|
36517
36785
|
function normalizeManifestSource(root, modulePath) {
|
|
36518
36786
|
const queryIndex = modulePath.indexOf("?");
|
|
36519
36787
|
const filePath = queryIndex === -1 ? modulePath : modulePath.slice(0, queryIndex);
|
|
@@ -44506,6 +44774,7 @@ __name(decodeCookiePart, "decodeCookiePart");
|
|
|
44506
44774
|
FARM_DEVTOOLS_LAUNCH_PARAM,
|
|
44507
44775
|
FARM_DEVTOOLS_PATH,
|
|
44508
44776
|
FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY,
|
|
44777
|
+
FARM_SERVER_FN_FAILURE_SYMBOL,
|
|
44509
44778
|
FARM_SERVER_FN_SYMBOL,
|
|
44510
44779
|
FARM_SERVER_QUERY_SYMBOL,
|
|
44511
44780
|
FarmClientPluginManager,
|
|
@@ -44528,7 +44797,9 @@ __name(decodeCookiePart, "decodeCookiePart");
|
|
|
44528
44797
|
PluginManager,
|
|
44529
44798
|
SPARouter,
|
|
44530
44799
|
ScalarAPIDocumentation,
|
|
44800
|
+
ServerActionError,
|
|
44531
44801
|
ServerActionRequestError,
|
|
44802
|
+
ServerFnFailure,
|
|
44532
44803
|
_parseServerFnSchema,
|
|
44533
44804
|
_runWithAfterNodeResponse,
|
|
44534
44805
|
_runWithAfterRequest,
|
|
@@ -44617,6 +44888,7 @@ __name(decodeCookiePart, "decodeCookiePart");
|
|
|
44617
44888
|
createServerAPIClient,
|
|
44618
44889
|
createServerActionRequestErrorResponse,
|
|
44619
44890
|
createServerFn,
|
|
44891
|
+
createServerFnTransportError,
|
|
44620
44892
|
createServerMiddleware,
|
|
44621
44893
|
createServerOnlyFn,
|
|
44622
44894
|
createServerQuery,
|
|
@@ -44670,6 +44942,7 @@ __name(decodeCookiePart, "decodeCookiePart");
|
|
|
44670
44942
|
getFarmDocsRouteTypeEntries,
|
|
44671
44943
|
getFarmIntegrationPluginServerRuntime,
|
|
44672
44944
|
getFarmLayerAliases,
|
|
44945
|
+
getFarmPresetRuntime,
|
|
44673
44946
|
getFarmRedirectError,
|
|
44674
44947
|
getFarmRequestDeploymentId,
|
|
44675
44948
|
getFarmResponseDeploymentId,
|
|
@@ -44733,6 +45006,7 @@ __name(decodeCookiePart, "decodeCookiePart");
|
|
|
44733
45006
|
isProgrammaticRouteManifest,
|
|
44734
45007
|
isProgrammaticRoutesFileName,
|
|
44735
45008
|
isSSGModule,
|
|
45009
|
+
isServerFnFailure,
|
|
44736
45010
|
isWebResponse,
|
|
44737
45011
|
jsonStream,
|
|
44738
45012
|
layout,
|