@farm.js/core 0.1.15 → 0.1.17
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/agent-runtime.d.mts +5 -2
- package/dist/agent-runtime.d.ts +5 -2
- package/dist/api/client.cjs +62 -28
- package/dist/api/client.d.mts +3 -2
- package/dist/api/client.d.ts +3 -2
- package/dist/api/client.mjs +3 -3
- package/dist/api/route-manager.cjs +69 -32
- package/dist/api/route-manager.d.mts +5 -2
- package/dist/api/route-manager.d.ts +5 -2
- package/dist/api/route-manager.mjs +5 -5
- package/dist/api/runtime.cjs +65 -29
- package/dist/api/runtime.d.mts +3 -2
- package/dist/api/runtime.d.ts +3 -2
- package/dist/api/runtime.mjs +6 -3
- package/dist/{api-client-C8d7BZNp.d.mts → api-client-Cx54IR5g.d.mts} +2 -1
- package/dist/{api-client-BWrEbxfO.d.ts → api-client-DykpaKcY.d.ts} +2 -1
- package/dist/api.cjs +106 -33
- package/dist/api.d.mts +7 -4
- package/dist/api.d.ts +7 -4
- package/dist/api.mjs +8 -8
- package/dist/{app-wIYse61b.d.ts → app-BHY_10Lm.d.ts} +3 -3
- package/dist/{app-B3nVSjen.d.mts → app-BMk0do23.d.mts} +3 -3
- package/dist/app-markdown.d.mts +6 -3
- package/dist/app-markdown.d.ts +6 -3
- package/dist/app-markdown.mjs +3 -3
- package/dist/cache.cjs +62 -28
- package/dist/cache.d.mts +11 -1
- package/dist/cache.d.ts +11 -1
- package/dist/cache.mjs +1 -1
- package/dist/{chunk-FOGLGRDS.mjs → chunk-4OOBRCJX.mjs} +122 -8
- package/dist/{chunk-JRF3C33L.mjs → chunk-56DAX2BE.mjs} +172 -53
- package/dist/{chunk-B76DT5Y6.mjs → chunk-57J3Y7Y3.mjs} +1 -1
- package/dist/{chunk-MOQNHLTS.mjs → chunk-5QOEPUYE.mjs} +5 -2
- package/dist/{chunk-HKLRP3BN.mjs → chunk-5SPPCN5J.mjs} +1 -1
- package/dist/{chunk-LUC2FAGW.mjs → chunk-6VQIKZZO.mjs} +1 -1
- package/dist/{chunk-7ZWL7XOU.mjs → chunk-76DG3LF3.mjs} +1 -1
- package/dist/{chunk-EWDK36MM.mjs → chunk-A72YEUZ3.mjs} +1 -1
- package/dist/{chunk-ZHOIQC6U.mjs → chunk-ATERBVHQ.mjs} +2 -2
- package/dist/{chunk-27JNCYEK.mjs → chunk-EN7WTEAY.mjs} +2 -2
- package/dist/{chunk-IGO2HEV7.mjs → chunk-F6SJAKFJ.mjs} +62 -28
- package/dist/{chunk-GSDIZACQ.mjs → chunk-FG5H2VCJ.mjs} +2 -2
- package/dist/{chunk-LZK5CXDW.mjs → chunk-KLSSO6YD.mjs} +2 -2
- package/dist/{chunk-KUO3GBPK.mjs → chunk-L6V3P73N.mjs} +1 -1
- package/dist/{chunk-FBHGHMOA.mjs → chunk-MVIWBEJF.mjs} +37 -27
- package/dist/{chunk-KTGFMHET.mjs → chunk-N6UROPT7.mjs} +1 -1
- package/dist/{chunk-NDD2YVGU.mjs → chunk-NRVGEI5I.mjs} +10 -3
- package/dist/{chunk-GNTPTTLA.mjs → chunk-QGVJVSNX.mjs} +5 -5
- package/dist/{chunk-6SCB2MXB.mjs → chunk-SXHV42UQ.mjs} +16 -1
- package/dist/{chunk-OWTIOHON.mjs → chunk-SYGGPS4A.mjs} +2 -2
- package/dist/{chunk-NC333MFA.mjs → chunk-TSWW5BVH.mjs} +7 -4
- package/dist/{chunk-LK6FGAQR.mjs → chunk-UDBJCUPA.mjs} +7 -4
- package/dist/{chunk-NJ47VORC.mjs → chunk-UTBVHYS3.mjs} +2 -2
- package/dist/{chunk-76MNRHTS.mjs → chunk-UUYF3CHN.mjs} +2 -2
- package/dist/{chunk-S3QW3BIS.mjs → chunk-WD4YXVLV.mjs} +99 -6
- package/dist/{chunk-W7IVHTOP.mjs → chunk-WD5PNSOB.mjs} +16 -3
- package/dist/{chunk-DPZUDPVJ.mjs → chunk-XP777LRD.mjs} +1 -1
- package/dist/{chunk-KATQ6I56.mjs → chunk-XWAYMDLB.mjs} +1 -1
- package/dist/{chunk-UE75PB52.mjs → chunk-YD4J4XCI.mjs} +1 -1
- package/dist/{chunk-Q3MDL7TM.mjs → chunk-ZCNJKLA2.mjs} +30 -11
- package/dist/{client-plugins-CslwYp3E.d.ts → client-plugins-C089bQhN.d.ts} +16 -4
- package/dist/{client-plugins-C1EgdoJM.d.mts → client-plugins-JXXmZliS.d.mts} +16 -4
- package/dist/client-plugins.d.mts +5 -2
- package/dist/client-plugins.d.ts +5 -2
- package/dist/client.cjs +62 -28
- package/dist/client.d.mts +8 -7
- package/dist/client.d.ts +8 -7
- package/dist/client.mjs +6 -6
- package/dist/config.d.mts +5 -2
- package/dist/config.d.ts +5 -2
- package/dist/cron.mjs +2 -2
- package/dist/{devtools-PCGEBRSC.mjs → devtools-UFVTMQX5.mjs} +7 -7
- package/dist/docs.cjs +83 -4
- package/dist/docs.mjs +9 -9
- package/dist/{route-CHBaW55F.d.ts → endpoint-1zA994xL.d.ts} +3 -128
- package/dist/{route-C6UClI1z.d.mts → endpoint-DAc96i93.d.mts} +3 -128
- package/dist/env.cjs +135 -8
- package/dist/env.d.mts +22 -2
- package/dist/env.d.ts +22 -2
- package/dist/env.mjs +4 -1
- package/dist/index.cjs +516 -105
- package/dist/index.d.mts +16 -15
- package/dist/index.d.ts +16 -15
- package/dist/index.mjs +46 -34
- package/dist/integrations.d.mts +5 -2
- package/dist/integrations.d.ts +5 -2
- package/dist/internal/app-markdown-runtime.d.mts +5 -2
- package/dist/internal/app-markdown-runtime.d.ts +5 -2
- package/dist/internal/app-markdown-runtime.mjs +2 -2
- package/dist/internal/build-runtime.cjs +600 -284
- package/dist/internal/build-runtime.d.mts +7 -4
- package/dist/internal/build-runtime.d.ts +7 -4
- package/dist/internal/build-runtime.mjs +23 -23
- package/dist/internal/cli-runtime.cjs +143 -33
- package/dist/internal/cli-runtime.mjs +13 -13
- package/dist/internal/client-error-overlay.cjs +1 -1
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/compression-runtime.d.mts +5 -2
- package/dist/internal/compression-runtime.d.ts +5 -2
- package/dist/internal/config-runtime.cjs +80 -4
- package/dist/internal/config-runtime.d.mts +6 -3
- package/dist/internal/config-runtime.d.ts +6 -3
- package/dist/internal/config-runtime.mjs +7 -7
- package/dist/internal/product-telemetry-runtime.cjs +1 -1
- package/dist/internal/product-telemetry-runtime.mjs +1 -1
- package/dist/internal/production-runtime.cjs +101 -41
- package/dist/internal/production-runtime.d.mts +11 -8
- package/dist/internal/production-runtime.d.ts +11 -8
- package/dist/internal/production-runtime.mjs +6 -6
- package/dist/markdown.cjs +16 -1
- package/dist/markdown.mjs +1 -1
- package/dist/{metadata-BsUcOEXg.d.ts → metadata-BcNJP4fq.d.ts} +1 -1
- package/dist/{metadata-B1bxCPUY.d.mts → metadata-C1Z9vLbb.d.mts} +1 -1
- package/dist/middleware.cjs +10 -3
- package/dist/middleware.d.mts +7 -4
- package/dist/middleware.d.ts +7 -4
- package/dist/middleware.mjs +4 -4
- package/dist/{nitro-ICBP5APY.mjs → nitro-CVZ36JM5.mjs} +8 -5
- package/dist/plugin.cjs +358 -106
- package/dist/plugin.d.mts +5 -2
- package/dist/plugin.d.ts +5 -2
- package/dist/plugin.mjs +19 -19
- package/dist/{production-runtime-BDllolVh.d.mts → production-runtime-jcrTlRTb.d.mts} +1 -1
- package/dist/{production-runtime-CsNn2-zx.d.ts → production-runtime-oKmC0WU-.d.ts} +1 -1
- package/dist/{render-plan-CNUlzylR.d.mts → render-plan-BLIfc4jt.d.mts} +1 -1
- package/dist/{render-plan-EG4hNFjy.d.ts → render-plan-DOB9cV-h.d.ts} +1 -1
- package/dist/renderer-client.cjs +62 -28
- package/dist/renderer-client.d.mts +5 -4
- package/dist/renderer-client.d.ts +5 -4
- package/dist/renderer-client.mjs +3 -3
- package/dist/{request-Blh_f7Z3.d.mts → request-Cr53NRHr.d.mts} +1 -1
- package/dist/{request-DsVSQVfD.d.ts → request-Dt2gNuQD.d.ts} +1 -1
- package/dist/request.d.mts +6 -3
- package/dist/request.d.ts +6 -3
- package/dist/route-B0XrsrFk.d.mts +128 -0
- package/dist/route-DOEpbyWZ.d.ts +128 -0
- package/dist/{route-rendering-hUETRCbM.d.ts → route-rendering-CWYd8Mv1.d.ts} +1 -1
- package/dist/{route-rendering-LT4XSoQK.d.mts → route-rendering-CeFBEAoZ.d.mts} +1 -1
- package/dist/routes.cjs +68 -31
- package/dist/routes.d.mts +5 -3
- package/dist/routes.d.ts +5 -3
- package/dist/routes.mjs +2 -2
- package/dist/server-fn-client.d.mts +3 -2
- package/dist/server-fn-client.d.ts +3 -2
- package/dist/server-fn.cjs +212 -32
- package/dist/server-fn.d.mts +72 -1
- package/dist/server-fn.d.ts +72 -1
- package/dist/server-fn.mjs +13 -2
- package/dist/server-plugins.d.mts +6 -3
- package/dist/server-plugins.d.ts +6 -3
- package/dist/server-query-client.cjs +62 -28
- package/dist/server-query-client.d.mts +1 -0
- package/dist/server-query-client.d.ts +1 -0
- package/dist/server-query-client.mjs +4 -4
- package/dist/server-query.cjs +131 -32
- package/dist/server-query.d.mts +6 -1
- package/dist/server-query.d.ts +6 -1
- package/dist/server-query.mjs +4 -3
- package/dist/server.cjs +393 -84
- package/dist/server.d.mts +9 -8
- package/dist/server.d.ts +9 -8
- package/dist/server.mjs +22 -22
- package/dist/{spa-router-csKR9Ebj.d.mts → spa-router-CQWiYGxS.d.mts} +2 -2
- package/dist/{spa-router-Y_2FSJQK.d.ts → spa-router-Wjiw-8hB.d.ts} +2 -2
- package/dist/testing.cjs +73 -32
- package/dist/testing.d.mts +5 -3
- package/dist/testing.d.ts +5 -3
- package/dist/testing.mjs +11 -7
- package/dist/{utils-jISOE9SD.d.ts → utils-B0XJmG_b.d.ts} +1 -1
- package/dist/{utils-DR2wfZAn.d.mts → utils-uUxF0K0P.d.mts} +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +500 -252
- package/dist/vite.d.mts +5 -2
- package/dist/vite.d.ts +5 -2
- package/dist/vite.mjs +19 -19
- package/dist/workflows.mjs +2 -2
- package/package.json +2 -2
- package/dist/{chunk-VO5SCWF5.mjs → chunk-BNGS6KJ6.mjs} +0 -0
- package/dist/{chunk-MUUZJLCI.mjs → chunk-EGJDUF4Q.mjs} +3 -3
- package/dist/{chunk-4L7SZOHZ.mjs → chunk-YHOCRI4H.mjs} +3 -3
|
@@ -129,7 +129,7 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
129
129
|
type Simplify<T> = {
|
|
130
130
|
[TKey in keyof T]: T[TKey];
|
|
131
131
|
} & {};
|
|
132
|
-
type UnionToIntersection
|
|
132
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer TIntersection) => void ? TIntersection : never;
|
|
133
133
|
type InferOutput<T> = RouteSchemaOutput<T>;
|
|
134
134
|
type InferInput<T> = T extends {
|
|
135
135
|
_input: infer I;
|
|
@@ -222,7 +222,7 @@ type ValidateEndpointMiddlewares<TMiddlewares extends readonly AnyEndpointMiddle
|
|
|
222
222
|
};
|
|
223
223
|
type ContextFromMiddlewareResult<TResult> = Exclude<TResult, Response | boolean> extends infer TContext ? [TContext] extends [never] ? {} : TContext extends object ? TContext : {} : {};
|
|
224
224
|
type ContextFromMiddleware<TMiddleware> = TMiddleware extends (...args: any[]) => infer TResult ? ContextFromMiddlewareResult<Awaited<TResult>> : {};
|
|
225
|
-
type InferEndpointMiddlewareContext<TMiddlewares extends readonly ((...args: any[]) => any)[], TContext extends object = {}> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest] ? TMiddleware extends (...args: any[]) => any ? TRest extends readonly ((...args: any[]) => any)[] ? InferEndpointMiddlewareContext<TRest, Simplify<TContext & ContextFromMiddleware<TMiddleware>>> : Simplify<TContext> : Simplify<TContext> : number extends TMiddlewares["length"] ? Simplify<TContext & UnionToIntersection
|
|
225
|
+
type InferEndpointMiddlewareContext<TMiddlewares extends readonly ((...args: any[]) => any)[], TContext extends object = {}> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest] ? TMiddleware extends (...args: any[]) => any ? TRest extends readonly ((...args: any[]) => any)[] ? InferEndpointMiddlewareContext<TRest, Simplify<TContext & ContextFromMiddleware<TMiddleware>>> : Simplify<TContext> : Simplify<TContext> : number extends TMiddlewares["length"] ? Simplify<TContext & UnionToIntersection<ContextFromMiddleware<TMiddlewares[number]>>> : Simplify<TContext>;
|
|
226
226
|
type EndpointOptions<TBody extends AnySchema = never, TQuery extends AnySchema = never, THeaders extends AnySchema = never, TMiddlewares extends readonly AnyEndpointMiddleware[] = readonly [], TErrors extends EndpointErrorDefinitions = {}> = {
|
|
227
227
|
method?: "GET" | "HEAD" | "QUERY" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
|
|
228
228
|
body?: TBody;
|
|
@@ -364,129 +364,4 @@ declare function OPTIONS<T = any>(handler: EndpointHandler<never, never, never,
|
|
|
364
364
|
declare function OPTIONS<const TOptions extends MethodlessEndpointOptions, TResponse = any>(options: TOptions, handler: ValidatedEndpointHandlerFromOptions<TOptions, TResponse>): CreatedEndpointFromOptions<TOptions, TResponse>;
|
|
365
365
|
declare function OPTIONS<TBody extends AnySchema = never, TQuery extends AnySchema = never, THeaders extends AnySchema = never, TResponse = any>(options: Omit<EndpointOptions<TBody, TQuery, THeaders, readonly []>, "method">, handler: EndpointHandler<TBody, TQuery, THeaders, TResponse>): CreatedEndpoint<TBody, TQuery, THeaders, TResponse>;
|
|
366
366
|
|
|
367
|
-
type
|
|
368
|
-
type RoutePathParams<Path extends string> = Path extends `${infer Head}/${infer Tail}` ? RoutePathParams<Head> & RoutePathParams<Tail> : Path extends `[[...${infer Name}]]` ? {
|
|
369
|
-
[K in Name]?: string[];
|
|
370
|
-
} : Path extends `[...${infer Name}]` ? {
|
|
371
|
-
[K in Name]: string[];
|
|
372
|
-
} : Path extends `[${infer Name}]` ? {
|
|
373
|
-
[K in Name]: string;
|
|
374
|
-
} : {};
|
|
375
|
-
interface RouteInputSchemas {
|
|
376
|
-
body?: RouteSchema;
|
|
377
|
-
query?: RouteSchema;
|
|
378
|
-
params?: RouteSchema;
|
|
379
|
-
headers?: RouteSchema;
|
|
380
|
-
}
|
|
381
|
-
type Input<I, K extends PropertyKey> = K extends keyof I ? RouteSchemaInput<I[K]> : never;
|
|
382
|
-
type Output<I, K extends PropertyKey, Fallback = unknown> = K extends keyof I ? RouteSchemaOutput<I[K]> : Fallback;
|
|
383
|
-
/** JSON responses have wire types, not server-side instances such as Date. */
|
|
384
|
-
type RouteJSON<T> = T extends Response ? unknown : T extends {
|
|
385
|
-
toJSON(): infer J;
|
|
386
|
-
} ? RouteJSON<J> : T extends bigint | symbol | ((...args: any[]) => any) ? never : T extends readonly (infer V)[] ? RouteJSON<V>[] : T extends object ? {
|
|
387
|
-
[K in keyof T]: RouteJSON<T[K]>;
|
|
388
|
-
} : T;
|
|
389
|
-
type RouteDefinition<P extends string = string, M extends RouteMethod = RouteMethod, E = any> = {
|
|
390
|
-
readonly path: P;
|
|
391
|
-
readonly method: M;
|
|
392
|
-
readonly endpoint: E;
|
|
393
|
-
};
|
|
394
|
-
type RouteEndpoint<P extends string, I extends RouteInputSchemas, R> = TypedEndpoint<Output<I, "body">, Input<I, "query">, RouteJSON<R>, Input<I, "headers">, never, Input<I, "body">> & {
|
|
395
|
-
__types: {
|
|
396
|
-
params: RoutePathParams<P>;
|
|
397
|
-
inputHeaders: Input<I, "headers">;
|
|
398
|
-
};
|
|
399
|
-
};
|
|
400
|
-
type TrimStart<P extends string> = P extends `/${infer Rest}` ? TrimStart<Rest> : P;
|
|
401
|
-
type Join<P extends string, C extends string> = C extends "" ? P : `${P}/${TrimStart<C>}`;
|
|
402
|
-
type ParamsCheck<P extends string, I extends RouteInputSchemas> = I extends {
|
|
403
|
-
params: infer S;
|
|
404
|
-
} ? Exclude<keyof RoutePathParams<P>, keyof RouteSchemaOutput<S>> extends never ? Exclude<keyof RouteSchemaOutput<S>, keyof RoutePathParams<P>> extends never ? unknown : {
|
|
405
|
-
__error_unknown_route_params: never;
|
|
406
|
-
} : {
|
|
407
|
-
__error_missing_route_params: never;
|
|
408
|
-
} : unknown;
|
|
409
|
-
type RouteMiddlewareResults = readonly (EndpointMiddlewareResult | Promise<EndpointMiddlewareResult>)[];
|
|
410
|
-
type RouteMiddlewares<Results extends readonly unknown[]> = {
|
|
411
|
-
readonly [K in keyof Results]: (context: Parameters<AnyEndpointMiddleware>[0]) => Results[K];
|
|
412
|
-
};
|
|
413
|
-
type RouteOptions<P extends string, I extends RouteInputSchemas, O extends RouteSchema | undefined, R, MiddlewareResults extends RouteMiddlewareResults = RouteMiddlewareResults> = {
|
|
414
|
-
input?: I & ParamsCheck<P, I>;
|
|
415
|
-
/** Validate plain JSON handler results. Raw Response/stream results are never buffered. */
|
|
416
|
-
output?: O;
|
|
417
|
-
/** Opt this app-owned endpoint into an installed MCP transport. */
|
|
418
|
-
mcp?: EndpointMCPOptions;
|
|
419
|
-
middleware?: RouteMiddlewares<MiddlewareResults>;
|
|
420
|
-
handler(request: Request, context: {
|
|
421
|
-
input: {
|
|
422
|
-
body: Output<I, "body">;
|
|
423
|
-
query: Output<I, "query", Record<string, string | string[]>>;
|
|
424
|
-
headers: Output<I, "headers", Record<string, string>>;
|
|
425
|
-
params: Output<I, "params", RoutePathParams<P>>;
|
|
426
|
-
};
|
|
427
|
-
params: Output<I, "params", RoutePathParams<P>>;
|
|
428
|
-
context: Readonly<InferEndpointMiddlewareContext<RouteMiddlewares<MiddlewareResults>>>;
|
|
429
|
-
}): R | Promise<R>;
|
|
430
|
-
};
|
|
431
|
-
type RouteBuilder<P extends string, M extends RouteMethod> = <const C extends string, const MiddlewareResults extends RouteMiddlewareResults, const I extends RouteInputSchemas = {}, O extends RouteSchema | undefined = undefined, R = unknown>(path: C, options: RouteOptions<Join<P, C>, I, O, R, MiddlewareResults>) => RouteDefinition<Join<P, C>, M, RouteEndpoint<Join<P, C>, I, Extract<Awaited<R>, Response> extends never ? O extends RouteSchema ? RouteSchemaOutput<O> : Awaited<R> : unknown>>;
|
|
432
|
-
type RouteFactory<P extends string = ""> = {
|
|
433
|
-
[M in Lowercase<RouteMethod>]: RouteBuilder<P, Uppercase<M> & RouteMethod>;
|
|
434
|
-
} & {
|
|
435
|
-
/** Return a new builder; never mutate the parent scope. */
|
|
436
|
-
scope<const C extends string>(path: C): RouteFactory<Join<P, C>>;
|
|
437
|
-
};
|
|
438
|
-
type PluginRoutes = readonly RouteDefinition[];
|
|
439
|
-
interface PluginLocalAPIEndpoint {
|
|
440
|
-
readonly path: string;
|
|
441
|
-
readonly method: RouteMethod;
|
|
442
|
-
readonly input: Readonly<RouteInputSchemas>;
|
|
443
|
-
readonly output?: RouteSchema;
|
|
444
|
-
readonly mcp?: EndpointMCPOptions;
|
|
445
|
-
invoke(request: Request, params?: Readonly<Record<string, string | string[]>>): Promise<Response>;
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Read-only access to app-owned API endpoints while plugin routes are mounted.
|
|
449
|
-
* Plugin routes are intentionally excluded so a plugin cannot recurse through
|
|
450
|
-
* itself or depend on plugin registration order.
|
|
451
|
-
*/
|
|
452
|
-
interface PluginLocalAPI {
|
|
453
|
-
/** False during type-only route discovery, where app endpoint modules are unavailable. */
|
|
454
|
-
readonly available: boolean;
|
|
455
|
-
get(method: RouteMethod, path: string): PluginLocalAPIEndpoint | undefined;
|
|
456
|
-
/** Enumerate app-owned endpoints. Plugin routes are excluded. */
|
|
457
|
-
list(): readonly PluginLocalAPIEndpoint[];
|
|
458
|
-
}
|
|
459
|
-
type PluginRoutesFactory<R extends PluginRoutes = PluginRoutes> = (context: {
|
|
460
|
-
route: RouteFactory;
|
|
461
|
-
api: PluginLocalAPI;
|
|
462
|
-
}) => R;
|
|
463
|
-
declare function createRouteFactory(): RouteFactory;
|
|
464
|
-
type UnionToIntersection<U> = (U extends unknown ? (v: U) => void : never) extends (v: infer I) => void ? I : never;
|
|
465
|
-
type RouteTree<P extends string, M extends string, E> = P extends `${infer Head}/${infer Tail}` ? {
|
|
466
|
-
[K in Head]: RouteTree<Tail, M, E>;
|
|
467
|
-
} : P extends "" ? {
|
|
468
|
-
[K in Lowercase<M>]: E;
|
|
469
|
-
} : {
|
|
470
|
-
[K in P]: {
|
|
471
|
-
[Method in Lowercase<M>]: E;
|
|
472
|
-
};
|
|
473
|
-
};
|
|
474
|
-
type HasMethodSegment<P extends string> = P extends `${infer H}/${infer T}` ? H extends Lowercase<RouteMethod> ? true : HasMethodSegment<T> : P extends Lowercase<RouteMethod> ? true : false;
|
|
475
|
-
type DefinitionTree<D> = D extends RouteDefinition<infer P, infer M, infer E> ? string extends P ? {} : (P extends `/api/integrations${string}` ? true : HasMethodSegment<P>) extends true ? {
|
|
476
|
-
[K in P extends `/api/${infer C}` ? `/${C}` : "/"]: {
|
|
477
|
-
[Method in Lowercase<M>]: E;
|
|
478
|
-
};
|
|
479
|
-
} : RouteTree<P extends `/api/${infer C}` ? C : "", M, E> : {};
|
|
480
|
-
type PluginAPIRouter<C> = C extends {
|
|
481
|
-
plugins: readonly (infer P)[];
|
|
482
|
-
} ? UnionToIntersection<P extends {
|
|
483
|
-
routes?: PluginRoutesFactory<infer R>;
|
|
484
|
-
} ? DefinitionTree<R[number]> : {}> : {};
|
|
485
|
-
declare function resolvePluginRoutes(plugins?: readonly {
|
|
486
|
-
name: string;
|
|
487
|
-
routes?: PluginRoutesFactory;
|
|
488
|
-
}[], context?: {
|
|
489
|
-
api?: PluginLocalAPI;
|
|
490
|
-
}): PluginRoutes;
|
|
491
|
-
|
|
492
|
-
export { type RouteOptions as $, type AnyEndpointMiddleware as A, type TypedFormData as B, type MultipartSchema as C, DELETE as D, EndpointFailure as E, type FarmStreamResponse as F, GET as G, HEAD as H, type InferEndpointMiddlewareContext as I, type FarmAPIStream as J, multipart as K, isMultipartSchema as L, type MultipartField as M, toFormData as N, OPTIONS as O, type PluginRoutesFactory as P, QUERY as Q, jsonStream as R, isJSONStreamResponse as S, type TypedEndpoint as T, readJSONStream as U, isFarmAPIStream as V, type RouteMethod as W, type RoutePathParams as X, type RouteInputSchemas as Y, type RouteJSON as Z, type RouteDefinition as _, type EndpointOpenAPIMetadata as a, type RouteFactory as a0, type PluginRoutes as a1, type PluginLocalAPIEndpoint as a2, type PluginLocalAPI as a3, createRouteFactory as a4, type PluginAPIRouter as a5, resolvePluginRoutes as a6, type RouteSchema as a7, type RouteSchemaOutput as a8, type RouteSchemaInput as a9, type OpenAPISecurityMode as aa, type EndpointErrorSchema as b, type EndpointErrorDefinition as c, type EndpointErrorDefinitions as d, type EndpointErrorContracts as e, type EndpointErrorHandler as f, type EndpointFail as g, type EndpointParamValue as h, isEndpointFailure as i, type EndpointParams as j, type EndpointMiddlewareContext as k, type EndpointMiddlewareResult as l, type EndpointMiddleware as m, type EndpointInvalidationTarget as n, type EndpointInvalidationContext as o, parseRouteSchema as p, type EndpointInvalidations as q, type EndpointMCPMetadata as r, type EndpointMCPOptions as s, type EndpointOptions as t, type EndpointHandler as u, createEndpoint as v, POST as w, PUT as x, PATCH as y, type MultipartValues as z };
|
|
367
|
+
export { type AnyEndpointMiddleware as A, type MultipartValues as B, type TypedFormData as C, DELETE as D, type EndpointMiddlewareResult as E, type MultipartSchema as F, GET as G, HEAD as H, type InferEndpointMiddlewareContext as I, type FarmStreamResponse as J, type FarmAPIStream as K, multipart as L, type MultipartField as M, isMultipartSchema as N, OPTIONS as O, POST as P, QUERY as Q, type RouteSchema as R, toFormData as S, type TypedEndpoint as T, jsonStream as U, isJSONStreamResponse as V, readJSONStream as W, isFarmAPIStream as X, type OpenAPISecurityMode as Y, type RouteSchemaOutput as a, type EndpointMCPOptions as b, type RouteSchemaInput as c, type EndpointMCPMetadata as d, EndpointFailure as e, type EndpointOpenAPIMetadata as f, type EndpointErrorSchema as g, type EndpointErrorDefinition as h, isEndpointFailure as i, type EndpointErrorDefinitions as j, type EndpointErrorContracts as k, type EndpointErrorHandler as l, type EndpointFail as m, type EndpointParamValue as n, type EndpointParams as o, parseRouteSchema as p, type EndpointMiddlewareContext as q, type EndpointMiddleware as r, type EndpointInvalidationTarget as s, type EndpointInvalidationContext as t, type EndpointInvalidations as u, type EndpointOptions as v, type EndpointHandler as w, createEndpoint as x, PUT as y, PATCH as z };
|
|
@@ -129,7 +129,7 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
129
129
|
type Simplify<T> = {
|
|
130
130
|
[TKey in keyof T]: T[TKey];
|
|
131
131
|
} & {};
|
|
132
|
-
type UnionToIntersection
|
|
132
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer TIntersection) => void ? TIntersection : never;
|
|
133
133
|
type InferOutput<T> = RouteSchemaOutput<T>;
|
|
134
134
|
type InferInput<T> = T extends {
|
|
135
135
|
_input: infer I;
|
|
@@ -222,7 +222,7 @@ type ValidateEndpointMiddlewares<TMiddlewares extends readonly AnyEndpointMiddle
|
|
|
222
222
|
};
|
|
223
223
|
type ContextFromMiddlewareResult<TResult> = Exclude<TResult, Response | boolean> extends infer TContext ? [TContext] extends [never] ? {} : TContext extends object ? TContext : {} : {};
|
|
224
224
|
type ContextFromMiddleware<TMiddleware> = TMiddleware extends (...args: any[]) => infer TResult ? ContextFromMiddlewareResult<Awaited<TResult>> : {};
|
|
225
|
-
type InferEndpointMiddlewareContext<TMiddlewares extends readonly ((...args: any[]) => any)[], TContext extends object = {}> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest] ? TMiddleware extends (...args: any[]) => any ? TRest extends readonly ((...args: any[]) => any)[] ? InferEndpointMiddlewareContext<TRest, Simplify<TContext & ContextFromMiddleware<TMiddleware>>> : Simplify<TContext> : Simplify<TContext> : number extends TMiddlewares["length"] ? Simplify<TContext & UnionToIntersection
|
|
225
|
+
type InferEndpointMiddlewareContext<TMiddlewares extends readonly ((...args: any[]) => any)[], TContext extends object = {}> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest] ? TMiddleware extends (...args: any[]) => any ? TRest extends readonly ((...args: any[]) => any)[] ? InferEndpointMiddlewareContext<TRest, Simplify<TContext & ContextFromMiddleware<TMiddleware>>> : Simplify<TContext> : Simplify<TContext> : number extends TMiddlewares["length"] ? Simplify<TContext & UnionToIntersection<ContextFromMiddleware<TMiddlewares[number]>>> : Simplify<TContext>;
|
|
226
226
|
type EndpointOptions<TBody extends AnySchema = never, TQuery extends AnySchema = never, THeaders extends AnySchema = never, TMiddlewares extends readonly AnyEndpointMiddleware[] = readonly [], TErrors extends EndpointErrorDefinitions = {}> = {
|
|
227
227
|
method?: "GET" | "HEAD" | "QUERY" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
|
|
228
228
|
body?: TBody;
|
|
@@ -364,129 +364,4 @@ declare function OPTIONS<T = any>(handler: EndpointHandler<never, never, never,
|
|
|
364
364
|
declare function OPTIONS<const TOptions extends MethodlessEndpointOptions, TResponse = any>(options: TOptions, handler: ValidatedEndpointHandlerFromOptions<TOptions, TResponse>): CreatedEndpointFromOptions<TOptions, TResponse>;
|
|
365
365
|
declare function OPTIONS<TBody extends AnySchema = never, TQuery extends AnySchema = never, THeaders extends AnySchema = never, TResponse = any>(options: Omit<EndpointOptions<TBody, TQuery, THeaders, readonly []>, "method">, handler: EndpointHandler<TBody, TQuery, THeaders, TResponse>): CreatedEndpoint<TBody, TQuery, THeaders, TResponse>;
|
|
366
366
|
|
|
367
|
-
type
|
|
368
|
-
type RoutePathParams<Path extends string> = Path extends `${infer Head}/${infer Tail}` ? RoutePathParams<Head> & RoutePathParams<Tail> : Path extends `[[...${infer Name}]]` ? {
|
|
369
|
-
[K in Name]?: string[];
|
|
370
|
-
} : Path extends `[...${infer Name}]` ? {
|
|
371
|
-
[K in Name]: string[];
|
|
372
|
-
} : Path extends `[${infer Name}]` ? {
|
|
373
|
-
[K in Name]: string;
|
|
374
|
-
} : {};
|
|
375
|
-
interface RouteInputSchemas {
|
|
376
|
-
body?: RouteSchema;
|
|
377
|
-
query?: RouteSchema;
|
|
378
|
-
params?: RouteSchema;
|
|
379
|
-
headers?: RouteSchema;
|
|
380
|
-
}
|
|
381
|
-
type Input<I, K extends PropertyKey> = K extends keyof I ? RouteSchemaInput<I[K]> : never;
|
|
382
|
-
type Output<I, K extends PropertyKey, Fallback = unknown> = K extends keyof I ? RouteSchemaOutput<I[K]> : Fallback;
|
|
383
|
-
/** JSON responses have wire types, not server-side instances such as Date. */
|
|
384
|
-
type RouteJSON<T> = T extends Response ? unknown : T extends {
|
|
385
|
-
toJSON(): infer J;
|
|
386
|
-
} ? RouteJSON<J> : T extends bigint | symbol | ((...args: any[]) => any) ? never : T extends readonly (infer V)[] ? RouteJSON<V>[] : T extends object ? {
|
|
387
|
-
[K in keyof T]: RouteJSON<T[K]>;
|
|
388
|
-
} : T;
|
|
389
|
-
type RouteDefinition<P extends string = string, M extends RouteMethod = RouteMethod, E = any> = {
|
|
390
|
-
readonly path: P;
|
|
391
|
-
readonly method: M;
|
|
392
|
-
readonly endpoint: E;
|
|
393
|
-
};
|
|
394
|
-
type RouteEndpoint<P extends string, I extends RouteInputSchemas, R> = TypedEndpoint<Output<I, "body">, Input<I, "query">, RouteJSON<R>, Input<I, "headers">, never, Input<I, "body">> & {
|
|
395
|
-
__types: {
|
|
396
|
-
params: RoutePathParams<P>;
|
|
397
|
-
inputHeaders: Input<I, "headers">;
|
|
398
|
-
};
|
|
399
|
-
};
|
|
400
|
-
type TrimStart<P extends string> = P extends `/${infer Rest}` ? TrimStart<Rest> : P;
|
|
401
|
-
type Join<P extends string, C extends string> = C extends "" ? P : `${P}/${TrimStart<C>}`;
|
|
402
|
-
type ParamsCheck<P extends string, I extends RouteInputSchemas> = I extends {
|
|
403
|
-
params: infer S;
|
|
404
|
-
} ? Exclude<keyof RoutePathParams<P>, keyof RouteSchemaOutput<S>> extends never ? Exclude<keyof RouteSchemaOutput<S>, keyof RoutePathParams<P>> extends never ? unknown : {
|
|
405
|
-
__error_unknown_route_params: never;
|
|
406
|
-
} : {
|
|
407
|
-
__error_missing_route_params: never;
|
|
408
|
-
} : unknown;
|
|
409
|
-
type RouteMiddlewareResults = readonly (EndpointMiddlewareResult | Promise<EndpointMiddlewareResult>)[];
|
|
410
|
-
type RouteMiddlewares<Results extends readonly unknown[]> = {
|
|
411
|
-
readonly [K in keyof Results]: (context: Parameters<AnyEndpointMiddleware>[0]) => Results[K];
|
|
412
|
-
};
|
|
413
|
-
type RouteOptions<P extends string, I extends RouteInputSchemas, O extends RouteSchema | undefined, R, MiddlewareResults extends RouteMiddlewareResults = RouteMiddlewareResults> = {
|
|
414
|
-
input?: I & ParamsCheck<P, I>;
|
|
415
|
-
/** Validate plain JSON handler results. Raw Response/stream results are never buffered. */
|
|
416
|
-
output?: O;
|
|
417
|
-
/** Opt this app-owned endpoint into an installed MCP transport. */
|
|
418
|
-
mcp?: EndpointMCPOptions;
|
|
419
|
-
middleware?: RouteMiddlewares<MiddlewareResults>;
|
|
420
|
-
handler(request: Request, context: {
|
|
421
|
-
input: {
|
|
422
|
-
body: Output<I, "body">;
|
|
423
|
-
query: Output<I, "query", Record<string, string | string[]>>;
|
|
424
|
-
headers: Output<I, "headers", Record<string, string>>;
|
|
425
|
-
params: Output<I, "params", RoutePathParams<P>>;
|
|
426
|
-
};
|
|
427
|
-
params: Output<I, "params", RoutePathParams<P>>;
|
|
428
|
-
context: Readonly<InferEndpointMiddlewareContext<RouteMiddlewares<MiddlewareResults>>>;
|
|
429
|
-
}): R | Promise<R>;
|
|
430
|
-
};
|
|
431
|
-
type RouteBuilder<P extends string, M extends RouteMethod> = <const C extends string, const MiddlewareResults extends RouteMiddlewareResults, const I extends RouteInputSchemas = {}, O extends RouteSchema | undefined = undefined, R = unknown>(path: C, options: RouteOptions<Join<P, C>, I, O, R, MiddlewareResults>) => RouteDefinition<Join<P, C>, M, RouteEndpoint<Join<P, C>, I, Extract<Awaited<R>, Response> extends never ? O extends RouteSchema ? RouteSchemaOutput<O> : Awaited<R> : unknown>>;
|
|
432
|
-
type RouteFactory<P extends string = ""> = {
|
|
433
|
-
[M in Lowercase<RouteMethod>]: RouteBuilder<P, Uppercase<M> & RouteMethod>;
|
|
434
|
-
} & {
|
|
435
|
-
/** Return a new builder; never mutate the parent scope. */
|
|
436
|
-
scope<const C extends string>(path: C): RouteFactory<Join<P, C>>;
|
|
437
|
-
};
|
|
438
|
-
type PluginRoutes = readonly RouteDefinition[];
|
|
439
|
-
interface PluginLocalAPIEndpoint {
|
|
440
|
-
readonly path: string;
|
|
441
|
-
readonly method: RouteMethod;
|
|
442
|
-
readonly input: Readonly<RouteInputSchemas>;
|
|
443
|
-
readonly output?: RouteSchema;
|
|
444
|
-
readonly mcp?: EndpointMCPOptions;
|
|
445
|
-
invoke(request: Request, params?: Readonly<Record<string, string | string[]>>): Promise<Response>;
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Read-only access to app-owned API endpoints while plugin routes are mounted.
|
|
449
|
-
* Plugin routes are intentionally excluded so a plugin cannot recurse through
|
|
450
|
-
* itself or depend on plugin registration order.
|
|
451
|
-
*/
|
|
452
|
-
interface PluginLocalAPI {
|
|
453
|
-
/** False during type-only route discovery, where app endpoint modules are unavailable. */
|
|
454
|
-
readonly available: boolean;
|
|
455
|
-
get(method: RouteMethod, path: string): PluginLocalAPIEndpoint | undefined;
|
|
456
|
-
/** Enumerate app-owned endpoints. Plugin routes are excluded. */
|
|
457
|
-
list(): readonly PluginLocalAPIEndpoint[];
|
|
458
|
-
}
|
|
459
|
-
type PluginRoutesFactory<R extends PluginRoutes = PluginRoutes> = (context: {
|
|
460
|
-
route: RouteFactory;
|
|
461
|
-
api: PluginLocalAPI;
|
|
462
|
-
}) => R;
|
|
463
|
-
declare function createRouteFactory(): RouteFactory;
|
|
464
|
-
type UnionToIntersection<U> = (U extends unknown ? (v: U) => void : never) extends (v: infer I) => void ? I : never;
|
|
465
|
-
type RouteTree<P extends string, M extends string, E> = P extends `${infer Head}/${infer Tail}` ? {
|
|
466
|
-
[K in Head]: RouteTree<Tail, M, E>;
|
|
467
|
-
} : P extends "" ? {
|
|
468
|
-
[K in Lowercase<M>]: E;
|
|
469
|
-
} : {
|
|
470
|
-
[K in P]: {
|
|
471
|
-
[Method in Lowercase<M>]: E;
|
|
472
|
-
};
|
|
473
|
-
};
|
|
474
|
-
type HasMethodSegment<P extends string> = P extends `${infer H}/${infer T}` ? H extends Lowercase<RouteMethod> ? true : HasMethodSegment<T> : P extends Lowercase<RouteMethod> ? true : false;
|
|
475
|
-
type DefinitionTree<D> = D extends RouteDefinition<infer P, infer M, infer E> ? string extends P ? {} : (P extends `/api/integrations${string}` ? true : HasMethodSegment<P>) extends true ? {
|
|
476
|
-
[K in P extends `/api/${infer C}` ? `/${C}` : "/"]: {
|
|
477
|
-
[Method in Lowercase<M>]: E;
|
|
478
|
-
};
|
|
479
|
-
} : RouteTree<P extends `/api/${infer C}` ? C : "", M, E> : {};
|
|
480
|
-
type PluginAPIRouter<C> = C extends {
|
|
481
|
-
plugins: readonly (infer P)[];
|
|
482
|
-
} ? UnionToIntersection<P extends {
|
|
483
|
-
routes?: PluginRoutesFactory<infer R>;
|
|
484
|
-
} ? DefinitionTree<R[number]> : {}> : {};
|
|
485
|
-
declare function resolvePluginRoutes(plugins?: readonly {
|
|
486
|
-
name: string;
|
|
487
|
-
routes?: PluginRoutesFactory;
|
|
488
|
-
}[], context?: {
|
|
489
|
-
api?: PluginLocalAPI;
|
|
490
|
-
}): PluginRoutes;
|
|
491
|
-
|
|
492
|
-
export { type RouteOptions as $, type AnyEndpointMiddleware as A, type TypedFormData as B, type MultipartSchema as C, DELETE as D, EndpointFailure as E, type FarmStreamResponse as F, GET as G, HEAD as H, type InferEndpointMiddlewareContext as I, type FarmAPIStream as J, multipart as K, isMultipartSchema as L, type MultipartField as M, toFormData as N, OPTIONS as O, type PluginRoutesFactory as P, QUERY as Q, jsonStream as R, isJSONStreamResponse as S, type TypedEndpoint as T, readJSONStream as U, isFarmAPIStream as V, type RouteMethod as W, type RoutePathParams as X, type RouteInputSchemas as Y, type RouteJSON as Z, type RouteDefinition as _, type EndpointOpenAPIMetadata as a, type RouteFactory as a0, type PluginRoutes as a1, type PluginLocalAPIEndpoint as a2, type PluginLocalAPI as a3, createRouteFactory as a4, type PluginAPIRouter as a5, resolvePluginRoutes as a6, type RouteSchema as a7, type RouteSchemaOutput as a8, type RouteSchemaInput as a9, type OpenAPISecurityMode as aa, type EndpointErrorSchema as b, type EndpointErrorDefinition as c, type EndpointErrorDefinitions as d, type EndpointErrorContracts as e, type EndpointErrorHandler as f, type EndpointFail as g, type EndpointParamValue as h, isEndpointFailure as i, type EndpointParams as j, type EndpointMiddlewareContext as k, type EndpointMiddlewareResult as l, type EndpointMiddleware as m, type EndpointInvalidationTarget as n, type EndpointInvalidationContext as o, parseRouteSchema as p, type EndpointInvalidations as q, type EndpointMCPMetadata as r, type EndpointMCPOptions as s, type EndpointOptions as t, type EndpointHandler as u, createEndpoint as v, POST as w, PUT as x, PATCH as y, type MultipartValues as z };
|
|
367
|
+
export { type AnyEndpointMiddleware as A, type MultipartValues as B, type TypedFormData as C, DELETE as D, type EndpointMiddlewareResult as E, type MultipartSchema as F, GET as G, HEAD as H, type InferEndpointMiddlewareContext as I, type FarmStreamResponse as J, type FarmAPIStream as K, multipart as L, type MultipartField as M, isMultipartSchema as N, OPTIONS as O, POST as P, QUERY as Q, type RouteSchema as R, toFormData as S, type TypedEndpoint as T, jsonStream as U, isJSONStreamResponse as V, readJSONStream as W, isFarmAPIStream as X, type OpenAPISecurityMode as Y, type RouteSchemaOutput as a, type EndpointMCPOptions as b, type RouteSchemaInput as c, type EndpointMCPMetadata as d, EndpointFailure as e, type EndpointOpenAPIMetadata as f, type EndpointErrorSchema as g, type EndpointErrorDefinition as h, isEndpointFailure as i, type EndpointErrorDefinitions as j, type EndpointErrorContracts as k, type EndpointErrorHandler as l, type EndpointFail as m, type EndpointParamValue as n, type EndpointParams as o, parseRouteSchema as p, type EndpointMiddlewareContext as q, type EndpointMiddleware as r, type EndpointInvalidationTarget as s, type EndpointInvalidationContext as t, type EndpointInvalidations as u, type EndpointOptions as v, type EndpointHandler as w, createEndpoint as x, PUT as y, PATCH as z };
|
package/dist/env.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/env.ts
|
|
22
22
|
var env_exports = {};
|
|
23
23
|
__export(env_exports, {
|
|
24
|
+
createBundledEnv: () => createBundledEnv,
|
|
24
25
|
env: () => env,
|
|
25
26
|
getEnv: () => getEnv,
|
|
26
27
|
getPublicEnv: () => getPublicEnv,
|
|
@@ -31,7 +32,23 @@ __export(env_exports, {
|
|
|
31
32
|
setEnv: () => setEnv
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(env_exports);
|
|
35
|
+
|
|
36
|
+
// src/utils/runtime-env.ts
|
|
37
|
+
function getFarmRuntimeBindings() {
|
|
38
|
+
const runtimeBindings = globalThis.__env__;
|
|
39
|
+
return runtimeBindings && typeof runtimeBindings === "object" ? runtimeBindings : void 0;
|
|
40
|
+
}
|
|
41
|
+
__name(getFarmRuntimeBindings, "getFarmRuntimeBindings");
|
|
42
|
+
function readFarmEnvironmentValue(name) {
|
|
43
|
+
const runtimeValue = getFarmRuntimeBindings()?.[name];
|
|
44
|
+
if (typeof runtimeValue === "string") return runtimeValue;
|
|
45
|
+
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
46
|
+
}
|
|
47
|
+
__name(readFarmEnvironmentValue, "readFarmEnvironmentValue");
|
|
48
|
+
|
|
49
|
+
// src/env.ts
|
|
34
50
|
var FARM_ENV_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env");
|
|
51
|
+
var FARM_ENV_RUNTIME_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env.runtime");
|
|
35
52
|
var farmEnvGlobal = globalThis;
|
|
36
53
|
var currentEnv = getInitialEnv();
|
|
37
54
|
function resolveEnv(config, source = getProcessEnv()) {
|
|
@@ -42,23 +59,45 @@ function resolveEnv(config, source = getProcessEnv()) {
|
|
|
42
59
|
return resolved;
|
|
43
60
|
}
|
|
44
61
|
__name(resolveEnv, "resolveEnv");
|
|
62
|
+
function createBundledEnv(env2, source = getProcessEnv()) {
|
|
63
|
+
const resolved = normalizeResolvedEnv(env2 ?? {});
|
|
64
|
+
const server = {};
|
|
65
|
+
const runtime = {};
|
|
66
|
+
for (const [key, value] of Object.entries(resolved.server)) {
|
|
67
|
+
const raw = source[key];
|
|
68
|
+
const type = getRuntimeEnvType(value);
|
|
69
|
+
if (raw !== void 0 && isSameEnvValue(coerceRuntimeEnvValue(raw, type), value)) {
|
|
70
|
+
runtime[key] = type;
|
|
71
|
+
} else {
|
|
72
|
+
server[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
server,
|
|
77
|
+
public: resolved.public,
|
|
78
|
+
...Object.keys(runtime).length > 0 ? { runtime: { server: runtime } } : {}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
__name(createBundledEnv, "createBundledEnv");
|
|
45
82
|
function setEnv(env2) {
|
|
46
|
-
currentEnv =
|
|
83
|
+
currentEnv = prepareEnv(env2);
|
|
47
84
|
if (typeof window === "undefined") {
|
|
48
85
|
farmEnvGlobal[FARM_ENV_SYMBOL] = currentEnv;
|
|
49
86
|
}
|
|
50
87
|
}
|
|
51
88
|
__name(setEnv, "setEnv");
|
|
52
89
|
function getResolvedEnv() {
|
|
53
|
-
|
|
90
|
+
const env2 = getCurrentEnv();
|
|
91
|
+
if (typeof window === "undefined") readRuntimeServerEnv(env2);
|
|
92
|
+
return env2;
|
|
54
93
|
}
|
|
55
94
|
__name(getResolvedEnv, "getResolvedEnv");
|
|
56
95
|
function getEnv(key) {
|
|
57
|
-
|
|
96
|
+
const server = getEnvScope("server");
|
|
58
97
|
if (key === void 0) {
|
|
59
|
-
return
|
|
98
|
+
return server;
|
|
60
99
|
}
|
|
61
|
-
return
|
|
100
|
+
return readServerEnvKey(server, key);
|
|
62
101
|
}
|
|
63
102
|
__name(getEnv, "getEnv");
|
|
64
103
|
function getPublicEnv(key) {
|
|
@@ -106,7 +145,7 @@ function createEnvProxy(scope) {
|
|
|
106
145
|
return void 0;
|
|
107
146
|
}
|
|
108
147
|
const env2 = getEnvScope(scope);
|
|
109
|
-
return env2[property];
|
|
148
|
+
return scope === "server" ? readServerEnvKey(env2, property) : env2[property];
|
|
110
149
|
},
|
|
111
150
|
ownKeys() {
|
|
112
151
|
return Reflect.ownKeys(getEnvScope(scope));
|
|
@@ -130,12 +169,99 @@ function createEnvProxy(scope) {
|
|
|
130
169
|
}
|
|
131
170
|
__name(createEnvProxy, "createEnvProxy");
|
|
132
171
|
function getEnvScope(scope) {
|
|
172
|
+
const env2 = getCurrentEnv();
|
|
133
173
|
if (scope === "server") {
|
|
134
174
|
assertServerEnvAccess();
|
|
175
|
+
readRuntimeServerEnv(env2);
|
|
135
176
|
}
|
|
136
|
-
return
|
|
177
|
+
return env2[scope] || {};
|
|
137
178
|
}
|
|
138
179
|
__name(getEnvScope, "getEnvScope");
|
|
180
|
+
function readServerEnvKey(server, key) {
|
|
181
|
+
const value = server[key];
|
|
182
|
+
if (value === void 0) {
|
|
183
|
+
const state = getCurrentEnv()[FARM_ENV_RUNTIME_SYMBOL];
|
|
184
|
+
if (state && key in state.pending && !state.warned.has(key)) {
|
|
185
|
+
state.warned.add(key);
|
|
186
|
+
console.warn(
|
|
187
|
+
`[Farm] Server env "${key}" was set when this app was built but is not set where the server runs, so it reads as undefined. Farm reads server env at runtime and does not store it in the build output; set "${key}" in the server's environment.`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
__name(readServerEnvKey, "readServerEnvKey");
|
|
194
|
+
function readRuntimeServerEnv(env2) {
|
|
195
|
+
const state = env2[FARM_ENV_RUNTIME_SYMBOL];
|
|
196
|
+
if (!state) return;
|
|
197
|
+
for (const [key, type] of Object.entries(state.pending)) {
|
|
198
|
+
const raw = readFarmEnvironmentValue(key);
|
|
199
|
+
if (raw === void 0) continue;
|
|
200
|
+
env2.server[key] = coerceRuntimeEnvValue(raw, type);
|
|
201
|
+
delete state.pending[key];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
__name(readRuntimeServerEnv, "readRuntimeServerEnv");
|
|
205
|
+
function getRuntimeEnvType(value) {
|
|
206
|
+
if (typeof value === "number") return "number";
|
|
207
|
+
if (typeof value === "boolean") return "boolean";
|
|
208
|
+
if (value !== null && typeof value === "object" && !(value instanceof Date)) return "json";
|
|
209
|
+
return "string";
|
|
210
|
+
}
|
|
211
|
+
__name(getRuntimeEnvType, "getRuntimeEnvType");
|
|
212
|
+
function coerceRuntimeEnvValue(raw, type) {
|
|
213
|
+
if (type === "number") {
|
|
214
|
+
const value = Number(raw);
|
|
215
|
+
return raw.trim() !== "" && Number.isFinite(value) ? value : raw;
|
|
216
|
+
}
|
|
217
|
+
if (type === "boolean") {
|
|
218
|
+
if (/^(true|1)$/i.test(raw.trim())) return true;
|
|
219
|
+
if (/^(false|0|)$/i.test(raw.trim())) return false;
|
|
220
|
+
return raw;
|
|
221
|
+
}
|
|
222
|
+
if (type === "json") {
|
|
223
|
+
try {
|
|
224
|
+
return JSON.parse(raw);
|
|
225
|
+
} catch {
|
|
226
|
+
return raw;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return raw;
|
|
230
|
+
}
|
|
231
|
+
__name(coerceRuntimeEnvValue, "coerceRuntimeEnvValue");
|
|
232
|
+
function isSameEnvValue(left, right) {
|
|
233
|
+
if (Object.is(left, right)) return true;
|
|
234
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
235
|
+
return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((item, index) => isSameEnvValue(item, right[index]));
|
|
236
|
+
}
|
|
237
|
+
if (!isPlainObject(left) || !isPlainObject(right)) return false;
|
|
238
|
+
const keys = Object.keys(left);
|
|
239
|
+
return keys.length === Object.keys(right).length && keys.every(
|
|
240
|
+
(key) => Object.prototype.hasOwnProperty.call(right, key) && isSameEnvValue(left[key], right[key])
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
__name(isSameEnvValue, "isSameEnvValue");
|
|
244
|
+
function isPlainObject(value) {
|
|
245
|
+
if (!value || typeof value !== "object") return false;
|
|
246
|
+
const prototype = Object.getPrototypeOf(value);
|
|
247
|
+
return prototype === Object.prototype || prototype === null;
|
|
248
|
+
}
|
|
249
|
+
__name(isPlainObject, "isPlainObject");
|
|
250
|
+
function prepareEnv(env2) {
|
|
251
|
+
const normalized = normalizeResolvedEnv(env2);
|
|
252
|
+
const runtime = env2.runtime?.server;
|
|
253
|
+
if (!isRecord(runtime) || Object.keys(runtime).length === 0) return normalized;
|
|
254
|
+
const prepared = { server: { ...normalized.server }, public: normalized.public };
|
|
255
|
+
Object.defineProperty(prepared, FARM_ENV_RUNTIME_SYMBOL, {
|
|
256
|
+
value: {
|
|
257
|
+
pending: { ...runtime },
|
|
258
|
+
warned: /* @__PURE__ */ new Set()
|
|
259
|
+
},
|
|
260
|
+
enumerable: false
|
|
261
|
+
});
|
|
262
|
+
return prepared;
|
|
263
|
+
}
|
|
264
|
+
__name(prepareEnv, "prepareEnv");
|
|
139
265
|
function assertServerEnvAccess() {
|
|
140
266
|
if (typeof window !== "undefined") {
|
|
141
267
|
throw new Error("Farm server env is not available in the browser. Use publicEnv.");
|
|
@@ -166,7 +292,7 @@ __name(getCurrentEnv, "getCurrentEnv");
|
|
|
166
292
|
function getInjectedEnv() {
|
|
167
293
|
try {
|
|
168
294
|
if (typeof __FARM_ENV__ !== "undefined" && __FARM_ENV__) {
|
|
169
|
-
return
|
|
295
|
+
return prepareEnv(__FARM_ENV__);
|
|
170
296
|
}
|
|
171
297
|
} catch {
|
|
172
298
|
}
|
|
@@ -203,6 +329,7 @@ function getProcessEnv() {
|
|
|
203
329
|
__name(getProcessEnv, "getProcessEnv");
|
|
204
330
|
// Annotate the CommonJS export names for ESM import in node:
|
|
205
331
|
0 && (module.exports = {
|
|
332
|
+
createBundledEnv,
|
|
206
333
|
env,
|
|
207
334
|
getEnv,
|
|
208
335
|
getPublicEnv,
|
package/dist/env.d.mts
CHANGED
|
@@ -31,8 +31,28 @@ type FarmPublicEnv = FarmEnvTypes extends {
|
|
|
31
31
|
public: infer TPublic;
|
|
32
32
|
} ? TPublic extends Record<string, any> ? TPublic : Record<string, unknown> : Record<string, unknown>;
|
|
33
33
|
type FarmTypedEnv = ResolvedFarmEnv<FarmServerEnv, FarmPublicEnv>;
|
|
34
|
+
type FarmEnvRuntimeType = "string" | "number" | "boolean" | "json";
|
|
35
|
+
/**
|
|
36
|
+
* The env a server bundle carries. `runtime.server` lists server keys that are
|
|
37
|
+
* read from the server's environment instead of being stored in the bundle,
|
|
38
|
+
* with the type their parsed value had at build time.
|
|
39
|
+
*/
|
|
40
|
+
interface BundledFarmEnv extends ResolvedFarmEnv {
|
|
41
|
+
runtime?: {
|
|
42
|
+
server: Record<string, FarmEnvRuntimeType>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
34
45
|
declare function resolveEnv<TConfig extends FarmEnvConfig<any, any> | undefined>(config: TConfig, source?: Record<string, string | undefined>): InferEnv<NonNullable<TConfig>>;
|
|
35
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Prepare resolved env for a server bundle. Server values that came from the
|
|
48
|
+
* build environment are left out and read from the server's environment when
|
|
49
|
+
* the server uses them, so secrets never land in build output and a restart
|
|
50
|
+
* picks up a rotated value. Values a parser produced without an env var
|
|
51
|
+
* (defaults) stay, and so do values the runtime cannot rebuild from the raw
|
|
52
|
+
* string, because the parser itself does not run in the server bundle.
|
|
53
|
+
*/
|
|
54
|
+
declare function createBundledEnv(env: ResolvedFarmEnv | FarmEnvConfig<any, any> | undefined, source?: Record<string, string | undefined>): BundledFarmEnv;
|
|
55
|
+
declare function setEnv(env: ResolvedFarmEnv | BundledFarmEnv): void;
|
|
36
56
|
declare function getResolvedEnv<TEnv extends ResolvedFarmEnv = FarmTypedEnv>(): TEnv;
|
|
37
57
|
declare function getEnv<TServer extends Record<string, any> = FarmServerEnv>(): TServer;
|
|
38
58
|
declare function getEnv<TKey extends Extract<keyof FarmServerEnv, string>>(key: TKey): FarmServerEnv[TKey];
|
|
@@ -42,4 +62,4 @@ declare const env: FarmServerEnv;
|
|
|
42
62
|
declare const serverEnv: Record<string, unknown>;
|
|
43
63
|
declare const publicEnv: FarmPublicEnv;
|
|
44
64
|
|
|
45
|
-
export { type EnvParser, type EnvSchema, type EnvShape, type FarmEnvConfig, type FarmEnvTypes, type FarmPublicEnv, type FarmServerEnv, type FarmTypedEnv, type InferEnv, type InferEnvParser, type InferEnvShape, type ResolvedFarmEnv, env, getEnv, getPublicEnv, getResolvedEnv, publicEnv, resolveEnv, serverEnv, setEnv };
|
|
65
|
+
export { type BundledFarmEnv, type EnvParser, type EnvSchema, type EnvShape, type FarmEnvConfig, type FarmEnvRuntimeType, type FarmEnvTypes, type FarmPublicEnv, type FarmServerEnv, type FarmTypedEnv, type InferEnv, type InferEnvParser, type InferEnvShape, type ResolvedFarmEnv, createBundledEnv, env, getEnv, getPublicEnv, getResolvedEnv, publicEnv, resolveEnv, serverEnv, setEnv };
|
package/dist/env.d.ts
CHANGED
|
@@ -31,8 +31,28 @@ type FarmPublicEnv = FarmEnvTypes extends {
|
|
|
31
31
|
public: infer TPublic;
|
|
32
32
|
} ? TPublic extends Record<string, any> ? TPublic : Record<string, unknown> : Record<string, unknown>;
|
|
33
33
|
type FarmTypedEnv = ResolvedFarmEnv<FarmServerEnv, FarmPublicEnv>;
|
|
34
|
+
type FarmEnvRuntimeType = "string" | "number" | "boolean" | "json";
|
|
35
|
+
/**
|
|
36
|
+
* The env a server bundle carries. `runtime.server` lists server keys that are
|
|
37
|
+
* read from the server's environment instead of being stored in the bundle,
|
|
38
|
+
* with the type their parsed value had at build time.
|
|
39
|
+
*/
|
|
40
|
+
interface BundledFarmEnv extends ResolvedFarmEnv {
|
|
41
|
+
runtime?: {
|
|
42
|
+
server: Record<string, FarmEnvRuntimeType>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
34
45
|
declare function resolveEnv<TConfig extends FarmEnvConfig<any, any> | undefined>(config: TConfig, source?: Record<string, string | undefined>): InferEnv<NonNullable<TConfig>>;
|
|
35
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Prepare resolved env for a server bundle. Server values that came from the
|
|
48
|
+
* build environment are left out and read from the server's environment when
|
|
49
|
+
* the server uses them, so secrets never land in build output and a restart
|
|
50
|
+
* picks up a rotated value. Values a parser produced without an env var
|
|
51
|
+
* (defaults) stay, and so do values the runtime cannot rebuild from the raw
|
|
52
|
+
* string, because the parser itself does not run in the server bundle.
|
|
53
|
+
*/
|
|
54
|
+
declare function createBundledEnv(env: ResolvedFarmEnv | FarmEnvConfig<any, any> | undefined, source?: Record<string, string | undefined>): BundledFarmEnv;
|
|
55
|
+
declare function setEnv(env: ResolvedFarmEnv | BundledFarmEnv): void;
|
|
36
56
|
declare function getResolvedEnv<TEnv extends ResolvedFarmEnv = FarmTypedEnv>(): TEnv;
|
|
37
57
|
declare function getEnv<TServer extends Record<string, any> = FarmServerEnv>(): TServer;
|
|
38
58
|
declare function getEnv<TKey extends Extract<keyof FarmServerEnv, string>>(key: TKey): FarmServerEnv[TKey];
|
|
@@ -42,4 +62,4 @@ declare const env: FarmServerEnv;
|
|
|
42
62
|
declare const serverEnv: Record<string, unknown>;
|
|
43
63
|
declare const publicEnv: FarmPublicEnv;
|
|
44
64
|
|
|
45
|
-
export { type EnvParser, type EnvSchema, type EnvShape, type FarmEnvConfig, type FarmEnvTypes, type FarmPublicEnv, type FarmServerEnv, type FarmTypedEnv, type InferEnv, type InferEnvParser, type InferEnvShape, type ResolvedFarmEnv, env, getEnv, getPublicEnv, getResolvedEnv, publicEnv, resolveEnv, serverEnv, setEnv };
|
|
65
|
+
export { type BundledFarmEnv, type EnvParser, type EnvSchema, type EnvShape, type FarmEnvConfig, type FarmEnvRuntimeType, type FarmEnvTypes, type FarmPublicEnv, type FarmServerEnv, type FarmTypedEnv, type InferEnv, type InferEnvParser, type InferEnvShape, type ResolvedFarmEnv, createBundledEnv, env, getEnv, getPublicEnv, getResolvedEnv, publicEnv, resolveEnv, serverEnv, setEnv };
|
package/dist/env.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createBundledEnv,
|
|
2
3
|
env,
|
|
3
4
|
getEnv,
|
|
4
5
|
getPublicEnv,
|
|
@@ -7,9 +8,11 @@ import {
|
|
|
7
8
|
resolveEnv,
|
|
8
9
|
serverEnv,
|
|
9
10
|
setEnv
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-4OOBRCJX.mjs";
|
|
12
|
+
import "./chunk-ONUEYC6N.mjs";
|
|
11
13
|
import "./chunk-LPEX4YW6.mjs";
|
|
12
14
|
export {
|
|
15
|
+
createBundledEnv,
|
|
13
16
|
env,
|
|
14
17
|
getEnv,
|
|
15
18
|
getPublicEnv,
|