@adonisjs/inertia 2.1.0 → 2.1.2

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.
@@ -146,6 +146,15 @@ var Inertia = class {
146
146
  }
147
147
  return newProps;
148
148
  }
149
+ /**
150
+ * Resolve a single prop
151
+ */
152
+ async #resolveProp(key, value) {
153
+ if (value instanceof OptionalProp || value instanceof MergeProp || value instanceof DeferProp || value instanceof AlwaysProp) {
154
+ return [key, await value.callback()];
155
+ }
156
+ return [key, value];
157
+ }
149
158
  /**
150
159
  * Resolve a single prop by calling the callback or resolving the promise
151
160
  */
@@ -154,12 +163,10 @@ var Inertia = class {
154
163
  await Promise.all(
155
164
  Object.entries(props).map(async ([key, value]) => {
156
165
  if (typeof value === "function") {
157
- return [key, await value(this.ctx)];
158
- }
159
- if (value instanceof OptionalProp || value instanceof MergeProp || value instanceof DeferProp || value instanceof AlwaysProp) {
160
- return [key, await value.callback()];
166
+ const result = await value(this.ctx);
167
+ return this.#resolveProp(key, result);
161
168
  }
162
- return [key, value];
169
+ return this.#resolveProp(key, value);
163
170
  })
164
171
  )
165
172
  );
@@ -355,16 +362,17 @@ var InertiaMiddleware = class {
355
362
  const { response, request } = ctx;
356
363
  ctx.inertia = new Inertia(ctx, this.config, this.vite);
357
364
  await next();
358
- const isInertiaRequest = !!request.header("x-inertia");
365
+ const isInertiaRequest = !!request.header(InertiaHeaders.Inertia);
359
366
  if (!isInertiaRequest) return;
360
- response.header("Vary", "Accept");
367
+ response.header("Vary", InertiaHeaders.Inertia);
361
368
  const method = request.method();
362
369
  if (response.getStatus() === 302 && ["PUT", "PATCH", "DELETE"].includes(method)) {
363
370
  response.status(303);
364
371
  }
365
372
  const version = this.config.versionCache.getVersion().toString();
366
- if (method === "GET" && request.header("x-inertia-version", "") !== version) {
367
- response.header("x-inertia-location", request.url());
373
+ if (method === "GET" && request.header(InertiaHeaders.Version, "") !== version) {
374
+ response.removeHeader(InertiaHeaders.Inertia);
375
+ response.header(InertiaHeaders.Location, request.url());
368
376
  response.status(409);
369
377
  }
370
378
  }
package/build/config.stub CHANGED
@@ -14,7 +14,7 @@ const inertiaConfig = defineConfig({
14
14
  * Data that should be shared with all rendered pages
15
15
  */
16
16
  sharedData: {
17
- errors: (ctx) => ctx.session?.flashMessages.get('errors'),
17
+ errors: (ctx) => ctx.inertia.always(() => ctx.session?.flashMessages.get('errors')),
18
18
  },
19
19
 
20
20
  /**
package/build/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Configure from '@adonisjs/core/commands/configure';
2
2
  import { ConfigProvider } from '@adonisjs/core/types';
3
- import { S as SharedData, I as InertiaConfig, R as ResolvedConfig } from './types-AyvioK68.js';
3
+ import { S as SharedData, I as InertiaConfig, R as ResolvedConfig } from './types-D6QX_SeH.js';
4
4
  import '@adonisjs/core/http';
5
5
  import '@tuyau/utils/types';
6
6
 
package/build/index.js CHANGED
@@ -198,7 +198,7 @@ var VersionCache = class {
198
198
  async #getManifestHash() {
199
199
  try {
200
200
  const crc32 = await import("crc-32");
201
- const manifestPath = new URL("public/assets/manifest.json", this.appRoot);
201
+ const manifestPath = new URL("public/assets/.vite/manifest.json", this.appRoot);
202
202
  const manifestFile = await readFile(manifestPath, "utf-8");
203
203
  this.#cachedVersion = crc32.default.str(manifestFile);
204
204
  return this.#cachedVersion;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-WLUCTKZW.js";
3
+ } from "../chunk-DLEGZFQ5.js";
4
4
 
5
5
  // providers/inertia_provider.ts
6
6
  import { configProvider } from "@adonisjs/core";
@@ -1,7 +1,7 @@
1
1
  import { Vite } from '@adonisjs/vite';
2
2
  import { HttpContext } from '@adonisjs/core/http';
3
3
  import { NextFn } from '@adonisjs/core/types/http';
4
- import { R as ResolvedConfig, D as Data, P as PageObject, M as MaybePromise, O as OptionalProp, a as MergeProp, A as AlwaysProp, b as DeferProp } from '../types-AyvioK68.js';
4
+ import { R as ResolvedConfig, D as Data, P as PageObject, M as MaybePromise, O as OptionalProp, a as MergeProp, A as AlwaysProp, b as DeferProp } from '../types-D6QX_SeH.js';
5
5
  import '@adonisjs/core/types';
6
6
  import '@tuyau/utils/types';
7
7
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-WLUCTKZW.js";
3
+ } from "../chunk-DLEGZFQ5.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import { PluginFn } from '@japa/runner/types';
2
2
  import { ApplicationService } from '@adonisjs/core/types';
3
- import { c as PageProps } from '../../../types-AyvioK68.js';
3
+ import { c as PageProps } from '../../../types-D6QX_SeH.js';
4
4
  import '@adonisjs/core/http';
5
5
  import '@tuyau/utils/types';
6
6
 
@@ -1,4 +1,4 @@
1
1
  import '@adonisjs/core/types';
2
2
  import '@adonisjs/core/http';
3
3
  import '@tuyau/utils/types';
4
- export { e as AssetsVersion, D as Data, I as InertiaConfig, h as InferPageProps, f as InferSharedProps, M as MaybePromise, P as PageObject, c as PageProps, i as RenderInertiaSsrApp, R as ResolvedConfig, S as SharedData, d as SharedDatumFactory, g as SharedProps } from '../types-AyvioK68.js';
4
+ export { e as AssetsVersion, D as Data, I as InertiaConfig, h as InferPageProps, f as InferSharedProps, M as MaybePromise, P as PageObject, c as PageProps, i as RenderInertiaSsrApp, R as ResolvedConfig, S as SharedData, d as SharedDatumFactory, g as SharedProps } from '../types-D6QX_SeH.js';
@@ -196,9 +196,9 @@ type InferProps<T> = {
196
196
  callback: () => MaybePromise<infer U>;
197
197
  } ? U : T[K];
198
198
  };
199
- type ReturnsTypesSharedData<T extends SharedData> = {} extends T ? {} : {
199
+ type ReturnsTypesSharedData<T extends SharedData> = {} extends T ? {} : InferProps<{
200
200
  [K in keyof T]: T[K] extends (...args: any[]) => MaybePromise<infer U> ? U : T[K];
201
- };
201
+ }>;
202
202
  /**
203
203
  * Infer shared data types from the config provider
204
204
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "2.1.0",
4
+ "version": "2.1.2",
5
5
  "engines": {
6
6
  "node": ">=20.6.0"
7
7
  },