webspresso 0.0.97 → 0.0.98

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 (100) hide show
  1. package/.agents/ADMIN.md +153 -5
  2. package/.agents/ARCHITECTURE.md +10 -0
  3. package/.agents/CLI.md +195 -1
  4. package/.agents/PLUGINS.md +153 -9
  5. package/.agents/QUEUE.md +43 -0
  6. package/bin/commands/add-esbuild.js +80 -0
  7. package/bin/commands/add-tailwind.js +76 -31
  8. package/bin/commands/analytics-prune.js +57 -0
  9. package/bin/commands/api.js +207 -15
  10. package/bin/commands/build.js +99 -0
  11. package/bin/commands/dev.js +64 -35
  12. package/bin/commands/doctor.js +26 -0
  13. package/bin/commands/email-prune.js +47 -0
  14. package/bin/commands/make-job.js +86 -0
  15. package/bin/commands/make-model.js +250 -0
  16. package/bin/commands/new.js +45 -28
  17. package/bin/commands/openapi.js +102 -0
  18. package/bin/commands/page.js +6 -3
  19. package/bin/commands/queue-prune.js +59 -0
  20. package/bin/commands/routes.js +52 -0
  21. package/bin/commands/service.js +6 -3
  22. package/bin/commands/typegen.js +106 -0
  23. package/bin/commands/upload-prune.js +79 -0
  24. package/bin/webspresso.js +22 -0
  25. package/core/applySchema.js +13 -6
  26. package/core/auth/hash.js +21 -12
  27. package/core/compression/middleware.js +23 -17
  28. package/core/openapi/build-from-api-routes.js +160 -29
  29. package/core/orm/cache/fingerprint.js +15 -1
  30. package/core/orm/cache/memory-provider.js +27 -2
  31. package/core/orm/index.js +12 -7
  32. package/core/orm/model.js +49 -7
  33. package/core/queue/adapters/database.js +94 -0
  34. package/core/queue/adapters/memory.js +62 -0
  35. package/core/queue/adapters/redis.js +80 -0
  36. package/core/queue/manager.js +123 -0
  37. package/core/ssr/stream.js +11 -0
  38. package/index.d.ts +660 -10
  39. package/index.js +44 -96
  40. package/package.json +1 -1
  41. package/plugins/admin-panel/api.js +279 -17
  42. package/plugins/admin-panel/app.js +114 -22
  43. package/plugins/admin-panel/client/parts/01-state-api-breadcrumb.js +314 -9
  44. package/plugins/admin-panel/client/parts/04-field-renderers.js +264 -67
  45. package/plugins/admin-panel/client/parts/05-rich-text-file-helpers.js +10 -5
  46. package/plugins/admin-panel/client/parts/06-login-setup-forms.js +119 -28
  47. package/plugins/admin-panel/client/parts/07-model-list.js +49 -8
  48. package/plugins/admin-panel/client/parts/08-record-list.js +243 -23
  49. package/plugins/admin-panel/client/parts/09-record-form.js +59 -12
  50. package/plugins/admin-panel/client/parts/10-export-registry.js +23 -0
  51. package/plugins/admin-panel/core/admin-module.js +13 -7
  52. package/plugins/admin-panel/core/api-extensions.js +30 -2
  53. package/plugins/admin-panel/core/registry.js +96 -16
  54. package/plugins/admin-panel/index.js +96 -0
  55. package/plugins/admin-panel/lib/login-rate-limiter.js +119 -0
  56. package/plugins/admin-panel/modules/admin-users.js +16 -1
  57. package/plugins/admin-panel/modules/bulk-actions.js +13 -5
  58. package/plugins/admin-panel/modules/custom-pages.js +492 -3
  59. package/plugins/admin-panel/modules/dashboard.js +283 -0
  60. package/plugins/admin-panel/modules/menu.js +56 -18
  61. package/plugins/admin-panel/modules/user-management.js +24 -6
  62. package/plugins/audit-log/admin-component.js +11 -0
  63. package/plugins/audit-log/api-handlers.js +34 -0
  64. package/plugins/audit-log/index.js +129 -3
  65. package/plugins/audit-log/purge.js +60 -10
  66. package/plugins/dashboard/app.js +152 -27
  67. package/plugins/dashboard/index.js +143 -39
  68. package/plugins/dashboard/styles.js +78 -0
  69. package/plugins/data-exchange/export-xlsx.js +9 -2
  70. package/plugins/data-exchange/import.js +9 -2
  71. package/plugins/data-exchange/index.js +6 -3
  72. package/plugins/email/index.js +132 -2
  73. package/plugins/email/purge.js +60 -10
  74. package/plugins/index.js +4 -0
  75. package/plugins/orm-cache-admin/index.js +4 -2
  76. package/plugins/queue/index.js +11 -0
  77. package/plugins/schema-explorer/admin-component.js +714 -0
  78. package/plugins/schema-explorer/relations-graph.js +205 -0
  79. package/plugins/schema-explorer.js +248 -69
  80. package/plugins/site-analytics/admin-component.js +23 -0
  81. package/plugins/site-analytics/api-handlers.js +42 -0
  82. package/plugins/site-analytics/index.js +147 -2
  83. package/plugins/site-analytics/purge.js +168 -0
  84. package/plugins/swagger.js +261 -13
  85. package/plugins/upload/index.js +26 -0
  86. package/plugins/upload/orphan-pruner.js +292 -0
  87. package/src/api/api-loader.js +3 -1
  88. package/src/bundle/index.js +517 -0
  89. package/src/bundle/manifest.js +165 -0
  90. package/src/dev/banner.js +296 -0
  91. package/src/dev/colors.js +70 -0
  92. package/src/dev/index.js +62 -0
  93. package/src/dev/profiler.js +354 -0
  94. package/src/dev/typegen.js +497 -0
  95. package/src/dev-reload/index.js +611 -0
  96. package/src/file-router.js +210 -62
  97. package/src/helpers.js +958 -98
  98. package/src/njk-frontmatter.js +12 -0
  99. package/src/pages/page-loader.js +61 -11
  100. package/src/server.js +629 -63
