@adonisjs/inertia 2.1.3 → 3.0.0

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.
@@ -73,6 +73,7 @@ var InertiaHeaders = {
73
73
  Reset: "x-inertia-reset",
74
74
  Version: "x-inertia-version",
75
75
  Location: "x-inertia-location",
76
+ ErrorBag: "X-Inertia-Error-Bag",
76
77
  PartialOnly: "x-inertia-partial-data",
77
78
  PartialExcept: "x-inertia-partial-except",
78
79
  PartialComponent: "x-inertia-partial-component"
@@ -358,9 +359,34 @@ var InertiaMiddleware = class {
358
359
  this.config = config;
359
360
  this.vite = vite;
360
361
  }
362
+ /**
363
+ * Resolves the validation errors to be shared with Inertia
364
+ */
365
+ #resolveValidationErrors(ctx) {
366
+ const { session, request } = ctx;
367
+ if (!session.flashMessages.has("errorsBag.E_VALIDATION_ERROR")) {
368
+ return session.flashMessages.get("errorsBag");
369
+ }
370
+ const errors = Object.entries(session.flashMessages.get("inputErrorsBag")).reduce(
371
+ (acc, [field, messages]) => {
372
+ acc[field] = Array.isArray(messages) ? messages[0] : messages;
373
+ return acc;
374
+ },
375
+ {}
376
+ );
377
+ const errorBag = request.header(InertiaHeaders.ErrorBag);
378
+ return errorBag ? { [errorBag]: errors } : errors;
379
+ }
380
+ /**
381
+ * Share validation and flashed errors with Inertia
382
+ */
383
+ #shareErrors(ctx) {
384
+ ctx.inertia.share({ errors: ctx.inertia.always(() => this.#resolveValidationErrors(ctx)) });
385
+ }
361
386
  async handle(ctx, next) {
362
387
  const { response, request } = ctx;
363
388
  ctx.inertia = new Inertia(ctx, this.config, this.vite);
389
+ this.#shareErrors(ctx);
364
390
  await next();
365
391
  const isInertiaRequest = !!request.header(InertiaHeaders.Inertia);
366
392
  if (!isInertiaRequest) return;
package/build/config.stub CHANGED
@@ -14,7 +14,7 @@ const inertiaConfig = defineConfig({
14
14
  * Data that should be shared with all rendered pages
15
15
  */
16
16
  sharedData: {
17
- errors: (ctx) => ctx.inertia.always(() => ctx.session?.flashMessages.get('errors')),
17
+ // user: (ctx) => ctx.inertia.always(() => ctx.auth.user),
18
18
  },
19
19
 
20
20
  /**
package/build/index.js CHANGED
@@ -184,6 +184,7 @@ import { slash } from "@poppinss/utils";
184
184
  import { configProvider } from "@adonisjs/core";
185
185
 
186
186
  // src/version_cache.ts
187
+ import { createHash } from "node:crypto";
187
188
  import { readFile } from "node:fs/promises";
188
189
  var VersionCache = class {
189
190
  constructor(appRoot, assetsVersion) {
@@ -197,10 +198,9 @@ var VersionCache = class {
197
198
  */
198
199
  async #getManifestHash() {
199
200
  try {
200
- const crc32 = await import("crc-32");
201
201
  const manifestPath = new URL("public/assets/.vite/manifest.json", this.appRoot);
202
202
  const manifestFile = await readFile(manifestPath, "utf-8");
203
- this.#cachedVersion = crc32.default.str(manifestFile);
203
+ this.#cachedVersion = createHash("md5").update(manifestFile).digest("hex");
204
204
  return this.#cachedVersion;
205
205
  } catch {
206
206
  this.#cachedVersion = "1";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-DLEGZFQ5.js";
3
+ } from "../chunk-5NMMBA7E.js";
4
4
 
5
5
  // providers/inertia_provider.ts
6
6
  import { configProvider } from "@adonisjs/core";
@@ -98,6 +98,7 @@ declare module '@adonisjs/core/http' {
98
98
  * set appropriate headers/status
99
99
  */
100
100
  declare class InertiaMiddleware {
101
+ #private;
101
102
  protected config: ResolvedConfig;
102
103
  protected vite?: Vite | undefined;
103
104
  constructor(config: ResolvedConfig, vite?: Vite | undefined);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-DLEGZFQ5.js";
3
+ } from "../chunk-5NMMBA7E.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "2.1.3",
4
+ "version": "3.0.0",
5
5
  "engines": {
6
6
  "node": ">=20.6.0"
7
7
  },
@@ -48,13 +48,13 @@
48
48
  "@japa/api-client": "^2.0.4",
49
49
  "@japa/assert": "3.0.0",
50
50
  "@japa/expect-type": "^2.0.2",
51
- "@japa/file-system": "^2.3.0",
51
+ "@japa/file-system": "^2.3.1",
52
52
  "@japa/plugin-adonisjs": "^3.0.1",
53
53
  "@japa/runner": "3.1.4",
54
- "@japa/snapshot": "^2.0.6",
55
- "@release-it/conventional-changelog": "^9.0.3",
56
- "@swc/core": "^1.10.1",
57
- "@types/node": "^22.10.2",
54
+ "@japa/snapshot": "^2.0.7",
55
+ "@release-it/conventional-changelog": "^9.0.4",
56
+ "@swc/core": "^1.10.4",
57
+ "@types/node": "^22.10.5",
58
58
  "@types/qs": "^6.9.17",
59
59
  "@types/supertest": "^6.0.2",
60
60
  "@vavite/multibuild": "^5.1.0",
@@ -66,17 +66,16 @@
66
66
  "eslint": "^9.17.0",
67
67
  "get-port": "^7.1.0",
68
68
  "prettier": "^3.4.2",
69
- "release-it": "^17.10.0",
69
+ "release-it": "^17.11.0",
70
70
  "supertest": "^7.0.0",
71
71
  "ts-node-maintained": "^10.9.4",
72
72
  "tsup": "^8.3.5",
73
73
  "typescript": "~5.7.2",
74
- "vite": "^6.0.3"
74
+ "vite": "^6.0.7"
75
75
  },
76
76
  "dependencies": {
77
- "@poppinss/utils": "^6.8.3",
77
+ "@poppinss/utils": "^6.9.2",
78
78
  "@tuyau/utils": "^0.0.6",
79
- "crc-32": "^1.2.2",
80
79
  "edge-error": "^4.0.1",
81
80
  "html-entities": "^2.5.2",
82
81
  "locate-path": "^7.2.0",
@@ -106,7 +105,6 @@
106
105
  "prettier": "@adonisjs/prettier-config",
107
106
  "release-it": {
108
107
  "git": {
109
- "requireCleanWorkingDir": true,
110
108
  "requireUpstream": true,
111
109
  "commitMessage": "chore(release): ${version}",
112
110
  "tagAnnotation": "v${version}",
@@ -156,5 +154,6 @@
156
154
  "format": "esm",
157
155
  "dts": true,
158
156
  "target": "esnext"
159
- }
157
+ },
158
+ "packageManager": "pnpm@9.15.2+sha512.93e57b0126f0df74ce6bff29680394c0ba54ec47246b9cf321f0121d8d9bb03f750a705f24edc3c1180853afd7c2c3b94196d0a3d53d3e069d9e2793ef11f321"
160
159
  }