@dokebi/app 0.4.7 → 0.4.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.
package/AI.md CHANGED
@@ -138,6 +138,8 @@ HTML forms need `dokebi-web.formBody: true` (urlencoded bodies). The flow needs
138
138
  ### Mounting modules (D-0032)
139
139
 
140
140
  - `modules: { '/prefix': module }`. The prefix is `/` or `/a/b` (lower-case letters, digits, `.`, `_`, `~`, `-`).
141
+ - A module that declares its pages as named sets (@dokebi/module 0.4.5, [D-0216](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0216-module-sets.md)) is mounted with the sets this app shows: `modules: { '/board': { module: board, use: 'admin' } }` (or `use: ['site', 'admin']`). Only those sets' routes, sockets and event streams are registered here. Mounting such a module whole, an unknown set, an empty or repeated choice, and `use` on a module without sets are `INVALID_DEFINITION`. One app may mount two sets of a module at two prefixes. Debug log `Module sets mounted` (app, module, prefix, use); `App set up` lists `/board -> board [admin]`; describe lists `use` per module.
142
+ - A module with a switch (`enabled`, @dokebi/module 0.4.5, D-0216) that is off answers on this app like an unknown path: its routes get the 404 (this app's `errors/404` page for a browser) as their first onRequest step, before login checks and body parsing, and its new socket upgrades and SSE streams are 404 too. Open connections stay open.
141
143
  - The module's routes, sockets and SSE routes (`events`, since @dokebi/module 0.1.3) are registered on this app's domains under the prefix, and `page.module` and `page.base` are filled in. Several apps can mount the same module under different prefixes. A mounted module's API is readable with `app.get(module)` without listing it in `requires`.
142
144
  - The module's root route (`route.get('/')`) answers both `/prefix` and `/prefix/`, so links and form actions may use either. Other paths match exactly (`/prefix/items/7/` is 404).
143
145
  - Module views are looked up in this order, so module pages render inside the app layout. To change a module page, an app puts the same file into `views/<template>/<module>/`.
@@ -147,6 +149,7 @@ HTML forms need `dokebi-web.formBody: true` (urlencoded bodies). The flow needs
147
149
  4. the module's `default`
148
150
  5. the app's views
149
151
  6. shared views
152
+ - Inertia apps (0.4.9, D-0218): a module's Vue pages live in its own `views/<template>/Pages/` and are rendered as `<module>/<path>` (`board/List`). The generated `views/app.js` and `views/ssr.js` import `virtual:dokebi/module-pages` (`dokebiInertia()` of `@dokebi/template-inertia/vite` writes it from this app's `modules`) and look a page up in the order above: the app's `views/<template>/Pages/board/List.vue`, the app's `default`, the module's `<template>`, the module's `default`. Only the sets this app mounts are bundled; a module page the app overrides in `default` is left out (@dokebi/module AI.md §4a). Every definition `defineApp` returns carries the sources for that build under `Symbol.for('dokebi.app.modulePages')` (`MODULE_PAGES`, not enumerable): `modulePageSources(definition)` → `[{ module, folder, skip }]` (one entry per module with views, `skip` the sets no mount of this app chose). Describe mode lists the module pages of an Inertia app in the pages section with `module` (`name` is `<module>/<path>`).
150
153
 
151
154
  ### Routing and WebSocket
152
155
 
@@ -276,7 +279,7 @@ dokebi-app:
276
279
 
277
280
  ## 5. API
278
281
 
