nextjs-cms 0.5.56 → 0.5.59

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 (90) hide show
  1. package/dist/api/index.d.ts +82 -45
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/lib/serverActions.d.ts +68 -5
  4. package/dist/api/lib/serverActions.d.ts.map +1 -1
  5. package/dist/api/lib/serverActions.js +33 -8
  6. package/dist/api/root.d.ts +953 -44
  7. package/dist/api/root.d.ts.map +1 -1
  8. package/dist/api/root.js +2 -1
  9. package/dist/api/routers/accountSettings.d.ts +1 -3
  10. package/dist/api/routers/accountSettings.d.ts.map +1 -1
  11. package/dist/api/routers/admins.d.ts +1 -3
  12. package/dist/api/routers/admins.d.ts.map +1 -1
  13. package/dist/api/routers/admins.js +1 -1
  14. package/dist/api/routers/auth.d.ts +1 -3
  15. package/dist/api/routers/auth.d.ts.map +1 -1
  16. package/dist/api/routers/categorySection.d.ts +1 -3
  17. package/dist/api/routers/categorySection.d.ts.map +1 -1
  18. package/dist/api/routers/cmsSettings.d.ts +1 -3
  19. package/dist/api/routers/cmsSettings.d.ts.map +1 -1
  20. package/dist/api/routers/cpanel.d.ts +1 -3
  21. package/dist/api/routers/cpanel.d.ts.map +1 -1
  22. package/dist/api/routers/files.d.ts +1 -3
  23. package/dist/api/routers/files.d.ts.map +1 -1
  24. package/dist/api/routers/gallery.d.ts +1 -3
  25. package/dist/api/routers/gallery.d.ts.map +1 -1
  26. package/dist/api/routers/gallery.js +7 -6
  27. package/dist/api/routers/googleAnalytics.d.ts +1 -3
  28. package/dist/api/routers/googleAnalytics.d.ts.map +1 -1
  29. package/dist/api/routers/hasItemsSection.d.ts +49 -5
  30. package/dist/api/routers/hasItemsSection.d.ts.map +1 -1
  31. package/dist/api/routers/navigation.d.ts +1 -3
  32. package/dist/api/routers/navigation.d.ts.map +1 -1
  33. package/dist/api/routers/simpleSection.d.ts +21 -4
  34. package/dist/api/routers/simpleSection.d.ts.map +1 -1
  35. package/dist/api/trpc/query-client.d.ts +3 -0
  36. package/dist/api/trpc/query-client.d.ts.map +1 -0
  37. package/dist/api/trpc/query-client.js +23 -0
  38. package/dist/api/trpc/server.d.ts +8 -0
  39. package/dist/api/trpc/server.d.ts.map +1 -0
  40. package/dist/api/trpc/server.js +23 -0
  41. package/dist/api/trpc.d.ts +6 -17
  42. package/dist/api/trpc.d.ts.map +1 -1
  43. package/dist/api/trpc.js +6 -9
  44. package/dist/auth/react.js +1 -1
  45. package/dist/core/config/config-loader.d.ts +1 -1
  46. package/dist/core/config/config-loader.d.ts.map +1 -1
  47. package/dist/core/config/config-loader.js +9 -6
  48. package/dist/core/config/index.d.ts +1 -0
  49. package/dist/core/config/index.d.ts.map +1 -1
  50. package/dist/core/config/index.js +1 -0
  51. package/dist/core/config/loader-with-esbuild.d.ts +8 -0
  52. package/dist/core/config/loader-with-esbuild.d.ts.map +1 -0
  53. package/dist/core/config/loader-with-esbuild.js +195 -0
  54. package/dist/core/config/loader-with-jiti.d.ts +13 -0
  55. package/dist/core/config/loader-with-jiti.d.ts.map +1 -0
  56. package/dist/core/config/loader-with-jiti.js +162 -0
  57. package/dist/core/config/loader.d.ts +1 -1
  58. package/dist/core/config/loader.d.ts.map +1 -1
  59. package/dist/core/config/loader.js +1 -75
  60. package/dist/core/factories/SectionFactory.d.ts +1 -109
  61. package/dist/core/factories/SectionFactory.d.ts.map +1 -1
  62. package/dist/core/factories/SectionFactory.js +1 -452
  63. package/dist/core/factories/section-factory-with-esbuild.d.ts +113 -0
  64. package/dist/core/factories/section-factory-with-esbuild.d.ts.map +1 -0
  65. package/dist/core/factories/section-factory-with-esbuild.js +545 -0
  66. package/dist/core/factories/section-factory-with-jiti.d.ts +113 -0
  67. package/dist/core/factories/section-factory-with-jiti.d.ts.map +1 -0
  68. package/dist/core/factories/section-factory-with-jiti.js +556 -0
  69. package/dist/core/fields/document.d.ts +0 -1
  70. package/dist/core/fields/document.d.ts.map +1 -1
  71. package/dist/core/fields/document.js +5 -4
  72. package/dist/core/fields/photo.d.ts +10 -7
  73. package/dist/core/fields/photo.d.ts.map +1 -1
  74. package/dist/core/fields/photo.js +44 -17
  75. package/dist/core/fields/richText.d.ts +0 -1
  76. package/dist/core/fields/richText.d.ts.map +1 -1
  77. package/dist/core/fields/richText.js +5 -4
  78. package/dist/core/fields/video.d.ts +0 -1
  79. package/dist/core/fields/video.d.ts.map +1 -1
  80. package/dist/core/fields/video.js +5 -4
  81. package/dist/core/sections/section.d.ts +17 -15
  82. package/dist/core/sections/section.d.ts.map +1 -1
  83. package/dist/core/sections/section.js +28 -5
  84. package/dist/core/submit/submit.d.ts.map +1 -1
  85. package/dist/core/submit/submit.js +13 -12
  86. package/dist/translations/dictionaries/ar.json +1 -0
  87. package/dist/translations/dictionaries/en.json +1 -0
  88. package/dist/translations/index.d.ts.map +1 -1
  89. package/dist/translations/index.js +1 -3
  90. package/package.json +16 -7
