@adonisjs/inertia 4.0.0-next.0 → 4.0.0-next.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.
- package/README.md +8 -5
- package/build/bin/test.d.ts +1 -0
- package/build/chunk-4EZ2J6OA.js +7 -0
- package/build/chunk-DISC5OYC.js +46 -0
- package/build/chunk-GO6QSFRS.js +761 -0
- package/build/chunk-MLKGABMK.js +9 -0
- package/build/chunk-PDP56GPP.js +75 -0
- package/build/factories/inertia_factory.d.ts +137 -0
- package/build/factories/main.d.ts +1 -0
- package/build/factories/main.js +175 -0
- package/build/index.d.ts +7 -19
- package/build/index.js +21 -307
- package/build/providers/inertia_provider.d.ts +86 -13
- package/build/providers/inertia_provider.js +48 -18
- package/build/src/client/helpers.d.ts +25 -0
- package/build/src/{helpers.js → client/helpers.js} +3 -1
- package/build/src/client/vite.d.ts +63 -0
- package/build/src/{plugins → client}/vite.js +6 -2
- package/build/src/debug.d.ts +22 -0
- package/build/src/define_config.d.ts +29 -0
- package/build/src/headers.d.ts +61 -0
- package/build/src/index_pages.d.ts +5 -0
- package/build/src/inertia.d.ts +253 -0
- package/build/src/inertia_manager.d.ts +46 -0
- package/build/src/inertia_middleware.d.ts +74 -87
- package/build/src/inertia_middleware.js +110 -3
- package/build/src/plugins/edge/plugin.d.ts +30 -6
- package/build/src/plugins/edge/plugin.js +13 -9
- package/build/src/plugins/edge/tags.d.ts +47 -0
- package/build/src/plugins/edge/utils.d.ts +26 -0
- package/build/src/plugins/japa/api_client.d.ts +136 -22
- package/build/src/plugins/japa/api_client.js +36 -48
- package/build/src/props.d.ts +269 -0
- package/build/src/server_renderer.d.ts +54 -0
- package/build/src/symbols.d.ts +25 -0
- package/build/src/types.d.ts +404 -4
- package/build/tests/helpers.d.ts +35 -0
- package/build/tests/index_pages.spec.d.ts +1 -0
- package/build/tests/inertia.spec.d.ts +1 -0
- package/build/tests/inertia_page.spec.d.ts +1 -0
- package/build/tests/middleware.spec.d.ts +1 -0
- package/build/tests/plugins/api_client.spec.d.ts +1 -0
- package/build/tests/plugins/edge.plugin.spec.d.ts +1 -0
- package/build/tests/provider.spec.d.ts +1 -0
- package/build/tests/types/shared_props.spec.d.ts +1 -0
- package/build/tests/types/to_component_props.spec.d.ts +1 -0
- package/build/tests/types/to_page_props.spec.d.ts +1 -0
- package/package.json +77 -67
- package/build/app.css.stub +0 -13
- package/build/chunk-AWCR2NAY.js +0 -412
- package/build/config.stub +0 -33
- package/build/react/app.tsx.stub +0 -38
- package/build/react/errors/not_found.tsx.stub +0 -14
- package/build/react/errors/server_error.tsx.stub +0 -14
- package/build/react/home.tsx.stub +0 -349
- package/build/react/root.edge.stub +0 -76
- package/build/react/ssr.tsx.stub +0 -17
- package/build/react/tsconfig.json.stub +0 -15
- package/build/solid/app.tsx.stub +0 -38
- package/build/solid/errors/not_found.tsx.stub +0 -14
- package/build/solid/errors/server_error.tsx.stub +0 -14
- package/build/solid/home.tsx.stub +0 -358
- package/build/solid/root.edge.stub +0 -73
- package/build/solid/ssr.tsx.stub +0 -19
- package/build/solid/tsconfig.json.stub +0 -16
- package/build/src/helpers.d.ts +0 -12
- package/build/src/plugins/vite.d.ts +0 -26
- package/build/svelte/app.ts.stub +0 -32
- package/build/svelte/errors/not_found.svelte.stub +0 -10
- package/build/svelte/errors/server_error.svelte.stub +0 -14
- package/build/svelte/home.svelte.stub +0 -339
- package/build/svelte/root.edge.stub +0 -75
- package/build/svelte/ssr.ts.stub +0 -19
- package/build/svelte/tsconfig.json.stub +0 -14
- package/build/types-DVqEHBD1.d.ts +0 -240
- package/build/vue/app.ts.stub +0 -41
- package/build/vue/errors/not_found.vue.stub +0 -10
- package/build/vue/errors/server_error.vue.stub +0 -14
- package/build/vue/home.vue.stub +0 -343
- package/build/vue/root.edge.stub +0 -75
- package/build/vue/ssr.ts.stub +0 -22
- package/build/vue/tsconfig.json.stub +0 -16
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/inertia",
|
|
3
3
|
"description": "Official Inertia.js adapter for AdonisJS",
|
|
4
|
-
"version": "4.0.0-next.
|
|
4
|
+
"version": "4.0.0-next.2",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=24.0.0"
|
|
7
7
|
},
|
|
8
8
|
"main": "build/index.js",
|
|
9
9
|
"type": "module",
|
|
@@ -13,89 +13,96 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": "./build/index.js",
|
|
15
15
|
"./types": "./build/src/types.js",
|
|
16
|
-
"./services/main": "./build/services/inertia.js",
|
|
17
16
|
"./inertia_middleware": "./build/src/inertia_middleware.js",
|
|
18
17
|
"./inertia_provider": "./build/providers/inertia_provider.js",
|
|
19
18
|
"./plugins/edge": "./build/src/plugins/edge/plugin.js",
|
|
20
19
|
"./plugins/api_client": "./build/src/plugins/japa/api_client.js",
|
|
21
|
-
"./
|
|
22
|
-
"./helpers": "./build/src/helpers.js"
|
|
20
|
+
"./vite": "./build/src/client/vite.js",
|
|
21
|
+
"./helpers": "./build/src/client/helpers.js",
|
|
22
|
+
"./factories": "./build/factories/main.js"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"clean": "del-cli build",
|
|
26
|
-
"copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"lint": "eslint",
|
|
29
|
-
"format": "prettier --write .",
|
|
30
|
-
"quick:test": "node --enable-source-maps --import=ts-node-maintained/register/esm bin/test.ts",
|
|
31
25
|
"pretest": "npm run lint",
|
|
32
26
|
"test": "c8 npm run quick:test",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"clean": "del-cli build",
|
|
29
|
+
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
30
|
+
"copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
|
|
33
31
|
"prebuild": "npm run lint && npm run clean",
|
|
34
|
-
"build": "
|
|
32
|
+
"build": "npm run compile",
|
|
35
33
|
"postbuild": "npm run copy:templates",
|
|
34
|
+
"prebenchmark": "npm run build",
|
|
35
|
+
"benchmark": "node benchmarks/index.js",
|
|
36
36
|
"release": "release-it",
|
|
37
37
|
"version": "npm run build",
|
|
38
|
-
"
|
|
38
|
+
"format": "prettier --write .",
|
|
39
|
+
"prepublishOnly": "npm run build",
|
|
40
|
+
"lint": "eslint",
|
|
41
|
+
"quick:test": "cross-env NODE_DEBUG=adonisjs:inertia node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts",
|
|
42
|
+
"docs": "typedoc"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"@adonisjs/assembler": "^
|
|
42
|
-
"@adonisjs/core": "
|
|
43
|
-
"@adonisjs/eslint-config": "^
|
|
45
|
+
"@adonisjs/assembler": "^8.0.0-next.9",
|
|
46
|
+
"@adonisjs/core": "^7.0.0-next.1",
|
|
47
|
+
"@adonisjs/eslint-config": "^3.0.0-next.1",
|
|
44
48
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
45
|
-
"@adonisjs/session": "^
|
|
46
|
-
"@adonisjs/tsconfig": "^
|
|
47
|
-
"@adonisjs/vite": "^5.0.
|
|
49
|
+
"@adonisjs/session": "^8.0.0-next.0",
|
|
50
|
+
"@adonisjs/tsconfig": "^2.0.0-next.0",
|
|
51
|
+
"@adonisjs/vite": "^5.0.1-next.0",
|
|
48
52
|
"@japa/api-client": "^3.1.0",
|
|
49
|
-
"@japa/assert": "4.
|
|
53
|
+
"@japa/assert": "4.1.1",
|
|
50
54
|
"@japa/expect-type": "^2.0.3",
|
|
51
55
|
"@japa/file-system": "^2.3.2",
|
|
52
|
-
"@japa/plugin-adonisjs": "^
|
|
53
|
-
"@japa/runner": "4.
|
|
54
|
-
"@japa/snapshot": "^2.0.
|
|
56
|
+
"@japa/plugin-adonisjs": "^5.0.0-next.0",
|
|
57
|
+
"@japa/runner": "4.4.0",
|
|
58
|
+
"@japa/snapshot": "^2.0.9",
|
|
59
|
+
"@poppinss/ts-exec": "^1.4.1",
|
|
55
60
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
56
|
-
"@
|
|
57
|
-
"@types/node": "^24.0.15",
|
|
58
|
-
"@types/qs": "^6.14.0",
|
|
61
|
+
"@types/node": "^24.3.1",
|
|
59
62
|
"@types/supertest": "^6.0.3",
|
|
60
63
|
"c8": "^10.1.3",
|
|
61
64
|
"copyfiles": "^2.4.1",
|
|
65
|
+
"cross-env": "^10.0.0",
|
|
62
66
|
"del-cli": "^6.0.0",
|
|
63
|
-
"edge
|
|
64
|
-
"
|
|
65
|
-
"eslint": "^9.31.0",
|
|
67
|
+
"edge.js": "^6.3.0",
|
|
68
|
+
"eslint": "^9.35.0",
|
|
66
69
|
"get-port": "^7.1.0",
|
|
67
70
|
"prettier": "^3.6.2",
|
|
68
71
|
"release-it": "^19.0.4",
|
|
69
|
-
"supertest": "^7.1.
|
|
70
|
-
"ts-node-maintained": "^10.9.5",
|
|
72
|
+
"supertest": "^7.1.4",
|
|
71
73
|
"tsup": "^8.5.0",
|
|
72
|
-
"typescript": "~5.
|
|
73
|
-
"vite": "^7.
|
|
74
|
+
"typescript": "~5.9.2",
|
|
75
|
+
"vite": "^7.1.5"
|
|
74
76
|
},
|
|
75
77
|
"dependencies": {
|
|
76
|
-
"@poppinss/utils": "^
|
|
77
|
-
"@tuyau/utils": "^0.0.9",
|
|
78
|
+
"@poppinss/utils": "^7.0.0-next.3",
|
|
78
79
|
"edge-error": "^4.0.2",
|
|
79
|
-
"html-entities": "^2.6.0"
|
|
80
|
-
"locate-path": "^7.2.0",
|
|
81
|
-
"qs": "^6.14.0"
|
|
80
|
+
"html-entities": "^2.6.0"
|
|
82
81
|
},
|
|
83
82
|
"peerDependencies": {
|
|
84
|
-
"@adonisjs/
|
|
85
|
-
"@adonisjs/
|
|
86
|
-
"@adonisjs/
|
|
87
|
-
"@
|
|
83
|
+
"@adonisjs/assembler": "^8.0.0-next.7",
|
|
84
|
+
"@adonisjs/core": "^7.0.0-next.0",
|
|
85
|
+
"@adonisjs/session": "^8.0.0-next.0",
|
|
86
|
+
"@adonisjs/vite": "^5.0.1-next.0",
|
|
87
|
+
"@japa/api-client": "^3.1.0",
|
|
88
|
+
"@japa/plugin-adonisjs": "^5.0.0-next.0",
|
|
88
89
|
"edge.js": "^6.0.0"
|
|
89
90
|
},
|
|
90
91
|
"peerDependenciesMeta": {
|
|
92
|
+
"@adonisjs/assembler": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
91
95
|
"@japa/api-client": {
|
|
92
96
|
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@japa/plugin-adonisjs": {
|
|
99
|
+
"optional": true
|
|
93
100
|
}
|
|
94
101
|
},
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
"keywords": [
|
|
103
|
+
"inertia",
|
|
104
|
+
"adonisjs"
|
|
105
|
+
],
|
|
99
106
|
"license": "MIT",
|
|
100
107
|
"homepage": "https://github.com/adonisjs/inertia#readme",
|
|
101
108
|
"repository": {
|
|
@@ -105,11 +112,14 @@
|
|
|
105
112
|
"bugs": {
|
|
106
113
|
"url": "https://github.com/adonisjs/inertia/issues"
|
|
107
114
|
},
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
"adonisjs"
|
|
115
|
+
"author": "Julien Ripouteau <julien@ripouteau.com>",
|
|
116
|
+
"contributors": [
|
|
117
|
+
"Harminder Virk <virk@adonisjs.com>"
|
|
111
118
|
],
|
|
112
|
-
"
|
|
119
|
+
"publishConfig": {
|
|
120
|
+
"access": "public",
|
|
121
|
+
"provenance": true
|
|
122
|
+
},
|
|
113
123
|
"release-it": {
|
|
114
124
|
"git": {
|
|
115
125
|
"requireUpstream": true,
|
|
@@ -123,8 +133,7 @@
|
|
|
123
133
|
},
|
|
124
134
|
"npm": {
|
|
125
135
|
"publish": true,
|
|
126
|
-
"skipChecks": true
|
|
127
|
-
"tag": "latest"
|
|
136
|
+
"skipChecks": true
|
|
128
137
|
},
|
|
129
138
|
"plugins": {
|
|
130
139
|
"@release-it/conventional-changelog": {
|
|
@@ -134,23 +143,13 @@
|
|
|
134
143
|
}
|
|
135
144
|
}
|
|
136
145
|
},
|
|
137
|
-
"c8": {
|
|
138
|
-
"reporter": [
|
|
139
|
-
"text",
|
|
140
|
-
"html"
|
|
141
|
-
],
|
|
142
|
-
"exclude": [
|
|
143
|
-
"tests/**",
|
|
144
|
-
"tests_helpers/**"
|
|
145
|
-
]
|
|
146
|
-
},
|
|
147
146
|
"tsup": {
|
|
148
147
|
"entry": [
|
|
149
148
|
"./index.ts",
|
|
150
149
|
"./src/types.ts",
|
|
151
|
-
"./src/
|
|
152
|
-
"./src/
|
|
153
|
-
"./
|
|
150
|
+
"./src/client/vite.ts",
|
|
151
|
+
"./src/client/helpers.ts",
|
|
152
|
+
"./factories/main.ts",
|
|
154
153
|
"./src/inertia_middleware.ts",
|
|
155
154
|
"./providers/inertia_provider.ts",
|
|
156
155
|
"./src/plugins/edge/plugin.ts",
|
|
@@ -159,8 +158,19 @@
|
|
|
159
158
|
"outDir": "./build",
|
|
160
159
|
"clean": true,
|
|
161
160
|
"format": "esm",
|
|
162
|
-
"dts":
|
|
161
|
+
"dts": false,
|
|
162
|
+
"sourcemaps": false,
|
|
163
163
|
"target": "esnext"
|
|
164
164
|
},
|
|
165
|
-
"
|
|
165
|
+
"c8": {
|
|
166
|
+
"reporter": [
|
|
167
|
+
"text",
|
|
168
|
+
"html"
|
|
169
|
+
],
|
|
170
|
+
"exclude": [
|
|
171
|
+
"tests/**",
|
|
172
|
+
"tests_helpers/**"
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"prettier": "@adonisjs/prettier-config"
|
|
166
176
|
}
|
package/build/app.css.stub
DELETED
package/build/chunk-AWCR2NAY.js
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
// src/server_renderer.ts
|
|
2
|
-
import { pathToFileURL } from "url";
|
|
3
|
-
var ServerRenderer = class _ServerRenderer {
|
|
4
|
-
constructor(config, vite) {
|
|
5
|
-
this.config = config;
|
|
6
|
-
this.vite = vite;
|
|
7
|
-
}
|
|
8
|
-
static runtime;
|
|
9
|
-
/**
|
|
10
|
-
* Render the page on the server
|
|
11
|
-
*
|
|
12
|
-
* On development, we use the Vite Runtime API
|
|
13
|
-
* On production, we just import and use the SSR bundle generated by Vite
|
|
14
|
-
*/
|
|
15
|
-
async render(pageObject) {
|
|
16
|
-
let render;
|
|
17
|
-
const devServer = this.vite?.getDevServer();
|
|
18
|
-
if (devServer) {
|
|
19
|
-
_ServerRenderer.runtime ??= await this.vite.createModuleRunner();
|
|
20
|
-
_ServerRenderer.runtime.clearCache();
|
|
21
|
-
render = await _ServerRenderer.runtime.import(this.config.ssr.entrypoint);
|
|
22
|
-
} else {
|
|
23
|
-
render = await import(pathToFileURL(this.config.ssr.bundle).href);
|
|
24
|
-
}
|
|
25
|
-
const result = await render.default(pageObject);
|
|
26
|
-
return { head: result.head, body: result.body };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// src/props.ts
|
|
31
|
-
var ignoreFirstLoadSymbol = Symbol("ignoreFirstLoad");
|
|
32
|
-
var MergeableProp = class {
|
|
33
|
-
shouldMerge = false;
|
|
34
|
-
merge() {
|
|
35
|
-
this.shouldMerge = true;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var OptionalProp = class {
|
|
40
|
-
constructor(callback) {
|
|
41
|
-
this.callback = callback;
|
|
42
|
-
}
|
|
43
|
-
[ignoreFirstLoadSymbol] = true;
|
|
44
|
-
};
|
|
45
|
-
var DeferProp = class extends MergeableProp {
|
|
46
|
-
constructor(callback, group) {
|
|
47
|
-
super();
|
|
48
|
-
this.callback = callback;
|
|
49
|
-
this.group = group;
|
|
50
|
-
}
|
|
51
|
-
[ignoreFirstLoadSymbol] = true;
|
|
52
|
-
getGroup() {
|
|
53
|
-
return this.group;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
var MergeProp = class extends MergeableProp {
|
|
57
|
-
constructor(callback) {
|
|
58
|
-
super();
|
|
59
|
-
this.callback = callback;
|
|
60
|
-
this.shouldMerge = true;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var AlwaysProp = class extends MergeableProp {
|
|
64
|
-
constructor(callback) {
|
|
65
|
-
super();
|
|
66
|
-
this.callback = callback;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/headers.ts
|
|
71
|
-
var InertiaHeaders = {
|
|
72
|
-
Inertia: "x-inertia",
|
|
73
|
-
Reset: "x-inertia-reset",
|
|
74
|
-
Version: "x-inertia-version",
|
|
75
|
-
Location: "x-inertia-location",
|
|
76
|
-
ErrorBag: "X-Inertia-Error-Bag",
|
|
77
|
-
PartialOnly: "x-inertia-partial-data",
|
|
78
|
-
PartialExcept: "x-inertia-partial-except",
|
|
79
|
-
PartialComponent: "x-inertia-partial-component"
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/inertia.ts
|
|
83
|
-
var Inertia = class {
|
|
84
|
-
constructor(ctx, config, vite) {
|
|
85
|
-
this.ctx = ctx;
|
|
86
|
-
this.config = config;
|
|
87
|
-
this.vite = vite;
|
|
88
|
-
this.#sharedData = config.sharedData;
|
|
89
|
-
this.#serverRenderer = new ServerRenderer(config, vite);
|
|
90
|
-
this.#shouldClearHistory = false;
|
|
91
|
-
this.#shouldEncryptHistory = config.history.encrypt;
|
|
92
|
-
}
|
|
93
|
-
#sharedData = {};
|
|
94
|
-
#serverRenderer;
|
|
95
|
-
#shouldClearHistory = false;
|
|
96
|
-
#shouldEncryptHistory = false;
|
|
97
|
-
/**
|
|
98
|
-
* Check if the current request is a partial request
|
|
99
|
-
*/
|
|
100
|
-
#isPartial(component) {
|
|
101
|
-
return this.ctx.request.header(InertiaHeaders.PartialComponent) === component;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Resolve the `only` partial request props.
|
|
105
|
-
* Only the props listed in the `x-inertia-partial-data` header
|
|
106
|
-
* will be returned
|
|
107
|
-
*/
|
|
108
|
-
#resolveOnly(props) {
|
|
109
|
-
const partialOnlyHeader = this.ctx.request.header(InertiaHeaders.PartialOnly);
|
|
110
|
-
const only = partialOnlyHeader.split(",").filter(Boolean);
|
|
111
|
-
let newProps = {};
|
|
112
|
-
for (const key of only) newProps[key] = props[key];
|
|
113
|
-
return newProps;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Resolve the `except` partial request props.
|
|
117
|
-
* Remove the props listed in the `x-inertia-partial-except` header
|
|
118
|
-
*/
|
|
119
|
-
#resolveExcept(props) {
|
|
120
|
-
const partialExceptHeader = this.ctx.request.header(InertiaHeaders.PartialExcept);
|
|
121
|
-
const except = partialExceptHeader.split(",").filter(Boolean);
|
|
122
|
-
for (const key of except) delete props[key];
|
|
123
|
-
return props;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Resolve the props for the current request
|
|
127
|
-
* by filtering out the props that are not needed
|
|
128
|
-
* based on the request headers
|
|
129
|
-
*/
|
|
130
|
-
#pickPropsToResolve(component, props = {}) {
|
|
131
|
-
const isPartial = this.#isPartial(component);
|
|
132
|
-
let newProps = props;
|
|
133
|
-
if (!isPartial) {
|
|
134
|
-
newProps = Object.fromEntries(
|
|
135
|
-
Object.entries(props).filter(([_, value]) => {
|
|
136
|
-
if (value && value[ignoreFirstLoadSymbol]) return false;
|
|
137
|
-
return true;
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
const partialOnlyHeader = this.ctx.request.header(InertiaHeaders.PartialOnly);
|
|
142
|
-
if (isPartial && partialOnlyHeader) newProps = this.#resolveOnly(props);
|
|
143
|
-
const partialExceptHeader = this.ctx.request.header(InertiaHeaders.PartialExcept);
|
|
144
|
-
if (isPartial && partialExceptHeader) newProps = this.#resolveExcept(newProps);
|
|
145
|
-
for (const [key, value] of Object.entries(props)) {
|
|
146
|
-
if (value instanceof AlwaysProp) newProps[key] = props[key];
|
|
147
|
-
}
|
|
148
|
-
return newProps;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Resolve a single prop
|
|
152
|
-
*/
|
|
153
|
-
async #resolveProp(key, value) {
|
|
154
|
-
if (value instanceof OptionalProp || value instanceof MergeProp || value instanceof DeferProp || value instanceof AlwaysProp) {
|
|
155
|
-
return [key, await value.callback()];
|
|
156
|
-
}
|
|
157
|
-
return [key, value];
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Resolve a single prop by calling the callback or resolving the promise
|
|
161
|
-
*/
|
|
162
|
-
async #resolvePageProps(props = {}) {
|
|
163
|
-
return Object.fromEntries(
|
|
164
|
-
await Promise.all(
|
|
165
|
-
Object.entries(props).map(async ([key, value]) => {
|
|
166
|
-
if (typeof value === "function") {
|
|
167
|
-
const result = await value(this.ctx);
|
|
168
|
-
return this.#resolveProp(key, result);
|
|
169
|
-
}
|
|
170
|
-
return this.#resolveProp(key, value);
|
|
171
|
-
})
|
|
172
|
-
)
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Resolve the deferred props listing. Will be returned only
|
|
177
|
-
* on the first visit to the page and will be used to make
|
|
178
|
-
* subsequent partial requests
|
|
179
|
-
*/
|
|
180
|
-
#resolveDeferredProps(component, pageProps) {
|
|
181
|
-
if (this.#isPartial(component)) return {};
|
|
182
|
-
const deferredProps = Object.entries(pageProps || {}).filter(([_, value]) => value instanceof DeferProp).map(([key, value]) => ({ key, group: value.getGroup() })).reduce(
|
|
183
|
-
(groups, { key, group }) => {
|
|
184
|
-
if (!groups[group]) groups[group] = [];
|
|
185
|
-
groups[group].push(key);
|
|
186
|
-
return groups;
|
|
187
|
-
},
|
|
188
|
-
{}
|
|
189
|
-
);
|
|
190
|
-
return Object.keys(deferredProps).length ? { deferredProps } : {};
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Resolve the props that should be merged
|
|
194
|
-
*/
|
|
195
|
-
#resolveMergeProps(pageProps) {
|
|
196
|
-
const inertiaResetHeader = this.ctx.request.header(InertiaHeaders.Reset) || "";
|
|
197
|
-
const resetProps = new Set(inertiaResetHeader.split(",").filter(Boolean));
|
|
198
|
-
const mergeProps = Object.entries(pageProps || {}).filter(([_, value]) => value instanceof MergeableProp && value.shouldMerge).map(([key]) => key).filter((key) => !resetProps.has(key));
|
|
199
|
-
return mergeProps.length ? { mergeProps } : {};
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Build the page object that will be returned to the client
|
|
203
|
-
*
|
|
204
|
-
* See https://inertiajs.com/the-protocol#the-page-object
|
|
205
|
-
*/
|
|
206
|
-
async #buildPageObject(component, pageProps) {
|
|
207
|
-
const propsToResolve = this.#pickPropsToResolve(component, {
|
|
208
|
-
...this.#sharedData,
|
|
209
|
-
...pageProps
|
|
210
|
-
});
|
|
211
|
-
return {
|
|
212
|
-
component,
|
|
213
|
-
url: this.ctx.request.url(true),
|
|
214
|
-
version: this.config.versionCache.getVersion(),
|
|
215
|
-
props: await this.#resolvePageProps(propsToResolve),
|
|
216
|
-
clearHistory: this.#shouldClearHistory,
|
|
217
|
-
encryptHistory: this.#shouldEncryptHistory,
|
|
218
|
-
...this.#resolveMergeProps(pageProps),
|
|
219
|
-
...this.#resolveDeferredProps(component, pageProps)
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* If the page should be rendered on the server or not
|
|
224
|
-
*
|
|
225
|
-
* The ssr.pages config can be a list of pages or a function that returns a boolean
|
|
226
|
-
*/
|
|
227
|
-
async #shouldRenderOnServer(component) {
|
|
228
|
-
const isSsrEnabled = this.config.ssr.enabled;
|
|
229
|
-
if (!isSsrEnabled) return false;
|
|
230
|
-
let isSsrEnabledForPage = false;
|
|
231
|
-
if (typeof this.config.ssr.pages === "function") {
|
|
232
|
-
isSsrEnabledForPage = await this.config.ssr.pages(this.ctx, component);
|
|
233
|
-
} else if (this.config.ssr.pages) {
|
|
234
|
-
isSsrEnabledForPage = this.config.ssr.pages?.includes(component);
|
|
235
|
-
} else {
|
|
236
|
-
isSsrEnabledForPage = true;
|
|
237
|
-
}
|
|
238
|
-
return isSsrEnabledForPage;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Resolve the root view
|
|
242
|
-
*/
|
|
243
|
-
#resolveRootView() {
|
|
244
|
-
return typeof this.config.rootView === "function" ? this.config.rootView(this.ctx) : this.config.rootView;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Render the page on the server
|
|
248
|
-
*/
|
|
249
|
-
async #renderOnServer(pageObject, viewProps) {
|
|
250
|
-
const { head, body } = await this.#serverRenderer.render(pageObject);
|
|
251
|
-
return this.ctx.view.render(this.#resolveRootView(), {
|
|
252
|
-
...viewProps,
|
|
253
|
-
page: { ssrHead: head, ssrBody: body, ...pageObject }
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Share data for the current request.
|
|
258
|
-
* This data will override any shared data defined in the config.
|
|
259
|
-
*/
|
|
260
|
-
share(data) {
|
|
261
|
-
this.#sharedData = { ...this.#sharedData, ...data };
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Render a page using Inertia
|
|
265
|
-
*/
|
|
266
|
-
async render(component, pageProps, viewProps) {
|
|
267
|
-
const pageObject = await this.#buildPageObject(component, pageProps);
|
|
268
|
-
const isInertiaRequest = !!this.ctx.request.header(InertiaHeaders.Inertia);
|
|
269
|
-
if (!isInertiaRequest) {
|
|
270
|
-
const shouldRenderOnServer = await this.#shouldRenderOnServer(component);
|
|
271
|
-
if (shouldRenderOnServer) return this.#renderOnServer(pageObject, viewProps);
|
|
272
|
-
return this.ctx.view.render(this.#resolveRootView(), { ...viewProps, page: pageObject });
|
|
273
|
-
}
|
|
274
|
-
this.ctx.response.header(InertiaHeaders.Inertia, "true");
|
|
275
|
-
return pageObject;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Clear history state.
|
|
279
|
-
*
|
|
280
|
-
* See https://v2.inertiajs.com/history-encryption#clearing-history
|
|
281
|
-
*/
|
|
282
|
-
clearHistory() {
|
|
283
|
-
this.#shouldClearHistory = true;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Encrypt history
|
|
287
|
-
*
|
|
288
|
-
* See https://v2.inertiajs.com/history-encryption
|
|
289
|
-
*/
|
|
290
|
-
encryptHistory(encrypt = true) {
|
|
291
|
-
this.#shouldEncryptHistory = encrypt;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Create a lazy prop
|
|
295
|
-
*
|
|
296
|
-
* Lazy props are never resolved on first visit, but only when the client
|
|
297
|
-
* request a partial reload explicitely with this value.
|
|
298
|
-
*
|
|
299
|
-
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
|
|
300
|
-
*
|
|
301
|
-
* @deprecated use `optional` instead
|
|
302
|
-
*/
|
|
303
|
-
lazy(callback) {
|
|
304
|
-
return new OptionalProp(callback);
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Create an optional prop
|
|
308
|
-
*
|
|
309
|
-
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
|
|
310
|
-
*/
|
|
311
|
-
optional(callback) {
|
|
312
|
-
return new OptionalProp(callback);
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Create a mergeable prop
|
|
316
|
-
*
|
|
317
|
-
* See https://v2.inertiajs.com/merging-props
|
|
318
|
-
*/
|
|
319
|
-
merge(callback) {
|
|
320
|
-
return new MergeProp(callback);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Create an always prop
|
|
324
|
-
*
|
|
325
|
-
* Always props are resolved on every request, no matter if it's a partial
|
|
326
|
-
* request or not.
|
|
327
|
-
*
|
|
328
|
-
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
|
|
329
|
-
*/
|
|
330
|
-
always(callback) {
|
|
331
|
-
return new AlwaysProp(callback);
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Create a deferred prop
|
|
335
|
-
*
|
|
336
|
-
* Deferred props feature allows you to defer the loading of certain
|
|
337
|
-
* page data until after the initial page render.
|
|
338
|
-
*
|
|
339
|
-
* See https://v2.inertiajs.com/deferred-props
|
|
340
|
-
*/
|
|
341
|
-
defer(callback, group = "default") {
|
|
342
|
-
return new DeferProp(callback, group);
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* This method can be used to redirect the user to an external website
|
|
346
|
-
* or even a non-inertia route of your application.
|
|
347
|
-
*
|
|
348
|
-
* See https://inertiajs.com/redirects#external-redirects
|
|
349
|
-
*/
|
|
350
|
-
async location(url) {
|
|
351
|
-
this.ctx.response.header(InertiaHeaders.Location, url);
|
|
352
|
-
this.ctx.response.status(409);
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
// src/inertia_middleware.ts
|
|
357
|
-
var InertiaMiddleware = class {
|
|
358
|
-
constructor(config, vite) {
|
|
359
|
-
this.config = config;
|
|
360
|
-
this.vite = vite;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Resolves the validation errors to be shared with Inertia
|
|
364
|
-
*/
|
|
365
|
-
#resolveValidationErrors(ctx) {
|
|
366
|
-
const { session, request } = ctx;
|
|
367
|
-
if (!session) {
|
|
368
|
-
return {};
|
|
369
|
-
}
|
|
370
|
-
if (!session.flashMessages.has("errorsBag.E_VALIDATION_ERROR")) {
|
|
371
|
-
return session.flashMessages.get("errorsBag");
|
|
372
|
-
}
|
|
373
|
-
const errors = Object.entries(session.flashMessages.get("inputErrorsBag")).reduce(
|
|
374
|
-
(acc, [field, messages]) => {
|
|
375
|
-
acc[field] = Array.isArray(messages) ? messages[0] : messages;
|
|
376
|
-
return acc;
|
|
377
|
-
},
|
|
378
|
-
{}
|
|
379
|
-
);
|
|
380
|
-
const errorBag = request.header(InertiaHeaders.ErrorBag);
|
|
381
|
-
return errorBag ? { [errorBag]: errors } : errors;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Share validation and flashed errors with Inertia
|
|
385
|
-
*/
|
|
386
|
-
#shareErrors(ctx) {
|
|
387
|
-
ctx.inertia.share({ errors: ctx.inertia.always(() => this.#resolveValidationErrors(ctx)) });
|
|
388
|
-
}
|
|
389
|
-
async handle(ctx, next) {
|
|
390
|
-
const { response, request } = ctx;
|
|
391
|
-
ctx.inertia = new Inertia(ctx, this.config, this.vite);
|
|
392
|
-
this.#shareErrors(ctx);
|
|
393
|
-
await next();
|
|
394
|
-
const isInertiaRequest = !!request.header(InertiaHeaders.Inertia);
|
|
395
|
-
if (!isInertiaRequest) return;
|
|
396
|
-
response.header("Vary", InertiaHeaders.Inertia);
|
|
397
|
-
const method = request.method();
|
|
398
|
-
if (response.getStatus() === 302 && ["PUT", "PATCH", "DELETE"].includes(method)) {
|
|
399
|
-
response.status(303);
|
|
400
|
-
}
|
|
401
|
-
const version = this.config.versionCache.getVersion().toString();
|
|
402
|
-
if (method === "GET" && request.header(InertiaHeaders.Version, "") !== version) {
|
|
403
|
-
response.removeHeader(InertiaHeaders.Inertia);
|
|
404
|
-
response.header(InertiaHeaders.Location, request.url());
|
|
405
|
-
response.status(409);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
export {
|
|
411
|
-
InertiaMiddleware
|
|
412
|
-
};
|
package/build/config.stub
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{{{
|
|
2
|
-
exports({ to: app.configPath('inertia.ts') })
|
|
3
|
-
}}}
|
|
4
|
-
import { defineConfig } from '@adonisjs/inertia'
|
|
5
|
-
import type { InferSharedProps } from '@adonisjs/inertia/types'
|
|
6
|
-
|
|
7
|
-
const inertiaConfig = defineConfig({
|
|
8
|
-
/**
|
|
9
|
-
* Path to the Edge view that will be used as the root view for Inertia responses
|
|
10
|
-
*/
|
|
11
|
-
rootView: 'inertia_layout',
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Data that should be shared with all rendered pages
|
|
15
|
-
*/
|
|
16
|
-
sharedData: {
|
|
17
|
-
// user: (ctx) => ctx.inertia.always(() => ctx.auth.user),
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Options for the server-side rendering
|
|
22
|
-
*/
|
|
23
|
-
ssr: {
|
|
24
|
-
enabled: {{ ssr }},
|
|
25
|
-
entrypoint: '{{ ssrEntrypoint }}'
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
export default inertiaConfig
|
|
30
|
-
|
|
31
|
-
declare module '@adonisjs/inertia/types' {
|
|
32
|
-
export interface SharedProps extends InferSharedProps<typeof inertiaConfig> {}
|
|
33
|
-
}
|