@adonisjs/inertia 3.1.1 → 4.0.0-next.1
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-74S2VAL7.js +761 -0
- package/build/chunk-DISC5OYC.js +46 -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/vite.d.ts +63 -0
- package/build/src/{plugins → client}/vite.js +9 -13
- 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 +88 -71
- package/build/app.css.stub +0 -13
- package/build/chunk-W7TVEB4V.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/helpers.js +0 -14
- 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
|
+
"version": "4.0.0-next.1",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=24.0.0"
|
|
7
7
|
},
|
|
8
8
|
"main": "build/index.js",
|
|
9
9
|
"type": "module",
|
|
@@ -13,96 +13,112 @@
|
|
|
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
|
-
"./
|
|
20
|
+
"./vite": "./build/src/client/vite.js",
|
|
21
|
+
"./factories": "./build/factories/main.js"
|
|
23
22
|
},
|
|
24
23
|
"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
24
|
"pretest": "npm run lint",
|
|
32
25
|
"test": "c8 npm run quick:test",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"clean": "del-cli build",
|
|
28
|
+
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
29
|
+
"copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
|
|
33
30
|
"prebuild": "npm run lint && npm run clean",
|
|
34
|
-
"build": "
|
|
31
|
+
"build": "npm run compile",
|
|
35
32
|
"postbuild": "npm run copy:templates",
|
|
33
|
+
"prebenchmark": "npm run build",
|
|
34
|
+
"benchmark": "node benchmarks/index.js",
|
|
36
35
|
"release": "release-it",
|
|
37
36
|
"version": "npm run build",
|
|
38
|
-
"
|
|
37
|
+
"format": "prettier --write .",
|
|
38
|
+
"prepublishOnly": "npm run build",
|
|
39
|
+
"lint": "eslint",
|
|
40
|
+
"quick:test": "cross-env NODE_DEBUG=adonisjs:inertia node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts",
|
|
41
|
+
"docs": "typedoc"
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
41
|
-
"@adonisjs/assembler": "^
|
|
42
|
-
"@adonisjs/core": "
|
|
43
|
-
"@adonisjs/eslint-config": "^
|
|
44
|
-
"@adonisjs/prettier-config": "^1.4.
|
|
45
|
-
"@adonisjs/session": "^
|
|
46
|
-
"@adonisjs/tsconfig": "^
|
|
47
|
-
"@adonisjs/vite": "^
|
|
48
|
-
"@japa/api-client": "^3.0
|
|
49
|
-
"@japa/assert": "4.
|
|
44
|
+
"@adonisjs/assembler": "^8.0.0-next.9",
|
|
45
|
+
"@adonisjs/core": "^7.0.0-next.1",
|
|
46
|
+
"@adonisjs/eslint-config": "^3.0.0-next.1",
|
|
47
|
+
"@adonisjs/prettier-config": "^1.4.5",
|
|
48
|
+
"@adonisjs/session": "^8.0.0-next.0",
|
|
49
|
+
"@adonisjs/tsconfig": "^2.0.0-next.0",
|
|
50
|
+
"@adonisjs/vite": "^5.0.1-next.0",
|
|
51
|
+
"@japa/api-client": "^3.1.0",
|
|
52
|
+
"@japa/assert": "4.1.1",
|
|
50
53
|
"@japa/expect-type": "^2.0.3",
|
|
51
54
|
"@japa/file-system": "^2.3.2",
|
|
52
|
-
"@japa/plugin-adonisjs": "^
|
|
53
|
-
"@japa/runner": "4.
|
|
54
|
-
"@japa/snapshot": "^2.0.
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@types/node": "^
|
|
58
|
-
"@types/
|
|
59
|
-
"@types/supertest": "^6.0.2",
|
|
60
|
-
"@vavite/multibuild": "^5.1.0",
|
|
55
|
+
"@japa/plugin-adonisjs": "^5.0.0-next.0",
|
|
56
|
+
"@japa/runner": "4.4.0",
|
|
57
|
+
"@japa/snapshot": "^2.0.9",
|
|
58
|
+
"@poppinss/ts-exec": "^1.4.1",
|
|
59
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
60
|
+
"@types/node": "^24.3.1",
|
|
61
|
+
"@types/supertest": "^6.0.3",
|
|
61
62
|
"c8": "^10.1.3",
|
|
62
63
|
"copyfiles": "^2.4.1",
|
|
64
|
+
"cross-env": "^10.0.0",
|
|
63
65
|
"del-cli": "^6.0.0",
|
|
64
|
-
"edge
|
|
65
|
-
"
|
|
66
|
-
"eslint": "^9.21.0",
|
|
66
|
+
"edge.js": "^6.3.0",
|
|
67
|
+
"eslint": "^9.35.0",
|
|
67
68
|
"get-port": "^7.1.0",
|
|
68
|
-
"prettier": "^3.
|
|
69
|
-
"release-it": "^
|
|
70
|
-
"supertest": "^7.
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"vite": "^6.2.1"
|
|
69
|
+
"prettier": "^3.6.2",
|
|
70
|
+
"release-it": "^19.0.4",
|
|
71
|
+
"supertest": "^7.1.4",
|
|
72
|
+
"tsup": "^8.5.0",
|
|
73
|
+
"typescript": "~5.9.2",
|
|
74
|
+
"vite": "^7.1.5"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@poppinss/utils": "^
|
|
78
|
-
"@tuyau/utils": "^0.0.7",
|
|
77
|
+
"@poppinss/utils": "^7.0.0-next.3",
|
|
79
78
|
"edge-error": "^4.0.2",
|
|
80
|
-
"html-entities": "^2.
|
|
81
|
-
"locate-path": "^7.2.0",
|
|
82
|
-
"qs": "^6.14.0"
|
|
79
|
+
"html-entities": "^2.6.0"
|
|
83
80
|
},
|
|
84
81
|
"peerDependencies": {
|
|
85
|
-
"@adonisjs/
|
|
86
|
-
"@adonisjs/
|
|
87
|
-
"@adonisjs/
|
|
88
|
-
"@
|
|
82
|
+
"@adonisjs/assembler": "^8.0.0-next.7",
|
|
83
|
+
"@adonisjs/core": "^7.0.0-next.0",
|
|
84
|
+
"@adonisjs/session": "^8.0.0-next.0",
|
|
85
|
+
"@adonisjs/vite": "^5.0.1-next.0",
|
|
86
|
+
"@japa/api-client": "^3.1.0",
|
|
87
|
+
"@japa/plugin-adonisjs": "^5.0.0-next.0",
|
|
89
88
|
"edge.js": "^6.0.0"
|
|
90
89
|
},
|
|
91
90
|
"peerDependenciesMeta": {
|
|
91
|
+
"@adonisjs/assembler": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
92
94
|
"@japa/api-client": {
|
|
93
95
|
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"@japa/plugin-adonisjs": {
|
|
98
|
+
"optional": true
|
|
94
99
|
}
|
|
95
100
|
},
|
|
96
|
-
"publishConfig": {
|
|
97
|
-
"access": "public"
|
|
98
|
-
},
|
|
99
|
-
"author": "Julien Ripouteau <julien@ripouteau.com>,adonisjs",
|
|
100
|
-
"license": "MIT",
|
|
101
101
|
"keywords": [
|
|
102
102
|
"inertia",
|
|
103
103
|
"adonisjs"
|
|
104
104
|
],
|
|
105
|
-
"
|
|
105
|
+
"license": "MIT",
|
|
106
|
+
"homepage": "https://github.com/adonisjs/inertia#readme",
|
|
107
|
+
"repository": {
|
|
108
|
+
"type": "git",
|
|
109
|
+
"url": "git+https://github.com/adonisjs/inertia.git"
|
|
110
|
+
},
|
|
111
|
+
"bugs": {
|
|
112
|
+
"url": "https://github.com/adonisjs/inertia/issues"
|
|
113
|
+
},
|
|
114
|
+
"author": "Julien Ripouteau <julien@ripouteau.com>",
|
|
115
|
+
"contributors": [
|
|
116
|
+
"Harminder Virk <virk@adonisjs.com>"
|
|
117
|
+
],
|
|
118
|
+
"publishConfig": {
|
|
119
|
+
"access": "public",
|
|
120
|
+
"provenance": true
|
|
121
|
+
},
|
|
106
122
|
"release-it": {
|
|
107
123
|
"git": {
|
|
108
124
|
"requireUpstream": true,
|
|
@@ -127,23 +143,12 @@
|
|
|
127
143
|
}
|
|
128
144
|
}
|
|
129
145
|
},
|
|
130
|
-
"c8": {
|
|
131
|
-
"reporter": [
|
|
132
|
-
"text",
|
|
133
|
-
"html"
|
|
134
|
-
],
|
|
135
|
-
"exclude": [
|
|
136
|
-
"tests/**",
|
|
137
|
-
"tests_helpers/**"
|
|
138
|
-
]
|
|
139
|
-
},
|
|
140
146
|
"tsup": {
|
|
141
147
|
"entry": [
|
|
142
148
|
"./index.ts",
|
|
143
149
|
"./src/types.ts",
|
|
144
|
-
"./src/
|
|
145
|
-
"./
|
|
146
|
-
"./services/inertia.ts",
|
|
150
|
+
"./src/client/vite.ts",
|
|
151
|
+
"./factories/main.ts",
|
|
147
152
|
"./src/inertia_middleware.ts",
|
|
148
153
|
"./providers/inertia_provider.ts",
|
|
149
154
|
"./src/plugins/edge/plugin.ts",
|
|
@@ -152,7 +157,19 @@
|
|
|
152
157
|
"outDir": "./build",
|
|
153
158
|
"clean": true,
|
|
154
159
|
"format": "esm",
|
|
155
|
-
"dts":
|
|
160
|
+
"dts": false,
|
|
161
|
+
"sourcemaps": false,
|
|
156
162
|
"target": "esnext"
|
|
157
|
-
}
|
|
163
|
+
},
|
|
164
|
+
"c8": {
|
|
165
|
+
"reporter": [
|
|
166
|
+
"text",
|
|
167
|
+
"html"
|
|
168
|
+
],
|
|
169
|
+
"exclude": [
|
|
170
|
+
"tests/**",
|
|
171
|
+
"tests_helpers/**"
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
"prettier": "@adonisjs/prettier-config"
|
|
158
175
|
}
|
package/build/app.css.stub
DELETED
package/build/chunk-W7TVEB4V.js
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
// src/server_renderer.ts
|
|
2
|
-
import { pathToFileURL } from "node: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
|
-
}
|