astro 4.7.0 → 4.8.0
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/client.d.ts +1 -0
- package/content-module.template.mjs +2 -0
- package/dist/@types/astro.d.ts +220 -4
- package/dist/actions/consts.d.ts +3 -0
- package/dist/actions/consts.js +8 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +72 -0
- package/dist/actions/runtime/middleware.d.ts +7 -0
- package/dist/actions/runtime/middleware.js +38 -0
- package/dist/actions/runtime/route.d.ts +2 -0
- package/dist/actions/runtime/route.js +37 -0
- package/dist/actions/runtime/store.d.ts +6 -0
- package/dist/actions/runtime/store.js +18 -0
- package/dist/actions/runtime/utils.d.ts +4 -0
- package/dist/actions/runtime/utils.js +23 -0
- package/dist/actions/runtime/virtual/client.d.ts +4 -0
- package/dist/actions/runtime/virtual/client.js +20 -0
- package/dist/actions/runtime/virtual/server.d.ts +21 -0
- package/dist/actions/runtime/virtual/server.js +98 -0
- package/dist/actions/runtime/virtual/shared.d.ts +37 -0
- package/dist/actions/runtime/virtual/shared.js +104 -0
- package/dist/actions/utils.d.ts +2 -0
- package/dist/actions/utils.js +18 -0
- package/dist/assets/build/generate.js +1 -1
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/service.js +2 -4
- package/dist/assets/services/sharp.js +2 -4
- package/dist/assets/services/squoosh.js +2 -4
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
- package/dist/assets/utils/getAssetsPrefix.js +2 -4
- package/dist/assets/utils/remotePattern.js +1 -2
- package/dist/assets/utils/remoteProbe.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
- package/dist/assets/vite-plugin-assets.js +1 -1
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/imports.js +4 -8
- package/dist/cli/add/index.js +23 -46
- package/dist/cli/add/wrapper.js +1 -2
- package/dist/cli/index.js +1 -2
- package/dist/cli/info/index.js +1 -2
- package/dist/cli/install-package.js +3 -6
- package/dist/cli/throw-and-exit.js +1 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +3 -3
- package/dist/content/index.d.ts +1 -2
- package/dist/content/index.js +1 -9
- package/dist/content/runtime.d.ts +2 -1
- package/dist/content/runtime.js +11 -20
- package/dist/content/server-listeners.js +5 -10
- package/dist/content/types-generator.js +5 -10
- package/dist/content/utils.d.ts +0 -4
- package/dist/content/utils.js +5 -18
- package/dist/content/vite-plugin-content-assets.d.ts +1 -1
- package/dist/content/vite-plugin-content-assets.js +14 -47
- package/dist/content/vite-plugin-content-imports.js +6 -11
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
- package/dist/core/app/index.js +11 -46
- package/dist/core/app/node.js +4 -3
- package/dist/core/app/pipeline.d.ts +7 -2
- package/dist/core/app/pipeline.js +70 -2
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/base-pipeline.d.ts +16 -1
- package/dist/core/build/generate.js +16 -62
- package/dist/core/build/index.js +3 -5
- package/dist/core/build/internal.d.ts +39 -9
- package/dist/core/build/internal.js +43 -54
- package/dist/core/build/page-data.js +6 -6
- package/dist/core/build/pipeline.d.ts +7 -3
- package/dist/core/build/pipeline.js +134 -23
- package/dist/core/build/plugins/plugin-analyzer.js +11 -32
- package/dist/core/build/plugins/plugin-content.d.ts +1 -0
- package/dist/core/build/plugins/plugin-content.js +34 -32
- package/dist/core/build/plugins/plugin-css.js +23 -51
- package/dist/core/build/plugins/plugin-manifest.js +8 -9
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
- package/dist/core/build/plugins/plugin-pages.js +10 -12
- package/dist/core/build/plugins/plugin-ssr.js +16 -14
- package/dist/core/build/plugins/util.d.ts +26 -11
- package/dist/core/build/plugins/util.js +22 -6
- package/dist/core/build/static-build.js +31 -26
- package/dist/core/build/types.d.ts +6 -6
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/compile/compile.js +1 -1
- package/dist/core/config/config.js +2 -7
- package/dist/core/config/logging.js +1 -2
- package/dist/core/config/schema.d.ts +92 -60
- package/dist/core/config/schema.js +6 -2
- package/dist/core/config/settings.js +1 -2
- package/dist/core/config/timer.js +4 -8
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +3 -6
- package/dist/core/dev/container.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -2
- package/dist/core/errors/errors-data.d.ts +25 -1
- package/dist/core/errors/errors-data.js +15 -4
- package/dist/core/errors/errors.js +1 -2
- package/dist/core/errors/index.d.ts +1 -0
- package/dist/core/errors/index.js +2 -0
- package/dist/core/errors/overlay.js +3 -4
- package/dist/core/errors/printer.js +2 -4
- package/dist/{content/error-map.js → core/errors/zod-error-map.js} +2 -4
- package/dist/core/fs/index.js +2 -4
- package/dist/core/logger/vite.js +9 -18
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +3 -2
- package/dist/core/middleware/callMiddleware.js +13 -3
- package/dist/core/middleware/index.js +12 -8
- package/dist/core/middleware/sequence.js +22 -4
- package/dist/core/module-loader/vite.js +1 -2
- package/dist/core/preview/index.js +1 -1
- package/dist/core/render/params-and-props.js +2 -4
- package/dist/core/render/slots.js +4 -8
- package/dist/core/render-context.d.ts +15 -5
- package/dist/core/render-context.js +134 -28
- package/dist/core/request.js +1 -2
- package/dist/core/routing/manifest/create.js +3 -6
- package/dist/core/routing/priority.d.ts +1 -1
- package/dist/core/sync/index.js +11 -4
- package/dist/core/util.d.ts +2 -0
- package/dist/core/util.js +18 -19
- package/dist/i18n/index.js +2 -4
- package/dist/i18n/middleware.js +1 -2
- package/dist/i18n/utils.js +1 -2
- package/dist/i18n/vite-plugin-i18n.js +1 -2
- package/dist/integrations/{index.js → hooks.js} +6 -2
- package/dist/jsx/babel.d.ts +3 -0
- package/dist/jsx/babel.js +9 -18
- package/dist/jsx/rehype.d.ts +11 -0
- package/dist/jsx/rehype.js +197 -0
- package/dist/jsx/server.js +20 -14
- package/dist/jsx/transform-options.d.ts +3 -0
- package/dist/jsx-runtime/index.js +8 -16
- package/dist/preferences/index.js +3 -6
- package/dist/preferences/store.js +3 -6
- package/dist/prefetch/index.js +8 -16
- package/dist/prefetch/vite-plugin-prefetch.js +2 -4
- package/dist/prerender/metadata.js +1 -2
- package/dist/prerender/routing.js +1 -1
- package/dist/prerender/utils.d.ts +1 -2
- package/dist/prerender/utils.js +2 -5
- package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
- package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
- package/dist/runtime/client/dev-toolbar/helpers.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/helpers.js +3 -5
- package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
- package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
- package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
- package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
- package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
- package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
- package/dist/runtime/client/visible.js +1 -2
- package/dist/runtime/server/astro-component.js +2 -4
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/runtime/server/astro-island.js +7 -14
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/index.js +3 -6
- package/dist/runtime/server/jsx.js +1 -2
- package/dist/runtime/server/render/any.js +1 -2
- package/dist/runtime/server/render/astro/instance.js +11 -12
- package/dist/runtime/server/render/astro/render.js +5 -10
- package/dist/runtime/server/render/component.js +6 -11
- package/dist/runtime/server/render/dom.js +1 -2
- package/dist/runtime/server/render/page.js +1 -2
- package/dist/runtime/server/render/script.js +1 -2
- package/dist/runtime/server/render/slot.js +1 -2
- package/dist/runtime/server/render/tags.js +2 -4
- package/dist/runtime/server/render/util.js +5 -5
- package/dist/runtime/server/shorthash.js +1 -2
- package/dist/runtime/server/transition.js +4 -8
- package/dist/runtime/server/util.js +1 -2
- package/dist/transitions/events.d.ts +6 -5
- package/dist/transitions/events.js +17 -10
- package/dist/transitions/router.js +100 -132
- package/dist/transitions/swap-functions.d.ts +12 -0
- package/dist/transitions/swap-functions.js +105 -0
- package/dist/vite-plugin-astro/compile.js +1 -2
- package/dist/vite-plugin-astro/hmr.js +5 -10
- package/dist/vite-plugin-astro/index.js +2 -4
- package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
- package/dist/vite-plugin-astro-server/pipeline.js +59 -11
- package/dist/vite-plugin-astro-server/plugin.js +6 -6
- package/dist/vite-plugin-astro-server/response.js +1 -2
- package/dist/vite-plugin-astro-server/route.js +36 -42
- package/dist/vite-plugin-astro-server/vite.js +5 -7
- package/dist/vite-plugin-config-alias/index.js +7 -14
- package/dist/vite-plugin-head/index.js +3 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/escape.js +2 -4
- package/dist/vite-plugin-html/transform/slots.js +1 -2
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-inject-env-ts/index.js +37 -11
- package/dist/vite-plugin-integrations-container/index.js +4 -7
- package/dist/vite-plugin-load-fallback/index.js +1 -2
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-mdx/index.d.ts +3 -0
- package/dist/vite-plugin-mdx/tag.d.ts +2 -0
- package/dist/vite-plugin-mdx/tag.js +3 -6
- package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
- package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
- package/dist/vite-plugin-scanner/index.js +4 -6
- package/dist/vite-plugin-scanner/scan.js +2 -4
- package/dist/vite-plugin-scripts/page-ssr.js +3 -6
- package/package.json +26 -22
- package/templates/actions.mjs +61 -0
- package/types/actions.d.ts +3 -0
- package/types/content.d.ts +2 -2
- /package/dist/{content/error-map.d.ts → core/errors/zod-error-map.d.ts} +0 -0
- /package/dist/integrations/{astroFeaturesValidation.d.ts → features-validation.d.ts} +0 -0
- /package/dist/integrations/{astroFeaturesValidation.js → features-validation.js} +0 -0
- /package/dist/integrations/{index.d.ts → hooks.d.ts} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getApiContext } from "../store.js";
|
|
3
|
+
import { hasContentType } from "../utils.js";
|
|
4
|
+
import {
|
|
5
|
+
ActionError,
|
|
6
|
+
ActionInputError,
|
|
7
|
+
callSafely
|
|
8
|
+
} from "./shared.js";
|
|
9
|
+
export * from "./shared.js";
|
|
10
|
+
import { z as z2 } from "zod";
|
|
11
|
+
import { getApiContext as getApiContext2 } from "../store.js";
|
|
12
|
+
function defineAction({
|
|
13
|
+
accept,
|
|
14
|
+
input: inputSchema,
|
|
15
|
+
handler
|
|
16
|
+
}) {
|
|
17
|
+
const serverHandler = accept === "form" ? getFormServerHandler(handler, inputSchema) : getJsonServerHandler(handler, inputSchema);
|
|
18
|
+
Object.assign(serverHandler, {
|
|
19
|
+
safe: async (unparsedInput) => {
|
|
20
|
+
return callSafely(() => serverHandler(unparsedInput));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return serverHandler;
|
|
24
|
+
}
|
|
25
|
+
function getFormServerHandler(handler, inputSchema) {
|
|
26
|
+
return async (unparsedInput) => {
|
|
27
|
+
if (!(unparsedInput instanceof FormData)) {
|
|
28
|
+
throw new ActionError({
|
|
29
|
+
code: "UNSUPPORTED_MEDIA_TYPE",
|
|
30
|
+
message: "This action only accepts FormData."
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (!(inputSchema instanceof z.ZodObject)) return await handler(unparsedInput);
|
|
34
|
+
const parsed = await inputSchema.safeParseAsync(formDataToObject(unparsedInput, inputSchema));
|
|
35
|
+
if (!parsed.success) {
|
|
36
|
+
throw new ActionInputError(parsed.error.issues);
|
|
37
|
+
}
|
|
38
|
+
return await handler(parsed.data);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function getJsonServerHandler(handler, inputSchema) {
|
|
42
|
+
return async (unparsedInput) => {
|
|
43
|
+
const context = getApiContext();
|
|
44
|
+
const contentType = context.request.headers.get("content-type");
|
|
45
|
+
if (!contentType || !hasContentType(contentType, ["application/json"])) {
|
|
46
|
+
throw new ActionError({
|
|
47
|
+
code: "UNSUPPORTED_MEDIA_TYPE",
|
|
48
|
+
message: "This action only accepts JSON."
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (!inputSchema) return await handler(unparsedInput);
|
|
52
|
+
const parsed = await inputSchema.safeParseAsync(unparsedInput);
|
|
53
|
+
if (!parsed.success) {
|
|
54
|
+
throw new ActionInputError(parsed.error.issues);
|
|
55
|
+
}
|
|
56
|
+
return await handler(parsed.data);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function formDataToObject(formData, schema) {
|
|
60
|
+
const obj = {};
|
|
61
|
+
for (const [key, baseValidator] of Object.entries(schema.shape)) {
|
|
62
|
+
let validator = baseValidator;
|
|
63
|
+
if (baseValidator instanceof z.ZodOptional || baseValidator instanceof z.ZodNullable) {
|
|
64
|
+
validator = baseValidator._def.innerType;
|
|
65
|
+
}
|
|
66
|
+
if (validator instanceof z.ZodBoolean) {
|
|
67
|
+
obj[key] = formData.has(key);
|
|
68
|
+
} else if (validator instanceof z.ZodArray) {
|
|
69
|
+
obj[key] = handleFormDataGetAll(key, formData, validator);
|
|
70
|
+
} else {
|
|
71
|
+
obj[key] = handleFormDataGet(key, formData, validator, baseValidator);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
function handleFormDataGetAll(key, formData, validator) {
|
|
77
|
+
const entries = Array.from(formData.getAll(key));
|
|
78
|
+
const elementValidator = validator._def.type;
|
|
79
|
+
if (elementValidator instanceof z.ZodNumber) {
|
|
80
|
+
return entries.map(Number);
|
|
81
|
+
} else if (elementValidator instanceof z.ZodBoolean) {
|
|
82
|
+
return entries.map(Boolean);
|
|
83
|
+
}
|
|
84
|
+
return entries;
|
|
85
|
+
}
|
|
86
|
+
function handleFormDataGet(key, formData, validator, baseValidator) {
|
|
87
|
+
const value = formData.get(key);
|
|
88
|
+
if (!value) {
|
|
89
|
+
return baseValidator instanceof z.ZodOptional ? void 0 : null;
|
|
90
|
+
}
|
|
91
|
+
return validator instanceof z.ZodNumber ? Number(value) : value;
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
defineAction,
|
|
95
|
+
formDataToObject,
|
|
96
|
+
getApiContext2 as getApiContext,
|
|
97
|
+
z2 as z
|
|
98
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { MaybePromise } from '../utils.js';
|
|
3
|
+
type ActionErrorCode = 'BAD_REQUEST' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'TIMEOUT' | 'CONFLICT' | 'PRECONDITION_FAILED' | 'PAYLOAD_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'UNPROCESSABLE_CONTENT' | 'TOO_MANY_REQUESTS' | 'CLIENT_CLOSED_REQUEST' | 'INTERNAL_SERVER_ERROR';
|
|
4
|
+
export type ErrorInferenceObject = Record<string, any>;
|
|
5
|
+
export declare class ActionError<T extends ErrorInferenceObject = ErrorInferenceObject> extends Error {
|
|
6
|
+
type: string;
|
|
7
|
+
code: ActionErrorCode;
|
|
8
|
+
status: number;
|
|
9
|
+
constructor(params: {
|
|
10
|
+
message?: string;
|
|
11
|
+
code: ActionErrorCode;
|
|
12
|
+
});
|
|
13
|
+
static codeToStatus(code: ActionErrorCode): number;
|
|
14
|
+
static statusToCode(status: number): ActionErrorCode;
|
|
15
|
+
static fromResponse(res: Response): Promise<ActionError<ErrorInferenceObject>>;
|
|
16
|
+
}
|
|
17
|
+
export declare function isInputError<T extends ErrorInferenceObject>(error?: ActionError<T>): error is ActionInputError<T>;
|
|
18
|
+
export type SafeResult<TInput extends ErrorInferenceObject, TOutput> = {
|
|
19
|
+
data: TOutput;
|
|
20
|
+
error: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
data: undefined;
|
|
23
|
+
error: ActionError<TInput>;
|
|
24
|
+
};
|
|
25
|
+
export declare class ActionInputError<T extends ErrorInferenceObject> extends ActionError {
|
|
26
|
+
type: string;
|
|
27
|
+
issues: z.ZodIssue[];
|
|
28
|
+
fields: z.ZodError<T>['formErrors']['fieldErrors'];
|
|
29
|
+
constructor(issues: z.ZodIssue[]);
|
|
30
|
+
}
|
|
31
|
+
export declare function callSafely<TOutput>(handler: () => MaybePromise<TOutput>): Promise<SafeResult<z.ZodType, TOutput>>;
|
|
32
|
+
export declare function getActionProps<T extends (args: FormData) => MaybePromise<unknown>>(action: T): {
|
|
33
|
+
readonly type: "hidden";
|
|
34
|
+
readonly name: "_astroAction";
|
|
35
|
+
readonly value: string;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const codeToStatusMap = {
|
|
2
|
+
// Implemented from tRPC error code table
|
|
3
|
+
// https://trpc.io/docs/server/error-handling#error-codes
|
|
4
|
+
BAD_REQUEST: 400,
|
|
5
|
+
UNAUTHORIZED: 401,
|
|
6
|
+
FORBIDDEN: 403,
|
|
7
|
+
NOT_FOUND: 404,
|
|
8
|
+
TIMEOUT: 405,
|
|
9
|
+
CONFLICT: 409,
|
|
10
|
+
PRECONDITION_FAILED: 412,
|
|
11
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
12
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
13
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
14
|
+
TOO_MANY_REQUESTS: 429,
|
|
15
|
+
CLIENT_CLOSED_REQUEST: 499,
|
|
16
|
+
INTERNAL_SERVER_ERROR: 500
|
|
17
|
+
};
|
|
18
|
+
const statusToCodeMap = Object.entries(codeToStatusMap).reduce(
|
|
19
|
+
// reverse the key-value pairs
|
|
20
|
+
(acc, [key, value]) => ({ ...acc, [value]: key }),
|
|
21
|
+
{}
|
|
22
|
+
);
|
|
23
|
+
class ActionError extends Error {
|
|
24
|
+
type = "AstroActionError";
|
|
25
|
+
code = "INTERNAL_SERVER_ERROR";
|
|
26
|
+
status = 500;
|
|
27
|
+
constructor(params) {
|
|
28
|
+
super(params.message);
|
|
29
|
+
this.code = params.code;
|
|
30
|
+
this.status = ActionError.codeToStatus(params.code);
|
|
31
|
+
}
|
|
32
|
+
static codeToStatus(code) {
|
|
33
|
+
return codeToStatusMap[code];
|
|
34
|
+
}
|
|
35
|
+
static statusToCode(status) {
|
|
36
|
+
return statusToCodeMap[status] ?? "INTERNAL_SERVER_ERROR";
|
|
37
|
+
}
|
|
38
|
+
static async fromResponse(res) {
|
|
39
|
+
if (res.status === 400 && res.headers.get("Content-Type")?.toLowerCase().startsWith("application/json")) {
|
|
40
|
+
const body = await res.json();
|
|
41
|
+
if (typeof body === "object" && body?.type === "AstroActionInputError" && Array.isArray(body.issues)) {
|
|
42
|
+
return new ActionInputError(body.issues);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return new ActionError({
|
|
46
|
+
message: res.statusText,
|
|
47
|
+
code: this.statusToCode(res.status)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function isInputError(error) {
|
|
52
|
+
return error instanceof ActionInputError;
|
|
53
|
+
}
|
|
54
|
+
class ActionInputError extends ActionError {
|
|
55
|
+
type = "AstroActionInputError";
|
|
56
|
+
// We don't expose all ZodError properties.
|
|
57
|
+
// Not all properties will serialize from server to client,
|
|
58
|
+
// and we don't want to import the full ZodError object into the client.
|
|
59
|
+
issues;
|
|
60
|
+
fields;
|
|
61
|
+
constructor(issues) {
|
|
62
|
+
super({ message: "Failed to validate", code: "BAD_REQUEST" });
|
|
63
|
+
this.issues = issues;
|
|
64
|
+
this.fields = {};
|
|
65
|
+
for (const issue of issues) {
|
|
66
|
+
if (issue.path.length > 0) {
|
|
67
|
+
const key = issue.path[0].toString();
|
|
68
|
+
this.fields[key] ??= [];
|
|
69
|
+
this.fields[key]?.push(issue.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function callSafely(handler) {
|
|
75
|
+
try {
|
|
76
|
+
const data = await handler();
|
|
77
|
+
return { data, error: void 0 };
|
|
78
|
+
} catch (e) {
|
|
79
|
+
if (e instanceof ActionError) {
|
|
80
|
+
return { data: void 0, error: e };
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
data: void 0,
|
|
84
|
+
error: new ActionError({
|
|
85
|
+
message: e instanceof Error ? e.message : "Unknown error",
|
|
86
|
+
code: "INTERNAL_SERVER_ERROR"
|
|
87
|
+
})
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function getActionProps(action) {
|
|
92
|
+
return {
|
|
93
|
+
type: "hidden",
|
|
94
|
+
name: "_astroAction",
|
|
95
|
+
value: action.toString()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
ActionError,
|
|
100
|
+
ActionInputError,
|
|
101
|
+
callSafely,
|
|
102
|
+
getActionProps,
|
|
103
|
+
isInputError
|
|
104
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AstroError } from "../core/errors/errors.js";
|
|
2
|
+
function hasActionsInternal(locals) {
|
|
3
|
+
return "_actionsInternal" in locals;
|
|
4
|
+
}
|
|
5
|
+
function createGetActionResult(locals) {
|
|
6
|
+
return (actionFn) => {
|
|
7
|
+
if (!hasActionsInternal(locals))
|
|
8
|
+
throw new AstroError({
|
|
9
|
+
name: "AstroActionError",
|
|
10
|
+
message: "Experimental actions are not enabled in your project.",
|
|
11
|
+
hint: "See https://docs.astro.build/en/reference/configuration-reference/#experimental-flags"
|
|
12
|
+
});
|
|
13
|
+
return locals._actionsInternal.getActionResult(actionFn);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
createGetActionResult
|
|
18
|
+
};
|
|
@@ -6,7 +6,7 @@ import { getTimeStat } from "../../core/build/util.js";
|
|
|
6
6
|
import { AstroError } from "../../core/errors/errors.js";
|
|
7
7
|
import { AstroErrorData } from "../../core/errors/index.js";
|
|
8
8
|
import { isRemotePath, removeLeadingForwardSlash } from "../../core/path.js";
|
|
9
|
-
import { isServerLikeOutput } from "../../
|
|
9
|
+
import { isServerLikeOutput } from "../../core/util.js";
|
|
10
10
|
import { getConfiguredImageService } from "../internal.js";
|
|
11
11
|
import { isESMImportedImage } from "../utils/imageKind.js";
|
|
12
12
|
import { loadRemoteImage } from "./remote.js";
|
package/dist/assets/internal.js
CHANGED
|
@@ -13,8 +13,7 @@ async function getConfiguredImageService() {
|
|
|
13
13
|
error.cause = e;
|
|
14
14
|
throw error;
|
|
15
15
|
});
|
|
16
|
-
if (!globalThis.astroAsset)
|
|
17
|
-
globalThis.astroAsset = {};
|
|
16
|
+
if (!globalThis.astroAsset) globalThis.astroAsset = {};
|
|
18
17
|
globalThis.astroAsset.imageService = service;
|
|
19
18
|
return service;
|
|
20
19
|
}
|
|
@@ -74,10 +74,8 @@ const baseService = {
|
|
|
74
74
|
if (!options.format) {
|
|
75
75
|
options.format = DEFAULT_OUTPUT_FORMAT;
|
|
76
76
|
}
|
|
77
|
-
if (options.width)
|
|
78
|
-
|
|
79
|
-
if (options.height)
|
|
80
|
-
options.height = Math.round(options.height);
|
|
77
|
+
if (options.width) options.width = Math.round(options.width);
|
|
78
|
+
if (options.height) options.height = Math.round(options.height);
|
|
81
79
|
return options;
|
|
82
80
|
},
|
|
83
81
|
getHTMLAttributes(options) {
|
|
@@ -27,11 +27,9 @@ const sharpService = {
|
|
|
27
27
|
getHTMLAttributes: baseService.getHTMLAttributes,
|
|
28
28
|
getSrcSet: baseService.getSrcSet,
|
|
29
29
|
async transform(inputBuffer, transformOptions, config) {
|
|
30
|
-
if (!sharp)
|
|
31
|
-
sharp = await loadSharp();
|
|
30
|
+
if (!sharp) sharp = await loadSharp();
|
|
32
31
|
const transform = transformOptions;
|
|
33
|
-
if (transform.format === "svg")
|
|
34
|
-
return { data: inputBuffer, format: "svg" };
|
|
32
|
+
if (transform.format === "svg") return { data: inputBuffer, format: "svg" };
|
|
35
33
|
const result = sharp(inputBuffer, {
|
|
36
34
|
failOnError: false,
|
|
37
35
|
pages: -1,
|
|
@@ -20,8 +20,7 @@ const qualityTable = {
|
|
|
20
20
|
};
|
|
21
21
|
async function getRotationForEXIF(inputBuffer, src) {
|
|
22
22
|
const meta = await imageMetadata(inputBuffer, src);
|
|
23
|
-
if (!meta)
|
|
24
|
-
return void 0;
|
|
23
|
+
if (!meta) return void 0;
|
|
25
24
|
switch (meta.orientation) {
|
|
26
25
|
case 3:
|
|
27
26
|
case 4:
|
|
@@ -45,8 +44,7 @@ const service = {
|
|
|
45
44
|
async transform(inputBuffer, transformOptions) {
|
|
46
45
|
const transform = transformOptions;
|
|
47
46
|
let format = transform.format;
|
|
48
|
-
if (format === "svg")
|
|
49
|
-
return { data: inputBuffer, format: "svg" };
|
|
47
|
+
if (format === "svg") return { data: inputBuffer, format: "svg" };
|
|
50
48
|
const operations = [];
|
|
51
49
|
const rotation = await getRotationForEXIF(inputBuffer, transform.src);
|
|
52
50
|
if (rotation) {
|
|
@@ -42,10 +42,8 @@ var Module = /* @__PURE__ */ function() {
|
|
|
42
42
|
scriptDirectory = dirname(getModuleURL(import.meta.url)) + "/";
|
|
43
43
|
}
|
|
44
44
|
read_ = function shell_read(filename, binary) {
|
|
45
|
-
if (!nodeFS)
|
|
46
|
-
|
|
47
|
-
if (!nodePath)
|
|
48
|
-
nodePath = require2("node:path");
|
|
45
|
+
if (!nodeFS) nodeFS = require2("node:fs");
|
|
46
|
+
if (!nodePath) nodePath = require2("node:path");
|
|
49
47
|
filename = nodePath["normalize"](filename);
|
|
50
48
|
return nodeFS["readFileSync"](filename, binary ? null : "utf8");
|
|
51
49
|
};
|
|
@@ -77,12 +75,9 @@ var Module = /* @__PURE__ */ function() {
|
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
moduleOverrides = null;
|
|
80
|
-
if (Module2["arguments"])
|
|
81
|
-
|
|
82
|
-
if (Module2["
|
|
83
|
-
thisProgram = Module2["thisProgram"];
|
|
84
|
-
if (Module2["quit"])
|
|
85
|
-
quit_ = Module2["quit"];
|
|
78
|
+
if (Module2["arguments"]) arguments_ = Module2["arguments"];
|
|
79
|
+
if (Module2["thisProgram"]) thisProgram = Module2["thisProgram"];
|
|
80
|
+
if (Module2["quit"]) quit_ = Module2["quit"];
|
|
86
81
|
var tempRet0 = 0;
|
|
87
82
|
var setTempRet0 = function(value) {
|
|
88
83
|
tempRet0 = value;
|
|
@@ -91,8 +86,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
91
86
|
return tempRet0;
|
|
92
87
|
};
|
|
93
88
|
var wasmBinary;
|
|
94
|
-
if (Module2["wasmBinary"])
|
|
95
|
-
wasmBinary = Module2["wasmBinary"];
|
|
89
|
+
if (Module2["wasmBinary"]) wasmBinary = Module2["wasmBinary"];
|
|
96
90
|
var noExitRuntime = Module2["noExitRuntime"] || true;
|
|
97
91
|
if (typeof WebAssembly !== "object") {
|
|
98
92
|
abort("no native wasm support detected");
|
|
@@ -109,23 +103,19 @@ var Module = /* @__PURE__ */ function() {
|
|
|
109
103
|
function UTF8ArrayToString(heap, idx, maxBytesToRead) {
|
|
110
104
|
var endIdx = idx + maxBytesToRead;
|
|
111
105
|
var endPtr = idx;
|
|
112
|
-
while (heap[endPtr] && !(endPtr >= endIdx))
|
|
113
|
-
++endPtr;
|
|
106
|
+
while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
114
107
|
return UTF8Decoder.decode(
|
|
115
108
|
heap.subarray ? heap.subarray(idx, endPtr) : new Uint8Array(heap.slice(idx, endPtr))
|
|
116
109
|
);
|
|
117
110
|
}
|
|
118
111
|
function UTF8ToString(ptr, maxBytesToRead) {
|
|
119
|
-
if (!ptr)
|
|
120
|
-
return "";
|
|
112
|
+
if (!ptr) return "";
|
|
121
113
|
var maxPtr = ptr + maxBytesToRead;
|
|
122
|
-
for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; )
|
|
123
|
-
++end;
|
|
114
|
+
for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; ) ++end;
|
|
124
115
|
return UTF8Decoder.decode(HEAPU8.subarray(ptr, end));
|
|
125
116
|
}
|
|
126
117
|
function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
|
|
127
|
-
if (!(maxBytesToWrite > 0))
|
|
128
|
-
return 0;
|
|
118
|
+
if (!(maxBytesToWrite > 0)) return 0;
|
|
129
119
|
var startIdx = outIdx;
|
|
130
120
|
var endIdx = outIdx + maxBytesToWrite - 1;
|
|
131
121
|
for (var i = 0; i < str.length; ++i) {
|
|
@@ -135,23 +125,19 @@ var Module = /* @__PURE__ */ function() {
|
|
|
135
125
|
u = 65536 + ((u & 1023) << 10) | u1 & 1023;
|
|
136
126
|
}
|
|
137
127
|
if (u <= 127) {
|
|
138
|
-
if (outIdx >= endIdx)
|
|
139
|
-
break;
|
|
128
|
+
if (outIdx >= endIdx) break;
|
|
140
129
|
heap[outIdx++] = u;
|
|
141
130
|
} else if (u <= 2047) {
|
|
142
|
-
if (outIdx + 1 >= endIdx)
|
|
143
|
-
break;
|
|
131
|
+
if (outIdx + 1 >= endIdx) break;
|
|
144
132
|
heap[outIdx++] = 192 | u >> 6;
|
|
145
133
|
heap[outIdx++] = 128 | u & 63;
|
|
146
134
|
} else if (u <= 65535) {
|
|
147
|
-
if (outIdx + 2 >= endIdx)
|
|
148
|
-
break;
|
|
135
|
+
if (outIdx + 2 >= endIdx) break;
|
|
149
136
|
heap[outIdx++] = 224 | u >> 12;
|
|
150
137
|
heap[outIdx++] = 128 | u >> 6 & 63;
|
|
151
138
|
heap[outIdx++] = 128 | u & 63;
|
|
152
139
|
} else {
|
|
153
|
-
if (outIdx + 3 >= endIdx)
|
|
154
|
-
break;
|
|
140
|
+
if (outIdx + 3 >= endIdx) break;
|
|
155
141
|
heap[outIdx++] = 240 | u >> 18;
|
|
156
142
|
heap[outIdx++] = 128 | u >> 12 & 63;
|
|
157
143
|
heap[outIdx++] = 128 | u >> 6 & 63;
|
|
@@ -170,14 +156,10 @@ var Module = /* @__PURE__ */ function() {
|
|
|
170
156
|
var u = str.charCodeAt(i);
|
|
171
157
|
if (u >= 55296 && u <= 57343)
|
|
172
158
|
u = 65536 + ((u & 1023) << 10) | str.charCodeAt(++i) & 1023;
|
|
173
|
-
if (u <= 127)
|
|
174
|
-
|
|
175
|
-
else if (u <=
|
|
176
|
-
|
|
177
|
-
else if (u <= 65535)
|
|
178
|
-
len += 3;
|
|
179
|
-
else
|
|
180
|
-
len += 4;
|
|
159
|
+
if (u <= 127) ++len;
|
|
160
|
+
else if (u <= 2047) len += 2;
|
|
161
|
+
else if (u <= 65535) len += 3;
|
|
162
|
+
else len += 4;
|
|
181
163
|
}
|
|
182
164
|
return len;
|
|
183
165
|
}
|
|
@@ -186,15 +168,13 @@ var Module = /* @__PURE__ */ function() {
|
|
|
186
168
|
var endPtr = ptr;
|
|
187
169
|
var idx = endPtr >> 1;
|
|
188
170
|
var maxIdx = idx + maxBytesToRead / 2;
|
|
189
|
-
while (!(idx >= maxIdx) && HEAPU16[idx])
|
|
190
|
-
++idx;
|
|
171
|
+
while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx;
|
|
191
172
|
endPtr = idx << 1;
|
|
192
173
|
return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
|
|
193
174
|
var str = "";
|
|
194
175
|
for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
|
|
195
176
|
var codeUnit = HEAP16[ptr + i * 2 >> 1];
|
|
196
|
-
if (codeUnit == 0)
|
|
197
|
-
break;
|
|
177
|
+
if (codeUnit == 0) break;
|
|
198
178
|
str += String.fromCharCode(codeUnit);
|
|
199
179
|
}
|
|
200
180
|
return str;
|
|
@@ -203,8 +183,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
203
183
|
if (maxBytesToWrite === void 0) {
|
|
204
184
|
maxBytesToWrite = 2147483647;
|
|
205
185
|
}
|
|
206
|
-
if (maxBytesToWrite < 2)
|
|
207
|
-
return 0;
|
|
186
|
+
if (maxBytesToWrite < 2) return 0;
|
|
208
187
|
maxBytesToWrite -= 2;
|
|
209
188
|
var startPtr = outPtr;
|
|
210
189
|
var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length;
|
|
@@ -224,8 +203,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
224
203
|
var str = "";
|
|
225
204
|
while (!(i >= maxBytesToRead / 4)) {
|
|
226
205
|
var utf32 = HEAP32[ptr + i * 4 >> 2];
|
|
227
|
-
if (utf32 == 0)
|
|
228
|
-
break;
|
|
206
|
+
if (utf32 == 0) break;
|
|
229
207
|
++i;
|
|
230
208
|
if (utf32 >= 65536) {
|
|
231
209
|
var ch = utf32 - 65536;
|
|
@@ -240,8 +218,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
240
218
|
if (maxBytesToWrite === void 0) {
|
|
241
219
|
maxBytesToWrite = 2147483647;
|
|
242
220
|
}
|
|
243
|
-
if (maxBytesToWrite < 4)
|
|
244
|
-
return 0;
|
|
221
|
+
if (maxBytesToWrite < 4) return 0;
|
|
245
222
|
var startPtr = outPtr;
|
|
246
223
|
var endPtr = startPtr + maxBytesToWrite - 4;
|
|
247
224
|
for (var i = 0; i < str.length; ++i) {
|
|
@@ -252,8 +229,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
252
229
|
}
|
|
253
230
|
HEAP32[outPtr >> 2] = codeUnit;
|
|
254
231
|
outPtr += 4;
|
|
255
|
-
if (outPtr + 4 > endPtr)
|
|
256
|
-
break;
|
|
232
|
+
if (outPtr + 4 > endPtr) break;
|
|
257
233
|
}
|
|
258
234
|
HEAP32[outPtr >> 2] = 0;
|
|
259
235
|
return outPtr - startPtr;
|
|
@@ -262,8 +238,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
262
238
|
var len = 0;
|
|
263
239
|
for (var i = 0; i < str.length; ++i) {
|
|
264
240
|
var codeUnit = str.charCodeAt(i);
|
|
265
|
-
if (codeUnit >= 55296 && codeUnit <= 57343)
|
|
266
|
-
++i;
|
|
241
|
+
if (codeUnit >= 55296 && codeUnit <= 57343) ++i;
|
|
267
242
|
len += 4;
|
|
268
243
|
}
|
|
269
244
|
return len;
|
|
@@ -1531,8 +1506,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
1531
1506
|
wasmTable.get(index)(a1, a2, a3, a4, a5, a6, a7);
|
|
1532
1507
|
} catch (e) {
|
|
1533
1508
|
stackRestore(sp);
|
|
1534
|
-
if (e !== e + 0 && e !== "longjmp")
|
|
1535
|
-
throw e;
|
|
1509
|
+
if (e !== e + 0 && e !== "longjmp") throw e;
|
|
1536
1510
|
_setThrew(1, 0);
|
|
1537
1511
|
}
|
|
1538
1512
|
}
|
|
@@ -1542,8 +1516,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
1542
1516
|
wasmTable.get(index)(a1, a2, a3, a4);
|
|
1543
1517
|
} catch (e) {
|
|
1544
1518
|
stackRestore(sp);
|
|
1545
|
-
if (e !== e + 0 && e !== "longjmp")
|
|
1546
|
-
throw e;
|
|
1519
|
+
if (e !== e + 0 && e !== "longjmp") throw e;
|
|
1547
1520
|
_setThrew(1, 0);
|
|
1548
1521
|
}
|
|
1549
1522
|
}
|
|
@@ -1553,8 +1526,7 @@ var Module = /* @__PURE__ */ function() {
|
|
|
1553
1526
|
return wasmTable.get(index)(a1, a2);
|
|
1554
1527
|
} catch (e) {
|
|
1555
1528
|
stackRestore(sp);
|
|
1556
|
-
if (e !== e + 0 && e !== "longjmp")
|
|
1557
|
-
throw e;
|
|
1529
|
+
if (e !== e + 0 && e !== "longjmp") throw e;
|
|
1558
1530
|
_setThrew(1, 0);
|
|
1559
1531
|
}
|
|
1560
1532
|
}
|
|
@@ -1564,17 +1536,14 @@ var Module = /* @__PURE__ */ function() {
|
|
|
1564
1536
|
return wasmTable.get(index)(a1, a2, a3, a4);
|
|
1565
1537
|
} catch (e) {
|
|
1566
1538
|
stackRestore(sp);
|
|
1567
|
-
if (e !== e + 0 && e !== "longjmp")
|
|
1568
|
-
throw e;
|
|
1539
|
+
if (e !== e + 0 && e !== "longjmp") throw e;
|
|
1569
1540
|
_setThrew(1, 0);
|
|
1570
1541
|
}
|
|
1571
1542
|
}
|
|
1572
1543
|
var calledRun;
|
|
1573
1544
|
dependenciesFulfilled = function runCaller() {
|
|
1574
|
-
if (!calledRun)
|
|
1575
|
-
|
|
1576
|
-
if (!calledRun)
|
|
1577
|
-
dependenciesFulfilled = runCaller;
|
|
1545
|
+
if (!calledRun) run();
|
|
1546
|
+
if (!calledRun) dependenciesFulfilled = runCaller;
|
|
1578
1547
|
};
|
|
1579
1548
|
function run(args) {
|
|
1580
1549
|
args = args || arguments_;
|
|
@@ -1586,16 +1555,13 @@ var Module = /* @__PURE__ */ function() {
|
|
|
1586
1555
|
return;
|
|
1587
1556
|
}
|
|
1588
1557
|
function doRun() {
|
|
1589
|
-
if (calledRun)
|
|
1590
|
-
return;
|
|
1558
|
+
if (calledRun) return;
|
|
1591
1559
|
calledRun = true;
|
|
1592
1560
|
Module2["calledRun"] = true;
|
|
1593
|
-
if (ABORT)
|
|
1594
|
-
return;
|
|
1561
|
+
if (ABORT) return;
|
|
1595
1562
|
initRuntime();
|
|
1596
1563
|
readyPromiseResolve(Module2);
|
|
1597
|
-
if (Module2["onRuntimeInitialized"])
|
|
1598
|
-
Module2["onRuntimeInitialized"]();
|
|
1564
|
+
if (Module2["onRuntimeInitialized"]) Module2["onRuntimeInitialized"]();
|
|
1599
1565
|
postRun();
|
|
1600
1566
|
}
|
|
1601
1567
|
if (Module2["setStatus"]) {
|