@arkstack/inertia 0.15.1 → 0.15.3

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 ADDED
@@ -0,0 +1,65 @@
1
+ # @arkstack/inertia
2
+
3
+ [![@arkstack/inertia](https://img.shields.io/npm/dt/@arkstack/inertia?style=flat-square&label=@arkstack/inertia&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F@arkstack/inertia)](https://www.npmjs.com/package/@arkstack/inertia)
4
+
5
+ A runtime-agnostic [InertiaJS](https://inertiajs.com) server-side adapter for Arkstack. Build a single-page app (Vue, React, or Svelte) without an API: controllers return page components and props, and Inertia handles client-side routing. Works with both the Express and H3 drivers.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pnpm add @arkstack/inertia
11
+ ```
12
+
13
+ Then register the middleware in `src/config/middleware.ts` under `before` (alongside `resora()`):
14
+
15
+ ```ts
16
+ import { inertia, resora } from '@arkstack/driver-express/middlewares' // or @arkstack/driver-h3/middlewares
17
+
18
+ export default (): MiddlewareConfig => ({
19
+ before: [resora(), inertia()],
20
+ })
21
+ ```
22
+
23
+ Publish the config and root template:
24
+
25
+ ```sh
26
+ ark publish --package @arkstack/inertia
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ts
32
+ import { inertia, Inertia } from '@arkstack/inertia'
33
+
34
+ // Render a page — JSON page object on Inertia visits, full HTML on first load
35
+ return inertia('Users/Index', { users: await User.all() })
36
+
37
+ // Shared props (global at boot, or request-scoped inside a handler)
38
+ inertia().share('appName', config('app.name'))
39
+
40
+ // Partial-reload helpers
41
+ inertia('Users/Index', {
42
+ users: await User.all(),
43
+ stats: Inertia.lazy(() => expensiveStats()), // only on a partial reload that asks for it
44
+ chart: Inertia.defer(() => buildChart()), // fetched by the client after load
45
+ auth: Inertia.always({ user: request.user }), // always present, even on partials
46
+ })
47
+
48
+ // Redirects (302 -> 303 for PUT/PATCH/DELETE) and external/full-page visits
49
+ Inertia.redirect('/users')
50
+ Inertia.location('https://example.com')
51
+ ```
52
+
53
+ ## Server-side rendering
54
+
55
+ Set `ssr.enabled` in `src/config/inertia.ts`, build an SSR bundle, and run it with the supervised command:
56
+
57
+ ```sh
58
+ ark inertia:ssr # runs dist-ssr/ssr.js, restarting it if it crashes
59
+ ```
60
+
61
+ The initial visit is then server-rendered and the client hydrates it; if the SSR server is unreachable the adapter falls back to client-side rendering.
62
+
63
+ ## Documentation
64
+
65
+ See the [Inertia guide](https://arkstack.toneflix.net/guide/inertia) for the full setup, partial reloads, asset versioning, configuration, and SSR.
@@ -1,4 +1,4 @@
1
- import { n as resolveSsrBundle, o as inertiaConfig, r as superviseProcess } from "../ssr-process-DkRTrGvf.js";
1
+ import { n as resolveSsrBundle, o as inertiaConfig, r as superviseProcess } from "../ssr-process-C6QRQAaQ.js";
2
2
  import { Arkstack } from "@arkstack/contract";
3
3
  import { Command } from "@h3ravel/musket";
4
4
  import { existsSync } from "node:fs";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Response } from "@arkstack/http";
2
+ import { ViewFactory } from "@arkstack/view";
2
3
 
3
4
  //#region src/types.d.ts
4
5
  /**
@@ -264,6 +265,23 @@ declare const builtInTemplate: (mount: string, head?: string) => string;
264
265
  */
265
266
  declare const renderRootHtml: (page: InertiaPage, config: InertiaConfig) => Promise<string>;
266
267
  //#endregion
268
+ //#region src/tags.d.ts
269
+ /**
270
+ * Register the `@inertia` and `@inertiaHead` Edge tags on a view factory.
271
+ *
272
+ * - `@inertia` renders the root mount element (`<div data-page="…">`), or the
273
+ * server-rendered markup when SSR is enabled.
274
+ * - `@inertiaHead` renders the SSR head tags (empty without SSR).
275
+ *
276
+ * Both read the values the adapter passes to the root template, so they replace
277
+ * the equivalent `{{{ inertia }}}` / `{{{ inertiaHead }}}` interpolations.
278
+ * Idempotent per factory.
279
+ *
280
+ * @param factory
281
+ * @returns
282
+ */
283
+ declare const registerInertiaTags: (factory: ViewFactory) => void;
284
+ //#endregion
267
285
  //#region src/ssr.d.ts
268
286
  /** The default address the Inertia SSR server listens on. */
269
287
  declare const DEFAULT_SSR_URL = "http://127.0.0.1:13714/render";
@@ -374,4 +392,4 @@ declare const SEE_OTHER_METHODS: Set<string>;
374
392
  */
375
393
  declare const shouldUpgradeRedirect: (method: string, status: number) => boolean;
376
394
  //#endregion
377
- export { AlwaysProp, AlwaysPropContract, DEFAULT_SSR_BUNDLE, DEFAULT_SSR_URL, DeferProp, DeferPropContract, Inertia, InertiaConfig, InertiaPage, InertiaPropWrapper, InertiaRequest, type InertiaStore, LazyProp, LazyPropContract, PageProps, SEE_OTHER_METHODS, type SsrProcessController, type SsrResponse, type SuperviseOptions, builtInTemplate, configure, currentStore, defaultConfig, escapeHtmlAttribute, flushShared, inertia, inertiaConfig, isAlwaysProp, isDeferProp, isLazyProp, isPropWrapper, renderDataPage, renderRootHtml, renderViaSsr, resetConfig, resolveProps, resolveSsrBundle, resolveVersion, runInertia, setVersion, shareData, sharedData, shouldUpgradeRedirect, superviseProcess };
395
+ export { AlwaysProp, AlwaysPropContract, DEFAULT_SSR_BUNDLE, DEFAULT_SSR_URL, DeferProp, DeferPropContract, Inertia, InertiaConfig, InertiaPage, InertiaPropWrapper, InertiaRequest, type InertiaStore, LazyProp, LazyPropContract, PageProps, SEE_OTHER_METHODS, type SsrProcessController, type SsrResponse, type SuperviseOptions, builtInTemplate, configure, currentStore, defaultConfig, escapeHtmlAttribute, flushShared, inertia, inertiaConfig, isAlwaysProp, isDeferProp, isLazyProp, isPropWrapper, registerInertiaTags, renderDataPage, renderRootHtml, renderViaSsr, resetConfig, resolveProps, resolveSsrBundle, resolveVersion, runInertia, setVersion, shareData, sharedData, shouldUpgradeRedirect, superviseProcess };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import { a as defaultConfig, c as resolveVersion, i as configure, l as setVersion, n as resolveSsrBundle, o as inertiaConfig, r as superviseProcess, s as resetConfig, t as DEFAULT_SSR_BUNDLE } from "./ssr-process-DkRTrGvf.js";
1
+ import { t as registerInertiaTags } from "./tags-DpBq4bSL.js";
2
+ import { a as defaultConfig, c as resolveVersion, i as configure, l as setVersion, n as resolveSsrBundle, o as inertiaConfig, r as superviseProcess, s as resetConfig, t as DEFAULT_SSR_BUNDLE } from "./ssr-process-C6QRQAaQ.js";
2
3
  import { AsyncLocalStorage } from "node:async_hooks";
3
4
  import { Response } from "@arkstack/http";
4
5
  //#region src/props.ts
@@ -191,7 +192,10 @@ const renderRootHtml = async (page, config) => {
191
192
  }
192
193
  try {
193
194
  const { view } = await import("@arkstack/view");
194
- if (view().exists(config.root_view)) return await view(config.root_view, {
195
+ const { registerInertiaTags } = await import("./tags-DpBq4bSL.js").then((n) => n.n);
196
+ const factory = view();
197
+ registerInertiaTags(factory);
198
+ if (factory.exists(config.root_view)) return await view(config.root_view, {
195
199
  page,
196
200
  inertia: mount,
197
201
  inertiaHead: head
@@ -391,4 +395,4 @@ function inertia(component, props = {}) {
391
395
  return Inertia.render(component, props);
392
396
  }
393
397
  //#endregion
394
- export { AlwaysProp, DEFAULT_SSR_BUNDLE, DEFAULT_SSR_URL, DeferProp, Inertia, LazyProp, SEE_OTHER_METHODS, builtInTemplate, configure, currentStore, defaultConfig, escapeHtmlAttribute, flushShared, inertia, inertiaConfig, isAlwaysProp, isDeferProp, isLazyProp, isPropWrapper, renderDataPage, renderRootHtml, renderViaSsr, resetConfig, resolveProps, resolveSsrBundle, resolveVersion, runInertia, setVersion, shareData, sharedData, shouldUpgradeRedirect, superviseProcess };
398
+ export { AlwaysProp, DEFAULT_SSR_BUNDLE, DEFAULT_SSR_URL, DeferProp, Inertia, LazyProp, SEE_OTHER_METHODS, builtInTemplate, configure, currentStore, defaultConfig, escapeHtmlAttribute, flushShared, inertia, inertiaConfig, isAlwaysProp, isDeferProp, isLazyProp, isPropWrapper, registerInertiaTags, renderDataPage, renderRootHtml, renderViaSsr, resetConfig, resolveProps, resolveSsrBundle, resolveVersion, runInertia, setVersion, shareData, sharedData, shouldUpgradeRedirect, superviseProcess };
@@ -0,0 +1,51 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ //#region src/tags.ts
14
+ var tags_exports = /* @__PURE__ */ __exportAll({ registerInertiaTags: () => registerInertiaTags });
15
+ /** Factories that already have the Inertia tags registered. */
16
+ const registered = /* @__PURE__ */ new WeakSet();
17
+ /**
18
+ * Build an Edge tag compiler that outputs a template data variable raw (falling
19
+ * back to an empty string when it is absent).
20
+ *
21
+ * @param name
22
+ * @returns
23
+ */
24
+ const outputVariable = (name) => {
25
+ return (parser, buffer, token) => {
26
+ const ast = parser.utils.transformAst(parser.utils.generateAST(`${name} || ""`, token.loc, token.filename), token.filename, parser);
27
+ buffer.outputExpression(parser.utils.stringify(ast), token.filename, token.loc.start.line, false);
28
+ };
29
+ };
30
+ /**
31
+ * Register the `@inertia` and `@inertiaHead` Edge tags on a view factory.
32
+ *
33
+ * - `@inertia` renders the root mount element (`<div data-page="…">`), or the
34
+ * server-rendered markup when SSR is enabled.
35
+ * - `@inertiaHead` renders the SSR head tags (empty without SSR).
36
+ *
37
+ * Both read the values the adapter passes to the root template, so they replace
38
+ * the equivalent `{{{ inertia }}}` / `{{{ inertiaHead }}}` interpolations.
39
+ * Idempotent per factory.
40
+ *
41
+ * @param factory
42
+ * @returns
43
+ */
44
+ const registerInertiaTags = (factory) => {
45
+ if (registered.has(factory)) return;
46
+ registered.add(factory);
47
+ factory.tag("inertia", false, false, outputVariable("inertia"));
48
+ factory.tag("inertiaHead", false, false, outputVariable("inertiaHead"));
49
+ };
50
+ //#endregion
51
+ export { tags_exports as n, registerInertiaTags as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/inertia",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "type": "module",
5
5
  "description": "InertiaJS server-side adapter for Arkstack, building the modern monolith with server-driven SPAs.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/inertia",
@@ -33,13 +33,13 @@
33
33
  "./package.json": "./package.json"
34
34
  },
35
35
  "dependencies": {
36
- "@arkstack/common": "^0.15.1"
36
+ "@arkstack/common": "^0.15.3"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@h3ravel/musket": "^2.2.1",
40
- "@arkstack/contract": "^0.15.1",
41
- "@arkstack/http": "^0.15.1",
42
- "@arkstack/view": "^0.15.1"
40
+ "@arkstack/contract": "^0.15.3",
41
+ "@arkstack/http": "^0.15.3",
42
+ "@arkstack/view": "^0.15.3"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@arkstack/view": {
@@ -1,5 +1,5 @@
1
- import type { InertiaConfig } from '@arkstack/inertia';
2
- import { env } from '@arkstack/common';
1
+ import type { InertiaConfig } from '@arkstack/inertia'
2
+ import { env } from '@arkstack/common'
3
3
 
4
4
  /**
5
5
  * Inertia adapter configuration.
@@ -36,5 +36,5 @@ export default (): InertiaConfig => {
36
36
  url: env('INERTIA_SSR_URL', 'http://127.0.0.1:13714/render'),
37
37
  bundle: 'dist-ssr/ssr.js',
38
38
  },
39
- };
40
- };
39
+ }
40
+ }
@@ -3,12 +3,10 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- {{{ inertiaHead }}}
7
- {{-- Replace with your Vite client + entry tags, e.g.: --}}
8
- {{-- <script type="module" src="http://localhost:5173/@@vite/client"></script> --}}
9
- {{-- <script type="module" src="http://localhost:5173/src/main.ts"></script> --}}
6
+ @inertiaHead
7
+ @vite('resources/js/app.ts')
10
8
  </head>
11
9
  <body>
12
- {{{ inertia }}}
10
+ @inertia
13
11
  </body>
14
12
  </html>