inertia-sails 1.1.0 → 1.3.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.
package/README.md CHANGED
@@ -75,7 +75,7 @@ Return an Inertia page response:
75
75
  return {
76
76
  page: 'users/index', // Component name
77
77
  props: { users: [...] }, // Props passed to component
78
- viewData: { title: '...' } // Data for root EJS template
78
+ locals: { title: '...' } // Locals for root EJS template
79
79
  }
80
80
  ```
81
81
 
@@ -106,12 +106,12 @@ Share data across all requests (app-wide):
106
106
  sails.inertia.shareGlobally('appName', 'My App')
107
107
  ```
108
108
 
109
- #### `viewData(key, value)`
109
+ #### `local(key, value)`
110
110
 
111
- Share data with the root EJS template:
111
+ Set a local variable for the root EJS template:
112
112
 
113
113
  ```js
114
- sails.inertia.viewData('title', 'Dashboard')
114
+ sails.inertia.local('title', 'Dashboard')
115
115
  ```
116
116
 
117
117
  ### Once Props (Cached)
package/index.js CHANGED
@@ -30,7 +30,7 @@
30
30
  * @typedef {Object} InertiaRenderData
31
31
  * @property {string} page - The component name to render
32
32
  * @property {Object.<string, *>} [props] - Props to pass to the component
33
- * @property {Object.<string, *>} [viewData] - Additional view data for the root template
33
+ * @property {Object.<string, *>} [locals] - Additional locals for the root EJS template
34
34
  */
35
35
 
36
36
  /**
@@ -116,7 +116,7 @@ module.exports = function defineInertiaHook(sails) {
116
116
  // Global shared props (for app-wide data like app name, version)
117
117
  // These are merged with request-scoped shares
118
118
  sails.inertia.globalSharedProps = {}
119
- sails.inertia.globalSharedViewData = {}
119
+ sails.inertia.globalSharedLocals = {}
120
120
  // Default history encryption from config
121
121
  sails.inertia.defaultEncryptHistory = sails.config.inertia.history.encrypt
122
122
  sails.on('router:before', function () {
@@ -215,42 +215,42 @@ module.exports = function defineInertiaHook(sails) {
215
215
  },
216
216
 
217
217
  /**
218
- * Add view data for the current request.
218
+ * Set a local for the current request's root EJS template.
219
219
  * Uses AsyncLocalStorage to ensure data doesn't leak between concurrent requests.
220
- * @param {string} key - The key of the view data
221
- * @param {*} value - The value of the view data
220
+ * @param {string} key - The local variable name
221
+ * @param {*} value - The value
222
222
  * @returns {*} - The value that was set
223
223
  */