279
- The API of `createPlugin` is `{ names, resolve(request), seal(request) }` (`AppGroupApi`). `seal(request)` is the `data.seal` of an EJS page for the request's host (`{ head }`, `''` on a plain host), for a page rendered outside an app route, such as the consent page of @dokebi/oauth (its form is then sealed like the app's). In its setup dokebi-app also registers the routing of bound routes with dokebi-web (`web.appRouting`, D-0132), before its own routes, and the app of each host (`web.requestApps`, D-0181), so other plugins ask `web.appOf(request)` without depending on dokebi-app — dokebi-i18n translates each app's requests with its layer (`src/apps/<app>/locales/`, @dokebi/i18n AI.md). `resolve` returns the request's `{ name, template, domain }` or undefined for an unknown host. Also exported: `APP_CONSTRAINT`, `hostOf(request)` (the Host header without the port, or the `:authority` of an HTTP/2 request, which wins when both are sent, as in dokebi-web `requestHost`; ignoring proxies), `withoutPort(host)`, `options` (the `defineOptions` declaration) and the types (`AppDefinition`, `AppContext`, `AppPage`, `RealtimeHandle`, …). Use `resolve` to decide the app.
282
+ The API of `createPlugin` is `{ names, resolve(request), seal(request) }` (`AppGroupApi`). `seal(request)` is the `data.seal` of an EJS page for the request's host (`{ head }`, `''` on a plain host), for a page rendered outside an app route, such as the consent page of @dokebi/oauth (its form is then sealed like the app's). In its setup dokebi-app also registers the routing of bound routes with dokebi-web (`web.appRouting`, D-0132), before its own routes, and the app of each host (`web.requestApps`, D-0181), so other plugins ask `web.appOf(request)` without depending on dokebi-app — dokebi-i18n translates each app's requests with its layer (`src/apps/<app>/locales/`, @dokebi/i18n AI.md). `resolve` returns the request's `{ name, template, domain }` or undefined for an unknown host. Also exported: `APP_CONSTRAINT`, `hostOf(request)` (the Host header without the port, or the `:authority` of an HTTP/2 request, which wins when both are sent, as in dokebi-web `requestHost`; ignoring proxies), `withoutPort(host)`, `options` (the `defineOptions` declaration), `MODULE_PAGES` and `modulePageSources(definition)` (D-0218, the module page sources of an Inertia build) and the types (`AppDefinition`, `AppContext`, `AppPage`, `RealtimeHandle`, …). Use `resolve` to decide the app.
280
283
 
281
284
  ## 6. Errors and what is refused at start
282
285
 
@@ -28,6 +28,11 @@ export interface DescribedPage {
28
28
  /** EJS: the view name (`home`, `errors/404`); Inertia: the component (`Posts/Index`). */
29
29
  readonly name: string;
30
30
  readonly file: string;
31
+ /**
32
+ * D-0218: the module whose views folder holds this Inertia page (`name` is then
33
+ * `<module>/<path under Pages>`); absent for the app's own pages.
34
+ */
35
+ readonly module?: string;
31
36
  }
32
37
  /** The app's templates and pages, read from its views folder. */
