@stratal/inertia 0.0.21 → 0.0.22
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/dist/decorate-CzXVx7ZH.mjs +9 -0
- package/dist/generator/type-generator.worker.mjs +1 -1
- package/dist/index.d.mts +68 -105
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +36 -382
- package/dist/index.mjs.map +1 -1
- package/dist/quarry.d.mts +44 -0
- package/dist/quarry.d.mts.map +1 -0
- package/dist/quarry.mjs +392 -0
- package/dist/quarry.mjs.map +1 -0
- package/dist/react.d.mts +1 -31
- package/dist/react.d.mts.map +1 -1
- package/dist/react.mjs +10 -42
- package/dist/react.mjs.map +1 -1
- package/dist/{type-generator-o_PxETTs.mjs → type-generator-bfo14BJI.mjs} +63 -11
- package/dist/type-generator-bfo14BJI.mjs.map +1 -0
- package/dist/vite.d.mts +19 -0
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +46 -7
- package/dist/vite.mjs.map +1 -1
- package/package.json +8 -10
- package/dist/type-generator-o_PxETTs.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DI_TOKENS, Scope, Transient, inject } from "stratal/di";
|
|
1
|
+
import { t as __decorate } from "./decorate-CzXVx7ZH.mjs";
|
|
3
2
|
import { ApplicationError } from "stratal/errors";
|
|
4
|
-
import { I18N_TOKENS } from "stratal/i18n";
|
|
5
3
|
import { Module } from "stratal/module";
|
|
6
4
|
import { Delete, Get, Patch, Post, Put, ROUTER_TOKENS, Route, RouterContext, SchemaValidationError } from "stratal/router";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { dirname, join, relative } from "node:path";
|
|
10
|
-
import { Command } from "stratal/quarry";
|
|
11
|
-
import { watch } from "node:fs/promises";
|
|
5
|
+
import { DI_TOKENS, Request, Singleton, Transient, inject } from "stratal/di";
|
|
6
|
+
import { I18N_TOKENS } from "stratal/i18n";
|
|
12
7
|
import { LOGGER_TOKENS } from "stratal/logger";
|
|
13
8
|
import { deleteCookie, getSignedCookie, setSignedCookie } from "hono/cookie";
|
|
14
9
|
import { z } from "stratal/validation";
|
|
@@ -49,325 +44,6 @@ function augmentRouterContext(resolveService) {
|
|
|
49
44
|
});
|
|
50
45
|
}
|
|
51
46
|
//#endregion
|
|
52
|
-
//#region src/vite/create-vite-config.ts
|
|
53
|
-
function writeTempViteConfig(options) {
|
|
54
|
-
const configPath = join(join(options.cwd, "node_modules", ".stratal"), "vite.config.mjs");
|
|
55
|
-
mkdirSync(dirname(configPath), { recursive: true });
|
|
56
|
-
const hasUserConfig = existsSync(join(options.cwd, "vite.config.ts"));
|
|
57
|
-
const serverConfig = options.server ? `server: { port: ${options.server.port}, host: ${options.server.host ? "true" : "undefined"} },` : "";
|
|
58
|
-
const outDirConfig = options.outDir ? `outDir: '${options.outDir}',` : "";
|
|
59
|
-
writeFileSync(configPath, `
|
|
60
|
-
import { mergeConfig } from 'vite'
|
|
61
|
-
import { cloudflare } from '@cloudflare/vite-plugin'
|
|
62
|
-
import { stratalInertia } from '@stratal/inertia/vite'
|
|
63
|
-
|
|
64
|
-
let inertiaPlugin = null
|
|
65
|
-
try {
|
|
66
|
-
const mod = await import('@inertiajs/vite')
|
|
67
|
-
const inertia = mod.default ?? mod
|
|
68
|
-
inertiaPlugin = inertia()
|
|
69
|
-
} catch {}
|
|
70
|
-
|
|
71
|
-
const baseConfig = {
|
|
72
|
-
plugins: [
|
|
73
|
-
cloudflare(${options.persistTo ? `{ persistState: { path: ${JSON.stringify(options.persistTo)} } }` : ""}),
|
|
74
|
-
...(inertiaPlugin ? [inertiaPlugin] : []),
|
|
75
|
-
...stratalInertia(),
|
|
76
|
-
],
|
|
77
|
-
publicDir: '${join(options.cwd, "src", "inertia", "public").replace(/\\/g, "/")}',
|
|
78
|
-
build: {
|
|
79
|
-
${outDirConfig}
|
|
80
|
-
},
|
|
81
|
-
${serverConfig}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
${hasUserConfig ? `const userModule = await import('${join(options.cwd, "vite.config.ts").replace(/\\/g, "/")}')
|
|
85
|
-
const userConfig = userModule.default ?? userModule
|
|
86
|
-
export default mergeConfig(baseConfig, userConfig)` : "export default baseConfig"}
|
|
87
|
-
`, "utf-8");
|
|
88
|
-
return configPath;
|
|
89
|
-
}
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/commands/inertia-build.command.ts
|
|
92
|
-
var InertiaBuildCommand = class extends Command {
|
|
93
|
-
static command = "inertia:build {--outDir=dist : Output directory} {--ssr : Also build SSR bundle}";
|
|
94
|
-
static description = "Build Inertia.js frontend for production";
|
|
95
|
-
async handle() {
|
|
96
|
-
const outDir = this.string("outDir") || "dist";
|
|
97
|
-
const shouldBuildSsr = this.boolean("ssr");
|
|
98
|
-
const cwd = process.cwd();
|
|
99
|
-
if (!existsSync(join(cwd, "src/inertia/app.tsx"))) {
|
|
100
|
-
this.fail("src/inertia/app.tsx not found. Run `quarry inertia:install` first.");
|
|
101
|
-
return 1;
|
|
102
|
-
}
|
|
103
|
-
const configPath = writeTempViteConfig({
|
|
104
|
-
cwd,
|
|
105
|
-
outDir
|
|
106
|
-
});
|
|
107
|
-
this.info("Building Inertia.js frontend for production...");
|
|
108
|
-
const clientCode = await this.spawnVite(cwd, configPath, ["build"]);
|
|
109
|
-
if (clientCode !== 0) {
|
|
110
|
-
this.fail("Client build failed.");
|
|
111
|
-
return clientCode;
|
|
112
|
-
}
|
|
113
|
-
this.success("Client build complete!");
|
|
114
|
-
if (shouldBuildSsr) {
|
|
115
|
-
this.info("Building SSR bundle...");
|
|
116
|
-
const ssrCode = await this.spawnVite(cwd, configPath, ["build", "--ssr"]);
|
|
117
|
-
if (ssrCode !== 0) {
|
|
118
|
-
this.fail("SSR build failed.");
|
|
119
|
-
return ssrCode;
|
|
120
|
-
}
|
|
121
|
-
this.success("SSR build complete!");
|
|
122
|
-
}
|
|
123
|
-
this.success(`Output in ${outDir}/`);
|
|
124
|
-
this.info("Deploy with: npx wrangler deploy");
|
|
125
|
-
return 0;
|
|
126
|
-
}
|
|
127
|
-
spawnVite(cwd, configPath, args) {
|
|
128
|
-
return new Promise((resolve) => {
|
|
129
|
-
const child = spawn("npx", [
|
|
130
|
-
"vite",
|
|
131
|
-
"--config",
|
|
132
|
-
configPath,
|
|
133
|
-
...args
|
|
134
|
-
], {
|
|
135
|
-
cwd,
|
|
136
|
-
stdio: "inherit",
|
|
137
|
-
shell: true
|
|
138
|
-
});
|
|
139
|
-
child.on("error", (err) => {
|
|
140
|
-
this.fail(`Vite process error: ${err.message}`);
|
|
141
|
-
resolve(1);
|
|
142
|
-
});
|
|
143
|
-
child.on("close", (code) => {
|
|
144
|
-
resolve(code ?? 0);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/commands/inertia-dev.command.ts
|
|
151
|
-
var InertiaDevCommand = class extends Command {
|
|
152
|
-
static command = "inertia:dev {--port= : Dev server port} {--host : Expose to network} {--persist-to= : Shared persist directory for @cloudflare/vite-plugin (relative to cwd; the plugin appends /v3). Use to share R2/KV/cache emulator state across multiple workers in dev.}";
|
|
153
|
-
static description = "Start Inertia.js Vite development server";
|
|
154
|
-
async handle() {
|
|
155
|
-
const port = this.number("port");
|
|
156
|
-
const host = this.boolean("host");
|
|
157
|
-
const persistTo = this.string("persist-to");
|
|
158
|
-
const cwd = process.cwd();
|
|
159
|
-
if (!existsSync(join(cwd, "src/inertia/app.tsx"))) {
|
|
160
|
-
this.fail("src/inertia/app.tsx not found. Run `quarry inertia:install` first.");
|
|
161
|
-
return 1;
|
|
162
|
-
}
|
|
163
|
-
const configPath = writeTempViteConfig({
|
|
164
|
-
cwd,
|
|
165
|
-
server: {
|
|
166
|
-
port,
|
|
167
|
-
host
|
|
168
|
-
},
|
|
169
|
-
persistTo
|
|
170
|
-
});
|
|
171
|
-
this.info("Starting Vite dev server...");
|
|
172
|
-
const args = [
|
|
173
|
-
"vite",
|
|
174
|
-
"dev",
|
|
175
|
-
"--config",
|
|
176
|
-
configPath
|
|
177
|
-
];
|
|
178
|
-
if (host) args.push("--host");
|
|
179
|
-
return new Promise((resolve) => {
|
|
180
|
-
const child = spawn("npx", args, {
|
|
181
|
-
cwd,
|
|
182
|
-
stdio: "inherit",
|
|
183
|
-
shell: true
|
|
184
|
-
});
|
|
185
|
-
child.on("error", (err) => {
|
|
186
|
-
this.fail(`Failed to start dev server: ${err.message}`);
|
|
187
|
-
resolve(1);
|
|
188
|
-
});
|
|
189
|
-
child.on("close", (code) => {
|
|
190
|
-
resolve(code ?? 0);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
//#endregion
|
|
196
|
-
//#region src/commands/inertia-install.command.ts
|
|
197
|
-
const ROOT_HTML = `<!DOCTYPE html>
|
|
198
|
-
<html lang="en">
|
|
199
|
-
<head>
|
|
200
|
-
<meta charset="utf-8" />
|
|
201
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
202
|
-
@viteHead
|
|
203
|
-
@inertiaHead
|
|
204
|
-
</head>
|
|
205
|
-
<body>
|
|
206
|
-
@inertia
|
|
207
|
-
@viteScripts
|
|
208
|
-
</body>
|
|
209
|
-
</html>`;
|
|
210
|
-
const APP_TSX = `import { createInertiaApp } from '@inertiajs/react'
|
|
211
|
-
|
|
212
|
-
createInertiaApp({
|
|
213
|
-
resolve: async (name) => {
|
|
214
|
-
const pages = import.meta.glob('./pages/**/*.tsx')
|
|
215
|
-
const page = await pages[\`./pages/\${name}.tsx\`]?.()
|
|
216
|
-
if (!page) throw new Error(\`Page not found: \${name}\`)
|
|
217
|
-
return page
|
|
218
|
-
},
|
|
219
|
-
})`;
|
|
220
|
-
const HOME_TSX = `export default function Home({ message }: { message: string }) {
|
|
221
|
-
return (
|
|
222
|
-
<div>
|
|
223
|
-
<h1>{message}</h1>
|
|
224
|
-
<p>This page is rendered with Inertia.js and Stratal.</p>
|
|
225
|
-
</div>
|
|
226
|
-
)
|
|
227
|
-
}`;
|
|
228
|
-
var InertiaInstallCommand = class extends Command {
|
|
229
|
-
static command = "inertia:install {--skip-deps : Skip installing npm dependencies}";
|
|
230
|
-
static description = "Scaffold Inertia.js files for a Stratal project";
|
|
231
|
-
async handle() {
|
|
232
|
-
const skipDeps = this.boolean("skip-deps");
|
|
233
|
-
const cwd = process.cwd();
|
|
234
|
-
const inertiaDir = join(cwd, "src", "inertia");
|
|
235
|
-
const pagesDir = join(inertiaDir, "pages");
|
|
236
|
-
this.info("Creating src/inertia/ directory...");
|
|
237
|
-
mkdirSync(pagesDir, { recursive: true });
|
|
238
|
-
const publicDir = join(inertiaDir, "public");
|
|
239
|
-
mkdirSync(publicDir, { recursive: true });
|
|
240
|
-
const gitkeepPath = join(publicDir, ".gitkeep");
|
|
241
|
-
if (!existsSync(gitkeepPath)) writeFileSync(gitkeepPath, "", "utf-8");
|
|
242
|
-
this.success("Created src/inertia/public/");
|
|
243
|
-
const files = [
|
|
244
|
-
{
|
|
245
|
-
path: join(inertiaDir, "root.html"),
|
|
246
|
-
content: ROOT_HTML,
|
|
247
|
-
name: "root.html"
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
path: join(inertiaDir, "app.tsx"),
|
|
251
|
-
content: APP_TSX,
|
|
252
|
-
name: "app.tsx"
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
path: join(pagesDir, "Home.tsx"),
|
|
256
|
-
content: HOME_TSX,
|
|
257
|
-
name: "pages/Home.tsx"
|
|
258
|
-
}
|
|
259
|
-
];
|
|
260
|
-
for (const file of files) if (existsSync(file.path)) this.warn(`Skipping ${file.name} (already exists)`);
|
|
261
|
-
else {
|
|
262
|
-
writeFileSync(file.path, file.content, "utf-8");
|
|
263
|
-
this.success(`Created src/inertia/${file.name}`);
|
|
264
|
-
}
|
|
265
|
-
const appModulePath = join(cwd, "src", "app.module.ts");
|
|
266
|
-
if (existsSync(appModulePath)) {
|
|
267
|
-
this.info("Updating src/app.module.ts...");
|
|
268
|
-
try {
|
|
269
|
-
if (await this.updateAppModule(appModulePath)) this.success("Updated src/app.module.ts with InertiaModule");
|
|
270
|
-
else this.info("InertiaModule already configured in app.module.ts");
|
|
271
|
-
} catch (err) {
|
|
272
|
-
this.warn(`Could not auto-update app.module.ts: ${err.message}`);
|
|
273
|
-
this.info("Please manually add InertiaModule.forRoot() to your module imports");
|
|
274
|
-
}
|
|
275
|
-
} else this.info("No src/app.module.ts found — please manually configure InertiaModule");
|
|
276
|
-
try {
|
|
277
|
-
const { outputPath, pageCount } = await runTypeGeneration(cwd);
|
|
278
|
-
const relPath = relative(cwd, outputPath);
|
|
279
|
-
this.success(`Generated ${relPath} (${pageCount} page${pageCount !== 1 ? "s" : ""})`);
|
|
280
|
-
} catch {
|
|
281
|
-
this.warn("Could not generate initial type definitions. Run `quarry inertia:types` manually.");
|
|
282
|
-
}
|
|
283
|
-
if (!skipDeps) {
|
|
284
|
-
this.newLine();
|
|
285
|
-
this.info("Install the following dependencies:");
|
|
286
|
-
this.line(" npm install @stratal/inertia @inertiajs/react @inertiajs/vite react react-dom");
|
|
287
|
-
this.line(" npm install -D @types/react @types/react-dom vite @cloudflare/vite-plugin");
|
|
288
|
-
}
|
|
289
|
-
this.newLine();
|
|
290
|
-
this.success("Inertia.js scaffolding complete!");
|
|
291
|
-
this.info("Run `quarry inertia:dev` to start the dev server");
|
|
292
|
-
return 0;
|
|
293
|
-
}
|
|
294
|
-
async updateAppModule(modulePath) {
|
|
295
|
-
const { Project, SyntaxKind } = await import("ts-morph");
|
|
296
|
-
const sourceFile = new Project({ useInMemoryFileSystem: false }).addSourceFileAtPath(modulePath);
|
|
297
|
-
if (sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === "@stratal/inertia")) return false;
|
|
298
|
-
sourceFile.addImportDeclaration({
|
|
299
|
-
defaultImport: "rootView",
|
|
300
|
-
moduleSpecifier: "./inertia/root.html?raw"
|
|
301
|
-
});
|
|
302
|
-
sourceFile.addImportDeclaration({
|
|
303
|
-
namedImports: ["InertiaModule"],
|
|
304
|
-
moduleSpecifier: "@stratal/inertia"
|
|
305
|
-
});
|
|
306
|
-
const classes = sourceFile.getClasses();
|
|
307
|
-
for (const cls of classes) {
|
|
308
|
-
const moduleDecorator = cls.getDecorator("Module");
|
|
309
|
-
if (!moduleDecorator) continue;
|
|
310
|
-
const args = moduleDecorator.getArguments();
|
|
311
|
-
if (args.length === 0) continue;
|
|
312
|
-
const objLiteral = args[0].asKind(SyntaxKind.ObjectLiteralExpression);
|
|
313
|
-
if (!objLiteral) continue;
|
|
314
|
-
const importsProp = objLiteral.getProperty("imports");
|
|
315
|
-
if (importsProp) {
|
|
316
|
-
const arrayLiteral = (importsProp.asKind(SyntaxKind.PropertyAssignment)?.getInitializer())?.asKind(SyntaxKind.ArrayLiteralExpression);
|
|
317
|
-
if (arrayLiteral) arrayLiteral.addElement(`InertiaModule.forRoot({\n rootView,\n })`);
|
|
318
|
-
} else objLiteral.addPropertyAssignment({
|
|
319
|
-
name: "imports",
|
|
320
|
-
initializer: `[\n InertiaModule.forRoot({\n rootView,\n }),\n ]`
|
|
321
|
-
});
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
await sourceFile.save();
|
|
325
|
-
return true;
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region src/commands/inertia-types.command.ts
|
|
330
|
-
var InertiaTypesCommand = class extends Command {
|
|
331
|
-
static command = "inertia:types {--watch : Watch for changes and regenerate}";
|
|
332
|
-
static description = "Generate Inertia.js page type definitions";
|
|
333
|
-
async handle() {
|
|
334
|
-
const cwd = process.cwd();
|
|
335
|
-
if (!existsSync(findPagesDir(cwd))) {
|
|
336
|
-
this.fail("src/inertia/pages/ not found. Run `quarry inertia:install` first.");
|
|
337
|
-
return 1;
|
|
338
|
-
}
|
|
339
|
-
if (!await this.generate(cwd)) return 1;
|
|
340
|
-
if (this.boolean("watch")) {
|
|
341
|
-
this.info("Watching for changes...");
|
|
342
|
-
await this.watchForChanges(cwd);
|
|
343
|
-
}
|
|
344
|
-
return 0;
|
|
345
|
-
}
|
|
346
|
-
async generate(cwd) {
|
|
347
|
-
try {
|
|
348
|
-
const { outputPath, pageCount } = await runTypeGeneration(cwd);
|
|
349
|
-
const relPath = relative(cwd, outputPath);
|
|
350
|
-
this.success(`Generated ${relPath} (${pageCount} page${pageCount !== 1 ? "s" : ""})`);
|
|
351
|
-
return true;
|
|
352
|
-
} catch (err) {
|
|
353
|
-
this.fail(`Type generation failed: ${err.message}`);
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
async watchForChanges(cwd) {
|
|
358
|
-
const srcDir = join(cwd, "src");
|
|
359
|
-
try {
|
|
360
|
-
const watcher = watch(srcDir, { recursive: true });
|
|
361
|
-
for await (const event of watcher) if (event.filename && /\.(tsx|ts)$/.test(event.filename)) {
|
|
362
|
-
this.info(`Change detected: ${event.filename}`);
|
|
363
|
-
await this.generate(cwd);
|
|
364
|
-
}
|
|
365
|
-
} catch (err) {
|
|
366
|
-
this.fail(`Watch failed: ${err.message}`);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
//#endregion
|
|
371
47
|
//#region src/inertia.tokens.ts
|
|
372
48
|
const INERTIA_TOKENS = {
|
|
373
49
|
Options: Symbol.for("stratal:inertia:options"),
|
|
@@ -377,11 +53,6 @@ const INERTIA_TOKENS = {
|
|
|
377
53
|
SsrRenderer: Symbol.for("stratal:inertia:ssr-renderer")
|
|
378
54
|
};
|
|
379
55
|
//#endregion
|
|
380
|
-
//#region \0@oxc-project+runtime@0.129.0/helpers/decorateMetadata.js
|
|
381
|
-
function __decorateMetadata(k, v) {
|
|
382
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
383
|
-
}
|
|
384
|
-
//#endregion
|
|
385
56
|
//#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
|
|
386
57
|
function __decorateParam(paramIndex, decorator) {
|
|
387
58
|
return function(target, key) {
|
|
@@ -389,14 +60,6 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
389
60
|
};
|
|
390
61
|
}
|
|
391
62
|
//#endregion
|
|
392
|
-
//#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
|
|
393
|
-
function __decorate(decorators, target, key, desc) {
|
|
394
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
395
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
396
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
397
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
398
|
-
}
|
|
399
|
-
//#endregion
|
|
400
63
|
//#region src/middleware/inertia.middleware.ts
|
|
401
64
|
let InertiaMiddleware = class InertiaMiddleware {
|
|
402
65
|
options;
|
|
@@ -440,11 +103,7 @@ let InertiaMiddleware = class InertiaMiddleware {
|
|
|
440
103
|
}
|
|
441
104
|
}
|
|
442
105
|
};
|
|
443
|
-
InertiaMiddleware = __decorate([
|
|
444
|
-
Transient(),
|
|
445
|
-
__decorateParam(0, inject(INERTIA_TOKENS.Options)),
|
|
446
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
447
|
-
], InertiaMiddleware);
|
|
106
|
+
InertiaMiddleware = __decorate([Transient(), __decorateParam(0, inject(INERTIA_TOKENS.Options))], InertiaMiddleware);
|
|
448
107
|
//#endregion
|
|
449
108
|
//#region src/types.ts
|
|
450
109
|
const INERTIA_PROP_OPTIONAL = Symbol.for("stratal:inertia:prop:optional");
|
|
@@ -545,8 +204,9 @@ let InertiaService = class InertiaService {
|
|
|
545
204
|
...renderOptions.clearHistory ? { clearHistory: true } : {},
|
|
546
205
|
...renderOptions.preserveFragment ? { preserveFragment: true } : {}
|
|
547
206
|
};
|
|
207
|
+
const status = renderOptions.status ?? 200;
|
|
548
208
|
if (isInertia) return new Response(JSON.stringify(page), {
|
|
549
|
-
status
|
|
209
|
+
status,
|
|
550
210
|
headers: {
|
|
551
211
|
"Content-Type": "application/json",
|
|
552
212
|
"X-Inertia": "true",
|
|
@@ -559,7 +219,7 @@ let InertiaService = class InertiaService {
|
|
|
559
219
|
} : await this.ssr.render(page);
|
|
560
220
|
const html = this.template.render(page, ssrResult.head, ssrResult.body);
|
|
561
221
|
return new Response(html, {
|
|
562
|
-
status
|
|
222
|
+
status,
|
|
563
223
|
headers: { "Content-Type": "text/html; charset=utf-8" }
|
|
564
224
|
});
|
|
565
225
|
}
|
|
@@ -619,6 +279,7 @@ let InertiaService = class InertiaService {
|
|
|
619
279
|
const partialDataHeader = ctx.header("x-inertia-partial-data");
|
|
620
280
|
const partialExceptHeader = ctx.header("x-inertia-partial-except");
|
|
621
281
|
const resetHeader = ctx.header("x-inertia-reset");
|
|
282
|
+
const shouldResolveDeferred = ctx.header("x-inertia-resolve-deferred") === "true";
|
|
622
283
|
const isPartialReload = isInertia && partialComponent === component && partialDataHeader;
|
|
623
284
|
const requestedProps = partialDataHeader?.split(",").map((s) => s.trim()) ?? [];
|
|
624
285
|
const exceptProps = partialExceptHeader?.split(",").map((s) => s.trim()) ?? [];
|
|
@@ -641,7 +302,8 @@ let InertiaService = class InertiaService {
|
|
|
641
302
|
}
|
|
642
303
|
if (this.isDeferredProp(value)) {
|
|
643
304
|
if (isPartialReload && this.isRequested(key, requestedProps)) resolvedProps[key] = await value.callback();
|
|
644
|
-
else if (!isPartialReload)
|
|
305
|
+
else if (!isPartialReload) if (shouldResolveDeferred) resolvedProps[key] = await value.callback();
|
|
306
|
+
else {
|
|
645
307
|
deferredProps[value.group] ??= [];
|
|
646
308
|
deferredProps[value.group].push(key);
|
|
647
309
|
}
|
|
@@ -728,15 +390,10 @@ let InertiaService = class InertiaService {
|
|
|
728
390
|
}
|
|
729
391
|
};
|
|
730
392
|
InertiaService = __decorate([
|
|
731
|
-
|
|
393
|
+
Request(INERTIA_TOKENS.InertiaService),
|
|
732
394
|
__decorateParam(0, inject(INERTIA_TOKENS.Options)),
|
|
733
395
|
__decorateParam(1, inject(INERTIA_TOKENS.TemplateService)),
|
|
734
|
-
__decorateParam(2, inject(INERTIA_TOKENS.SsrRenderer))
|
|
735
|
-
__decorateMetadata("design:paramtypes", [
|
|
736
|
-
Object,
|
|
737
|
-
Object,
|
|
738
|
-
Object
|
|
739
|
-
])
|
|
396
|
+
__decorateParam(2, inject(INERTIA_TOKENS.SsrRenderer))
|
|
740
397
|
], InertiaService);
|
|
741
398
|
//#endregion
|
|
742
399
|
//#region src/services/manifest.service.ts
|
|
@@ -744,12 +401,11 @@ const DEFAULT_ENTRY_CLIENT_PATH = "src/inertia/app.tsx";
|
|
|
744
401
|
let ManifestService = class ManifestService {
|
|
745
402
|
manifest;
|
|
746
403
|
entryClientPath;
|
|
404
|
+
isDev = Boolean(import.meta.env.DEV);
|
|
747
405
|
constructor(options) {
|
|
748
|
-
this.manifest =
|
|
406
|
+
this.manifest = globalThis.__STRATAL_INERTIA_MANIFEST__ ?? null;
|
|
749
407
|
this.entryClientPath = (options.entryClientPath ?? DEFAULT_ENTRY_CLIENT_PATH).replace(/^\/+/, "");
|
|
750
|
-
|
|
751
|
-
get isDev() {
|
|
752
|
-
return this.manifest === null;
|
|
408
|
+
if (!this.isDev && !this.manifest) throw new Error("@stratal/inertia: production build is missing the Vite client manifest. This is wired by stratalInertia() in vite.config.ts — confirm it is in your plugin list and that the client environment built successfully before the worker environment.");
|
|
753
409
|
}
|
|
754
410
|
getHeadTags() {
|
|
755
411
|
if (this.isDev) return "<link rel=\"stylesheet\" href=\"/__inertia/ssr-css\" data-ssr-css />";
|
|
@@ -779,11 +435,7 @@ hot.on("vite:afterUpdate", () => {
|
|
|
779
435
|
return tags.join("\n");
|
|
780
436
|
}
|
|
781
437
|
};
|
|
782
|
-
ManifestService = __decorate([
|
|
783
|
-
Transient(),
|
|
784
|
-
__decorateParam(0, inject(INERTIA_TOKENS.Options)),
|
|
785
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
786
|
-
], ManifestService);
|
|
438
|
+
ManifestService = __decorate([Transient(), __decorateParam(0, inject(INERTIA_TOKENS.Options))], ManifestService);
|
|
787
439
|
//#endregion
|
|
788
440
|
//#region src/services/ssr-renderer.service.ts
|
|
789
441
|
let SsrRendererService = class SsrRendererService {
|
|
@@ -827,10 +479,9 @@ let SsrRendererService = class SsrRendererService {
|
|
|
827
479
|
}
|
|
828
480
|
};
|
|
829
481
|
SsrRendererService = __decorate([
|
|
830
|
-
|
|
482
|
+
Singleton(),
|
|
831
483
|
__decorateParam(0, inject(INERTIA_TOKENS.Options)),
|
|
832
|
-
__decorateParam(1, inject(LOGGER_TOKENS.LoggerService))
|
|
833
|
-
__decorateMetadata("design:paramtypes", [Object, Object])
|
|
484
|
+
__decorateParam(1, inject(LOGGER_TOKENS.LoggerService))
|
|
834
485
|
], SsrRendererService);
|
|
835
486
|
//#endregion
|
|
836
487
|
//#region src/services/template.service.ts
|
|
@@ -860,8 +511,7 @@ let TemplateService = class TemplateService {
|
|
|
860
511
|
TemplateService = __decorate([
|
|
861
512
|
Transient(),
|
|
862
513
|
__decorateParam(0, inject(INERTIA_TOKENS.Options)),
|
|
863
|
-
__decorateParam(1, inject(INERTIA_TOKENS.ManifestService))
|
|
864
|
-
__decorateMetadata("design:paramtypes", [Object, Object])
|
|
514
|
+
__decorateParam(1, inject(INERTIA_TOKENS.ManifestService))
|
|
865
515
|
], TemplateService);
|
|
866
516
|
//#endregion
|
|
867
517
|
//#region src/inertia.module.ts
|
|
@@ -894,7 +544,7 @@ let InertiaModule = _InertiaModule = class InertiaModule {
|
|
|
894
544
|
if (context.type !== "http") return void 0;
|
|
895
545
|
if (this.isPrecognitionRequest(context)) return this.handlePrecognitionValidationError(error, context);
|
|
896
546
|
if (!this.isInertiaRequest(context)) return void 0;
|
|
897
|
-
const issues = error.
|
|
547
|
+
const issues = error.issues ?? [];
|
|
898
548
|
const errors = {};
|
|
899
549
|
for (const issue of issues) errors[issue.path] = issue.message;
|
|
900
550
|
context.ctx.flash("errors", errors);
|
|
@@ -902,12 +552,22 @@ let InertiaModule = _InertiaModule = class InertiaModule {
|
|
|
902
552
|
});
|
|
903
553
|
handler.renderable(ApplicationError, (error, context) => {
|
|
904
554
|
if (context.type !== "http") return void 0;
|
|
905
|
-
const message =
|
|
555
|
+
const message = error.message;
|
|
906
556
|
if (this.isPrecognitionRequest(context)) return this.createPrecognitionErrorResponse({ _form: message });
|
|
907
557
|
if (!this.isInertiaRequest(context)) return void 0;
|
|
908
558
|
context.ctx.flash("errors", { _form: message });
|
|
909
559
|
return this.redirectBack(context);
|
|
910
560
|
});
|
|
561
|
+
handler.errorPage(async (errorResponse, status, context) => {
|
|
562
|
+
try {
|
|
563
|
+
return await context.ctx.getContainer().resolve(INERTIA_TOKENS.InertiaService).render(context.ctx, `Errors/${status}`, {
|
|
564
|
+
status,
|
|
565
|
+
message: errorResponse.message
|
|
566
|
+
}, { status });
|
|
567
|
+
} catch {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
});
|
|
911
571
|
}
|
|
912
572
|
onInitialize() {
|
|
913
573
|
augmentRouterContext((ctx) => {
|
|
@@ -921,7 +581,7 @@ let InertiaModule = _InertiaModule = class InertiaModule {
|
|
|
921
581
|
return context.ctx.header("precognition") === "true";
|
|
922
582
|
}
|
|
923
583
|
handlePrecognitionValidationError(error, context) {
|
|
924
|
-
const issues = error.
|
|
584
|
+
const issues = error.issues ?? [];
|
|
925
585
|
let errors = {};
|
|
926
586
|
for (const issue of issues) errors[issue.path] = issue.message;
|
|
927
587
|
const validateOnly = context.ctx.header("precognition-validate-only");
|
|
@@ -964,8 +624,7 @@ let InertiaModule = _InertiaModule = class InertiaModule {
|
|
|
964
624
|
InertiaModule = _InertiaModule = __decorate([Module({ providers: [
|
|
965
625
|
{
|
|
966
626
|
provide: INERTIA_TOKENS.InertiaService,
|
|
967
|
-
useClass: InertiaService
|
|
968
|
-
scope: Scope.Request
|
|
627
|
+
useClass: InertiaService
|
|
969
628
|
},
|
|
970
629
|
{
|
|
971
630
|
provide: INERTIA_TOKENS.TemplateService,
|
|
@@ -977,13 +636,8 @@ InertiaModule = _InertiaModule = __decorate([Module({ providers: [
|
|
|
977
636
|
},
|
|
978
637
|
{
|
|
979
638
|
provide: INERTIA_TOKENS.SsrRenderer,
|
|
980
|
-
useClass: SsrRendererService
|
|
981
|
-
|
|
982
|
-
},
|
|
983
|
-
InertiaInstallCommand,
|
|
984
|
-
InertiaTypesCommand,
|
|
985
|
-
InertiaDevCommand,
|
|
986
|
-
InertiaBuildCommand
|
|
639
|
+
useClass: SsrRendererService
|
|
640
|
+
}
|
|
987
641
|
] })], InertiaModule);
|
|
988
642
|
//#endregion
|
|
989
643
|
//#region src/flash/cookie-flash-store.ts
|
|
@@ -1175,6 +829,6 @@ let HandlePrecognitiveRequests = class HandlePrecognitiveRequests {
|
|
|
1175
829
|
};
|
|
1176
830
|
HandlePrecognitiveRequests = __decorate([Transient()], HandlePrecognitiveRequests);
|
|
1177
831
|
//#endregion
|
|
1178
|
-
export { CookieFlashStore, HandlePrecognitiveRequests, INERTIA_TOKENS,
|
|
832
|
+
export { CookieFlashStore, HandlePrecognitiveRequests, INERTIA_TOKENS, InertiaDelete, InertiaGet, InertiaMiddleware, InertiaModule, InertiaPatch, InertiaPost, InertiaPut, InertiaRoute, InertiaService, ManifestService, SsrRendererService, TemplateService };
|
|
1179
833
|
|
|
1180
834
|
//# sourceMappingURL=index.mjs.map
|