@@ -1,452 +1 @@
1
- import { glob } from 'glob';
2
- import { cloneDeep } from 'lodash-es';
3
- import { resolve } from 'path';
4
- import chalk from 'chalk';
5
- import { eq } from 'drizzle-orm';
6
- import chokidar from 'chokidar';
7
- import fs from 'fs';
8
- import { createRequire } from 'module';
9
- import { db } from '../../db/client.js';
10
- import { AdminPrivilegesTable } from '../../db/schema.js';
11
- import { getCMSConfig } from '../config/index.js';
12
- const cmsConfig = getCMSConfig();
13
- const hotMarkerFile = resolve(process.cwd(), 'components/form/helpers/_section-hot-reload.js');
14
- // Create a require function that works in ES modules
15
- const safeRequire = createRequire(import.meta.url);
16
- /**
17
- * Register esbuild-register only once per process.
18
- * Node's require cache ensures each TS module is evaluated once.
19
- */
20
- let tsLoaderRegistered = false;
21
- /**
22
- * When we runtime-load TS (via esbuild-register) using CommonJS `require`, our TS sources may contain NodeNext-style
23
- * specifiers like `./foo.js` that point at `./foo.ts` in the source tree. Node's CJS resolver won't find `foo.js`.
24
- *
25
- * In normal builds this is fine because `dist/foo.js` exists, but in dev/tests we load from `src/`.
26
- * This helper patches Node's CJS resolver to fall back from `*.js` → `*.ts` for relative imports.
27
- */
28
- const withPatchedCjsResolveJsToTs = (fn) => {
29
- const NodeModule = safeRequire('module');
30
- const originalResolve = NodeModule._resolveFilename;
31
- NodeModule._resolveFilename = function (request, parent, isMain, options) {
32
- try {
33
- return originalResolve.call(this, request, parent, isMain, options);
34
- }
35
- catch (err) {
36
- if (typeof request === 'string' && /^(\.{1,2}\/.*)\.js$/.test(request)) {
37
- const tsRequest = request.replace(/\.js$/, '.ts');
38
- try {
39
- return originalResolve.call(this, tsRequest, parent, isMain, options);
40
- }
41
- catch {
42
- // fall through to rethrow original error
43
- }
44
- }
45
- throw err;
46
- }
47
- };
48
- try {
49
- return fn();
50
- }
51
- finally {
52
- NodeModule._resolveFilename = originalResolve;
53
- }
54
- };
55
- /**
56
- * Require a TypeScript module at runtime.
57
- * @param absPath - The absolute path to the section file.
58
- * @returns The default export of the section file.
59
- */
60
- const requireModuleRuntime = (absPath) => {
61
- const isTs = absPath.endsWith('.ts') || absPath.endsWith('.cts') || absPath.endsWith('.mts');
62
- if (isTs && !tsLoaderRegistered) {
63
- try {
64
- const { register } = safeRequire('esbuild-register/dist/node');
65
- register({ format: 'cjs', loader: 'ts' });
66
- tsLoaderRegistered = true;
67
- }
68
- catch {
69
- throw new Error(`Cannot load section file '${absPath}' (TypeScript). Install 'esbuild-register' in nextjs-cms/cms or provide JS files.`);
70
- }
71
- }
72
- const mod = process.env.NODE_ENV === 'test'
73
- ? isTs
74
- ? withPatchedCjsResolveJsToTs(() => safeRequire(absPath))
75
- : safeRequire(absPath)
76
- : safeRequire(absPath);
77
- // Only return the default export, ignore named exports
78
- return mod?.default;
79
- };
80
- /**
81
- * Log a message to the console if debug mode is enabled
82
- * @param args - The arguments to log
83
- * @returns void
84
- */
85
- const log = (...args) => {
86
- if (!cmsConfig.debug)
87
- return;
88
- console.log(chalk.black.bgGreen(`[${new Date().toISOString()}][next-cms-debug]`, ...args));
89
- };
90
- export class SectionFactory {
91
- /**
92
- * These are the fixed sections that can not be present in the sections folder.
93
- */
94
- static fixedSections = ['admins', 'analytics', 'emails', 'dashboard'];
95
- static isDev = process.env.NODE_ENV !== 'production';
96
- static isProd = !this.isDev;
97
- static sectionProcessingErrors = {};
98
- static sectionFetchingErrors = {};
99
- static errorCount = 0;
100
- /**
101
- * Global in-process cache for all section configs.
102
- * Populated once per Node process via loadAllSections(),
103
- * reused by all get*() calls until the process is restarted,
104
- * so all subsequent calls reuse this array.
105
- */
106
- static allSectionsPromise = null;
107
- static allSectionsLoaded = false;
108
- static watcherStarted = false;
109
- static bumpHotMarker() {
110
- if (!SectionFactory.isDev)
111
- return;
112
- const content = `/**\n` +
113
- ` * AUTO-GENERATED. DO NOT EDIT.\n` +
114
- ` * This file is used to track the last time the sections schema was updated.\n` +
115
- ` * It is used to trigger a hot reload of the section schema in development mode.\n` +
116
- ` */\n` +
117
- `\n` +
118
- `export const revalidate = 0\n` +
119
- `\n` +
120
- `// @refresh reset\n` +
121
- `\n` +
122
- `export const sectionSchemaLastUpdated = ${Date.now()}\n`;
123
- try {
124
- fs.writeFileSync(hotMarkerFile, content, 'utf8');
125
- log('Bumped _section-hot-reload.js to trigger Next Fast Refresh');
126
- }
127
- catch (err) {
128
- console.error('Failed to bump _section-hot-reload.js:', err);
129
- }
130
- }
131
- // ---------- PUBLIC API ----------
132
- /**
133
- * Get all sections
134
- * @param type - The type of sections to get
135
- * @returns The sections
136
- */
137
- static async getSections(type) {
138
- return await this.get({ type });
139
- }
140
- /**
141
- * Get all accessible sections for an admin
142
- * @param type - The type of section to get
143
- * @param admin - The admin to get the sections for
144
- * @returns The sections for the admin
145
- */
146
- static async getSectionsForAdmin({ type, admin, }) {
147
- const sections = await this.get({ type, admin });
148
- const privileges = await db
149
- .select({
150
- sectionName: AdminPrivilegesTable.sectionName,
151
- operations: AdminPrivilegesTable.operations,
152
- })
153
- .from(AdminPrivilegesTable)
154
- .where(eq(AdminPrivilegesTable.adminId, admin.id));
155
- const fixedSections = privileges
156
- .filter((privilege) => this.fixedSections.includes(privilege.sectionName))
157
- .map((privilege) => privilege.sectionName);
158
- const simpleSections = sections.filter((section) => section.type === 'simple');
159
- const hasItemsSections = sections.filter((section) => section.type === 'has_items');
160
- const categorySections = sections.filter((section) => section.type === 'category');
161
- return {
162
- simple: simpleSections,
163
- has_items: hasItemsSections,
164
- category: categorySections,
165
- fixed: fixedSections,
166
- };
167
- }
168
- /**
169
- * Get a section
170
- * @param name - The name of the section to get
171
- * @param type - The type of section to get
172
- * @returns The section
173
- */
174
- static async getSection({ name, type, }) {
175
- const section = await this.get({ name, type });
176
- return section[0] ? section[0] : null;
177
- }
178
- /**
179
- * Get an accessible section for an admin
180
- * @param name - The name of the section to get
181
- * @param type - The type of section to get
182
- * @param admin - The admin to get the section for
183
- * @returns The section for the admin
184
- */
185
- static async getSectionForAdmin({ name, type, admin, }) {
186
- const section = await this.get({ type, admin, name });
187
- return section[0] ? section[0] : null;
188
- }
189
- /**
190
- * Create a Section instance from a section config
191
- * The config must have a build() method (created via helper functions like simpleSection(), hasItemsSection(), etc.)
192
- *
193
- * Note: This factory only accepts configs. If you already have a Section instance,
194
- * use it directly - don't pass it to this factory.
195
- *
196
- * @param config - A section config object with a build() method
197
- * @returns A Section instance
198
- * @throws Error if config doesn't have a build() method
199
- */
200
- static create(config) {
201
- if (typeof config.build === 'function') {
202
- return config.build();
203
- }
204
- throw new Error('Section config must have a build() method. Use helper functions like simpleSection(), hasItemsSection(), categorySection() to create configs.');
205
- }
206
- // ---------- INTERNAL CORE ----------
207
- /**
208
- * Return a clone of the section(s) info to get a fresh copy of the section(s).
209
- * Not cloning will cause the original section(s) (in *.section.ts file) to be modified!
210
- * Each *.section.ts file must have exactly one default export (arrays are not allowed).
211
-
212
- * @param name - The name of the section to get
213
- * @param type - The type of section to get
214
- * @param admin - The admin to get the section for
215
- * @returns The section(s)
216
- */
217
- static async get({ name, type, admin, }) {
218
- try {
219
- const allSections = await this.loadAllSections();
220
- /**
221
- * Always show errors if there are any.
222
- * This is to make sure the errors are shown on every request (technically, every time the section is requested).
223
- * This way devs can notice the errors and fix them.
224
- */
225
- if (this.errorCount > 0) {
226
- console.log(`\n${chalk.bgRed.bold(` Errors while fetching sections `)}${chalk.red.bold('-------')}\n`);
227
- if (Object.keys(this.sectionProcessingErrors).length > 0) {
228
- console.log(`${chalk.bold.redBright(`Processing errors:`)}`);
229
- for (const [file, errors] of Object.entries(this.sectionProcessingErrors)) {
230
- console.log('');
231
- console.log(chalk.bold(`[${file}]:`));
232
- for (const error of errors) {
233
- console.error(error);
234
- }
235
- console.log('');
236
- }
237
- }
238
- if (Object.keys(this.sectionFetchingErrors).length > 0) {
239
- console.log(`\n${chalk.bold.redBright(`Importing errors:`)}`);
240
- for (const [file, errors] of Object.entries(this.sectionFetchingErrors)) {
241
- console.log('');
242
- console.log(chalk.bold(`[${file}]:`));
243
- for (const error of errors) {
244
- console.error(error);
245
- }
246
- console.log('');
247
- }
248
- }
249
- console.log(`${chalk.red.bold('-------')}`);
250
- }
251
- const types = type
252
- ? Array.isArray(type)
253
- ? type
254
- : [type]
255
- : ['has_items', 'simple', 'category'];
256
- // Filter by type first
257
- let filtered = allSections.filter((section) => types.includes(section.type));
258
- // If admin is provided, restrict to privileged sections
259
- if (admin && admin.id) {
260
- const privileges = await db
261
- .select({
262
- sectionName: AdminPrivilegesTable.sectionName,
263
- operations: AdminPrivilegesTable.operations,
264
- })
265
- .from(AdminPrivilegesTable)
266
- .where(eq(AdminPrivilegesTable.adminId, admin.id));
267
- const privilegedSections = [];
268
- privileges.forEach((privilege) => {
269
- if (admin.requiredRole) {
270
- if (privilege.operations.includes(admin.requiredRole)) {
271
- privilegedSections.push(privilege.sectionName);
272
- }
273
- }
274
- else {
275
- privilegedSections.push(privilege.sectionName);
276
- }
277
- });
278
- filtered = filtered.filter((section) => privilegedSections.includes(section.name));
279
- }
280
- if (name) {
281
- const found = filtered.find((section) => section.name === name);
282
- return found ? [cloneDeep(found)] : [];
283
- }
284
- return filtered.map((section) => cloneDeep(section));
285
- }
286
- catch (err) {
287
- console.error('Error loading section configs:', err);
288
- return [];
289
- }
290
- }
291
- /**
292
- * Load all *.section.ts files once, require their default exports,
293
- * and cache the resulting configs for the lifetime of the process
294
- * (until invalidated in dev by file changes).
295
- */
296
- static async loadAllSections() {
297
- if (this.allSectionsPromise)
298
- return this.allSectionsPromise;
299
- if (this.isDev) {
300
- // In dev, watch for changes and reload on demand
301
- // This wll lazy load on first get() as well
302
- this.startWatcher();
303
- }
304
- this.allSectionsPromise = (async () => {
305
- if (!this.allSectionsLoaded) {
306
- log('Loading all sections from disk...', this.isDev ? '(dev mode)' : '(production mode)');
307
- }
308
- const sections = [];
309
- try {
310
- const sectionFiles = await glob('**/*.section.ts', {
311
- cwd: cmsConfig.sections.path,
312
- });
313
- for (const file of sectionFiles) {
314
- try {
315
- const absPath = resolve(cmsConfig.sections.path, file);
316
- const defaultExport = requireModuleRuntime(absPath);
317
- if (!defaultExport) {
318
- if (!this.sectionFetchingErrors[file]) {
319
- this.sectionFetchingErrors[file] = [];
320
- }
321
- this.sectionFetchingErrors[file].push(chalk.rgb(255, 100, 0)('Section file must have a default export. Skipping.'));
322
- this.errorCount++;
323
- continue;
324
- }
325
- if (Array.isArray(defaultExport)) {
326
- if (!this.sectionFetchingErrors[file]) {
327
- this.sectionFetchingErrors[file] = [];
328
- }
329
- this.sectionFetchingErrors[file].push(chalk.rgb(255, 100, 0)('Section file exports an array. Each file must export exactly one section. Skipping.'));
330
- this.errorCount++;
331
- continue;
332
- }
333
- if (!defaultExport.type || !defaultExport.name) {
334
- if (!this.sectionFetchingErrors[file]) {
335
- this.sectionFetchingErrors[file] = [];
336
- }
337
- this.sectionFetchingErrors[file].push(chalk.rgb(255, 100, 0)('Section file default export must have "type" and "name". Skipping.'));
338
- this.errorCount++;
339
- continue;
340
- }
341
- sections.push(defaultExport);
342
- }
343
- catch (importErr) {
344
- if (importErr instanceof Error) {
345
- /**
346
- * Only display the error message, not the stack trace.
347
- */
348
- if (!this.sectionProcessingErrors[file]) {
349
- this.sectionProcessingErrors[file] = [];
350
- }
351
- this.sectionProcessingErrors[file].push(importErr.message);
352
- }
353
- else {
354
- if (!this.sectionFetchingErrors[file]) {
355
- this.sectionFetchingErrors[file] = [];
356
- }
357
- this.sectionFetchingErrors[file].push(chalk.rgb(255, 100, 0)(`Unknown error type: ${typeof importErr}`));
358
- throw new Error(`${chalk.bgRed(` Error importing ${file}: `)}, ${importErr}`);
359
- }
360
- this.errorCount++;
361
- /**
362
- * Remove the section from the cache so it will be reloaded next time.
363
- */
364
- delete require.cache[resolve(cmsConfig.sections.path, file)];
365
- }
366
- }
367
- }
368
- catch (err) {
369
- console.error('Error finding section files:', err);
370
- }
371
- this.allSectionsLoaded = true;
372
- /**
373
- * If `strict` mode is enabled,
374
- * don't return sections if there are errors.
375
- */
376
- if (cmsConfig.sections.strict && this.errorCount > 0) {
377
- return [];
378
- }
379
- log(`Loaded ${sections.length} section(s)`);
380
- return sections;
381
- })();
382
- return this.allSectionsPromise;
383
- }
384
- // ---------- DEV WATCHER & CACHE INVALIDATION ----------
385
- static startWatcher() {
386
- if (!this.isDev || this.watcherStarted)
387
- return;
388
- this.watcherStarted = true;
389
- const watcher = chokidar.watch('**/*.section.ts', {
390
- cwd: cmsConfig.sections.path,
391
- ignoreInitial: true,
392
- });
393
- log('Starting section watcher in dev mode...');
394
- /**
395
- * This is triggering nextjs to reload the section module when a section file is changed.
396
- * We used [refresh-reset](https://nextjs.org/docs/architecture/fast-refresh#:~:text=you%20can%20add-,//%20%40refresh%20reset,-anywhere%20in%20the) to let fast-refresh
397
- * trigger a react-query invalidation in the form component to re-fetch the new section config.
398
- * @param relPath
399
- */
400
- const invalidateForRelPath = (relPath) => {
401
- const absPath = resolve(cmsConfig.sections.path, relPath);
402
- const req = eval('require');
403
- try {
404
- const resolved = req.resolve(absPath);
405
- if (req.cache[resolved]) {
406
- delete req.cache[resolved];
407
- log('Cleared require cache for', relPath);
408
- }
409
- // Also clear the require cache for the hot marker file
410
- if (req.cache[hotMarkerFile]) {
411
- delete req.cache[hotMarkerFile];
412
- log('Cleared require cache for', hotMarkerFile);
413
- }
414
- this.sectionProcessingErrors = {};
415
- this.sectionFetchingErrors = {};
416
- this.errorCount = 0;
417
- }
418
- catch {
419
- // ignore if not resolvable
420
- }
421
- this.allSectionsPromise = null;
422
- this.allSectionsLoaded = false;
423
- log('Invalidated section cache due to change in', relPath);
424
- this.bumpHotMarker();
425
- };
426
- watcher
427
- .on('add', (path) => {
428
- log('Section file added:', path);
429
- invalidateForRelPath(path);
430
- })
431
- .on('change', (path) => {
432
- log('Section file changed:', path);
433
- invalidateForRelPath(path);
434
- })
435
- .on('unlink', (path) => {
436
- log('Section file removed:', path);
437
- invalidateForRelPath(path);
438
- });
439
- }
440
- static init() {
441
- if (this.isProd) {
442
- // Preload all sections at startup in production
443
- void this.loadAllSections();
444
- }
445
- }
446
- /**
447
- * Run initialization once when the module is loaded
448
- */
449
- static {
450
- this.init();
451
- }
452
- }
1
+ export * from './section-factory-with-esbuild.js';
@@ -0,0 +1,113 @@
1
+ import { HasItemsSection, SimpleSection, CategorySection } from '../sections/index.js';
2
+ import type { CategorySectionConfig, HasItemsSectionConfig, SimpleSectionConfig } from '../sections/index.js';
3
+ import type { SectionTypes } from '../types/index.js';
4
+ type AnySectionConfig = HasItemsSectionConfig | SimpleSectionConfig | CategorySectionConfig;
5
+ export declare class SectionFactory {
6
+ /**
7
+ * These are the fixed sections that can not be present in the sections folder.
8
+ */
9
+ static readonly fixedSections: string[];
10
+ private static readonly isDev;
11
+ private static readonly isProd;
12
+ private static sectionProcessingErrors;
13
+ private static sectionFetchingErrors;
14
+ private static errorCount;
15
+ /**
16
+ * Global in-process cache for all section configs.
17
+ * Populated once per Node process via loadAllSections(),
18
+ * reused by all get*() calls until the process is restarted,
19
+ * so all subsequent calls reuse this array.
20
+ */
21
+ private static allSectionsPromise;
22
+ private static allSectionsLoaded;
23
+ private static watcherStarted;
24
+ private static configVersion;
25
+ private static sectionWatcher;
26
+ private static ensureConfigFresh;
27
+ static bumpHotMarker(): void;
28
+ /**
29
+ * Get all sections
30
+ * @param type - The type of sections to get
31
+ * @returns The sections
32
+ */
33
+ static getSections(type?: SectionTypes | SectionTypes[]): Promise<AnySectionConfig[]>;
34
+ /**
35
+ * Get all accessible sections for an admin
36
+ * @param type - The type of section to get
37
+ * @param admin - The admin to get the sections for
38
+ * @returns The sections for the admin
39
+ */
40
+ static getSectionsForAdmin({ type, admin, }: {
41
+ type?: SectionTypes | SectionTypes[];
42
+ admin: {
43
+ id: string;
44
+ requiredRole?: 'C' | 'U' | 'D';
45
+ };
46
+ }): Promise<{
47
+ simple: SimpleSectionConfig[];
48
+ has_items: HasItemsSectionConfig[];
49
+ category: CategorySectionConfig[];
50
+ fixed: string[];
51
+ }>;
52
+ /**
53
+ * Get a section
54
+ * @param name - The name of the section to get
55
+ * @param type - The type of section to get
56
+ * @returns The section
57
+ */
58
+ static getSection({ name, type, }: {
59
+ name: string;
60
+ type?: SectionTypes | SectionTypes[];
61
+ }): Promise<AnySectionConfig | null>;
62
+ /**
63
+ * Get an accessible section for an admin
64
+ * @param name - The name of the section to get
65
+ * @param type - The type of section to get
66
+ * @param admin - The admin to get the section for
67
+ * @returns The section for the admin
68
+ */
69
+ static getSectionForAdmin({ name, type, admin, }: {
70
+ name: string;
71
+ type?: SectionTypes | SectionTypes[];
72
+ admin: {
73
+ id: string;
74
+ requiredRole?: 'C' | 'U' | 'D';
75
+ };
76
+ }): Promise<AnySectionConfig | null>;
77
+ /**
78
+ * Create a Section instance from a section config
79
+ * The config must have a build() method (created via helper functions like simpleSection(), hasItemsSection(), etc.)
80
+ *
81
+ * Note: This factory only accepts configs. If you already have a Section instance,
82
+ * use it directly - don't pass it to this factory.
83
+ *
84
+ * @param config - A section config object with a build() method
85
+ * @returns A Section instance
86
+ * @throws Error if config doesn't have a build() method
87
+ */
88
+ static create(config: {
89
+ build: () => HasItemsSection | SimpleSection | CategorySection;
90
+ [key: string]: any;
91
+ }): HasItemsSection | SimpleSection | CategorySection;
92
+ /**
93
+ * Return a clone of the section(s) info to get a fresh copy of the section(s).
94
+ * Not cloning will cause the original section(s) (in *.section.ts file) to be modified!
95
+ * Each *.section.ts file must have exactly one default export (arrays are not allowed).
96
+ *
97
+ * @param name - The name of the section to get
98
+ * @param type - The type of section to get
99
+ * @param admin - The admin to get the section for
100
+ * @returns The section(s)
101
+ */
102
+ private static get;
103
+ /**
104
+ * Load all *.section.ts files once, import their default exports,
105
+ * and cache the resulting configs for the lifetime of the process
106
+ * (until invalidated in dev by file changes).
107
+ */
108
+ private static loadAllSections;
109
+ private static startWatcher;
110
+ private static init;
111
+ }
112
+ export {};
113
+ //# sourceMappingURL=section-factory-with-esbuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section-factory-with-esbuild.d.ts","sourceRoot":"","sources":["../../../src/core/factories/section-factory-with-esbuild.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC7G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AA8IrD,KAAK,gBAAgB,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,qBAAqB,CAAA;AAY3F,qBAAa,cAAc;IACvB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,WAAiD;IAE9E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAwC;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAc;IAE5C,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAA+B;IACrE,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAA+B;IACnE,OAAO,CAAC,MAAM,C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