33
38
  export declare function appPages(name: string, views: URL | undefined, inertia: boolean): Promise<{
@@ -35,3 +40,12 @@ export declare function appPages(name: string, views: URL | undefined, inertia:
35
40
  pages: DescribedPage[];
36
41
  folder: string | null;
37
42
  }>;
43
+ /**
44
+ * D-0218: the Inertia pages of the modules an app mounts (`<folder>/<template>/Pages/**`, the pages
45
+ * of sets the app did not choose left out). An app page of the same name wins when shown.
46
+ */
47
+ export declare function modulePages(name: string, sources: readonly {
48
+ module: string;
49
+ folder: string;
50
+ skip: readonly string[];
51
+ }[]): Promise<DescribedPage[]>;
package/dist/describe.js CHANGED
@@ -77,3 +77,30 @@ export async function appPages(name, views, inertia) {
77
77
  const ordered = [...templates].sort((a, b) => a === 'default' ? -1 : b === 'default' ? 1 : a.localeCompare(b));
78
78
  return { templates: ordered, pages, folder: display(folder) };
79
79
  }
80
+ /**
81
+ * D-0218: the Inertia pages of the modules an app mounts (`<folder>/<template>/Pages/**`, the pages
82
+ * of sets the app did not choose left out). An app page of the same name wins when shown.
83
+ */
84
+ export async function modulePages(name, sources) {
85
+ const pages = [];
86
+ for (const source of sources) {
87
+ const list = await files(source.folder);
88
+ for (const file of list) {
89
+ const match = /^([^/]+)\/Pages\/(.+)$/.exec(file);
90
+ if (!match || !file.endsWith('.vue'))
91
+ continue;
92
+ const [, template, rest] = match;
93
+ if (source.skip.some((set) => rest.startsWith(`${set}/`)))
94
+ continue;
95
+ pages.push({
96
+ app: name,
97
+ engine: 'inertia',
98
+ template,
99
+ name: `${source.module}/${rest.slice(0, -'.vue'.length)}`,
100
+ file: display(join(source.folder, file)),
101
+ module: source.module,
102
+ });
103
+ }
104
+ }
105
+ return pages;
106
+ }
package/dist/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DokebiError } from '@dokebi/core';
2
2
  const FIX = {
3
- INVALID_DEFINITION: 'defineApp takes requires, controllers, views (a file: URL), inertia, modules ({ "/prefix": defineModule(...) }), shared, routes, sockets, events, setup, start and drain; hooks are functions.',
3
+ INVALID_DEFINITION: 'defineApp takes requires, controllers, views (a file: URL), inertia, modules ({ "/prefix": defineModule(...) }, or { "/prefix": { module, use: "<set>" } } for a module of named sets), shared, routes, sockets, events, setup, start and drain; hooks are functions.',
4
4
  INVALID_ENTRY: 'Pass { apps: { <name>: defineApp(...) } } (src/dokebi.generated.ts does); names match ^[a-z][a-z0-9-]{0,31}$.',
5
5
  DEPENDENCY_CONFLICT: 'Two apps (or an app and dokebi-app) require one plugin with version ranges no release satisfies together: align requires of defineApp in src/apps/<app>/app.ts, or update the app that needs the older major.',
6
6
  UNKNOWN_APP: 'Every app named in options.dokebi-app.domains.<host>.app and options.dokebi-app.apps must be defined (npx dokebi app add <name>, or remove the entry from dokebi.yaml).',
package/dist/index.d.ts CHANGED
@@ -4,6 +4,14 @@ import { type WebErrorResponse, type WebRoute } from '@dokebi/web';
4
4
  import type { FastifyReply, FastifyRequest } from 'fastify';
5
5
  export { AppError, type AppErrorCode } from './errors.js';
6
6
  export { type AppPluginOptions, options } from './options.js';
7
+ /**
8
+ * A module of `defineApp({ modules })`: mounted whole, or `{ module, use }` (D-0216) to show only
9
+ * the named sets of a module that declares its routes, sockets and events as sets.
10
+ */
11
+ export type AppModuleMount = Plugin<unknown> | {
12
+ readonly module: Plugin<unknown>;
13
+ readonly use: string | readonly string[];
14
+ };
7
15
  /** The Fastify route constraint that selects an app by request host. */
8
16
  export declare const APP_CONSTRAINT = "dokebiApp";
9
17
  /** Which app answered a request, with the template and the host it came in on. */
@@ -291,9 +299,10 @@ export interface AppDefinition {
291
299
  readonly inertia?: AppInertiaOptions;
292
300
  /**
293
301
  * Modules (D-0032) mounted under a prefix: `{ '/board': boardModule }`. Their routes and
294
- * sockets answer on this app's domains only; they need not be listed in `requires`.
302
+ * sockets answer on this app's domains only; they need not be listed in `requires`. A module
303
+ * that declares named sets is mounted as `{ module, use: 'admin' }` (D-0216).
295
304
  */
296
- readonly modules?: Readonly<Record<string, Plugin<unknown>>>;
305
+ readonly modules?: Readonly<Record<string, AppModuleMount>>;
297
306
  /**
298
307
  * Data merged under the data of every EJS page this app renders, its own and its modules'
299
308
  * (like Inertia shared props): what the app layout needs, such as the menu. Page data wins.
@@ -320,6 +329,28 @@ export interface AppDefinition {
320
329
  }
321
330
  /** Declares one app. Its name is the key under which the generated code registers it. */
322
331
  export declare function defineApp(definition: AppDefinition): AppDefinition;
332
+ /**
333
+ * D-0218: the key of an app definition's module page sources, read by structure (the Inertia
334
+ * build plugin does not import @dokebi/app).
335
+ */
336
+ export declare const MODULE_PAGES: unique symbol;
337
+ /** One module whose Inertia pages an app shows (D-0218). */
338
+ export interface ModulePageSource {
339
+ /** The module name: its pages are named `<module>/<path under Pages>`. */
340
+ readonly module: string;
341
+ /** The module's views folder (absolute path); its pages are `<template>/Pages/**`. */
342
+ readonly folder: string;
343
+ /**
344
+ * Sets of the module the app chose in none of its mounts: their pages (`Pages/<set>/**`) are
345
+ * left out. Empty for a module mounted whole.
346
+ */
347
+ readonly skip: readonly string[];
348
+ }
349
+ /**
350
+ * The modules of `definition.modules` that have views, one entry per module (two mounts of one
351
+ * module show the sets of both), in mount order.
352
+ */
353
+ export declare function modulePageSources(definition: AppDefinition): ModulePageSource[];
323
354
  interface DomainTarget {
324
355
  readonly app: string;
325
356
  readonly template: string;
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { collectViewData, realtime, viewData, viewEngines, } from '@dokebi/web/p
9
9
  import Range from 'semver/classes/range.js';
10
10
  import minVersion from 'semver/ranges/min-version.js';
11
11
  import validRange from 'semver/ranges/valid.js';
12
- import { appPages, describePoint } from './describe.js';
12
+ import { appPages, describePoint, modulePages } from './describe.js';
13
13
  import { AppError } from './errors.js';
14
14
  import { options as declaration } from './options.js';
15
15
  export { AppError } from './errors.js';
@@ -27,6 +27,18 @@ function mountOf(plugin) {
27
27
  ? plugin[MODULE_MOUNT]
28
28
  : undefined;
29
29
  }
30
+ function mountedPlugin(value) {
31
+ return mountOf(value)
32
+ ? value
33
+ : value.module;
34
+ }
35
+ /** The sets an app chose for a mount (checked by defineApp), or undefined for a whole module. */
36
+ function chosenSets(value) {
37
+ if (mountOf(value))
38
+ return undefined;
39
+ const use = value.use;
40
+ return typeof use === 'string' ? [use] : use;
41
+ }
30
42
  /** `/board` + `/` → `/board`, `/board` + `/x` → `/board/x`, `/` + `/x` → `/x`. */
31
43
  function joinPath(base, path) {
32
44
  if (!base)
@@ -69,20 +81,83 @@ export function defineApp(definition) {
69
81
  if (definition.modules !== undefined) {
70
82
  if (!plain(definition.modules))
71
83
  throw invalidDefinition('App modules must be a plain object');
72
- for (const [prefix, plugin] of Object.entries(definition.modules)) {
84
+ for (const [prefix, value] of Object.entries(definition.modules)) {
73
85
  if (!PREFIX.test(prefix))
74
86
  throw invalidDefinition('Invalid module prefix: ' + prefix);
75
- if (!mountOf(plugin))
87
+ const whole = mountOf(value);
88
+ const given = value;
89
+ const mount = whole ?? mountOf(given?.module);
90
+ if (!mount)
76
91
  throw invalidDefinition('App modules must be made with defineModule');
92
+ const sets = mount.sets;
93
+ if (whole) {
94
+ // A module of named sets is never mounted whole: the app says which pages it shows.
95
+ if (sets)
96
+ throw invalidDefinition(`Module ${mount.name} at ${prefix} has the sets ${sets.join(', ')}: mount it as { module, use: '<set>' }`);
97
+ continue;
98
+ }
99
+ const use = typeof given?.use === 'string' ? [given.use] : given?.use;
100
+ if (!Array.isArray(use) ||
101
+ !use.length ||
102
+ Object.keys(given).some((key) => key !== 'module' && key !== 'use') ||
103
+ new Set(use).size !== use.length)
104
+ throw invalidDefinition(`Module mount at ${prefix} is { module, use: '<set>' | ['<set>', …] }`);
105
+ // An older @dokebi/module has neither sets nor hooks.
106
+ if (!sets || typeof mount.hooks !== 'function')
107
+ throw invalidDefinition(`Module ${mount.name} at ${prefix} has no sets: mount the module itself`);
108
+ const unknown = use.filter((set) => !sets.includes(set));
109
+ if (unknown.length)
110
+ throw invalidDefinition(`Module ${mount.name} at ${prefix} has no set ${unknown.join(', ')} (it has ${sets.join(', ')})`);
77
111
  }
78
112
  }
79
113
  for (const hook of ['shared', 'routes', 'sockets', 'events', 'setup', 'start', 'drain'])
80
114
  if (definition[hook] !== undefined && typeof definition[hook] !== 'function')
81
115
  throw invalidDefinition(`App ${hook} must be a function`);
82
- const frozen = Object.freeze({ ...definition });
116
+ const copy = { ...definition };
117
+ // D-0218: the Inertia build (dokebiInertia() of @dokebi/template-inertia) reads the page
118
+ // folders of the mounted modules through this, without importing this package.
119
+ Object.defineProperty(copy, MODULE_PAGES, { value: () => modulePageSources(copy) });
120
+ const frozen = Object.freeze(copy);
83
121
  defined.add(frozen);
84
122
  return frozen;
85
123
  }
124
+ /**
125
+ * D-0218: the key of an app definition's module page sources, read by structure (the Inertia
126
+ * build plugin does not import @dokebi/app).
127
+ */
128
+ export const MODULE_PAGES = Symbol.for('dokebi.app.modulePages');
129
+ /**
130
+ * The modules of `definition.modules` that have views, one entry per module (two mounts of one
131
+ * module show the sets of both), in mount order.
132
+ */
133
+ export function modulePageSources(definition) {
134
+ const found = new Map();
135
+ for (const value of Object.values(definition.modules ?? {})) {
136
+ const mount = mountOf(mountedPlugin(value));
137
+ if (!mount?.folder)
138
+ continue;
139
+ const chosen = chosenSets(value);
140
+ let entry = found.get(mount.name);
141
+ if (!entry) {
142
+ entry = {
143
+ folder: fileURLToPath(mount.folder),
144
+ sets: mount.sets ?? [],
145
+ used: new Set(),
146
+ };
147
+ found.set(mount.name, entry);
148
+ }
149
+ if (!chosen)
150
+ entry.used = undefined;
151
+ else
152
+ for (const set of chosen)
153
+ entry.used?.add(set);
154
+ }
155
+ return [...found].map(([module, entry]) => Object.freeze({
156
+ module,
157
+ folder: entry.folder,
158
+ skip: Object.freeze(entry.used ? entry.sets.filter((set) => !entry.used?.has(set)) : []),
159
+ }));
160
+ }
86
161
  function plain(value) {
87
162
  return (value !== null &&
88
163
  typeof value === 'object' &&
@@ -621,6 +696,30 @@ class AppRuntime {
621
696
  let ejsRoot;
622
697
  /** Each app's error answer (D-0074), by app name. */
623
698
  const answers = new Map();
699
+ /**
700
+ * D-0216: the switch of each module socket and event stream route, by `<app> <path>`. The
701
+ * transports register those routes themselves, so the gate comes in through a route hook (a
702
+ * module's own HTTP routes get it as their first onRequest step instead, below).
703
+ */
704
+ const switches = new Map();
705
+ http.routeHook({
706
+ plugin: 'dokebi-app',
707
+ route: (route) => {
708
+ const app = route.constraints[APP_CONSTRAINT];
709
+ const on = typeof app === 'string' ? switches.get(`${app} ${route.url}`) : undefined;
710
+ if (!on)
711
+ return undefined;
712
+ return {
713
+ preValidation: async (_request, reply) => {
714
+ if (on())
715
+ return undefined;
716
+ // The 404 of an unknown path on this app's host (its error page, JSON for an API).
717
+ reply.callNotFound();
718
+ return reply;
719
+ },
720
+ };
721
+ },
722
+ });
624
723
  for (const [name, definition] of this.apps) {
625
724
  context.signal.throwIfAborted();
626
725
  const begin = performance.now();
@@ -664,7 +763,10 @@ class AppRuntime {
664
763
  });
665
764
  return { ...rest, tenant: `${chosen}:${identity.tenant}` };
666
765
  };
667
- const allowed = new Set([...(definition.requires ?? []), ...Object.values(definition.modules ?? {})].map((item) => requirement(item).name));
766
+ const allowed = new Set([
767
+ ...(definition.requires ?? []),
768
+ ...Object.values(definition.modules ?? {}).map(mountedPlugin),
769
+ ].map((item) => requirement(item).name));
668
770
  let controllers;
669
771
  const appContext = Object.freeze({
670
772
  name,
@@ -726,7 +828,7 @@ class AppRuntime {
726
828
  });
727
829
  controllers = await createControllers(factoryContext, definition.controllers ?? []);
728
830
  const templates = new Set();
729
- const hasModuleViews = Object.values(definition.modules ?? {}).some((module) => mountOf(module)?.views);
831
+ const hasModuleViews = Object.values(definition.modules ?? {}).some((module) => mountOf(mountedPlugin(module))?.views);
730
832
  if (definition.views) {
731
833
  // The app's folder is loaded as `<app>/…`; the engine's root renderer serves every scope.
732
834
  ejsRoot = await engine('ejs', name).scope({
@@ -835,13 +937,32 @@ class AppRuntime {
835
937
  return new RequestPage(info, entry?.sealed === true, moduleName, base, inertiaApi, request, viewOf);
836
938
  };
837
939
  };
838
- const routerFor = (page, base) => {
940
+ const routerFor = (page, base, on) => {
941
+ /**
942
+ * D-0216: a switched-off module answers the 404 of an unknown path before anything else
943
+ * of the request runs (login checks, body parsing): its first onRequest step.
944
+ */
945
+ const gate = on
946
+ ? async (_request, reply) => {
947
+ if (on())
948
+ return undefined;
949
+ reply.callNotFound();
950
+ return reply;
951
+ }
952
+ : undefined;
839
953
  const add = (options) => {
840
954
  const { handler, ...rest } = options;
841
955
  routeCount++;
842
956
  const url = joinPath(base, rest.url);
957
+ const own = rest.onRequest;
958
+ const onRequest = (gate
959
+ ? own === undefined || own === null
960
+ ? [gate]
961
+ : [gate, ...(Array.isArray(own) ? own : [own])]
962
+ : own);
843
963
  const register = (path) => http.route({
844
964
  ...rest,
965
+ ...(onRequest === undefined ? {} : { onRequest }),
845
966
  url: path,
846
967
  constraints: { [APP_CONSTRAINT]: name },
847
968
  handler(request, reply) {
@@ -964,17 +1085,44 @@ class AppRuntime {
964
1085
  mountSockets((await definition.sockets?.(appContext)) ?? [], '', `App ${name}`);
965
1086
  mountEvents((await definition.events?.(appContext)) ?? [], '', `App ${name}`);
966
1087
  // Mounted modules (D-0032): their routes, sockets and SSE routes under the prefix, here only.
967
- for (const [prefix, plugin] of Object.entries(definition.modules ?? {})) {
968
- const mount = mountOf(plugin);
1088
+ for (const [prefix, value] of Object.entries(definition.modules ?? {})) {
1089
+ const mount = mountOf(mountedPlugin(value));
969
1090
  const base = prefix === '/' ? '' : prefix;
970
1091
  const module = mount.context();
971
1092
  const page = pageFor({ name: mount.name, views: mount.views, base });
972
- await mount.routes?.(routerFor(page, base), module);
973
- mountSockets(
974
- // defineSocket results; the module types them by shape only.
975
- ((await mount.sockets?.(module)) ?? []), base, `Module ${mount.name} (app ${name})`);
1093
+ // D-0216: only the chosen sets of a module of sets; a whole module as before.
1094
+ const chosen = chosenSets(value);
1095
+ const hooks = chosen && mount.hooks
1096
+ ? mount.hooks(chosen)
1097
+ : {
1098
+ routes: mount.routes ? [mount.routes] : [],
1099
+ sockets: mount.sockets ? [mount.sockets] : [],
1100
+ events: mount.events ? [mount.events] : [],
1101
+ };
1102
+ // D-0216: the module's switch (older module packages have none: always on).
1103
+ const on = typeof mount.enabled === 'function' ? () => mount.enabled?.() ?? true : undefined;
1104
+ for (const routes of hooks.routes)
1105
+ await routes(routerFor(page, base, on), module);
1106
+ const gateRealtime = (routes) => {
1107
+ if (on)
1108
+ for (const route of routes)
1109
+ switches.set(`${name} ${joinPath(base, route.path)}`, on);
1110
+ return routes;
1111
+ };
1112
+ if (chosen && logger.isEnabled('debug'))
1113
+ logger.log('debug', 'Module sets mounted', {
1114
+ app: name,
1115
+ module: mount.name,
1116
+ prefix,
1117
+ use: chosen,
1118
+ });
1119
+ for (const sockets of hooks.sockets)
1120
+ mountSockets(
1121
+ // defineSocket results; the module types them by shape only.
1122
+ gateRealtime(((await sockets(module)) ?? [])), base, `Module ${mount.name} (app ${name})`);
976
1123
  // SSE routes of the module (@dokebi/module 0.1.3; older modules have no `events`).
977
- mountEvents(((await mount.events?.(module)) ?? []), base, `Module ${mount.name} (app ${name})`);
1124
+ for (const events of hooks.events)
1125
+ mountEvents(gateRealtime(((await events(module)) ?? [])), base, `Module ${mount.name} (app ${name})`);
978
1126
  }
979
1127
  this.#mounted.push({ name, definition, context: appContext });
980
1128
  logger.log('debug', 'App set up', {
@@ -983,7 +1131,7 @@ class AppRuntime {
983
1131
  controllers: definition.controllers?.length ?? 0,
984
1132
  templates: [...templates],
985
1133
  inertia: Boolean(inertiaApi),
986
- modules: Object.entries(definition.modules ?? {}).map(([prefix, plugin]) => `${prefix} -> ${mountOf(plugin).name}`),
1134
+ modules: Object.entries(definition.modules ?? {}).map(([prefix, value]) => `${prefix} -> ${mountOf(mountedPlugin(value)).name}${chosenSets(value) ? ` [${chosenSets(value)?.join(', ')}]` : ''}`),
987
1135
  routes: routeCount,
988
1136
  sockets: socketCount,
989
1137
  events: eventCount,
@@ -1018,14 +1166,17 @@ class AppRuntime {
1018
1166
  for (const [name, definition] of this.apps) {
1019
1167
  const found = await appPages(name, definition.views, definition.inertia !== undefined);
1020
1168
  pages.push(...found.pages);
1169
+ if (definition.inertia)
1170
+ pages.push(...(await modulePages(name, modulePageSources(definition))));
1021
1171
  apps.push({
1022
1172
  name,
1023
1173
  engine: definition.inertia ? 'inertia' : definition.views ? 'ejs' : null,
1024
1174
  views: found.folder,
1025
1175
  templates: found.templates,
1026
- modules: Object.entries(definition.modules ?? {}).map(([prefix, plugin]) => ({
1176
+ modules: Object.entries(definition.modules ?? {}).map(([prefix, value]) => ({
1027
1177
  prefix,
1028
- module: mountOf(plugin)?.name ?? plugin.metadata.name,
1178
+ module: mountOf(mountedPlugin(value))?.name ?? mountedPlugin(value).metadata.name,
1179
+ ...(chosenSets(value) ? { use: chosenSets(value) } : {}),
1029
1180
  })),
1030
1181
  requires: (definition.requires ?? []).map((item) => requirement(item).name),
1031
1182
  namespaces: [...(this.options.apps.get(name)?.namespaces ?? [name])],
@@ -1123,7 +1274,7 @@ function missingViews(name) {
1123
1274
  }
1124
1275
  export const createPlugin = definePlugin({
1125
1276
  name: 'dokebi-app',
1126
- version: '0.4.7',
1277
+ version: '0.4.9',
1127
1278
  core: '^0.4.0',
1128
1279
  options: declaration,
1129
1280
  entry: parseEntry,
@@ -1155,7 +1306,10 @@ function mergeRequirements(apps) {
1155
1306
  for (const dependency of [web, seal, session, files])
1156
1307
  add('dokebi-app', dependency);
1157
1308
  for (const [name, app] of apps)
1158
- for (const item of [...(app.requires ?? []), ...Object.values(app.modules ?? {})])
1309
+ for (const item of [
1310
+ ...(app.requires ?? []),
1311
+ ...Object.values(app.modules ?? {}).map(mountedPlugin),
1312
+ ])
1159
1313
  add(name, requirement(item));
1160
1314
  const merged = [];
1161
1315
  for (const [name, list] of needs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/app",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "Multiple apps per project for Dokebi: pick the app and template by request domain, with EJS and Inertia skeletons.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -1,6 +1,12 @@
1
1
  // Browser entry of this app (Vite input). Pages and the layout are looked up in the template the
2
2
  // domain selected and then in `default`, like the EJS views. The template comes from the shared
3
3
  // prop `app.template` (dokebi-app) of the first page; it is fixed for a domain.
4
+
5
+ // The Vue pages of the modules this app mounts (D-0218), from each module's own
6
+ // views/<template>/Pages/: a module renders 'board/List' and its file is
7
+ // <module>/views/<template>/Pages/List.vue. dokebiInertia() of vite.config.ts writes this module
8
+ // from the app's app.ts (pages of sets the app did not choose are left out).
9
+ import modulePages from 'virtual:dokebi/module-pages';
4
10
  import { pageI18n } from '@dokebi/template-inertia/i18n';
5
11
  import { createInertiaApp, http, router } from '@inertiajs/vue3';
6
12
  import { createApp, createSSRApp, h } from 'vue';
@@ -26,8 +32,10 @@ const template = first.props?.app?.template ?? 'default';
26
32
  const pick = (path) => files[`./${template}/${path}.vue`] ?? files[`./default/${path}.vue`];
27
33
 
28
34
  await createInertiaApp({
35
+ // A page of this app's views/<template>/Pages/ first (Pages/board/List.vue overrides the board
36
+ // module's List.vue), then the module's own page of the template, then of `default`.
29
37
  resolve(name) {
30
- const page = pick(`Pages/${name}`);
38
+ const page = pick(`Pages/${name}`) ?? modulePages.page(template, name);
31
39
  if (!page) throw new Error(`Unknown page: ${name}`);
32
40
  return page;
33
41
  },
@@ -2,6 +2,10 @@
2
2
  // vite.ssr.config.ts); app.ts names that file in `inertia.ssr.bundle`, and
3
3
  // @dokebi/template-inertia calls render(page) for the first HTML of every page. Pages and the
4
4
  // layout are looked up as views/app.js does in the browser, so both draw the same markup.
5
+
6
+ // The pages of the modules this app mounts, as in views/app.js (D-0218). vite.ssr.config.ts needs
7
+ // dokebiInertia() for this import.
8
+ import modulePages from 'virtual:dokebi/module-pages';
5
9
  import { pageI18n } from '@dokebi/template-inertia/i18n';
6
10
  import { createInertiaApp } from '@inertiajs/vue3';
7
11
  import { renderToString } from 'vue/server-renderer';
@@ -14,7 +18,7 @@ export async function render(page) {
14
18
  // On the server, createInertiaApp without `page` returns (page, renderToString).
15
19
  const app = await createInertiaApp({
16
20
  resolve(name) {
17
- const found = pick(`Pages/${name}`);
21
+ const found = pick(`Pages/${name}`) ?? modulePages.page(template, name);
18
22
  if (!found) throw new Error(`Unknown page: ${name}`);
19
23
  return found;
20
24
  },
@@ -6,6 +6,9 @@
6
6
  // usePage<{ … }>(). Written once by `dokebi app add --inertia`; this file is yours to change.
7
7
  // @dokebi/i18n with http.enabled adds `locale` and `i18n` (the messages views/app.js hands to
8
8
  // pageI18n; pages translate with useI18n() from @dokebi/template-inertia/i18n, or $t()).
9
+ // The reference below types `virtual:dokebi/module-pages` (the Vue pages of the modules an app
10
+ // mounts, D-0218) for views/app.js and views/ssr.js.
11
+ /// <reference types="@dokebi/template-inertia/module-pages" />
9
12
  import '@inertiajs/core';
10
13
  import type { PageI18nPayload } from '@dokebi/template-inertia/i18n';
11
14
 
@@ -3,7 +3,9 @@
3
3
  // @dokebi/template-inertia serves the built files at /build/. New Inertia apps are found
4
4
  // automatically. dokebiInertia() keeps the browser modules the app serves itself out of the
5
5
  // bundle: every import of '@dokebi/seal/http' (the views/app.js bootstrap, sealedFetch in pages)
6
- // loads /dokebi/seal/http.mjs, one instance with one seal, in the build and in `dokebi dev`.
6
+ // loads /dokebi/seal/http.mjs, one instance with one seal, in the build and in `dokebi dev`. It
7
+ // also writes `virtual:dokebi/module-pages` for views/app.js: the Vue pages of the modules each
8
+ // app mounts, from the modules' own views folders (D-0218).
7
9
  //
8
10
  // dokebiInertia() also decides which files the dev server (`dokebi dev`) may serve (D-0129): only
9
11
  // the views folders of the apps, node_modules, the files those modules import and the folders
@@ -2,8 +2,12 @@
2
2
  // src/apps/<app>/views/ssr.js becomes dist/ssr/<app>/ssr.js, which the app names in
3
3
  // `inertia.ssr.bundle`. Runs after the browser build (`npm run build`). dist/ssr/ is not served:
4
4
  // @dokebi/template-inertia serves only the files of the manifest's folders (dist/assets).
5
+ // dokebiInertia() writes `virtual:dokebi/module-pages` (the Vue pages of the modules each app
6
+ // mounts, D-0218) for views/ssr.js as it does for views/app.js; server rendering leaves the seal
7
+ // imports to Node.
5
8
  // Written once by `dokebi app add --inertia --ssr`; this file is yours to change.
6
9
  import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
10
+ import { dokebiInertia } from '@dokebi/template-inertia/vite';
7
11
  import vue from '@vitejs/plugin-vue';
8
12
  import { defineConfig } from 'vite';
9
13
 
@@ -21,7 +25,7 @@ const apps = readdirSync('src/apps', { withFileTypes: true })
21
25
 
22
26
  export default defineConfig({
23
27
  publicDir: false,
24
- plugins: [vue({ script: { fs: vueTypeFiles } })],
28
+ plugins: [vue({ script: { fs: vueTypeFiles } }), dokebiInertia()],
25
29
  build: {
26
30
  outDir: 'dist/ssr',
27
31
  // Kept like the browser build: a worker started before this build still imports the lazy