@adonisjs/inertia 1.0.0-0 → 1.0.0-10
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/build/app.css.stub +39 -0
- package/build/chunk-CXICUKHN.js +165 -0
- package/build/{stubs/config.stub → config.stub} +9 -1
- package/build/index.d.ts +18 -3
- package/build/index.js +231 -11
- package/build/providers/inertia_provider.d.ts +12 -12
- package/build/providers/inertia_provider.js +47 -46
- package/build/react/app.tsx.stub +25 -0
- package/build/react/home.tsx.stub +21 -0
- package/build/react/root.edge.stub +22 -0
- package/build/react/ssr.tsx.stub +17 -0
- package/build/react/tsconfig.json.stub +25 -0
- package/build/solid/app.tsx.stub +24 -0
- package/build/solid/home.tsx.stub +21 -0
- package/build/solid/root.edge.stub +21 -0
- package/build/solid/ssr.tsx.stub +19 -0
- package/build/solid/tsconfig.json.stub +26 -0
- package/build/src/helpers.d.ts +12 -0
- package/build/src/helpers.js +14 -0
- package/build/src/inertia_middleware.d.ts +68 -7
- package/build/src/inertia_middleware.js +6 -47
- package/build/src/plugins/edge/plugin.d.ts +8 -0
- package/build/src/plugins/edge/plugin.js +85 -0
- package/build/src/plugins/{api_client.d.ts → japa/api_client.d.ts} +9 -4
- package/build/src/plugins/japa/api_client.js +70 -0
- package/build/src/plugins/vite.d.ts +26 -0
- package/build/src/plugins/vite.js +33 -0
- package/build/src/types.d.ts +72 -8
- package/build/src/types.js +0 -9
- package/build/vue/app.ts.stub +27 -0
- package/build/vue/home.vue.stub +21 -0
- package/build/vue/root.edge.stub +21 -0
- package/build/vue/ssr.ts.stub +22 -0
- package/build/vue/tsconfig.json.stub +26 -0
- package/package.json +64 -47
- package/build/configure.js +0 -82
- package/build/src/debug.d.ts +0 -3
- package/build/src/debug.js +0 -10
- package/build/src/define_config.d.ts +0 -5
- package/build/src/define_config.js +0 -14
- package/build/src/inertia.d.ts +0 -39
- package/build/src/inertia.js +0 -119
- package/build/src/plugins/api_client.js +0 -62
- package/build/src/plugins/edge.d.ts +0 -5
- package/build/src/plugins/edge.js +0 -43
- package/build/src/version_cache.d.ts +0 -27
- package/build/src/version_cache.js +0 -68
- package/build/stubs/main.d.ts +0 -1
- package/build/stubs/main.js +0 -10
- package/providers/inertia_provider.ts +0 -66
- package/src/debug.ts +0 -12
- package/src/define_config.ts +0 -17
- package/src/inertia.ts +0 -140
- package/src/inertia_middleware.ts +0 -54
- package/src/plugins/api_client.ts +0 -127
- package/src/plugins/edge.ts +0 -50
- package/src/types.ts +0 -48
- package/src/version_cache.ts +0 -74
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/views/root.edge') })
|
|
3
|
+
}}}
|
|
4
|
+
<!DOCTYPE html>
|
|
5
|
+
<html>
|
|
6
|
+
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
+
|
|
11
|
+
<title inertia>AdonisJS x Inertia x React</title>
|
|
12
|
+
|
|
13
|
+
@viteReactRefresh()
|
|
14
|
+
@vite(['resources/app.tsx'])
|
|
15
|
+
@inertiaHead()
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
@inertia()
|
|
20
|
+
</body>
|
|
21
|
+
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/ssr.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import ReactDOMServer from 'react-dom/server'
|
|
5
|
+
import { createInertiaApp } from '@inertiajs/react'
|
|
6
|
+
|
|
7
|
+
export default function render(page: any) {
|
|
8
|
+
return createInertiaApp({
|
|
9
|
+
page,
|
|
10
|
+
render: ReactDOMServer.renderToString,
|
|
11
|
+
resolve: (name) => {
|
|
12
|
+
const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
|
|
13
|
+
{{ 'return pages[`./pages/${name}.tsx`]' }}
|
|
14
|
+
},
|
|
15
|
+
setup: ({ App, props }) => <App {...props} />,
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/tsconfig.json') })
|
|
3
|
+
}}}
|
|
4
|
+
{
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
|
|
9
|
+
"useDefineForClassFields": true,
|
|
10
|
+
"baseUrl": ".",
|
|
11
|
+
"module": "ESNext",
|
|
12
|
+
"moduleResolution": "Bundler",
|
|
13
|
+
"paths": {
|
|
14
|
+
"@/*": ["./*"],
|
|
15
|
+
"~/*": ["../*"],
|
|
16
|
+
},
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"types": ["vite/client"],
|
|
19
|
+
"allowSyntheticDefaultImports": true,
|
|
20
|
+
"esModuleInterop": true,
|
|
21
|
+
"verbatimModuleSyntax": true,
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
},
|
|
24
|
+
"include": ["./**/*.ts", "./**/*.tsx"],
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/app.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import './css/app.css'
|
|
5
|
+
|
|
6
|
+
import { render } from 'solid-js/web'
|
|
7
|
+
import { createInertiaApp } from 'inertia-adapter-solid'
|
|
8
|
+
|
|
9
|
+
const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
|
|
10
|
+
|
|
11
|
+
createInertiaApp({
|
|
12
|
+
progress: { color: '#5468FF' },
|
|
13
|
+
|
|
14
|
+
title: (title) => {{ '`${title} - ${appName}`' }},
|
|
15
|
+
|
|
16
|
+
resolve(name) {
|
|
17
|
+
const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
|
|
18
|
+
{{ 'return pages[`./pages/${name}.tsx`]' }}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
setup({ el, App, props }) {
|
|
22
|
+
render(() => <App {...props} />, el)
|
|
23
|
+
},
|
|
24
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/pages/home.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import { Title } from '@solidjs/meta'
|
|
5
|
+
|
|
6
|
+
export default function Home(props: { version: number }) {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Title>Homepage</Title>
|
|
10
|
+
|
|
11
|
+
<div class="container">
|
|
12
|
+
<div class="title">AdonisJS {props.version} x Inertia x Solid.js</div>
|
|
13
|
+
|
|
14
|
+
<span>
|
|
15
|
+
Learn more about AdonisJS and Inertia.js by visiting the{' '}
|
|
16
|
+
<a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
|
|
17
|
+
</span>
|
|
18
|
+
</div>
|
|
19
|
+
</>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/views/root.edge') })
|
|
3
|
+
}}}
|
|
4
|
+
<!DOCTYPE html>
|
|
5
|
+
<html>
|
|
6
|
+
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
+
|
|
11
|
+
<title inertia>AdonisJS x Inertia x SolidJS</title>
|
|
12
|
+
|
|
13
|
+
@vite(['resources/app.tsx'])
|
|
14
|
+
@inertiaHead()
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
@inertia()
|
|
19
|
+
</body>
|
|
20
|
+
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/ssr.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
|
|
5
|
+
import { hydrate } from 'solid-js/web'
|
|
6
|
+
import { createInertiaApp } from 'inertia-adapter-solid'
|
|
7
|
+
|
|
8
|
+
export default function render(page: any) {
|
|
9
|
+
return createInertiaApp({
|
|
10
|
+
page,
|
|
11
|
+
resolve: (name) => {
|
|
12
|
+
const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
|
|
13
|
+
{{ 'return pages[`./pages/${name}.tsx`]' }}
|
|
14
|
+
},
|
|
15
|
+
setup({ el, App, props }) {
|
|
16
|
+
hydrate(() => <App {...props} />, el)
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/tsconfig.json') })
|
|
3
|
+
}}}
|
|
4
|
+
{
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"jsx": "preserve",
|
|
8
|
+
"jsxImportSource": "solid-js",
|
|
9
|
+
"lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
|
|
10
|
+
"useDefineForClassFields": true,
|
|
11
|
+
"baseUrl": ".",
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"moduleResolution": "Bundler",
|
|
14
|
+
"paths": {
|
|
15
|
+
"@/*": ["./*"],
|
|
16
|
+
"~/*": ["../*"],
|
|
17
|
+
},
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"types": ["vite/client"],
|
|
20
|
+
"allowSyntheticDefaultImports": true,
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"verbatimModuleSyntax": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
},
|
|
25
|
+
"include": ["./**/*.ts", "./**/*.tsx"],
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility function to resolve a page component
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* return resolvePageComponent(
|
|
6
|
+
* `./pages/${name}.vue`,
|
|
7
|
+
* import.meta.glob<DefineComponent>("./pages/**\/*.vue")
|
|
8
|
+
* )
|
|
9
|
+
*/
|
|
10
|
+
declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
|
|
11
|
+
|
|
12
|
+
export { resolvePageComponent };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/helpers.ts
|
|
2
|
+
async function resolvePageComponent(path, pages) {
|
|
3
|
+
for (const p of Array.isArray(path) ? path : [path]) {
|
|
4
|
+
const page = pages[p];
|
|
5
|
+
if (typeof page === "undefined") {
|
|
6
|
+
continue;
|
|
7
|
+
}
|
|
8
|
+
return typeof page === "function" ? page() : page;
|
|
9
|
+
}
|
|
10
|
+
throw new Error(`Page not found: ${path}`);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
resolvePageComponent
|
|
14
|
+
};
|
|
@@ -1,12 +1,73 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { Vite } from '@adonisjs/vite';
|
|
2
|
+
import { HttpContext } from '@adonisjs/core/http';
|
|
3
|
+
import { NextFn } from '@adonisjs/core/types/http';
|
|
4
|
+
import { ViteRuntime } from 'vite/runtime';
|
|
5
|
+
import { ResolvedConfig, Data, PageProps, MaybePromise } from './types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Symbol used to identify lazy props
|
|
9
|
+
*/
|
|
10
|
+
declare const kLazySymbol: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* Main class used to interact with Inertia
|
|
13
|
+
*/
|
|
14
|
+
declare class Inertia {
|
|
15
|
+
#private;
|
|
16
|
+
protected ctx: HttpContext;
|
|
17
|
+
protected config: ResolvedConfig;
|
|
18
|
+
protected viteRuntime?: ViteRuntime | undefined;
|
|
19
|
+
constructor(ctx: HttpContext, config: ResolvedConfig, viteRuntime?: ViteRuntime | undefined);
|
|
20
|
+
/**
|
|
21
|
+
* Share data for the current request.
|
|
22
|
+
* This data will override any shared data defined in the config.
|
|
23
|
+
*/
|
|
24
|
+
share(data: Record<string, Data>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Render a page using Inertia
|
|
27
|
+
*/
|
|
28
|
+
render<TPageProps extends Record<string, any> = PageProps, TViewProps extends Record<string, any> = PageProps>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | {
|
|
29
|
+
component: string;
|
|
30
|
+
version: string | number;
|
|
31
|
+
props: any;
|
|
32
|
+
url: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Create a lazy prop
|
|
36
|
+
*
|
|
37
|
+
* Lazy props are never resolved on first visit, but only when the client
|
|
38
|
+
* request a partial reload explicitely with this value.
|
|
39
|
+
*
|
|
40
|
+
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
|
|
41
|
+
*/
|
|
42
|
+
lazy(callback: () => MaybePromise<any>): {
|
|
43
|
+
[kLazySymbol]: () => MaybePromise<any>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* This method can be used to redirect the user to an external website
|
|
47
|
+
* or even a non-inertia route of your application.
|
|
48
|
+
*
|
|
49
|
+
* See https://inertiajs.com/redirects#external-redirects
|
|
50
|
+
*/
|
|
51
|
+
location(url: string): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* HttpContext augmentations
|
|
56
|
+
*/
|
|
57
|
+
declare module '@adonisjs/core/http' {
|
|
58
|
+
interface HttpContext {
|
|
59
|
+
inertia: Inertia;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
4
62
|
/**
|
|
5
63
|
* Inertia middleware to handle the Inertia requests and
|
|
6
64
|
* set appropriate headers/status
|
|
7
65
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
66
|
+
declare class InertiaMiddleware {
|
|
67
|
+
#private;
|
|
68
|
+
protected config: ResolvedConfig;
|
|
69
|
+
constructor(config: ResolvedConfig, vite?: Vite);
|
|
70
|
+
handle(ctx: HttpContext, next: NextFn): Promise<void>;
|
|
12
71
|
}
|
|
72
|
+
|
|
73
|
+
export { InertiaMiddleware as default };
|
|
@@ -1,47 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Inertia middleware to handle the Inertia requests and
|
|
11
|
-
* set appropriate headers/status
|
|
12
|
-
*/
|
|
13
|
-
export default class InertiaMiddleware {
|
|
14
|
-
version;
|
|
15
|
-
constructor(version) {
|
|
16
|
-
this.version = version;
|
|
17
|
-
}
|
|
18
|
-
async handle({ request, response }, next) {
|
|
19
|
-
await next();
|
|
20
|
-
const isInertiaRequest = !!request.header('x-inertia');
|
|
21
|
-
if (!isInertiaRequest)
|
|
22
|
-
return;
|
|
23
|
-
response.header('Vary', 'Accept');
|
|
24
|
-
response.header('X-Inertia', 'true');
|
|
25
|
-
/**
|
|
26
|
-
* When redirecting a PUT/PATCH/DELETE request, we need to change the
|
|
27
|
-
* we must use a 303 status code instead of a 302 to force
|
|
28
|
-
* the browser to use a GET request after redirecting.
|
|
29
|
-
*
|
|
30
|
-
* See https://inertiajs.com/redirects
|
|
31
|
-
*/
|
|
32
|
-
const method = request.method();
|
|
33
|
-
if (response.getStatus() === 302 && ['PUT', 'PATCH', 'DELETE'].includes(method)) {
|
|
34
|
-
response.status(303);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Handle version change
|
|
38
|
-
*
|
|
39
|
-
* See https://inertiajs.com/the-protocol#asset-versioning
|
|
40
|
-
*/
|
|
41
|
-
const version = this.version.getVersion();
|
|
42
|
-
if (method === 'GET' && request.header('x-inertia-version', '') !== version) {
|
|
43
|
-
response.header('x-inertia-location', request.url());
|
|
44
|
-
response.status(409);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
InertiaMiddleware
|
|
3
|
+
} from "../chunk-CXICUKHN.js";
|
|
4
|
+
export {
|
|
5
|
+
InertiaMiddleware as default
|
|
6
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/plugins/edge/plugin.ts
|
|
2
|
+
import { encode } from "html-entities";
|
|
3
|
+
|
|
4
|
+
// src/debug.ts
|
|
5
|
+
import { debuglog } from "node:util";
|
|
6
|
+
var debug_default = debuglog("adonisjs:inertia");
|
|
7
|
+
|
|
8
|
+
// src/plugins/edge/tags.ts
|
|
9
|
+
import { EdgeError } from "edge-error";
|
|
10
|
+
|
|
11
|
+
// src/plugins/edge/utils.ts
|
|
12
|
+
function isSubsetOf(expression, expressions, errorCallback) {
|
|
13
|
+
if (!expressions.includes(expression.type)) {
|
|
14
|
+
errorCallback();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/plugins/edge/tags.ts
|
|
19
|
+
var inertiaTag = {
|
|
20
|
+
block: false,
|
|
21
|
+
tagName: "inertia",
|
|
22
|
+
seekable: true,
|
|
23
|
+
compile(parser, buffer, { filename, loc, properties }) {
|
|
24
|
+
if (properties.jsArg.trim() === "") {
|
|
25
|
+
buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
properties.jsArg = `(${properties.jsArg})`;
|
|
29
|
+
const parsed = parser.utils.transformAst(
|
|
30
|
+
parser.utils.generateAST(properties.jsArg, loc, filename),
|
|
31
|
+
filename,
|
|
32
|
+
parser
|
|
33
|
+
);
|
|
34
|
+
isSubsetOf(parsed, ["ObjectExpression"], () => {
|
|
35
|
+
const { line, col } = parser.utils.getExpressionLoc(parsed);
|
|
36
|
+
throw new EdgeError(
|
|
37
|
+
`"${properties.jsArg}" is not a valid argument for @inertia`,
|
|
38
|
+
"E_UNALLOWED_EXPRESSION",
|
|
39
|
+
{ line, col, filename }
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
const attributes = parser.utils.stringify(parsed);
|
|
43
|
+
buffer.writeExpression(
|
|
44
|
+
`out += state.inertia(state.page, ${attributes})`,
|
|
45
|
+
filename,
|
|
46
|
+
loc.start.line
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var inertiaHeadTag = {
|
|
51
|
+
block: false,
|
|
52
|
+
tagName: "inertiaHead",
|
|
53
|
+
seekable: false,
|
|
54
|
+
compile(_, buffer, { filename, loc }) {
|
|
55
|
+
buffer.writeExpression(`out += state.inertiaHead(state.page)`, filename, loc.start.line);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/plugins/edge/plugin.ts
|
|
60
|
+
var edgePluginInertia = () => {
|
|
61
|
+
return (edge) => {
|
|
62
|
+
debug_default("sharing globals and inertia tags with edge");
|
|
63
|
+
edge.global(
|
|
64
|
+
"inertia",
|
|
65
|
+
(page = {}, attributes = {}) => {
|
|
66
|
+
if (page.ssrBody)
|
|
67
|
+
return page.ssrBody;
|
|
68
|
+
const className = attributes?.class ? ` class="${attributes.class}"` : "";
|
|
69
|
+
const id = attributes?.id ? ` id="${attributes.id}"` : ' id="app"';
|
|
70
|
+
const tag = attributes?.as || "div";
|
|
71
|
+
const dataPage = encode(JSON.stringify(page));
|
|
72
|
+
return `<${tag}${id}${className} data-page="${dataPage}"></${tag}>`;
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
edge.global("inertiaHead", (page) => {
|
|
76
|
+
const { ssrHead = [] } = page || {};
|
|
77
|
+
return ssrHead.join("\n");
|
|
78
|
+
});
|
|
79
|
+
edge.registerTag(inertiaHeadTag);
|
|
80
|
+
edge.registerTag(inertiaTag);
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
edgePluginInertia
|
|
85
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { PluginFn } from '@japa/runner/types';
|
|
2
|
+
import { ApplicationService } from '@adonisjs/core/types';
|
|
3
|
+
import { PageProps } from '../../types.js';
|
|
4
|
+
import '@adonisjs/core/http';
|
|
5
|
+
|
|
3
6
|
declare module '@japa/api-client' {
|
|
4
7
|
interface ApiRequest {
|
|
5
8
|
/**
|
|
@@ -19,7 +22,7 @@ declare module '@japa/api-client' {
|
|
|
19
22
|
/**
|
|
20
23
|
* The inertia response props
|
|
21
24
|
*/
|
|
22
|
-
inertiaProps:
|
|
25
|
+
inertiaProps: Record<string, any>;
|
|
23
26
|
/**
|
|
24
27
|
* Assert component name of inertia response
|
|
25
28
|
*/
|
|
@@ -34,4 +37,6 @@ declare module '@japa/api-client' {
|
|
|
34
37
|
assertInertiaPropsContains(props: PageProps): this;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
|
|
40
|
+
declare function inertiaApiClient(app: ApplicationService): PluginFn;
|
|
41
|
+
|
|
42
|
+
export { inertiaApiClient };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/plugins/japa/api_client.ts
|
|
2
|
+
import { configProvider } from "@adonisjs/core";
|
|
3
|
+
import { RuntimeException } from "@poppinss/utils";
|
|
4
|
+
import { ApiRequest, ApiResponse } from "@japa/api-client";
|
|
5
|
+
function ensureIsInertiaResponse() {
|
|
6
|
+
if (!this.header("x-inertia")) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"Response is not an Inertia response. Make sure to call `withInertia()` on the request"
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function inertiaApiClient(app) {
|
|
13
|
+
return async () => {
|
|
14
|
+
const inertiaConfigProvider = app.config.get("inertia");
|
|
15
|
+
const config = await configProvider.resolve(app, inertiaConfigProvider);
|
|
16
|
+
if (!config) {
|
|
17
|
+
throw new RuntimeException(
|
|
18
|
+
'Invalid "config/inertia.ts" file. Make sure you are using the "defineConfig" method'
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
ApiRequest.macro("withInertia", function() {
|
|
22
|
+
this.header("x-inertia", "true");
|
|
23
|
+
this.header("x-inertia-version", config.versionCache.getVersion().toString());
|
|
24
|
+
return this;
|
|
25
|
+
});
|
|
26
|
+
ApiRequest.macro(
|
|
27
|
+
"withInertiaPartialReload",
|
|
28
|
+
function(component, data) {
|
|
29
|
+
this.withInertia();
|
|
30
|
+
this.header("X-Inertia-Partial-Data", data.join(","));
|
|
31
|
+
this.header("X-Inertia-Partial-Component", component);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
ApiResponse.getter("inertiaComponent", function() {
|
|
36
|
+
ensureIsInertiaResponse.call(this);
|
|
37
|
+
return this.body().component;
|
|
38
|
+
});
|
|
39
|
+
ApiResponse.getter("inertiaProps", function() {
|
|
40
|
+
ensureIsInertiaResponse.call(this);
|
|
41
|
+
return this.body().props;
|
|
42
|
+
});
|
|
43
|
+
ApiResponse.macro("assertInertiaComponent", function(component) {
|
|
44
|
+
ensureIsInertiaResponse.call(this);
|
|
45
|
+
this.assert.deepEqual(this.body().component, component);
|
|
46
|
+
return this;
|
|
47
|
+
});
|
|
48
|
+
ApiResponse.macro(
|
|
49
|
+
"assertInertiaProps",
|
|
50
|
+
function(props) {
|
|
51
|
+
this.ensureHasAssert();
|
|
52
|
+
ensureIsInertiaResponse.call(this);
|
|
53
|
+
this.assert.deepEqual(this.body().props, props);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
ApiResponse.macro(
|
|
58
|
+
"assertInertiaPropsContains",
|
|
59
|
+
function(props) {
|
|
60
|
+
this.ensureHasAssert();
|
|
61
|
+
ensureIsInertiaResponse.call(this);
|
|
62
|
+
this.assert.containsSubset(this.body().props, props);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
inertiaApiClient
|
|
70
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
|
|
3
|
+
type InertiaPluginOptions = {
|
|
4
|
+
ssr?: {
|
|
5
|
+
/**
|
|
6
|
+
* Whether or not to enable server-side rendering
|
|
7
|
+
*/
|
|
8
|
+
enabled: true;
|
|
9
|
+
/**
|
|
10
|
+
* The entrypoint for the server-side rendering
|
|
11
|
+
*/
|
|
12
|
+
entrypoint: string;
|
|
13
|
+
/**
|
|
14
|
+
* The output directory for the server-side rendering bundle
|
|
15
|
+
*/
|
|
16
|
+
output?: string;
|
|
17
|
+
} | {
|
|
18
|
+
enabled: false;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Inertia plugin for Vite that is tailored for AdonisJS
|
|
23
|
+
*/
|
|
24
|
+
declare function inertia(options?: InertiaPluginOptions): PluginOption;
|
|
25
|
+
|
|
26
|
+
export { type InertiaPluginOptions, inertia as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/plugins/vite.ts
|
|
2
|
+
function inertia(options) {
|
|
3
|
+
return {
|
|
4
|
+
name: "vite-plugin-inertia",
|
|
5
|
+
config: () => {
|
|
6
|
+
if (!options?.ssr?.enabled)
|
|
7
|
+
return {};
|
|
8
|
+
return {
|
|
9
|
+
buildSteps: [
|
|
10
|
+
{
|
|
11
|
+
name: "build-client",
|
|
12
|
+
description: "build inertia client bundle",
|
|
13
|
+
config: { build: { outDir: "build/public/assets/" } }
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "build-ssr",
|
|
17
|
+
description: "build inertia server bundle",
|
|
18
|
+
config: {
|
|
19
|
+
build: {
|
|
20
|
+
ssr: true,
|
|
21
|
+
outDir: options.ssr.output || "build/ssr",
|
|
22
|
+
rollupOptions: { input: options.ssr.entrypoint }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
inertia as default
|
|
33
|
+
};
|