@dokebi/app 0.4.8 → 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
@@ -149,6 +149,7 @@ HTML forms need `dokebi-web.formBody: true` (urlencoded bodies). The flow needs
149
149
  4. the module's `default`
150
150
  5. the app's views
151
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>`).
152
153
 
153
154
  ### Routing and WebSocket
154
155
 
@@ -278,7 +279,7 @@ dokebi-app:
278
279
 
279
280
  ## 5. API
280
281
 
281
- 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.
282
283
 
283
284
  ## 6. Errors and what is refused at start
284
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/index.d.ts CHANGED
@@ -329,6 +329,28 @@ export interface AppDefinition {
329
329
  }
330
330
  /** Declares one app. Its name is the key under which the generated code registers it. */
331
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[];
332
354
  interface DomainTarget {
333
355
  readonly app: string;
334
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';
@@ -113,10 +113,51 @@ export function defineApp(definition) {
113
113
  for (const hook of ['shared', 'routes', 'sockets', 'events', 'setup', 'start', 'drain'])
114
114
  if (definition[hook] !== undefined && typeof definition[hook] !== 'function')
115
115
  throw invalidDefinition(`App ${hook} must be a function`);
116
- 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);
117
121
  defined.add(frozen);
118
122
  return frozen;
119
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
+ }
120
161
  function plain(value) {
121
162
  return (value !== null &&
122
163
  typeof value === 'object' &&
@@ -1125,6 +1166,8 @@ class AppRuntime {
1125
1166
  for (const [name, definition] of this.apps) {
1126
1167
  const found = await appPages(name, definition.views, definition.inertia !== undefined);
1127
1168
  pages.push(...found.pages);
1169
+ if (definition.inertia)
1170
+ pages.push(...(await modulePages(name, modulePageSources(definition))));
1128
1171
  apps.push({
1129
1172
  name,
1130
1173
  engine: definition.inertia ? 'inertia' : definition.views ? 'ejs' : null,
@@ -1231,7 +1274,7 @@ function missingViews(name) {
1231
1274
  }
1232
1275
  export const createPlugin = definePlugin({
1233
1276
  name: 'dokebi-app',
1234
- version: '0.4.8',
1277
+ version: '0.4.9',
1235
1278
  core: '^0.4.0',
1236
1279
  options: declaration,
1237
1280
  entry: parseEntry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/app",
3
- "version": "0.4.8",
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