@nara-web/inertia-vue 1.0.1 → 1.0.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/dist/index.cjs CHANGED
@@ -38,8 +38,8 @@ module.exports = __toCommonJS(index_exports);
38
38
 
39
39
  // src/middleware.ts
40
40
  function inertiaMiddleware(options = {}) {
41
- const { rootView = "inertia.html", version = "1.0.0" } = options;
42
- return async (req, res, next) => {
41
+ const { rootView = "inertia.html", version = "1.0.0", viewFn = null } = options;
42
+ return (req, res, next) => {
43
43
  res.inertia = async (component, inertiaProps = {}, viewProps = {}) => {
44
44
  const url = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
45
45
  const props = {
@@ -59,11 +59,15 @@ function inertiaMiddleware(options = {}) {
59
59
  };
60
60
  if (!req.header("X-Inertia")) {
61
61
  try {
62
- const viewService = await import("@services/View").catch(() => null);
63
- if (!viewService || !viewService.view) {
62
+ let viewFunc = viewFn;
63
+ if (!viewFunc) {
64
+ const viewService = await import("@services/View").catch(() => null);
65
+ viewFunc = viewService?.view;
66
+ }
67
+ if (!viewFunc) {
64
68
  throw new Error("View service unavailable");
65
69
  }
66
- const html = await viewService.view(rootView, {
70
+ const html = await viewFunc(rootView, {
67
71
  page: JSON.stringify(inertiaObject),
68
72
  title: process.env["TITLE"] || "Nara App"
69
73
  });
package/dist/index.d.cts CHANGED
@@ -41,6 +41,11 @@ interface VueAdapterOptions {
41
41
  * @default '1.0.0'
42
42
  */
43
43
  version?: string;
44
+ /**
45
+ * Optional view function to render templates
46
+ * If not provided, will try to import from @services/View
47
+ */
48
+ viewFn?: (filename: string, data?: any) => string | Promise<string>;
44
49
  }
45
50
 
46
51
  /**
package/dist/index.d.ts CHANGED
@@ -41,6 +41,11 @@ interface VueAdapterOptions {
41
41
  * @default '1.0.0'
42
42
  */
43
43
  version?: string;
44
+ /**
45
+ * Optional view function to render templates
46
+ * If not provided, will try to import from @services/View
47
+ */
48
+ viewFn?: (filename: string, data?: any) => string | Promise<string>;
44
49
  }
45
50
 
46
51
  /**
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
 
5
5
  // src/middleware.ts
6
6
  function inertiaMiddleware(options = {}) {
7
- const { rootView = "inertia.html", version = "1.0.0" } = options;
8
- return async (req, res, next) => {
7
+ const { rootView = "inertia.html", version = "1.0.0", viewFn = null } = options;
8
+ return (req, res, next) => {
9
9
  res.inertia = async (component, inertiaProps = {}, viewProps = {}) => {
10
10
  const url = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
11
11
  const props = {
@@ -25,11 +25,15 @@ function inertiaMiddleware(options = {}) {
25
25
  };
26
26
  if (!req.header("X-Inertia")) {
27
27
  try {
28
- const viewService = await import("@services/View").catch(() => null);
29
- if (!viewService || !viewService.view) {
28
+ let viewFunc = viewFn;
29
+ if (!viewFunc) {
30
+ const viewService = await import("@services/View").catch(() => null);
31
+ viewFunc = viewService?.view;
32
+ }
33
+ if (!viewFunc) {
30
34
  throw new Error("View service unavailable");
31
35
  }
32
- const html = await viewService.view(rootView, {
36
+ const html = await viewFunc(rootView, {
33
37
  page: JSON.stringify(inertiaObject),
34
38
  title: process.env["TITLE"] || "Nara App"
35
39
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nara-web/inertia-vue",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Vue 3 + Inertia.js adapter for NARA",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",