@adonisjs/inertia 4.0.0-next.10 → 4.0.0-next.12
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/debug-CBMTuPUm.js +3 -0
- package/build/factories/main.js +59 -172
- package/build/headers-DafWEpBh.js +11 -0
- package/build/index.js +5 -24
- package/build/inertia-D5A2KtfR.js +57 -0
- package/build/inertia_manager-Di3J3hSG.js +403 -0
- package/build/providers/inertia_provider.js +25 -79
- package/build/src/client/helpers.js +11 -28
- package/build/src/client/react/context.d.ts +3 -3
- package/build/src/client/react/index.js +20 -63
- package/build/src/client/react/link.d.ts +10 -9
- package/build/src/client/react/router.d.ts +2 -2
- package/build/src/client/vite.js +16 -29
- package/build/src/inertia_middleware.js +45 -111
- package/build/src/plugins/edge/plugin.js +49 -81
- package/build/src/plugins/japa/api_client.js +44 -59
- package/build/src/types.d.ts +14 -21
- package/build/src/types.js +1 -0
- package/build/tests/types/react.spec.d.ts +58 -55
- package/package.json +17 -14
- package/build/chunk-4EZ2J6OA.js +0 -7
- package/build/chunk-5QRJHXXQ.js +0 -91
- package/build/chunk-DISC5OYC.js +0 -46
- package/build/chunk-MLKGABMK.js +0 -9
- package/build/chunk-YQ72YL64.js +0 -813
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { UserRegistry } from '@tuyau/core/types';
|
|
3
|
-
import { Link as InertiaLink } from '@inertiajs/react';
|
|
2
|
+
import type { UserRegistry, InferRoutes } from '@tuyau/core/types';
|
|
4
3
|
import { AreAllOptional } from '@poppinss/utils/types';
|
|
4
|
+
import { Link as InertiaLink } from '@inertiajs/react';
|
|
5
|
+
type Routes = InferRoutes<UserRegistry>;
|
|
5
6
|
/**
|
|
6
7
|
* Get parameter tuple type for a route
|
|
7
8
|
*/
|
|
8
|
-
type ExtractParamsTuple<Route extends keyof
|
|
9
|
+
type ExtractParamsTuple<Route extends keyof Routes> = Routes[Route]['types']['paramsTuple'];
|
|
9
10
|
/**
|
|
10
11
|
* Get parameter object type for a route
|
|
11
12
|
*/
|
|
12
|
-
type ExtractParamsObject<Route extends keyof
|
|
13
|
+
type ExtractParamsObject<Route extends keyof Routes> = Routes[Route]['types']['params'];
|
|
13
14
|
/**
|
|
14
15
|
* Get params format for a route
|
|
15
16
|
*/
|
|
16
|
-
type RouteParamsFormats<Route extends keyof
|
|
17
|
+
type RouteParamsFormats<Route extends keyof Routes> = ExtractParamsObject<Route> extends Record<string, never> ? never : ExtractParamsTuple<Route> | ExtractParamsObject<Route>;
|
|
17
18
|
/**
|
|
18
19
|
* Parameters required for route navigation with proper type safety.
|
|
19
20
|
*/
|
|
20
|
-
export type LinkParams<Route extends keyof
|
|
21
|
+
export type LinkParams<Route extends keyof Routes> = {
|
|
21
22
|
route: Route;
|
|
22
23
|
} & (RouteParamsFormats<Route> extends never ? {
|
|
23
24
|
params?: never;
|
|
@@ -30,7 +31,7 @@ export type LinkParams<Route extends keyof UserRegistry> = {
|
|
|
30
31
|
* Props for the Link component extending InertiaLink props
|
|
31
32
|
* with route-specific type safety and parameter validation.
|
|
32
33
|
*/
|
|
33
|
-
type LinkProps<Route extends keyof
|
|
34
|
+
type LinkProps<Route extends keyof Routes> = Omit<React.ComponentPropsWithoutRef<typeof InertiaLink>, 'href' | 'method'> & LinkParams<Route>;
|
|
34
35
|
/**
|
|
35
36
|
* Internal Link component implementation with forward ref support.
|
|
36
37
|
* Resolves route parameters and generates the appropriate URL and HTTP method
|
|
@@ -39,7 +40,7 @@ type LinkProps<Route extends keyof UserRegistry> = Omit<React.ComponentPropsWith
|
|
|
39
40
|
* @param props - Link properties including route and parameters
|
|
40
41
|
* @param ref - Forward ref for the underlying InertiaLink component
|
|
41
42
|
*/
|
|
42
|
-
declare function LinkInner<Route extends keyof
|
|
43
|
+
declare function LinkInner<Route extends keyof Routes>(props: LinkProps<Route>, ref?: React.ForwardedRef<React.ElementRef<typeof InertiaLink>>): React.JSX.Element;
|
|
43
44
|
/**
|
|
44
45
|
* Type-safe Link component for Inertia.js navigation.
|
|
45
46
|
*
|
|
@@ -58,7 +59,7 @@ declare function LinkInner<Route extends keyof UserRegistry>(props: LinkProps<Ro
|
|
|
58
59
|
* </Link>
|
|
59
60
|
* ```
|
|
60
61
|
*/
|
|
61
|
-
export declare const Link: <Route extends keyof
|
|
62
|
+
export declare const Link: <Route extends keyof Routes>(props: LinkProps<Route> & {
|
|
62
63
|
ref?: React.Ref<React.ElementRef<typeof InertiaLink>>;
|
|
63
64
|
}) => ReturnType<typeof LinkInner>;
|
|
64
65
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UserRegistry } from '@tuyau/core/types';
|
|
1
|
+
import type { UserRegistry, InferRoutes } from '@tuyau/core/types';
|
|
2
2
|
import { router as InertiaRouter } from '@inertiajs/react';
|
|
3
3
|
import type { LinkParams } from './link.tsx';
|
|
4
4
|
/**
|
|
@@ -29,5 +29,5 @@ export declare function useRouter(): {
|
|
|
29
29
|
* router.visit({ route: 'user.edit', params: { id: userId } })
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
visit: <Route extends keyof UserRegistry
|
|
32
|
+
visit: <Route extends keyof InferRoutes<UserRegistry>>(props: LinkParams<Route>, options?: Parameters<typeof InertiaRouter.visit>[1]) => any;
|
|
33
33
|
};
|
package/build/src/client/vite.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
import "../../chunk-MLKGABMK.js";
|
|
2
|
-
|
|
3
|
-
// src/client/vite.ts
|
|
4
1
|
function inertia(options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
rollupOptions: { input: options.ssr.entrypoint }
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
};
|
|
2
|
+
return {
|
|
3
|
+
name: "vite-plugin-inertia",
|
|
4
|
+
config: (_, { command }) => {
|
|
5
|
+
if (command === "build") process.env.NODE_ENV = "production";
|
|
6
|
+
return {
|
|
7
|
+
builder: {},
|
|
8
|
+
build: { outDir: "build/public/assets" },
|
|
9
|
+
environments: { ...options?.ssr?.enabled && { ssr: { build: {
|
|
10
|
+
ssr: true,
|
|
11
|
+
outDir: options.ssr.output || "build/ssr",
|
|
12
|
+
rollupOptions: { input: options.ssr.entrypoint }
|
|
13
|
+
} } } }
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
28
17
|
}
|
|
29
|
-
export {
|
|
30
|
-
inertia as default
|
|
31
|
-
};
|
|
18
|
+
export { inertia as default };
|
|
@@ -1,113 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "../
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "../chunk-DISC5OYC.js";
|
|
10
|
-
import "../chunk-MLKGABMK.js";
|
|
11
|
-
|
|
12
|
-
// src/inertia_middleware.ts
|
|
13
|
-
var MUTATION_METHODS = ["PUT", "PATCH", "DELETE"];
|
|
1
|
+
import { t as InertiaManager } from "../inertia_manager-Di3J3hSG.js";
|
|
2
|
+
import { t as InertiaHeaders } from "../headers-DafWEpBh.js";
|
|
3
|
+
import { t as debug_default } from "../debug-CBMTuPUm.js";
|
|
4
|
+
const MUTATION_METHODS = [
|
|
5
|
+
"PUT",
|
|
6
|
+
"PATCH",
|
|
7
|
+
"DELETE"
|
|
8
|
+
];
|
|
14
9
|
var BaseInertiaMiddleware = class {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* Initialize the Inertia instance for the current request
|
|
52
|
-
*
|
|
53
|
-
* This method creates an Inertia instance and attaches it to the
|
|
54
|
-
* HTTP context, making it available throughout the request lifecycle.
|
|
55
|
-
*
|
|
56
|
-
* @param ctx - The HTTP context object
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* await middleware.init(ctx)
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
async init(ctx) {
|
|
64
|
-
debug_default("initiating inertia");
|
|
65
|
-
const inertiaContainer = await ctx.containerResolver.make(InertiaManager);
|
|
66
|
-
ctx.inertia = inertiaContainer.createForRequest(ctx);
|
|
67
|
-
if (this.share) {
|
|
68
|
-
ctx.inertia.share(() => this.share(ctx));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Clean up and finalize the Inertia response
|
|
73
|
-
*
|
|
74
|
-
* This method handles the final processing of Inertia requests including:
|
|
75
|
-
* - Setting appropriate response headers
|
|
76
|
-
* - Handling redirects for mutation methods (PUT/PATCH/DELETE)
|
|
77
|
-
* - Managing asset versioning conflicts
|
|
78
|
-
*
|
|
79
|
-
* @param ctx - The HTTP context object
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```ts
|
|
83
|
-
* await middleware.dispose(ctx)
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
dispose(ctx) {
|
|
87
|
-
const requestInfo = ctx.inertia.requestInfo();
|
|
88
|
-
if (!requestInfo.isInertiaRequest) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
debug_default("disposing as inertia request");
|
|
92
|
-
ctx.response.header("Vary", InertiaHeaders.Inertia);
|
|
93
|
-
const method = ctx.request.method();
|
|
94
|
-
if (ctx.response.getStatus() === 302 && MUTATION_METHODS.includes(method)) {
|
|
95
|
-
debug_default("upgrading response status from 302 to 303");
|
|
96
|
-
ctx.response.status(303);
|
|
97
|
-
}
|
|
98
|
-
const version = ctx.inertia.getVersion();
|
|
99
|
-
const clientVersion = requestInfo.version ?? "";
|
|
100
|
-
if (method === "GET" && clientVersion !== version) {
|
|
101
|
-
debug_default("version mis-match. Reloading page");
|
|
102
|
-
if (ctx.session) {
|
|
103
|
-
ctx.session.reflash();
|
|
104
|
-
}
|
|
105
|
-
ctx.response.removeHeader(InertiaHeaders.Inertia);
|
|
106
|
-
ctx.response.header(InertiaHeaders.Location, ctx.request.url(true));
|
|
107
|
-
ctx.response.status(409);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
export {
|
|
112
|
-
BaseInertiaMiddleware as default
|
|
10
|
+
getValidationErrors(ctx) {
|
|
11
|
+
if (!ctx.session) return {};
|
|
12
|
+
const inputErrors = ctx.session.flashMessages.get("inputErrorsBag", {});
|
|
13
|
+
const errors = Object.entries(inputErrors).reduce((result, [field, messages]) => {
|
|
14
|
+
result[field] = Array.isArray(messages) ? messages[0] : messages;
|
|
15
|
+
return result;
|
|
16
|
+
}, {});
|
|
17
|
+
const errorBag = ctx.request.header(InertiaHeaders.ErrorBag);
|
|
18
|
+
if (errorBag) return { [errorBag]: errors };
|
|
19
|
+
return errors;
|
|
20
|
+
}
|
|
21
|
+
async init(ctx) {
|
|
22
|
+
debug_default("initiating inertia");
|
|
23
|
+
ctx.inertia = (await ctx.containerResolver.make(InertiaManager)).createForRequest(ctx);
|
|
24
|
+
if (this.share) ctx.inertia.share(() => this.share(ctx));
|
|
25
|
+
}
|
|
26
|
+
dispose(ctx) {
|
|
27
|
+
const requestInfo = ctx.inertia.requestInfo();
|
|
28
|
+
if (!requestInfo.isInertiaRequest) return;
|
|
29
|
+
debug_default("disposing as inertia request");
|
|
30
|
+
ctx.response.header("Vary", InertiaHeaders.Inertia);
|
|
31
|
+
const method = ctx.request.method();
|
|
32
|
+
if (ctx.response.getStatus() === 302 && MUTATION_METHODS.includes(method)) {
|
|
33
|
+
debug_default("upgrading response status from 302 to 303");
|
|
34
|
+
ctx.response.status(303);
|
|
35
|
+
}
|
|
36
|
+
const version = ctx.inertia.getVersion();
|
|
37
|
+
const clientVersion = requestInfo.version ?? "";
|
|
38
|
+
if (method === "GET" && clientVersion !== version) {
|
|
39
|
+
debug_default("version mis-match. Reloading page");
|
|
40
|
+
if (ctx.session) ctx.session.reflash();
|
|
41
|
+
ctx.response.removeHeader(InertiaHeaders.Inertia);
|
|
42
|
+
ctx.response.header(InertiaHeaders.Location, ctx.request.url(true));
|
|
43
|
+
ctx.response.status(409);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
113
46
|
};
|
|
47
|
+
export { BaseInertiaMiddleware as default };
|
|
@@ -1,88 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
debug_default
|
|
3
|
-
} from "../../../chunk-4EZ2J6OA.js";
|
|
4
|
-
import "../../../chunk-MLKGABMK.js";
|
|
5
|
-
|
|
6
|
-
// src/plugins/edge/plugin.ts
|
|
1
|
+
import { t as debug_default } from "../../../debug-CBMTuPUm.js";
|
|
7
2
|
import { encode } from "html-entities";
|
|
8
|
-
|
|
9
|
-
// src/plugins/edge/tags.ts
|
|
10
3
|
import { EdgeError } from "edge-error";
|
|
11
|
-
|
|
12
|
-
// src/plugins/edge/utils.ts
|
|
13
4
|
function isSubsetOf(expression, expressions, errorCallback) {
|
|
14
|
-
|
|
15
|
-
errorCallback();
|
|
16
|
-
}
|
|
5
|
+
if (!expressions.includes(expression.type)) errorCallback();
|
|
17
6
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{ line, col, filename }
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
const attributes = parser.utils.stringify(parsed);
|
|
44
|
-
buffer.outputExpression(
|
|
45
|
-
`state.inertia(state.page, ${attributes})`,
|
|
46
|
-
filename,
|
|
47
|
-
loc.start.line,
|
|
48
|
-
false
|
|
49
|
-
);
|
|
50
|
-
}
|
|
7
|
+
const inertiaTag = {
|
|
8
|
+
block: false,
|
|
9
|
+
tagName: "inertia",
|
|
10
|
+
seekable: true,
|
|
11
|
+
compile(parser, buffer, { filename, loc, properties }) {
|
|
12
|
+
if (properties.jsArg.trim() === "") {
|
|
13
|
+
buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
properties.jsArg = `(${properties.jsArg})`;
|
|
17
|
+
const parsed = parser.utils.transformAst(parser.utils.generateAST(properties.jsArg, loc, filename), filename, parser);
|
|
18
|
+
isSubsetOf(parsed, ["ObjectExpression"], () => {
|
|
19
|
+
const { line, col } = parser.utils.getExpressionLoc(parsed);
|
|
20
|
+
throw new EdgeError(`"${properties.jsArg}" is not a valid argument for @inertia`, "E_UNALLOWED_EXPRESSION", {
|
|
21
|
+
line,
|
|
22
|
+
col,
|
|
23
|
+
filename
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
const attributes = parser.utils.stringify(parsed);
|
|
27
|
+
buffer.outputExpression(`state.inertia(state.page, ${attributes})`, filename, loc.start.line, false);
|
|
28
|
+
}
|
|
51
29
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
30
|
+
const inertiaHeadTag = {
|
|
31
|
+
block: false,
|
|
32
|
+
tagName: "inertiaHead",
|
|
33
|
+
seekable: false,
|
|
34
|
+
compile(_, buffer, { filename, loc }) {
|
|
35
|
+
buffer.outputExpression("state.inertiaHead(state.page)", filename, loc.start.line, false);
|
|
36
|
+
}
|
|
59
37
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
78
|
-
edge.global("inertiaHead", (page) => {
|
|
79
|
-
const { ssrHead = [] } = page || {};
|
|
80
|
-
return ssrHead.join("\n");
|
|
81
|
-
});
|
|
82
|
-
edge.registerTag(inertiaHeadTag);
|
|
83
|
-
edge.registerTag(inertiaTag);
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
export {
|
|
87
|
-
edgePluginInertia
|
|
38
|
+
const edgePluginInertia = () => {
|
|
39
|
+
return (edge) => {
|
|
40
|
+
debug_default("sharing globals and inertia tags with edge");
|
|
41
|
+
edge.global("inertia", (page = {}, attributes = {}) => {
|
|
42
|
+
if (page.ssrBody) return page.ssrBody;
|
|
43
|
+
const className = attributes?.class ? ` class="${attributes.class}"` : "";
|
|
44
|
+
const id = attributes?.id ? ` id="${attributes.id}"` : " id=\"app\"";
|
|
45
|
+
const tag = attributes?.as || "div";
|
|
46
|
+
return `<${tag}${id}${className} data-page="${encode(JSON.stringify(page))}"></${tag}>`;
|
|
47
|
+
});
|
|
48
|
+
edge.global("inertiaHead", (page) => {
|
|
49
|
+
const { ssrHead = [] } = page || {};
|
|
50
|
+
return ssrHead.join("\n");
|
|
51
|
+
});
|
|
52
|
+
edge.registerTag(inertiaHeadTag);
|
|
53
|
+
edge.registerTag(inertiaTag);
|
|
54
|
+
};
|
|
88
55
|
};
|
|
56
|
+
export { edgePluginInertia };
|
|
@@ -1,66 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InertiaHeaders
|
|
3
|
-
} from "../../../chunk-DISC5OYC.js";
|
|
4
|
-
import "../../../chunk-MLKGABMK.js";
|
|
5
|
-
|
|
6
|
-
// src/plugins/japa/api_client.ts
|
|
1
|
+
import { t as InertiaHeaders } from "../../../headers-DafWEpBh.js";
|
|
7
2
|
import { ApiRequest, ApiResponse } from "@japa/api-client";
|
|
8
3
|
function ensureIsInertiaResponse() {
|
|
9
|
-
|
|
10
|
-
throw new Error(
|
|
11
|
-
'Not an Inertia response. Make sure to use "withInertia()" method when making the request'
|
|
12
|
-
);
|
|
13
|
-
}
|
|
4
|
+
if (!this.header("x-inertia")) throw new Error("Not an Inertia response. Make sure to use \"withInertia()\" method when making the request");
|
|
14
5
|
}
|
|
15
6
|
function ensureHasAssert(assertLib) {
|
|
16
|
-
|
|
17
|
-
throw new Error(
|
|
18
|
-
"Response assertions are not available. Make sure to install the @japa/assert plugin"
|
|
19
|
-
);
|
|
20
|
-
}
|
|
7
|
+
if (!assertLib) throw new Error("Response assertions are not available. Make sure to install the @japa/assert plugin");
|
|
21
8
|
}
|
|
22
9
|
function inertiaApiClient(app) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
10
|
+
return async () => {
|
|
11
|
+
const inertiaConfig = app.config.get("inertia");
|
|
12
|
+
ApiRequest.macro("withInertia", function() {
|
|
13
|
+
this.header(InertiaHeaders.Inertia, "true");
|
|
14
|
+
this.header(InertiaHeaders.Version, String(inertiaConfig.assetsVersion ?? "1"));
|
|
15
|
+
return this;
|
|
16
|
+
});
|
|
17
|
+
ApiRequest.macro("withInertiaPartialReload", function(component, data) {
|
|
18
|
+
this.withInertia();
|
|
19
|
+
this.header(InertiaHeaders.PartialComponent, component);
|
|
20
|
+
this.header(InertiaHeaders.PartialOnly, data.join(","));
|
|
21
|
+
return this;
|
|
22
|
+
});
|
|
23
|
+
ApiResponse.getter("inertiaComponent", function() {
|
|
24
|
+
ensureIsInertiaResponse.call(this);
|
|
25
|
+
return this.body().component;
|
|
26
|
+
});
|
|
27
|
+
ApiResponse.getter("inertiaProps", function() {
|
|
28
|
+
ensureIsInertiaResponse.call(this);
|
|
29
|
+
return this.body().props;
|
|
30
|
+
});
|
|
31
|
+
ApiResponse.macro("assertInertiaComponent", function(component) {
|
|
32
|
+
ensureIsInertiaResponse.call(this);
|
|
33
|
+
ensureHasAssert(this.assert);
|
|
34
|
+
this.assert.equal(this.body().component, component);
|
|
35
|
+
return this;
|
|
36
|
+
});
|
|
37
|
+
ApiResponse.macro("assertInertiaProps", function(props) {
|
|
38
|
+
ensureIsInertiaResponse.call(this);
|
|
39
|
+
ensureHasAssert(this.assert);
|
|
40
|
+
this.assert.deepEqual(this.body().props, props);
|
|
41
|
+
return this;
|
|
42
|
+
});
|
|
43
|
+
ApiResponse.macro("assertInertiaPropsContains", function(props) {
|
|
44
|
+
ensureIsInertiaResponse.call(this);
|
|
45
|
+
ensureHasAssert(this.assert);
|
|
46
|
+
this.assert.containSubset(this.body().props, props);
|
|
47
|
+
return this;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
63
50
|
}
|
|
64
|
-
export {
|
|
65
|
-
inertiaApiClient
|
|
66
|
-
};
|
|
51
|
+
export { inertiaApiClient };
|
package/build/src/types.d.ts
CHANGED
|
@@ -4,34 +4,27 @@ import type { JSONDataTypes } from '@adonisjs/core/types/transformers';
|
|
|
4
4
|
import type { AsyncOrSync, DeepPartial, Prettify } from '@adonisjs/core/types/common';
|
|
5
5
|
import { type DEEP_MERGE, type ALWAYS_PROP, type OPTIONAL_PROP, type TO_BE_MERGED, type DEFERRED_PROP } from './symbols.ts';
|
|
6
6
|
/**
|
|
7
|
-
* Representation of a resource item, collection and paginator that can be
|
|
7
|
+
* Representation of a resource item, collection and paginator that can be resolved to
|
|
8
|
+
* get normalized objects
|
|
8
9
|
*
|
|
9
|
-
* @template T - The type that the
|
|
10
|
+
* @template T - The type that the resource resolves to
|
|
10
11
|
*/
|
|
11
|
-
export type
|
|
12
|
-
|
|
13
|
-
* Serializes the object using the container resolver
|
|
14
|
-
*
|
|
15
|
-
* @param container - The container resolver instance
|
|
16
|
-
* @param depth - Current serialization depth
|
|
17
|
-
* @param maxDepth - Maximum allowed serialization depth
|
|
18
|
-
* @returns Promise that resolves to the serialized object
|
|
19
|
-
*/
|
|
20
|
-
serialize(container: ContainerResolver<any>, depth: number, maxDepth?: number): Promise<T>;
|
|
12
|
+
export type ResolvableOf<T> = {
|
|
13
|
+
resolve(container: ContainerResolver<any>, depth: number, maxDepth?: number): Promise<T>;
|
|
21
14
|
};
|
|
22
15
|
/**
|
|
23
16
|
* Union type representing unpacked page prop values that can be either JSON data or serializable objects
|
|
24
17
|
*
|
|
25
18
|
* @template T - The JSON data type, defaults to JSONDataTypes
|
|
26
19
|
*/
|
|
27
|
-
export type UnPackedPageProps<T extends JSONDataTypes = JSONDataTypes> = T |
|
|
20
|
+
export type UnPackedPageProps<T extends JSONDataTypes = JSONDataTypes> = T | ResolvableOf<T>;
|
|
28
21
|
/**
|
|
29
22
|
* Utility type that extracts the resolved type from a SerializableOf wrapper
|
|
30
23
|
* If the type is already unwrapped, returns it as-is
|
|
31
24
|
*
|
|
32
25
|
* @template T - The type to unwrap, potentially wrapped in SerializableOf
|
|
33
26
|
*/
|
|
34
|
-
export type UnpackProp<T> = T extends
|
|
27
|
+
export type UnpackProp<T> = T extends ResolvableOf<infer A> ? A : T;
|
|
35
28
|
/**
|
|
36
29
|
* Information extracted from Inertia request headers
|
|
37
30
|
* Contains metadata about the current request type and filtering preferences
|
|
@@ -117,13 +110,13 @@ type PagePropsLazyDataTypes<T extends JSONDataTypes> =
|
|
|
117
110
|
* - Can be explicitly requested for
|
|
118
111
|
* - Can be dropped during cherry-picking
|
|
119
112
|
*/
|
|
120
|
-
DeferProp<T |
|
|
113
|
+
DeferProp<T | ResolvableOf<T>>
|
|
121
114
|
/**
|
|
122
115
|
* - Never included on standard visit
|
|
123
116
|
* - Can be explicitly requested for
|
|
124
117
|
* - Can be dropped during cherry-picking
|
|
125
118
|
*/
|
|
126
|
-
| OptionalProp<T |
|
|
119
|
+
| OptionalProp<T | ResolvableOf<T>>;
|
|
127
120
|
/**
|
|
128
121
|
* Eager props are always included during standard Inertia visits, but
|
|
129
122
|
* can be removed via cherry-picking when only specific props are requested
|
|
@@ -140,17 +133,17 @@ T
|
|
|
140
133
|
* - Always included on standard visit.
|
|
141
134
|
* - Can be dropped during cherry-picking
|
|
142
135
|
*/
|
|
143
|
-
|
|
|
136
|
+
| ResolvableOf<T>
|
|
144
137
|
/**
|
|
145
138
|
* - Always included on standard visit.
|
|
146
139
|
* - Can be dropped during cherry-picking
|
|
147
140
|
*/
|
|
148
|
-
| (() => AsyncOrSync<T |
|
|
141
|
+
| (() => AsyncOrSync<T | ResolvableOf<T>>)
|
|
149
142
|
/**
|
|
150
143
|
* - Always included on standard visit
|
|
151
144
|
* - Cannot be dropped during cherry-picking
|
|
152
145
|
*/
|
|
153
|
-
| AlwaysProp<T |
|
|
146
|
+
| AlwaysProp<T | ResolvableOf<T>>;
|
|
154
147
|
/**
|
|
155
148
|
* Following is the list of acceptable Page props data types
|
|
156
149
|
* Combines both eager and lazy prop data types for comprehensive prop handling
|
|
@@ -175,7 +168,7 @@ export type ComponentProps = Record<string, JSONDataTypes>;
|
|
|
175
168
|
* @template Props - The page props object type to analyze
|
|
176
169
|
*/
|
|
177
170
|
export type GetOptionalProps<Props> = {
|
|
178
|
-
[K in keyof Props]: Props[K] extends OptionalProp<any> ? K : Props[K] extends DeferProp<any> ? K : [undefined] extends Props[K] ? K : Props[K] extends MergeableProp<infer A> ? A extends DeferProp<any> ? K : never : never;
|
|
171
|
+
[K in keyof Props]: Props[K] extends OptionalProp<any> ? K : Props[K] extends DeferProp<any> ? K : [undefined] extends [Props[K]] ? K : Props[K] extends MergeableProp<infer A> ? A extends DeferProp<any> ? K : never : never;
|
|
179
172
|
}[keyof Props];
|
|
180
173
|
/**
|
|
181
174
|
* Utility type to extract required prop keys from a props object
|
|
@@ -184,7 +177,7 @@ export type GetOptionalProps<Props> = {
|
|
|
184
177
|
* @template Props - The page props object type to analyze
|
|
185
178
|
*/
|
|
186
179
|
export type GetRequiredProps<Props> = {
|
|
187
|
-
[K in keyof Props]: Props[K] extends OptionalProp<any> ? never : Props[K] extends DeferProp<any> ? never : [undefined] extends Props[K] ? never : Props[K] extends MergeableProp<infer A> ? A extends DeferProp<any> ? never : K : K;
|
|
180
|
+
[K in keyof Props]: Props[K] extends OptionalProp<any> ? never : Props[K] extends DeferProp<any> ? never : [undefined] extends [Props[K]] ? never : Props[K] extends MergeableProp<infer A> ? A extends DeferProp<any> ? never : K : K;
|
|
188
181
|
}[keyof Props];
|
|
189
182
|
/**
|
|
190
183
|
* Utility type to simplify value of a required prop by unwrapping branded types
|
package/build/src/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|