224
- viewData(key, value) {
224
+ local(key, value) {
225
225
  const context = requestContext.getContext()
226
226
  if (context) {
227
- requestContext.setSharedViewData(key, value)
227
+ requestContext.setSharedLocal(key, value)
228
228
  return value
229
229
  }
230
230
  // Fallback to global if called outside request
231
- sails.inertia.globalSharedViewData[key] = value
231
+ sails.inertia.globalSharedLocals[key] = value
232
232
  return value
233
233
  },
234
234
 
235
235
  /**
236
- * Add view data globally across all requests.
237
- * @param {string} key - The key of the view data
238
- * @param {*} value - The value of the view data
236
+ * Set a local globally across all requests.
237
+ * @param {string} key - The local variable name
238
+ * @param {*} value - The value
239
239
  * @returns {*} - The value that was set
240
240
  */
241
- viewDataGlobally(key, value) {
242
- sails.inertia.globalSharedViewData[key] = value
241
+ localGlobally(key, value) {
242
+ sails.inertia.globalSharedLocals[key] = value
243
243
  return value
244
244
  },
245
245
 
246
246
  /**
247
- * Get view data (merges global + request-scoped)
248
- * @param {string} key - The key of the view data to get
249
- * @returns {*} - The view data
247
+ * Get locals (merges global + request-scoped)
248
+ * @param {string} key - The local variable name to get
249
+ * @returns {*} - The locals
250
250
  */
251
- getViewData(key) {
252
- const globalData = sails.inertia.globalSharedViewData
253
- const requestData = requestContext.getSharedViewData()
251
+ getLocals(key) {
252
+ const globalData = sails.inertia.globalSharedLocals
253
+ const requestData = requestContext.getSharedLocals()
254
254
  const merged = { ...globalData, ...requestData }
255
255
  return key ? merged[key] : merged
256
256
  },
@@ -11,7 +11,7 @@
11
11
  * req: Request,
12
12
  * res: Response,
13
13
  * sharedProps: {}, // Request-scoped shared props
14
- * sharedViewData: {}, // Request-scoped view data
14
+ * sharedLocals: {}, // Request-scoped locals for root EJS template
15
15
  * encryptHistory: null, // Request-scoped history encryption (null = use default)
16
16
  * clearHistory: false, // Request-scoped clear history flag
17
17
  * refreshOnceProps: [], // Props to force-refresh for this request
@@ -40,7 +40,7 @@ module.exports = {
40
40
  req,
41
41
  res,
42
42
  sharedProps: {},
43
- sharedViewData: {},
43
+ sharedLocals: {},
44
44
  encryptHistory: null,
45
45
  clearHistory: false,
46
46
  refreshOnceProps: [], // Props to force-refresh for this request
@@ -97,23 +97,23 @@ module.exports = {
97
97
  },
98
98
 
99
99
  /**
100
- * Get request-scoped shared view data
101
- * @returns {Object} - The shared view data for this request
100
+ * Get request-scoped shared locals
101
+ * @returns {Object} - The shared locals for this request
102
102
  */
103
- getSharedViewData() {
103
+ getSharedLocals() {
104
104
  const context = requestContext.getStore()
105
- return context?.sharedViewData || {}
105
+ return context?.sharedLocals || {}
106
106
  },
107
107
 
108
108
  /**
109
- * Set request-scoped shared view data
109
+ * Set a request-scoped shared local
110
110
  * @param {string} key - The key
111
111
  * @param {*} value - The value
112
112
  */
113
- setSharedViewData(key, value) {
113
+ setSharedLocal(key, value) {
114
114
  const context = requestContext.getStore()
115
115
  if (context) {
116
- context.sharedViewData[key] = value
116
+ context.sharedLocals[key] = value
117
117
  }
118
118
  },
119
119
 
package/lib/render.js CHANGED
@@ -8,11 +8,11 @@ module.exports = async function render(req, res, data) {
8
8
  // Use request-scoped rootView if set, otherwise fall back to config
9
9
  const rootView = requestContext.getRootView() || sails.config.inertia.rootView
10
10
 
11
- // Use request-scoped view data merged with global view data
12
- // This prevents view data from leaking between concurrent requests
13
- const allViewData = {
14
- ...sails.inertia.getViewData(), // Merges global + request-scoped
15
- ...data.viewData
11
+ // Use request-scoped locals merged with global locals
12
+ // This prevents locals from leaking between concurrent requests
13
+ const allLocals = {
14
+ ...sails.inertia.getLocals(), // Merges global + request-scoped
15
+ ...data.locals
16
16
  }
17
17
 
18
18
  let page = await buildPageObject(req, data.page, data.props)
@@ -32,9 +32,6 @@ module.exports = async function render(req, res, data) {
32
32
  return res.json(page)
33
33
  } else {
34
34
  // Implements full page reload
35
- return res.view(rootView, {
36
- page,
37
- viewData: allViewData
38
- })
35
+ return res.view(rootView, { page, ...allLocals })
39
36
  }
40
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-sails",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "The Sails adapter for Inertia.",
5
5
  "main": "index.js",
6
6
  "sails": {