astro 5.4.1 → 5.4.3
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 +2 -2
- package/components/Debug.astro +3 -2
- package/dist/actions/consts.d.ts +2 -2
- package/dist/actions/consts.js +4 -4
- package/dist/actions/integration.js +1 -5
- package/dist/actions/loadActions.d.ts +8 -0
- package/dist/actions/loadActions.js +13 -0
- package/dist/actions/plugins.d.ts +8 -0
- package/dist/actions/plugins.js +24 -5
- package/dist/actions/runtime/virtual/server.d.ts +2 -2
- package/dist/actions/runtime/virtual/server.js +1 -2
- package/dist/actions/runtime/virtual/shared.d.ts +2 -0
- package/dist/actions/runtime/virtual/shared.js +8 -1
- package/dist/assets/utils/imageKind.d.ts +18 -0
- package/dist/assets/utils/imageKind.js +5 -1
- package/dist/assets/utils/index.d.ts +6 -1
- package/dist/assets/utils/index.js +0 -2
- package/dist/assets/utils/metadata.d.ts +8 -0
- package/dist/assets/utils/metadata.js +16 -15
- package/dist/assets/utils/node/emitAsset.d.ts +9 -0
- package/dist/assets/utils/node/emitAsset.js +1 -1
- package/dist/assets/utils/queryParams.d.ts +9 -0
- package/dist/assets/utils/remoteProbe.d.ts +7 -0
- package/dist/assets/utils/transformToPath.d.ts +30 -0
- package/dist/cli/add/index.js +44 -73
- package/dist/cli/install-package.d.ts +0 -6
- package/dist/cli/install-package.js +17 -54
- package/dist/content/content-layer.js +3 -3
- package/dist/content/runtime.js +2 -1
- package/dist/core/app/types.d.ts +6 -0
- package/dist/core/base-pipeline.d.ts +9 -1
- package/dist/core/base-pipeline.js +40 -1
- package/dist/core/build/generate.js +5 -3
- package/dist/core/build/internal.d.ts +2 -1
- package/dist/core/build/internal.js +3 -1
- package/dist/core/build/plugins/index.js +2 -0
- package/dist/core/build/plugins/plugin-actions.d.ts +4 -0
- package/dist/core/build/plugins/plugin-actions.js +16 -0
- package/dist/core/build/plugins/plugin-css.js +1 -27
- package/dist/core/build/plugins/plugin-middleware.d.ts +0 -1
- package/dist/core/build/plugins/plugin-middleware.js +0 -2
- package/dist/core/build/plugins/plugin-ssr.js +4 -1
- package/dist/core/build/static-build.js +9 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +11 -0
- package/dist/core/errors/errors-data.js +6 -0
- package/dist/core/messages.js +6 -5
- package/dist/core/render-context.d.ts +7 -5
- package/dist/core/render-context.js +28 -13
- package/dist/transitions/router.js +5 -2
- package/dist/transitions/swap-functions.d.ts +1 -0
- package/dist/transitions/swap-functions.js +15 -11
- package/dist/vite-plugin-astro/index.d.ts +2 -2
- package/dist/vite-plugin-astro/index.js +3 -9
- package/dist/vite-plugin-astro/types.d.ts +0 -20
- package/dist/vite-plugin-astro-server/pipeline.d.ts +0 -1
- package/dist/vite-plugin-astro-server/pipeline.js +0 -10
- package/dist/vite-plugin-astro-server/plugin.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +5 -1
- package/package.json +18 -19
- package/templates/actions.mjs +8 -4
- package/dist/actions/runtime/middleware.d.ts +0 -1
- package/dist/actions/runtime/middleware.js +0 -14
- package/dist/actions/runtime/virtual/get-action.d.ts +0 -8
- package/dist/actions/runtime/virtual/get-action.js +0 -29
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getActionContext } from "../actions/runtime/virtual/server.js";
|
|
1
2
|
import { deserializeActionResult } from "../actions/runtime/virtual/shared.js";
|
|
2
3
|
import { createCallAction, createGetActionResult, hasActionPayload } from "../actions/utils.js";
|
|
3
4
|
import {
|
|
@@ -29,10 +30,11 @@ import { copyRequest, getOriginPathname, setOriginPathname } from "./routing/rew
|
|
|
29
30
|
import { AstroSession } from "./session.js";
|
|
30
31
|
const apiContextRoutesSymbol = Symbol.for("context.routes");
|
|
31
32
|
class RenderContext {
|
|
32
|
-
constructor(pipeline, locals, middleware, pathname, request, routeData, status, clientAddress, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = new URL(request.url), props = {}, partial = void 0, session = pipeline.manifest.sessionConfig ? new AstroSession(cookies, pipeline.manifest.sessionConfig) : void 0) {
|
|
33
|
+
constructor(pipeline, locals, middleware, actions, pathname, request, routeData, status, clientAddress, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = new URL(request.url), props = {}, partial = void 0, session = pipeline.manifest.sessionConfig ? new AstroSession(cookies, pipeline.manifest.sessionConfig) : void 0) {
|
|
33
34
|
this.pipeline = pipeline;
|
|
34
35
|
this.locals = locals;
|
|
35
36
|
this.middleware = middleware;
|
|
37
|
+
this.actions = actions;
|
|
36
38
|
this.pathname = pathname;
|
|
37
39
|
this.request = request;
|
|
38
40
|
this.routeData = routeData;
|
|
@@ -63,14 +65,17 @@ class RenderContext {
|
|
|
63
65
|
clientAddress,
|
|
64
66
|
status = 200,
|
|
65
67
|
props,
|
|
66
|
-
partial = void 0
|
|
68
|
+
partial = void 0,
|
|
69
|
+
actions
|
|
67
70
|
}) {
|
|
68
71
|
const pipelineMiddleware = await pipeline.getMiddleware();
|
|
72
|
+
const pipelineActions = actions ?? await pipeline.getActions();
|
|
69
73
|
setOriginPathname(request, pathname);
|
|
70
74
|
return new RenderContext(
|
|
71
75
|
pipeline,
|
|
72
76
|
locals,
|
|
73
77
|
sequence(...pipeline.internalMiddleware, middleware ?? pipelineMiddleware),
|
|
78
|
+
pipelineActions,
|
|
74
79
|
pathname,
|
|
75
80
|
request,
|
|
76
81
|
routeData,
|
|
@@ -106,7 +111,8 @@ class RenderContext {
|
|
|
106
111
|
serverLike,
|
|
107
112
|
base: manifest.base
|
|
108
113
|
});
|
|
109
|
-
const
|
|
114
|
+
const actionApiContext = this.createActionAPIContext();
|
|
115
|
+
const apiContext = this.createAPIContext(props, actionApiContext);
|
|
110
116
|
this.counter++;
|
|
111
117
|
if (this.counter === 4) {
|
|
112
118
|
return new Response("Loop Detected", {
|
|
@@ -153,6 +159,13 @@ class RenderContext {
|
|
|
153
159
|
this.status = 200;
|
|
154
160
|
}
|
|
155
161
|
let response2;
|
|
162
|
+
if (!ctx.isPrerendered) {
|
|
163
|
+
const { action, setActionResult, serializeActionResult } = getActionContext(ctx);
|
|
164
|
+
if (action?.calledFrom === "form") {
|
|
165
|
+
const actionResult = await action.handler();
|
|
166
|
+
setActionResult(action.name, serializeActionResult(actionResult));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
156
169
|
switch (this.routeData.type) {
|
|
157
170
|
case "endpoint": {
|
|
158
171
|
response2 = await renderEndpoint(
|
|
@@ -166,7 +179,7 @@ class RenderContext {
|
|
|
166
179
|
case "redirect":
|
|
167
180
|
return renderRedirect(this);
|
|
168
181
|
case "page": {
|
|
169
|
-
const result = await this.createResult(componentInstance);
|
|
182
|
+
const result = await this.createResult(componentInstance, actionApiContext);
|
|
170
183
|
try {
|
|
171
184
|
response2 = await renderPage(
|
|
172
185
|
result,
|
|
@@ -209,8 +222,7 @@ class RenderContext {
|
|
|
209
222
|
attachCookiesToResponse(response, cookies);
|
|
210
223
|
return response;
|
|
211
224
|
}
|
|
212
|
-
createAPIContext(props) {
|
|
213
|
-
const context = this.createActionAPIContext();
|
|
225
|
+
createAPIContext(props, context) {
|
|
214
226
|
const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
|
|
215
227
|
Reflect.set(context, apiContextRoutesSymbol, this.pipeline);
|
|
216
228
|
return Object.assign(context, {
|
|
@@ -295,7 +307,7 @@ class RenderContext {
|
|
|
295
307
|
session
|
|
296
308
|
};
|
|
297
309
|
}
|
|
298
|
-
async createResult(mod) {
|
|
310
|
+
async createResult(mod, ctx) {
|
|
299
311
|
const { cookies, pathname, pipeline, routeData, status } = this;
|
|
300
312
|
const { clientDirectives, inlinedScripts, compressHTML, manifest, renderers, resolve } = pipeline;
|
|
301
313
|
const { links, scripts, styles } = await pipeline.headElements(routeData);
|
|
@@ -324,7 +336,7 @@ class RenderContext {
|
|
|
324
336
|
compressHTML,
|
|
325
337
|
cookies,
|
|
326
338
|
/** This function returns the `Astro` faux-global */
|
|
327
|
-
createAstro: (astroGlobal, props, slots) => this.createAstro(result, astroGlobal, props, slots),
|
|
339
|
+
createAstro: (astroGlobal, props, slots) => this.createAstro(result, astroGlobal, props, slots, ctx),
|
|
328
340
|
links,
|
|
329
341
|
params: this.params,
|
|
330
342
|
partial,
|
|
@@ -361,17 +373,19 @@ class RenderContext {
|
|
|
361
373
|
*
|
|
362
374
|
* The page level partial is used as the prototype of the user-visible `Astro` global object, which is instantiated once per use of a component.
|
|
363
375
|
*/
|
|
364
|
-
createAstro(result, astroStaticPartial, props, slotValues) {
|
|
376
|
+
createAstro(result, astroStaticPartial, props, slotValues, apiContext) {
|
|
365
377
|
let astroPagePartial;
|
|
366
378
|
if (this.isRewriting) {
|
|
367
379
|
astroPagePartial = this.#astroPagePartial = this.createAstroPagePartial(
|
|
368
380
|
result,
|
|
369
|
-
astroStaticPartial
|
|
381
|
+
astroStaticPartial,
|
|
382
|
+
apiContext
|
|
370
383
|
);
|
|
371
384
|
} else {
|
|
372
385
|
astroPagePartial = this.#astroPagePartial ??= this.createAstroPagePartial(
|
|
373
386
|
result,
|
|
374
|
-
astroStaticPartial
|
|
387
|
+
astroStaticPartial,
|
|
388
|
+
apiContext
|
|
375
389
|
);
|
|
376
390
|
}
|
|
377
391
|
const astroComponentPartial = { props, self: null };
|
|
@@ -394,7 +408,7 @@ class RenderContext {
|
|
|
394
408
|
});
|
|
395
409
|
return Astro;
|
|
396
410
|
}
|
|
397
|
-
createAstroPagePartial(result, astroStaticPartial) {
|
|
411
|
+
createAstroPagePartial(result, astroStaticPartial, apiContext) {
|
|
398
412
|
const renderContext = this;
|
|
399
413
|
const { cookies, locals, params, pipeline, url, session } = this;
|
|
400
414
|
const { response } = result;
|
|
@@ -409,6 +423,7 @@ class RenderContext {
|
|
|
409
423
|
const rewrite = async (reroutePayload) => {
|
|
410
424
|
return await this.#executeRewrite(reroutePayload);
|
|
411
425
|
};
|
|
426
|
+
const callAction = createCallAction(apiContext);
|
|
412
427
|
return {
|
|
413
428
|
generator: astroStaticPartial.generator,
|
|
414
429
|
glob: astroStaticPartial.glob,
|
|
@@ -437,7 +452,7 @@ class RenderContext {
|
|
|
437
452
|
site: pipeline.site,
|
|
438
453
|
getActionResult: createGetActionResult(locals),
|
|
439
454
|
get callAction() {
|
|
440
|
-
return
|
|
455
|
+
return callAction;
|
|
441
456
|
},
|
|
442
457
|
url,
|
|
443
458
|
get originPathname() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TRANSITION_AFTER_SWAP, doPreparation, doSwap } from "./events.js";
|
|
2
|
+
import { detectScriptExecuted } from "./swap-functions.js";
|
|
2
3
|
const inBrowser = import.meta.env.SSR === false;
|
|
3
4
|
const pushState = inBrowser && history.pushState.bind(history);
|
|
4
5
|
const replaceState = inBrowser && history.replaceState.bind(history);
|
|
@@ -326,7 +327,9 @@ async function transition(direction, from, to, options, historyState) {
|
|
|
326
327
|
skipTransition: () => {
|
|
327
328
|
currentTransition.transitionSkipped = true;
|
|
328
329
|
document.documentElement.removeAttribute(OLD_NEW_ATTR);
|
|
329
|
-
}
|
|
330
|
+
},
|
|
331
|
+
types: /* @__PURE__ */ new Set()
|
|
332
|
+
// empty by default
|
|
330
333
|
};
|
|
331
334
|
}
|
|
332
335
|
currentTransition.viewTransition?.updateCallbackDone.finally(async () => {
|
|
@@ -417,7 +420,7 @@ if (inBrowser) {
|
|
|
417
420
|
}
|
|
418
421
|
}
|
|
419
422
|
for (const script of document.getElementsByTagName("script")) {
|
|
420
|
-
script
|
|
423
|
+
detectScriptExecuted(script);
|
|
421
424
|
}
|
|
422
425
|
}
|
|
423
426
|
async function prepareForClientOnlyComponents(newDocument, toLocation, signal) {
|
|
@@ -3,6 +3,7 @@ export type SavedFocus = {
|
|
|
3
3
|
start?: number | null;
|
|
4
4
|
end?: number | null;
|
|
5
5
|
};
|
|
6
|
+
export declare function detectScriptExecuted(script: HTMLScriptElement): boolean;
|
|
6
7
|
export declare function deselectScripts(doc: Document): void;
|
|
7
8
|
export declare function swapRootAttributes(doc: Document): void;
|
|
8
9
|
export declare function swapHeadElements(doc: Document): void;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
const PERSIST_ATTR = "data-astro-transition-persist";
|
|
2
|
+
const scriptsAlreadyRan = /* @__PURE__ */ new Set();
|
|
3
|
+
function detectScriptExecuted(script) {
|
|
4
|
+
const key = script.src ? new URL(script.src, location.href).href : script.textContent;
|
|
5
|
+
if (scriptsAlreadyRan.has(key)) return true;
|
|
6
|
+
scriptsAlreadyRan.add(key);
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
2
9
|
function deselectScripts(doc) {
|
|
3
|
-
for (const
|
|
4
|
-
|
|
5
|
-
if
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
) {
|
|
11
|
-
s2.dataset.astroExec = "";
|
|
12
|
-
break;
|
|
13
|
-
}
|
|
10
|
+
for (const s2 of doc.scripts) {
|
|
11
|
+
if (
|
|
12
|
+
// Check if the script should be rerun regardless of it being the same
|
|
13
|
+
!s2.hasAttribute("data-astro-rerun") && // Check if the script has already been executed
|
|
14
|
+
detectScriptExecuted(s2)
|
|
15
|
+
) {
|
|
16
|
+
s2.dataset.astroExec = "";
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -106,6 +109,7 @@ const swap = (doc) => {
|
|
|
106
109
|
};
|
|
107
110
|
export {
|
|
108
111
|
deselectScripts,
|
|
112
|
+
detectScriptExecuted,
|
|
109
113
|
restoreFocus,
|
|
110
114
|
saveFocus,
|
|
111
115
|
swap,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
2
|
import type { Logger } from '../core/logger/core.js';
|
|
3
3
|
import type { AstroSettings } from '../types/astro.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { PluginMetadata as AstroPluginMetadata } from './types.js';
|
|
5
5
|
export { getAstroMetadata } from './metadata.js';
|
|
6
|
-
export type { AstroPluginMetadata
|
|
6
|
+
export type { AstroPluginMetadata };
|
|
7
7
|
interface AstroPluginOptions {
|
|
8
8
|
settings: AstroSettings;
|
|
9
9
|
logger: Logger;
|
|
@@ -89,15 +89,9 @@ function astro({ settings, logger }) {
|
|
|
89
89
|
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
|
|
90
90
|
return {
|
|
91
91
|
code: result.code,
|
|
92
|
-
//
|
|
93
|
-
// if the
|
|
94
|
-
meta: result.isGlobal ? void 0 : {
|
|
95
|
-
astroCss: {
|
|
96
|
-
cssScopeTo: {
|
|
97
|
-
[filename]: ["default"]
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
92
|
+
// `vite.cssScopeTo` is a Vite feature that allows this CSS to be treeshaken
|
|
93
|
+
// if the Astro component's default export is not used
|
|
94
|
+
meta: result.isGlobal ? void 0 : { vite: { cssScopeTo: [filename, "default"] } }
|
|
101
95
|
};
|
|
102
96
|
}
|
|
103
97
|
case "script": {
|
|
@@ -15,26 +15,6 @@ export interface PluginMetadata {
|
|
|
15
15
|
pageOptions: PageOptions;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
export interface PluginCssMetadata {
|
|
19
|
-
astroCss: {
|
|
20
|
-
/**
|
|
21
|
-
* For Astro CSS virtual modules, it can scope to the main Astro module's default export
|
|
22
|
-
* so that if those exports are treeshaken away, the CSS module will also be treeshaken.
|
|
23
|
-
*
|
|
24
|
-
* Example config if the CSS id is `/src/Foo.astro?astro&type=style&lang.css`:
|
|
25
|
-
* ```js
|
|
26
|
-
* cssScopeTo: {
|
|
27
|
-
* '/src/Foo.astro': ['default']
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* The above is the only config we use today, but we're exposing as a `Record` to follow the
|
|
32
|
-
* upstream Vite implementation: https://github.com/vitejs/vite/pull/16058. When/If that lands,
|
|
33
|
-
* we can also remove our custom implementation.
|
|
34
|
-
*/
|
|
35
|
-
cssScopeTo: Record<string, string[]>;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
18
|
export interface CompileMetadata {
|
|
39
19
|
/** Used for HMR to compare code changes */
|
|
40
20
|
originalCode: string;
|
|
@@ -29,5 +29,4 @@ export declare class DevPipeline extends Pipeline {
|
|
|
29
29
|
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
30
30
|
tryRewrite(payload: RewritePayload, request: Request): Promise<TryRewriteResult>;
|
|
31
31
|
setManifestData(manifestData: RoutesList): void;
|
|
32
|
-
rewriteKnownRoute(route: string, sourceRoute: RouteData): ComponentInstance;
|
|
33
32
|
}
|
|
@@ -154,16 +154,6 @@ class DevPipeline extends Pipeline {
|
|
|
154
154
|
setManifestData(manifestData) {
|
|
155
155
|
this.routesList = manifestData;
|
|
156
156
|
}
|
|
157
|
-
rewriteKnownRoute(route, sourceRoute) {
|
|
158
|
-
if (this.serverLike && sourceRoute.prerender) {
|
|
159
|
-
for (let def of this.defaultRoutes) {
|
|
160
|
-
if (route === def.route) {
|
|
161
|
-
return def.instance;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
throw new Error("Unknown route");
|
|
166
|
-
}
|
|
167
157
|
}
|
|
168
158
|
export {
|
|
169
159
|
DevPipeline
|
|
@@ -29,7 +29,7 @@ function createVitePluginAstroServer({
|
|
|
29
29
|
}) {
|
|
30
30
|
return {
|
|
31
31
|
name: "astro:server",
|
|
32
|
-
configureServer(viteServer) {
|
|
32
|
+
async configureServer(viteServer) {
|
|
33
33
|
const loader = createViteLoader(viteServer);
|
|
34
34
|
const pipeline = DevPipeline.create(routesList, {
|
|
35
35
|
loader,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loadActions } from "../actions/loadActions.js";
|
|
1
2
|
import {
|
|
2
3
|
DEFAULT_404_COMPONENT,
|
|
3
4
|
NOOP_MIDDLEWARE_HEADER,
|
|
@@ -104,6 +105,8 @@ async function handleRoute({
|
|
|
104
105
|
let renderContext;
|
|
105
106
|
let mod = void 0;
|
|
106
107
|
let route;
|
|
108
|
+
const actions = await loadActions(loader);
|
|
109
|
+
pipeline.setActions(actions);
|
|
107
110
|
const middleware = (await loadMiddleware(loader)).onRequest;
|
|
108
111
|
const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
|
|
109
112
|
const { preloadedComponent } = matchedRoute;
|
|
@@ -128,7 +131,8 @@ async function handleRoute({
|
|
|
128
131
|
middleware: isDefaultPrerendered404(matchedRoute.route) ? void 0 : middleware,
|
|
129
132
|
request,
|
|
130
133
|
routeData: route,
|
|
131
|
-
clientAddress: incomingRequest.socket.remoteAddress
|
|
134
|
+
clientAddress: incomingRequest.socket.remoteAddress,
|
|
135
|
+
actions
|
|
132
136
|
});
|
|
133
137
|
let response;
|
|
134
138
|
let statusCode = 200;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.3",
|
|
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",
|
|
@@ -133,35 +133,34 @@
|
|
|
133
133
|
"kleur": "^4.1.5",
|
|
134
134
|
"magic-string": "^0.30.17",
|
|
135
135
|
"magicast": "^0.3.5",
|
|
136
|
-
"mrmime": "^2.0.
|
|
136
|
+
"mrmime": "^2.0.1",
|
|
137
137
|
"neotraverse": "^0.6.18",
|
|
138
138
|
"p-limit": "^6.2.0",
|
|
139
139
|
"p-queue": "^8.1.0",
|
|
140
|
+
"package-manager-detector": "^1.0.0",
|
|
140
141
|
"picomatch": "^4.0.2",
|
|
141
|
-
"preferred-pm": "^4.1.1",
|
|
142
142
|
"prompts": "^2.4.2",
|
|
143
143
|
"rehype": "^13.0.2",
|
|
144
144
|
"semver": "^7.7.1",
|
|
145
145
|
"shiki": "^1.29.2",
|
|
146
146
|
"tinyexec": "^0.3.2",
|
|
147
147
|
"tinyglobby": "^0.2.12",
|
|
148
|
-
"tsconfck": "^3.1.
|
|
148
|
+
"tsconfck": "^3.1.5",
|
|
149
149
|
"ultrahtml": "^1.5.3",
|
|
150
150
|
"unist-util-visit": "^5.0.0",
|
|
151
|
-
"unstorage": "^1.
|
|
151
|
+
"unstorage": "^1.15.0",
|
|
152
152
|
"vfile": "^6.0.3",
|
|
153
153
|
"vite": "^6.2.0",
|
|
154
|
-
"vitefu": "^1.0.
|
|
155
|
-
"which-pm": "^3.0.1",
|
|
154
|
+
"vitefu": "^1.0.6",
|
|
156
155
|
"xxhash-wasm": "^1.1.0",
|
|
157
156
|
"yargs-parser": "^21.1.1",
|
|
158
|
-
"yocto-spinner": "^0.2.
|
|
159
|
-
"zod": "^3.24.
|
|
160
|
-
"zod-to-json-schema": "^3.24.
|
|
157
|
+
"yocto-spinner": "^0.2.1",
|
|
158
|
+
"zod": "^3.24.2",
|
|
159
|
+
"zod-to-json-schema": "^3.24.3",
|
|
161
160
|
"zod-to-ts": "^1.2.0",
|
|
162
|
-
"@astrojs/internal-helpers": "0.6.
|
|
163
|
-
"@astrojs/
|
|
164
|
-
"@astrojs/
|
|
161
|
+
"@astrojs/internal-helpers": "0.6.1",
|
|
162
|
+
"@astrojs/markdown-remark": "6.2.1",
|
|
163
|
+
"@astrojs/telemetry": "3.2.0"
|
|
165
164
|
},
|
|
166
165
|
"optionalDependencies": {
|
|
167
166
|
"sharp": "^0.33.3"
|
|
@@ -186,8 +185,8 @@
|
|
|
186
185
|
"cheerio": "1.0.0",
|
|
187
186
|
"eol": "^0.10.0",
|
|
188
187
|
"execa": "^8.0.1",
|
|
189
|
-
"expect-type": "^1.
|
|
190
|
-
"fs-fixture": "^2.7.
|
|
188
|
+
"expect-type": "^1.2.0",
|
|
189
|
+
"fs-fixture": "^2.7.1",
|
|
191
190
|
"mdast-util-mdx": "^3.0.0",
|
|
192
191
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
193
192
|
"node-mocks-http": "^1.16.2",
|
|
@@ -196,11 +195,11 @@
|
|
|
196
195
|
"rehype-slug": "^6.0.0",
|
|
197
196
|
"rehype-toc": "^3.0.2",
|
|
198
197
|
"remark-code-titles": "^0.1.2",
|
|
199
|
-
"rollup": "^4.34.
|
|
200
|
-
"sass": "^1.
|
|
201
|
-
"undici": "^7.
|
|
198
|
+
"rollup": "^4.34.9",
|
|
199
|
+
"sass": "^1.85.1",
|
|
200
|
+
"undici": "^7.4.0",
|
|
202
201
|
"unified": "^11.0.5",
|
|
203
|
-
"vitest": "^3.0.
|
|
202
|
+
"vitest": "^3.0.7",
|
|
204
203
|
"astro-scripts": "0.0.14"
|
|
205
204
|
},
|
|
206
205
|
"engines": {
|
package/templates/actions.mjs
CHANGED
|
@@ -2,10 +2,12 @@ import {
|
|
|
2
2
|
ACTION_QUERY_PARAMS,
|
|
3
3
|
ActionError,
|
|
4
4
|
appendForwardSlash,
|
|
5
|
+
astroCalledServerError,
|
|
5
6
|
deserializeActionResult,
|
|
6
7
|
getActionQueryString,
|
|
7
8
|
} from 'astro:actions';
|
|
8
9
|
|
|
10
|
+
const apiContextRoutesSymbol = Symbol.for('context.routes');
|
|
9
11
|
const ENCODED_DOT = '%2E';
|
|
10
12
|
|
|
11
13
|
function toActionProxy(actionCallback = {}, aggregatedPath = '') {
|
|
@@ -73,11 +75,13 @@ export function getActionPath(action) {
|
|
|
73
75
|
*/
|
|
74
76
|
async function handleAction(param, path, context) {
|
|
75
77
|
// When running server-side, import the action and call it.
|
|
76
|
-
if (import.meta.env.SSR) {
|
|
77
|
-
const
|
|
78
|
-
|
|
78
|
+
if (import.meta.env.SSR && context) {
|
|
79
|
+
const pipeline = Reflect.get(context, apiContextRoutesSymbol);
|
|
80
|
+
if (!pipeline) {
|
|
81
|
+
throw astroCalledServerError();
|
|
82
|
+
}
|
|
83
|
+
const action = await pipeline.getAction(path);
|
|
79
84
|
if (!action) throw new Error(`Action not found: ${path}`);
|
|
80
|
-
|
|
81
85
|
return action.bind(context)(param);
|
|
82
86
|
}
|
|
83
87
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const onRequest: import("../../types/public/common.js").MiddlewareHandler;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineMiddleware } from "../../virtual-modules/middleware.js";
|
|
2
|
-
import { getActionContext } from "./virtual/server.js";
|
|
3
|
-
const onRequest = defineMiddleware(async (context, next) => {
|
|
4
|
-
if (context.isPrerendered) return next();
|
|
5
|
-
const { action, setActionResult, serializeActionResult } = getActionContext(context);
|
|
6
|
-
if (action?.calledFrom === "form") {
|
|
7
|
-
const actionResult = await action.handler();
|
|
8
|
-
setActionResult(action.name, serializeActionResult(actionResult));
|
|
9
|
-
}
|
|
10
|
-
return next();
|
|
11
|
-
});
|
|
12
|
-
export {
|
|
13
|
-
onRequest
|
|
14
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ZodType } from 'zod';
|
|
2
|
-
import type { ActionAccept, ActionClient } from './server.js';
|
|
3
|
-
/**
|
|
4
|
-
* Get server-side action based on the route path.
|
|
5
|
-
* Imports from the virtual module `astro:internal-actions`, which maps to
|
|
6
|
-
* the user's `src/actions/index.ts` file at build-time.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getAction(path: string): Promise<ActionClient<unknown, ActionAccept, ZodType>>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ActionNotFoundError } from "../../../core/errors/errors-data.js";
|
|
2
|
-
import { AstroError } from "../../../core/errors/errors.js";
|
|
3
|
-
async function getAction(path) {
|
|
4
|
-
const pathKeys = path.split(".").map((key) => decodeURIComponent(key));
|
|
5
|
-
let { server: actionLookup } = await import("astro:internal-actions");
|
|
6
|
-
if (actionLookup == null || !(typeof actionLookup === "object")) {
|
|
7
|
-
throw new TypeError(
|
|
8
|
-
`Expected \`server\` export in actions file to be an object. Received ${typeof actionLookup}.`
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
for (const key of pathKeys) {
|
|
12
|
-
if (!(key in actionLookup)) {
|
|
13
|
-
throw new AstroError({
|
|
14
|
-
...ActionNotFoundError,
|
|
15
|
-
message: ActionNotFoundError.message(pathKeys.join("."))
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
actionLookup = actionLookup[key];
|
|
19
|
-
}
|
|
20
|
-
if (typeof actionLookup !== "function") {
|
|
21
|
-
throw new TypeError(
|
|
22
|
-
`Expected handler for action ${pathKeys.join(".")} to be a function. Received ${typeof actionLookup}.`
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
return actionLookup;
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
getAction
|
|
29
|
-
};
|