@@ -152,9 +152,20 @@ function loadNjkRouteTemplate(absPath, isDev) {
152
152
  return fresh;
153
153
  }
154
154
 
155
+ const clearHooks = new Set();
156
+
157
+ function registerClearHook(fn) {
158
+ if (typeof fn === 'function') clearHooks.add(fn);
159
+ }
160
+
155
161
  function clearNjkFrontmatterCaches() {
156
162
  prodRouteCache.clear();
157
163
  devRouteCache.clear();
164
+ for (const fn of clearHooks) {
165
+ try {
166
+ fn();
167
+ } catch (_) {}
168
+ }
158
169
  }
159
170
 
160
171
  module.exports = {
@@ -162,5 +173,6 @@ module.exports = {
162
173
  frontmatterToPatches,
163
174
  loadNjkRouteTemplate,
164
175
  clearNjkFrontmatterCaches,
176
+ registerClearHook,
165
177
  extractFrontmatterBlock,
166
178
  };
@@ -8,8 +8,16 @@
8
8
 
9
9
  const fs = require('fs');
10
10
  const path = require('path');
11
- const { createHelpers } = require('../helpers');
12
- const { loadI18n, createTranslator, detectLocale, resolveMiddlewares } = require('../file-router');
11
+ const { createHelpers, getAssetManager } = require('../helpers');
12
+ const {
13
+ loadI18n,
14
+ createTranslator,
15
+ detectLocale,
16
+ resolveMiddlewares,
17
+ translatorCache,
18
+ resolvePageAssets,
19
+ applyPageAssetsToTemplateData,
20
+ } = require('../file-router');
13
21
 
14
22
  const EMPTY_ARRAY = Object.freeze([]);
15
23
 
@@ -111,13 +119,29 @@ function createPageHandler(descriptor, context) {
111
119
 
112
120
  // i18n
113
121
  const defaultLocale = process.env.DEFAULT_LOCALE || 'en';
114
- const translations = loadI18n(pagesDir, '', locale, isDev);
115
- const fallbackTranslations = locale !== defaultLocale ? loadI18n(pagesDir, '', defaultLocale, isDev) : undefined;
116
- const t = createTranslator(translations, {
117
- locale,
118
- fallbackTranslations,
119
- fallbackLocale: defaultLocale,
120
- });
122
+ let t;
123
+ if (!isDev && translatorCache) {
124
+ const transKey = `${pagesDir}::::${locale}::${defaultLocale}`;
125
+ t = translatorCache.get(transKey);
126
+ if (!t) {
127
+ const translations = loadI18n(pagesDir, '', locale, false);
128
+ const fallbackTranslations = locale !== defaultLocale ? loadI18n(pagesDir, '', defaultLocale, false) : undefined;
129
+ t = createTranslator(translations, {
130
+ locale,
131
+ fallbackTranslations,
132
+ fallbackLocale: defaultLocale,
133
+ });
134
+ translatorCache.set(transKey, t);
135
+ }
136
+ } else {
137
+ const translations = loadI18n(pagesDir, '', locale, isDev);
138
+ const fallbackTranslations = locale !== defaultLocale ? loadI18n(pagesDir, '', defaultLocale, isDev) : undefined;
139
+ t = createTranslator(translations, {
140
+ locale,
141
+ fallbackTranslations,
142
+ fallbackLocale: defaultLocale,
143
+ });
144
+ }
121
145
 
122
146
  const pageCtx = {
123
147
  req,
@@ -163,10 +187,36 @@ function createPageHandler(descriptor, context) {
163
187
  const templateExists = hasNjkTemplate !== null ? hasNjkTemplate : fs.existsSync(njkCandidate);
164
188
 
165
189
  if (templateExists && nunjucks) {
190
+ let pageHead = headData;
191
+ let pageAssetsActive = false;
192
+ const pageAssetsOpt = context.pageAssets || (appOptions && appOptions.pageAssets);
193
+ if (pageAssetsOpt) {
194
+ const pageAssetsResolved = resolvePageAssets(pageAssetsOpt);
195
+ if (pageAssetsResolved.enabled) {
196
+ const pageAssetBundle = applyPageAssetsToTemplateData(
197
+ pageAssetsResolved,
198
+ loadedData,
199
+ {
200
+ file: descriptor.source || descriptor.file,
201
+ routePath: descriptor.path,
202
+ },
203
+ fsy?.assetManager || getAssetManager()
204
+ );
205
+ loadedData = pageAssetBundle.data;
206
+ pageHead = {
207
+ ...headData,
208
+ stylesheets: [...(headData.stylesheets || []), ...(pageAssetBundle.pageHead?.stylesheets || [])],
209
+ scripts: [...(headData.scripts || []), ...(pageAssetBundle.pageHead?.scripts || [])],
210
+ };
211
+ pageAssetsActive = true;
212
+ }
213
+ }
214
+
166
215
  const templateData = {
167
216
  ...loadedData,
168
- head: headData,
169
- pageHead: headData,
217
+ head: pageHead,
218
+ pageHead,
219
+ pageAssets: pageAssetsActive || Boolean(loadedData.pageAssets),
170
220
  fsy,
171
221
  locale,
172
222
  t,