@gravito/ion 3.0.0 → 3.0.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/dist/index.cjs CHANGED
@@ -159,21 +159,31 @@ var OrbitIon = class {
159
159
  this.options = options;
160
160
  }
161
161
  /**
162
- * Install the Inertia orbit into PlanetCore
162
+ * Install the inertia orbit into PlanetCore
163
163
  */
164
164
  install(core) {
165
- core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed");
165
+ core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed (Callable Interface)");
166
166
  const appVersion = this.options.version ?? core.config.get("APP_VERSION", "1.0.0");
167
167
  const rootView = this.options.rootView ?? "app";
168
168
  core.adapter.use("*", async (c, next) => {
169
- const gravitoCtx = c;
170
- const inertia = new InertiaService(gravitoCtx, {
169
+ const service = new InertiaService(c, {
171
170
  version: String(appVersion),
172
171
  rootView
173
172
  });
174
- c.set("inertia", inertia);
175
- await next();
176
- return void 0;
173
+ const inertiaProxy = (component, props = {}, rootVars = {}) => {
174
+ return service.render(component, props, rootVars);
175
+ };
176
+ Object.assign(inertiaProxy, {
177
+ share: service.share.bind(service),
178
+ shareAll: service.shareAll.bind(service),
179
+ getSharedProps: service.getSharedProps.bind(service),
180
+ render: service.render.bind(service),
181
+ // Also allow .render()
182
+ service
183
+ // Access to the raw service instance
184
+ });
185
+ c.set("inertia", inertiaProxy);
186
+ return await next();
177
187
  });
178
188
  }
179
189
  };
package/dist/index.d.cts CHANGED
@@ -122,39 +122,80 @@ declare class InertiaService {
122
122
  * @since 1.0.0
123
123
  */
124
124
 
125
- declare module '@gravito/core' {
126
- interface GravitoVariables {
127
- /** Inertia.js service for SPA rendering */
128
- inertia?: InertiaService;
129
- }
130
- }
131
125
  /**
132
- * OrbitIon - Inertia.js integration orbit
133
- *
134
- * This orbit provides seamless Inertia.js integration, enabling
135
- * SPA-like navigation with server-side routing.
126
+ * InertiaHelper is a callable function and service suite injected into the Gravito context.
127
+ * It allows you to render Inertia components directly or manage shared data.
136
128
  *
137
129
  * @example
138
130
  * ```typescript
139
- * import { PlanetCore, defineConfig } from '@gravito/core'
140
- * import { OrbitIon } from '@gravito/ion'
131
+ * // Direct call rendering
132
+ * return ctx.get('inertia')('Welcome', { user });
141
133
  *
142
- * const core = await PlanetCore.boot(defineConfig({
143
- * orbits: [OrbitIon]
144
- * }))
134
+ * // Using shared data
135
+ * ctx.get('inertia').share('appName', 'Gravito App');
145
136
  * ```
137
+ * @public
138
+ */
139
+ interface InertiaHelper {
140
+ /**
141
+ * Render an Inertia component.
142
+ * Shortcut for context.get('inertia').render()
143
+ *
144
+ * @param component - The name of the frontend component (e.g., 'Pages/Home')
145
+ * @param props - Data to pass to the component
146
+ * @param rootVars - Variables for the root HTML template (e.g., meta tags)
147
+ */
148
+ (component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
149
+ /** Share data with all Inertia responses for the remainder of the request */
150
+ share(key: string, value: unknown): void;
151
+ /** Share multiple props at once */
152
+ shareAll(props: Record<string, unknown>): void;
153
+ /** Get all currently shared props */
154
+ getSharedProps(): Record<string, unknown>;
155
+ /** Explicitly render an Inertia component */
156
+ render(component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
157
+ /** Direct access to the low-level Inertia service instance */
158
+ service: InertiaService;
159
+ }
160
+ /**
161
+ * Options for configuring OrbitIon.
162
+ * @public
146
163
  */
147
164
  interface OrbitIonOptions {
165
+ /** Current asset version to detect staleness (X-Inertia-Version) */
148
166
  version?: string;
167
+ /** The root HTML template view (default: 'app') */
149
168
  rootView?: string;
150
169
  }
170
+ /**
171
+ * OrbitIon provides official Inertia.js integration for Gravito.
172
+ *
173
+ * It handles Inertia requests, partial reloads, asset versioning, and seamless
174
+ * data sharing between the server and your frontend application (React, Vue, etc.).
175
+ *
176
+ * It injects an `InertiaHelper` into the context, allowing you to render
177
+ * components with a simple function call: `c.get('inertia')('Page', { props })`.
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * import { OrbitIon } from '@gravito/ion';
182
+ *
183
+ * core.addOrbit(new OrbitIon({
184
+ * version: '1.0.0',
185
+ * rootView: 'app'
186
+ * }));
187
+ * ```
188
+ *
189
+ * @public
190
+ * @since 3.0.0
191
+ */
151
192
  declare class OrbitIon implements GravitoOrbit {
152
193
  private options;
153
194
  constructor(options?: OrbitIonOptions);
154
195
  /**
155
- * Install the Inertia orbit into PlanetCore
196
+ * Install the inertia orbit into PlanetCore
156
197
  */
157
198
  install(core: PlanetCore): void;
158
199
  }
159
200
 
160
- export { type InertiaConfig, InertiaService, OrbitIon, type OrbitIonOptions, OrbitIon as default };
201
+ export { type InertiaConfig, type InertiaHelper, InertiaService, OrbitIon, type OrbitIonOptions, OrbitIon as default };
package/dist/index.d.ts CHANGED
@@ -122,39 +122,80 @@ declare class InertiaService {
122
122
  * @since 1.0.0
123
123
  */
124
124
 
125
- declare module '@gravito/core' {
126
- interface GravitoVariables {
127
- /** Inertia.js service for SPA rendering */
128
- inertia?: InertiaService;
129
- }
130
- }
131
125
  /**
132
- * OrbitIon - Inertia.js integration orbit
133
- *
134
- * This orbit provides seamless Inertia.js integration, enabling
135
- * SPA-like navigation with server-side routing.
126
+ * InertiaHelper is a callable function and service suite injected into the Gravito context.
127
+ * It allows you to render Inertia components directly or manage shared data.
136
128
  *
137
129
  * @example
138
130
  * ```typescript
139
- * import { PlanetCore, defineConfig } from '@gravito/core'
140
- * import { OrbitIon } from '@gravito/ion'
131
+ * // Direct call rendering
132
+ * return ctx.get('inertia')('Welcome', { user });
141
133
  *
142
- * const core = await PlanetCore.boot(defineConfig({
143
- * orbits: [OrbitIon]
144
- * }))
134
+ * // Using shared data
135
+ * ctx.get('inertia').share('appName', 'Gravito App');
145
136
  * ```
137
+ * @public
138
+ */
139
+ interface InertiaHelper {
140
+ /**
141
+ * Render an Inertia component.
142
+ * Shortcut for context.get('inertia').render()
143
+ *
144
+ * @param component - The name of the frontend component (e.g., 'Pages/Home')
145
+ * @param props - Data to pass to the component
146
+ * @param rootVars - Variables for the root HTML template (e.g., meta tags)
147
+ */
148
+ (component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
149
+ /** Share data with all Inertia responses for the remainder of the request */
150
+ share(key: string, value: unknown): void;
151
+ /** Share multiple props at once */
152
+ shareAll(props: Record<string, unknown>): void;
153
+ /** Get all currently shared props */
154
+ getSharedProps(): Record<string, unknown>;
155
+ /** Explicitly render an Inertia component */
156
+ render(component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
157
+ /** Direct access to the low-level Inertia service instance */
158
+ service: InertiaService;
159
+ }
160
+ /**
161
+ * Options for configuring OrbitIon.
162
+ * @public
146
163
  */
147
164
  interface OrbitIonOptions {
165
+ /** Current asset version to detect staleness (X-Inertia-Version) */
148
166
  version?: string;
167
+ /** The root HTML template view (default: 'app') */
149
168
  rootView?: string;
150
169
  }
170
+ /**
171
+ * OrbitIon provides official Inertia.js integration for Gravito.
172
+ *
173
+ * It handles Inertia requests, partial reloads, asset versioning, and seamless
174
+ * data sharing between the server and your frontend application (React, Vue, etc.).
175
+ *
176
+ * It injects an `InertiaHelper` into the context, allowing you to render
177
+ * components with a simple function call: `c.get('inertia')('Page', { props })`.
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * import { OrbitIon } from '@gravito/ion';
182
+ *
183
+ * core.addOrbit(new OrbitIon({
184
+ * version: '1.0.0',
185
+ * rootView: 'app'
186
+ * }));
187
+ * ```
188
+ *
189
+ * @public
190
+ * @since 3.0.0
191
+ */
151
192
  declare class OrbitIon implements GravitoOrbit {
152
193
  private options;
153
194
  constructor(options?: OrbitIonOptions);
154
195
  /**
155
- * Install the Inertia orbit into PlanetCore
196
+ * Install the inertia orbit into PlanetCore
156
197
  */
157
198
  install(core: PlanetCore): void;
158
199
  }
159
200
 
160
- export { type InertiaConfig, InertiaService, OrbitIon, type OrbitIonOptions, OrbitIon as default };
201
+ export { type InertiaConfig, type InertiaHelper, InertiaService, OrbitIon, type OrbitIonOptions, OrbitIon as default };
package/dist/index.js CHANGED
@@ -131,21 +131,31 @@ var OrbitIon = class {
131
131
  this.options = options;
132
132
  }
133
133
  /**
134
- * Install the Inertia orbit into PlanetCore
134
+ * Install the inertia orbit into PlanetCore
135
135
  */
136
136
  install(core) {
137
- core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed");
137
+ core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed (Callable Interface)");
138
138
  const appVersion = this.options.version ?? core.config.get("APP_VERSION", "1.0.0");
139
139
  const rootView = this.options.rootView ?? "app";
140
140
  core.adapter.use("*", async (c, next) => {
141
- const gravitoCtx = c;
142
- const inertia = new InertiaService(gravitoCtx, {
141
+ const service = new InertiaService(c, {
143
142
  version: String(appVersion),
144
143
  rootView
145
144
  });
146
- c.set("inertia", inertia);
147
- await next();
148
- return void 0;
145
+ const inertiaProxy = (component, props = {}, rootVars = {}) => {
146
+ return service.render(component, props, rootVars);
147
+ };
148
+ Object.assign(inertiaProxy, {
149
+ share: service.share.bind(service),
150
+ shareAll: service.shareAll.bind(service),
151
+ getSharedProps: service.getSharedProps.bind(service),
152
+ render: service.render.bind(service),
153
+ // Also allow .render()
154
+ service
155
+ // Access to the raw service instance
156
+ });
157
+ c.set("inertia", inertiaProxy);
158
+ return await next();
149
159
  });
150
160
  }
151
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/ion",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Inertia.js adapter for Gravito",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",