@adonisjs/inertia 2.1.1 → 2.1.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.
@@ -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
  );
package/build/config.stub CHANGED
@@ -2,7 +2,7 @@
2
2
  exports({ to: app.configPath('inertia.ts') })
3
3
  }}}
4
4
  import { defineConfig } from '@adonisjs/inertia'
5
- import type { InferSharedProps } from '@adonisjs/inertia/types'
5
+ import type { InferSharedProps, PageProps } from '@adonisjs/inertia/types'
6
6
 
7
7
  const inertiaConfig = defineConfig({
8
8
  /**
@@ -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
  /**
@@ -29,5 +29,5 @@ const inertiaConfig = defineConfig({
29
29
  export default inertiaConfig
30
30
 
31
31
  declare module '@adonisjs/inertia/types' {
32
- export interface SharedProps extends InferSharedProps<typeof inertiaConfig> {}
32
+ export interface SharedProps extends InferSharedProps<typeof inertiaConfig>, PageProps {}
33
33
  }
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
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-3SVIWNBM.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-3SVIWNBM.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';
@@ -8,6 +8,7 @@ import '../css/app.css';
8
8
 
9
9
  import { createInertiaApp } from '@inertiajs/svelte'
10
10
  import { resolvePageComponent } from '@adonisjs/inertia/helpers'
11
+ import { hydrate, mount } from 'svelte'
11
12
 
12
13
  const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
13
14
 
@@ -24,10 +25,10 @@ createInertiaApp({
24
25
  },
25
26
 
26
27
  setup({ el, App, props }) {
27
- {{#if ssr}}
28
- new App({ target: el, props, hydrate: true })
29
- {{#else}}
30
- new App({ target: el, props })
31
- {{/if}}
28
+ if (el.dataset.serverRendered === 'true') {
29
+ hydrate(App, { target: el, props })
30
+ } else {
31
+ mount(App, { target: el, props })
32
+ }
32
33
  },
33
34
  })
@@ -3,6 +3,7 @@
3
3
  }}}
4
4
 
5
5
  import { createInertiaApp } from '@inertiajs/svelte'
6
+ import { render as svelteRender } from 'svelte/server'
6
7
 
7
8
  export default function render(page: any) {
8
9
  return createInertiaApp({
@@ -10,6 +11,9 @@ export default function render(page: any) {
10
11
  resolve: (name) => {
11
12
  const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
12
13
  {{ 'return pages[`../pages/${name}.svelte`]' }}
13
- }
14
+ },
15
+ setup({ el, App, props }) {
16
+ return svelteRender(App, { props })
17
+ },
14
18
  })
15
19
  }
@@ -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.1",
4
+ "version": "2.1.3",
5
5
  "engines": {
6
6
  "node": ">=20.6.0"
7
7
  },