@raketa-cloud/admin 1.8.8 → 1.8.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/HonoAdapter.js +26 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-cloud/admin",
3
- "version": "1.8.8",
3
+ "version": "1.8.9",
4
4
  "main": "src/index.js",
5
5
  "files": [
6
6
  "src/",
@@ -65,11 +65,19 @@ function putIn(result, key, value) {
65
65
  const sanitizePath = (filePath) =>
66
66
  path.normalize(path.join("/", ...filePath.split("/")));
67
67
 
68
+ function packageFallbackPaths(views, suffix) {
69
+ const rest = views.split("/").slice(1);
70
+ return ["resources", "resource_revisions"].map((base) =>
71
+ sanitizePath(`${currentPath}/views/${[base, ...rest].join("/")}/${suffix}`),
72
+ );
73
+ }
74
+
68
75
  // Find template path, preferring an app override over the package template
69
76
  function getPartialPath(partialPath, views) {
70
77
  const paths = [
71
78
  sanitizePath(`${process.cwd()}/src/views/${views}/${partialPath}`),
72
79
  sanitizePath(`${currentPath}/views/${views}/${partialPath}`),
80
+ ...packageFallbackPaths(views, partialPath),
73
81
  ].filter(Boolean);
74
82
 
75
83
  // Return first existing path
@@ -78,7 +86,7 @@ function getPartialPath(partialPath, views) {
78
86
  if (existingPath) return existingPath;
79
87
 
80
88
  throw new Error(
81
- `Template not found: "${partialPath}"\nSearched in:\n${paths.join("\n")}`
89
+ `Template not found: "${partialPath}"\nSearched in:\n${paths.join("\n")}`,
82
90
  );
83
91
  }
84
92
 
@@ -136,10 +144,16 @@ export default class HonoAdapter {
136
144
  }
137
145
 
138
146
  getActionPath(views, action) {
139
- const packagePath = `${currentPath}/views/${views}/${action}.ejs`;
140
147
  const appPath = `${process.cwd()}/src/views/${views}/${action}.ejs`;
148
+ if (existsSync(appPath)) return appPath;
141
149
 
142
- return existsSync(appPath) ? appPath : packagePath;
150
+ const packagePath = `${currentPath}/views/${views}/${action}.ejs`;
151
+ if (existsSync(packagePath)) return packagePath;
152
+
153
+ const fallback = packageFallbackPaths(views, `${action}.ejs`).find(
154
+ existsSync,
155
+ );
156
+ return fallback ?? packagePath;
143
157
  }
144
158
 
145
159
  getHelpers(viewHelpersConfig) {
@@ -180,7 +194,7 @@ export default class HonoAdapter {
180
194
  ...assigns,
181
195
  ...localAssigns,
182
196
  },
183
- { filename: partialPath }
197
+ { filename: partialPath },
184
198
  );
185
199
 
186
200
  return rendered;
@@ -210,7 +224,7 @@ export default class HonoAdapter {
210
224
  ...renderAssigns,
211
225
  render_partial: renderPartialHelper,
212
226
  },
213
- { filename: fullTemplatePath }
227
+ { filename: fullTemplatePath },
214
228
  );
215
229
 
216
230
  const fullPage = this.renderLayout(renderAssigns, rendered);
@@ -276,7 +290,7 @@ export default class HonoAdapter {
276
290
 
277
291
  async createAction(
278
292
  [verb, path, resource, views, action, handler],
279
- resourceConfig
293
+ resourceConfig,
280
294
  ) {
281
295
  const { i18n } = this.globalConfig;
282
296
 
@@ -290,7 +304,7 @@ export default class HonoAdapter {
290
304
  next,
291
305
  verb,
292
306
  resource,
293
- action
307
+ action,
294
308
  );
295
309
 
296
310
  // Set context properties
@@ -324,7 +338,7 @@ export default class HonoAdapter {
324
338
  };
325
339
 
326
340
  ctx.logger.info(
327
- `${ctx.method} "${ctx.rawPath}" -> ${resource}/${action} | ${JSON.stringify(ctx.params)}`
341
+ `${ctx.method} "${ctx.rawPath}" -> ${resource}/${action} | ${JSON.stringify(ctx.params)}`,
328
342
  );
329
343
 
330
344
  const assigns = {
@@ -369,7 +383,7 @@ export default class HonoAdapter {
369
383
 
370
384
  Object.assign(
371
385
  assigns.afterFilterAssigns,
372
- afterResult.assigns || {}
386
+ afterResult.assigns || {},
373
387
  );
374
388
  }
375
389
  }
@@ -390,7 +404,7 @@ export default class HonoAdapter {
390
404
  action,
391
405
  assigns: fullAssigns,
392
406
  },
393
- this.globalConfig?.helpers || {}
407
+ this.globalConfig?.helpers || {},
394
408
  );
395
409
 
396
410
  return routerCtx.html(rendered);
@@ -401,7 +415,7 @@ export default class HonoAdapter {
401
415
  // Single method to handle all route types
402
416
  routeCollection(mapping, resourceConfig) {
403
417
  mapping.forEach((handlerMap) =>
404
- this.createAction(handlerMap, resourceConfig)
418
+ this.createAction(handlerMap, resourceConfig),
405
419
  );
406
420
  }
407
421
 
@@ -423,7 +437,7 @@ export default class HonoAdapter {
423
437
  applyHeaders(headers, router) {
424
438
  if (!headers) return;
425
439
  Object.entries(headers).forEach(([key, value]) =>
426
- router.header(key, value)
440
+ router.header(key, value),
427
441
  );
428
442
  }
429
443