astro 4.14.4 → 4.14.5

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.
@@ -4,7 +4,8 @@ import type { MarkdownHeading, MarkdownVFile, RehypePlugins, RemarkPlugins, Rema
4
4
  import type * as babel from '@babel/core';
5
5
  import type * as rollup from 'rollup';
6
6
  import type * as vite from 'vite';
7
- import type { ActionAccept, ActionClient, ActionInputSchema, ActionReturnType } from '../actions/runtime/virtual/server.js';
7
+ import type { z } from 'zod';
8
+ import type { ActionAccept, ActionClient, ActionReturnType } from '../actions/runtime/virtual/server.js';
8
9
  import type { RemotePattern } from '../assets/utils/remotePattern.js';
9
10
  import type { DataEntry, RenderedContent } from '../content/data-store.js';
10
11
  import type { AssetsPrefix, SSRManifest, SerializedSSRManifest } from '../core/app/types.js';
@@ -2757,11 +2758,11 @@ interface AstroSharedContext<Props extends Record<string, any> = Record<string,
2757
2758
  /**
2758
2759
  * Get action result on the server when using a form POST.
2759
2760
  */
2760
- getActionResult: <TAccept extends ActionAccept, TInputSchema extends ActionInputSchema<TAccept>, TAction extends ActionClient<unknown, TAccept, TInputSchema>>(action: TAction) => ActionReturnType<TAction> | undefined;
2761
+ getActionResult: <TAccept extends ActionAccept, TInputSchema extends z.ZodType, TAction extends ActionClient<unknown, TAccept, TInputSchema>>(action: TAction) => ActionReturnType<TAction> | undefined;
2761
2762
  /**
2762
2763
  * Call action handler from the server.
2763
2764
  */
2764
- callAction: <TAccept extends ActionAccept, TInputSchema extends ActionInputSchema<TAccept>, TOutput, TAction extends ActionClient<TOutput, TAccept, TInputSchema> | ActionClient<TOutput, TAccept, TInputSchema>['orThrow']>(action: TAction, input: Parameters<TAction>[0]) => Promise<ActionReturnType<TAction>>;
2765
+ callAction: <TAccept extends ActionAccept, TInputSchema extends z.ZodType, TOutput, TAction extends ActionClient<TOutput, TAccept, TInputSchema> | ActionClient<TOutput, TAccept, TInputSchema>['orThrow']>(action: TAction, input: Parameters<TAction>[0]) => Promise<ActionReturnType<TAction>>;
2765
2766
  /**
2766
2767
  * Route parameters for this request if this is a dynamic route.
2767
2768
  */
@@ -4,16 +4,15 @@ import { type SafeResult } from './shared.js';
4
4
  export * from './shared.js';
5
5
  export { z } from 'zod';
6
6
  export type ActionAccept = 'form' | 'json';
7
- export type ActionInputSchema<T extends ActionAccept | undefined> = T extends 'form' ? z.AnyZodObject | z.ZodType<FormData> : z.ZodType;
8
7
  export type ActionHandler<TInputSchema, TOutput> = TInputSchema extends z.ZodType ? (input: z.infer<TInputSchema>, context: ActionAPIContext) => MaybePromise<TOutput> : (input: any, context: ActionAPIContext) => MaybePromise<TOutput>;
9
8
  export type ActionReturnType<T extends ActionHandler<any, any>> = Awaited<ReturnType<T>>;
10
- export type ActionClient<TOutput, TAccept extends ActionAccept | undefined, TInputSchema extends ActionInputSchema<TAccept> | undefined> = TInputSchema extends z.ZodType ? ((input: TAccept extends 'form' ? FormData : z.input<TInputSchema>) => Promise<SafeResult<z.input<TInputSchema> extends ErrorInferenceObject ? z.input<TInputSchema> : ErrorInferenceObject, Awaited<TOutput>>>) & {
9
+ export type ActionClient<TOutput, TAccept extends ActionAccept | undefined, TInputSchema extends z.ZodType | undefined> = TInputSchema extends z.ZodType ? ((input: TAccept extends 'form' ? FormData : z.input<TInputSchema>) => Promise<SafeResult<z.input<TInputSchema> extends ErrorInferenceObject ? z.input<TInputSchema> : ErrorInferenceObject, Awaited<TOutput>>>) & {
11
10
  queryString: string;
12
11
  orThrow: (input: TAccept extends 'form' ? FormData : z.input<TInputSchema>) => Promise<Awaited<TOutput>>;
13
12
  } : ((input?: any) => Promise<SafeResult<never, Awaited<TOutput>>>) & {
14
13
  orThrow: (input?: any) => Promise<Awaited<TOutput>>;
15
14
  };
16
- export declare function defineAction<TOutput, TAccept extends ActionAccept | undefined = undefined, TInputSchema extends ActionInputSchema<ActionAccept> | undefined = TAccept extends 'form' ? z.ZodType<FormData> : undefined>({ accept, input: inputSchema, handler, }: {
15
+ export declare function defineAction<TOutput, TAccept extends ActionAccept | undefined = undefined, TInputSchema extends z.ZodType | undefined = TAccept extends 'form' ? z.ZodType<FormData> : undefined>({ accept, input: inputSchema, handler, }: {
17
16
  input?: TInputSchema;
18
17
  accept?: TAccept;
19
18
  handler: ActionHandler<TInputSchema, TOutput>;
@@ -34,8 +34,11 @@ function getFormServerHandler(handler, inputSchema) {
34
34
  message: "This action only accepts FormData."
35
35
  });
36
36
  }
37
- if (!(inputSchema instanceof z.ZodObject)) return await handler(unparsedInput, context);
38
- const parsed = await inputSchema.safeParseAsync(formDataToObject(unparsedInput, inputSchema));
37
+ if (!inputSchema) return await handler(unparsedInput, context);
38
+ const baseSchema = unwrapSchemaEffects(inputSchema);
39
+ const parsed = await inputSchema.safeParseAsync(
40
+ baseSchema instanceof z.ZodObject ? formDataToObject(unparsedInput, baseSchema) : unparsedInput
41
+ );
39
42
  if (!parsed.success) {
40
43
  throw new ActionInputError(parsed.error.issues);
41
44
  }
@@ -59,7 +62,7 @@ function getJsonServerHandler(handler, inputSchema) {
59
62
  };
60
63
  }
61
64
  function formDataToObject(formData, schema) {
62
- const obj = {};
65
+ const obj = schema._def.unknownKeys === "passthrough" ? Object.fromEntries(formData.entries()) : {};
63
66
  for (const [key, baseValidator] of Object.entries(schema.shape)) {
64
67
  let validator = baseValidator;
65
68
  while (validator instanceof z.ZodOptional || validator instanceof z.ZodNullable || validator instanceof z.ZodDefault) {
@@ -98,6 +101,17 @@ function handleFormDataGet(key, formData, validator, baseValidator) {
98
101
  }
99
102
  return validator instanceof z.ZodNumber ? Number(value) : value;
100
103
  }
104
+ function unwrapSchemaEffects(schema) {
105
+ while (schema instanceof z.ZodEffects || schema instanceof z.ZodPipeline) {
106
+ if (schema instanceof z.ZodEffects) {
107
+ schema = schema._def.schema;
108
+ }
109
+ if (schema instanceof z.ZodPipeline) {
110
+ schema = schema._def.in;
111
+ }
112
+ }
113
+ return schema;
114
+ }
101
115
  export {
102
116
  defineAction,
103
117
  formDataToObject,
@@ -1,5 +1,6 @@
1
1
  import type { z } from 'zod';
2
- import type { ErrorInferenceObject, MaybePromise } from '../utils.js';
2
+ import type { ErrorInferenceObject, MaybePromise, ActionAPIContext as _ActionAPIContext } from '../utils.js';
3
+ export type ActionAPIContext = _ActionAPIContext;
3
4
  export declare const ACTION_QUERY_PARAMS: {
4
5
  actionName: string;
5
6
  actionPayload: string;
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.14.4";
1
+ const ASTRO_VERSION = "4.14.5";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
4
4
  const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
23
23
  await telemetry.record([]);
24
24
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
25
25
  const logger = restart.container.logger;
26
- const currentVersion = "4.14.4";
26
+ const currentVersion = "4.14.5";
27
27
  const isPrerelease = currentVersion.includes("-");
28
28
  if (!isPrerelease) {
29
29
  try {
@@ -38,7 +38,7 @@ function serverStart({
38
38
  host,
39
39
  base
40
40
  }) {
41
- const version = "4.14.4";
41
+ const version = "4.14.5";
42
42
  const localPrefix = `${dim("\u2503")} Local `;
43
43
  const networkPrefix = `${dim("\u2503")} Network `;
44
44
  const emptyPrefix = " ".repeat(11);
@@ -270,7 +270,7 @@ function printHelp({
270
270
  message.push(
271
271
  linebreak(),
272
272
  ` ${bgGreen(black(` ${commandName} `))} ${green(
273
- `v${"4.14.4"}`
273
+ `v${"4.14.5"}`
274
274
  )} ${headline}`
275
275
  );
276
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.14.4",
3
+ "version": "4.14.5",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -172,8 +172,8 @@
172
172
  "zod": "^3.23.8",
173
173
  "zod-to-json-schema": "^3.23.2",
174
174
  "zod-to-ts": "^1.2.0",
175
- "@astrojs/markdown-remark": "5.2.0",
176
175
  "@astrojs/internal-helpers": "0.4.1",
176
+ "@astrojs/markdown-remark": "5.2.0",
177
177
  "@astrojs/telemetry": "3.1.0"
178
178
  },
179
179
  "optionalDependencies": {
@@ -93,7 +93,9 @@ async function handleAction(param, path, context) {
93
93
  body,
94
94
  headers,
95
95
  });
96
- if (rawResult.status === 204) return;
96
+ if (rawResult.status === 204) {
97
+ return deserializeActionResult({ type: 'empty', status: 204 });
98
+ }
97
99
 
98
100
  return deserializeActionResult({
99
101
  type: rawResult.ok ? 'data' : 'error',