@dokebi/app 0.4.1 → 0.4.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/app",
3
- "version": "0.4.1",
3
+ "version": "0.4.5",
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",
@@ -37,12 +37,15 @@
37
37
  "typecheck": "tsc -p tsconfig.test.json --noEmit",
38
38
  "test": "node -e \"require('node:fs').rmSync('.tmp/tests',{recursive:true,force:true})\" && tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
39
39
  },
40
+ "dependencies": {
41
+ "semver": "7.8.5"
42
+ },
40
43
  "peerDependencies": {
41
44
  "@dokebi/controller": "^0.4.0",
42
45
  "@dokebi/core": "^0.4.0",
43
46
  "@dokebi/module": "^0.4.0",
44
47
  "@dokebi/template-ejs": "^0.4.0",
45
- "@dokebi/web": "^0.4.1",
48
+ "@dokebi/web": "^0.4.3",
46
49
  "fastify": "^5.12.7"
47
50
  },
48
51
  "peerDependenciesMeta": {
@@ -53,11 +56,13 @@
53
56
  "devDependencies": {
54
57
  "@dokebi/module": "^0.4.0",
55
58
  "@dokebi/session": "^0.4.0",
56
- "@dokebi/sse": "^0.4.0",
59
+ "@dokebi/sse": "^0.4.2",
60
+ "@dokebi/static": "^0.1.0",
57
61
  "@dokebi/template-ejs": "^0.4.0",
58
62
  "@dokebi/template-inertia": "^0.4.0",
59
63
  "@dokebi/websocket": "^0.4.0",
60
64
  "@dokebi/websocket-hub": "^0.4.0",
65
+ "@types/semver": "7.8.0",
61
66
  "ws": "8.22.0"
62
67
  },
63
68
  "dokebi": {
@@ -67,7 +72,7 @@
67
72
  "dependencies": [
68
73
  {
69
74
  "name": "dokebi-web",
70
- "version": "^0.4.1",
75
+ "version": "^0.4.3",
71
76
  "package": "@dokebi/web"
72
77
  },
73
78
  {
@@ -89,11 +94,20 @@
89
94
  "name": "dokebi-session",
90
95
  "version": "^0.4.0",
91
96
  "optional": true
97
+ },
98
+ {
99
+ "name": "dokebi-static",
100
+ "version": "^0.1.0",
101
+ "optional": true
92
102
  }
93
103
  ],
94
104
  "collects": [
95
105
  "dokebi-web:view-engine",
96
- "dokebi-web:realtime"
106
+ "dokebi-web:realtime",
107
+ "dokebi-web:view-data"
108
+ ],
109
+ "contributes": [
110
+ "core:describe"
97
111
  ],
98
112
  "hosts": [
99
113
  "apps"
@@ -120,7 +134,8 @@
120
134
  ],
121
135
  "recipes": [
122
136
  "api",
123
- "blog"
137
+ "blog",
138
+ "site"
124
139
  ]
125
140
  },
126
141
  "publishConfig": {
@@ -1,10 +1,14 @@
1
1
  import type { AppInfo } from '@dokebi/app';
2
2
  import { defineController } from '@dokebi/controller';
3
- import { describe } from '../models/site.ts';
3
+ import { SiteService } from '../services/site.ts';
4
4
 
5
5
  export class HomeController {
6
+ readonly #service: SiteService;
7
+ constructor(service: SiteService) {
8
+ this.#service = service;
9
+ }
6
10
  home(app: AppInfo) {
7
- return { title: app.name, message: describe(app) };
11
+ return this.#service.home({ name: app.name, domain: app.domain, template: app.template });
8
12
  }
9
13
  }
10
- export const homeController = defineController('home', () => new HomeController());
14
+ export const homeController = defineController('home', () => new HomeController(new SiteService()));
@@ -1,6 +1,6 @@
1
- import type { AppInfo } from '@dokebi/app';
1
+ export type SiteIdentity = { name: string; domain: string; template: string };
2
2
 
3
- /** Models are plain code; controllers pass them the plugin APIs they need. */
4
- export function describe(app: AppInfo): string {
5
- return `${app.name} app on ${app.domain} (template: ${app.template})`;
3
+ /** A pure model for this starter; replace it with feature persistence as needed. */
4
+ export function describe(site: SiteIdentity): string {
5
+ return `${site.name} app on ${site.domain} (template: ${site.template})`;
6
6
  }
@@ -0,0 +1,7 @@
1
+ import { describe, type SiteIdentity } from '../models/site.ts';
2
+
3
+ export class SiteService {
4
+ home(site: SiteIdentity) {
5
+ return { title: site.name, message: describe(site) };
6
+ }
7
+ }
@@ -1,10 +1,14 @@
1
1
  import type { AppInfo } from '@dokebi/app';
2
2
  import { defineController } from '@dokebi/controller';
3
- import { describe } from '../models/site.ts';
3
+ import { SiteService } from '../services/site.ts';
4
4
 
5
5
  export class HomeController {
6
+ readonly #service: SiteService;
7
+ constructor(service: SiteService) {
8
+ this.#service = service;
9
+ }
6
10
  home(app: AppInfo) {
7
- return { title: app.name, message: describe(app) };
11
+ return this.#service.home({ name: app.name, domain: app.domain, template: app.template });
8
12
  }
9
13
  }
10
- export const homeController = defineController('home', () => new HomeController());
14
+ export const homeController = defineController('home', () => new HomeController(new SiteService()));
@@ -1,6 +1,6 @@
1
- import type { AppInfo } from '@dokebi/app';
1
+ export type SiteIdentity = { name: string; domain: string; template: string };
2
2
 
3
- /** Models are plain code; controllers pass them the plugin APIs they need. */
4
- export function describe(app: AppInfo): string {
5
- return `${app.name} app on ${app.domain} (template: ${app.template})`;
3
+ /** A pure model for this starter; replace it with feature persistence as needed. */
4
+ export function describe(site: SiteIdentity): string {
5
+ return `${site.name} app on ${site.domain} (template: ${site.template})`;
6
6
  }
@@ -0,0 +1,7 @@
1
+ import { describe, type SiteIdentity } from '../models/site.ts';
2
+
3
+ export class SiteService {
4
+ home(site: SiteIdentity) {
5
+ return { title: site.name, message: describe(site) };
6
+ }
7
+ }
@@ -1,21 +1,25 @@
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
- import { createInertiaApp, http } from '@inertiajs/vue3';
4
+ import { pageI18n } from '@dokebi/template-inertia/i18n';
5
+ import { createInertiaApp, http, router } from '@inertiajs/vue3';
5
6
  import { createApp, createSSRApp, h } from 'vue';
6
7
 
7
8
  // A seal host (`seal: true` in dokebi-app domains, D-0062) sends the first page sealed. The
8
- // @dokebi/seal plugin serves its browser module: it opens the page and seals every later visit.
9
- // Plain pages skip this, so a project without @dokebi/seal never loads it.
9
+ // @dokebi/seal plugin serves its browser module (/dokebi/seal/http.mjs): it opens the page and
10
+ // seals every later visit. dokebiInertia() of vite.config.ts makes every import of
11
+ // '@dokebi/seal/http' load that served file, so pages import sealedFetch and currentSealBridge
12
+ // from '@dokebi/seal/http' as usual and share this bootstrap's seal. Plain pages skip this, so a
13
+ // project without @dokebi/seal never loads it.
10
14
  if (document.querySelector('script[data-page][data-sealed="true"]'))
11
- await (await import(/* @vite-ignore */ '/dokebi/seal/http.mjs')).sealInertia(http);
15
+ await (await import('@dokebi/seal/http')).sealInertia(http);
12
16
 
13
17
  const files = import.meta.glob('./*/{Layout,Pages/**/*}.vue', { eager: true });
14
18
  const first = JSON.parse(document.querySelector('script[data-page]')?.textContent || '{}');
15
19
  const template = first.props?.app?.template ?? 'default';
16
20
  const pick = (path) => files[`./${template}/${path}.vue`] ?? files[`./default/${path}.vue`];
17
21
 
18
- createInertiaApp({
22
+ await createInertiaApp({
19
23
  resolve(name) {
20
24
  const page = pick(`Pages/${name}`);
21
25
  if (!page) throw new Error(`Unknown page: ${name}`);
@@ -28,6 +32,10 @@ createInertiaApp({
28
32
  const create = el.hasAttribute('data-server-rendered') ? createSSRApp : createApp;
29
33
  create({ render: () => h(App, props) })
30
34
  .use(plugin)
35
+ // Translations (D-0099): with @dokebi/i18n (http.enabled) every page has the shared prop
36
+ // `i18n` from the server's catalogs (src/shared/locales); pages call useI18n() for t(), n()
37
+ // and d(), templates use $t(). Without that prop this installs nothing.
38
+ .use(pageI18n(props.initialPage, { router }))
31
39
  .mount(el);
32
40
  },
33
41
  });
@@ -1,6 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { useI18n } from '@dokebi/template-inertia/i18n';
3
+
4
+ // Translations (@dokebi/i18n with http.enabled, D-0099); undefined while they are not installed.
5
+ // biome-ignore lint/correctness/noUnusedVariables: used by the template below.
6
+ const i18n = useI18n({ optional: true });
7
+ </script>
1
8
  <template>
2
9
  <main>
3
- <header>{{ $page.props.app?.name }} · {{ $page.props.app?.domain }} · template {{ $page.props.app?.template }}</header>
10
+ <header>
11
+ {{ $page.props.app?.name }} · {{ $page.props.app?.domain }} · template {{ $page.props.app?.template }}
12
+ <nav v-if="i18n && i18n.locales.value.length > 1" aria-label="Language">
13
+ <button
14
+ v-for="code in i18n.locales.value"
15
+ :key="code"
16
+ type="button"
17
+ :aria-pressed="code === i18n.locale.value"
18
+ @click="i18n.switchLocale(code)"
19
+ >
20
+ {{ i18n.localeName(code) }}
21
+ </button>
22
+ </nav>
23
+ </header>
4
24
  <slot />
5
25
  </main>
6
26
  </template>
@@ -1,8 +1,8 @@
1
- <script setup>
1
+ <script setup lang="ts">
2
2
  // The error page of this app (`errorPage: 'Error'` in app.ts, D-0074): an unknown address, a
3
3
  // forbidden page or a server error, for Inertia visits and page loads alike. Validation errors
4
4
  // never come here: they go back to the form, in `form.errors`.
5
- defineProps({ status: Number, error: String, message: String, hint: String });
5
+ defineProps<{ status: number; error?: string; message?: string; hint?: string }>();
6
6
  </script>
7
7
  <template>
8
8
  <h1>{{ status === 404 ? 'Page not found' : `Error ${status}` }}</h1>
@@ -1,5 +1,6 @@
1
- <script setup>
2
- defineProps({ title: String, message: String });
1
+ <script setup lang="ts">
2
+ // `npm run typecheck` checks this script and the template (typecheck-vue.mjs).
3
+ defineProps<{ title: string; message: string }>();
3
4
  </script>
4
5
  <template>
5
6
  <h1>{{ title }}</h1>
@@ -2,6 +2,7 @@
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
+ import { pageI18n } from '@dokebi/template-inertia/i18n';
5
6
  import { createInertiaApp } from '@inertiajs/vue3';
6
7
  import { renderToString } from 'vue/server-renderer';
7
8
 
@@ -20,6 +21,8 @@ export async function render(page) {
20
21
  // Requests of different templates render at the same time, so the page modules are not
21
22
  // changed: the layout of this request's template is the default layout.
22
23
  layout: () => pick('Layout')?.default,
24
+ // The same translations as views/app.js (D-0099), from this request's `i18n` prop.
25
+ withApp: (vue) => vue.use(pageI18n(page)),
23
26
  });
24
27
  return app(page, renderToString);
25
28
  }
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "scripts": {
3
3
  "build": "vite build",
4
- "buildSsr": "vite build && vite build --config vite.ssr.config.ts"
4
+ "buildSsr": "vite build && vite build --config vite.ssr.config.ts",
5
+ "typecheck": "tsc -p tsconfig.json --noEmit && node typecheck-vue.mjs -p tsconfig.vue.json"
5
6
  },
6
7
  "devDependencies": {
7
8
  "@inertiajs/vue3": "3.9.1",
9
+ "@typescript/typescript6": "6.0.2",
8
10
  "@vitejs/plugin-vue": "6.0.10",
9
11
  "vite": "8.3.4",
10
- "vue": "3.5.44"
12
+ "vue": "3.5.44",
13
+ "vue-tsc": "3.3.13"
11
14
  }
12
15
  }
@@ -0,0 +1,21 @@
1
+ // The props every Inertia page of this project receives, for `npm run typecheck` (the .vue
2
+ // files, see typecheck-vue.mjs) and the editor: `$page.props` and usePage().props have these
3
+ // types. dokebi-app shares `app` (the app, template and domain that answer the request) and
4
+ // `sealed` (whether that domain has `seal: true`). Add a key here for every prop
5
+ // src/infra/inertia/shared.ts returns; a prop only some pages get is typed on the page with
6
+ // usePage<{ … }>(). Written once by `dokebi app add --inertia`; this file is yours to change.
7
+ // @dokebi/i18n with http.enabled adds `locale` and `i18n` (the messages views/app.js hands to
8
+ // pageI18n; pages translate with useI18n() from @dokebi/template-inertia/i18n, or $t()).
9
+ import '@inertiajs/core';
10
+ import type { PageI18nPayload } from '@dokebi/template-inertia/i18n';
11
+
12
+ declare module '@inertiajs/core' {
13
+ export interface InertiaConfig {
14
+ sharedPageProps: {
15
+ app: { name: string; template: string; domain: string };
16
+ sealed: boolean;
17
+ locale?: string;
18
+ i18n?: PageI18nPayload;
19
+ };
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "types": ["vite/client", "@inertiajs/vue3"]
7
+ },
8
+ "include": ["src/**/*.vue", "src/**/*.d.ts"]
9
+ }
@@ -0,0 +1,14 @@
1
+ // Type-checks the Vue pages (the <script> and the <template> of every .vue file) for
2
+ // `npm run typecheck`, which runs `tsc` for the server code first and then this file with
3
+ // tsconfig.vue.json: Vite resolves the browser imports (moduleResolution Bundler), and the
4
+ // browser has the types of Vite (import.meta.glob, import.meta.env) and of Inertia ($page).
5
+ // vue-tsc drives the TypeScript compiler through its JavaScript API, which TypeScript 7 (the
6
+ // project's `tsc`) no longer ships. @typescript/typescript6 is the TypeScript team's package of
7
+ // TypeScript 6 for such tools; it is installed next to TypeScript 7 and used only here.
8
+ // vue-tsc, @typescript/typescript6 and this file are part of the Inertia build that
9
+ // `dokebi app add --inertia` prepares. Written once; this file is yours to change.
10
+ import { createRequire } from 'node:module';
11
+
12
+ const require = createRequire(import.meta.url);
13
+ // tsc reads its arguments from the command line (`-p tsconfig.vue.json`) and sets the exit code.
14
+ require('vue-tsc').run(require.resolve('@typescript/typescript6/lib/tsc.js'));
@@ -1,11 +1,30 @@
1
1
  // Builds the browser side of every Inertia app (src/apps/<app>/views/app.js) into dist/ with a
2
2
  // manifest. Each app reads the manifest through `inertia.vite` in its app.ts, and
3
3
  // @dokebi/template-inertia serves the built files at /build/. New Inertia apps are found
4
- // automatically. Written once by `dokebi app add --inertia`; this file is yours to change.
5
- import { existsSync, readdirSync } from 'node:fs';
4
+ // automatically. dokebiInertia() keeps the browser modules the app serves itself out of the
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`.
7
+ //
8
+ // dokebiInertia() also decides which files the dev server (`dokebi dev`) may serve (D-0129): only
9
+ // the views folders of the apps, node_modules, the files those modules import and the folders
10
+ // you add with dokebiInertia({ allow: ['src/shared/browser'] }). dokebi.yaml, .env, .dokebi/,
11
+ // keys, compose files and the server code (src/ outside views/, tests/, scripts/) are refused with
12
+ // 403, also through a devHosts tunnel. Do not set server.fs here: a server.fs.strict: false or a
13
+ // server.fs.deny of your own cannot remove the framework's entries, and `dokebi check` warns.
14
+ // Written once by `dokebi app add --inertia`; this file is yours to change.
15
+ import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
16
+ import { dokebiInertia } from '@dokebi/template-inertia/vite';
6
17
  import vue from '@vitejs/plugin-vue';
7
18
  import { defineConfig } from 'vite';
8
19
 
20
+ // The Vue compiler reads the props types a page imports (defineProps<ImportedProps>()) from files:
21
+ // with TypeScript 7 it has no file access of its own, so `vite build` would fail without this.
22
+ const vueTypeFiles = {
23
+ fileExists: (file: string) => existsSync(file),
24
+ readFile: (file: string) => readFileSync(file, 'utf8'),
25
+ realpath: (file: string) => realpathSync(file),
26
+ };
27
+
9
28
  const apps = readdirSync('src/apps', { withFileTypes: true })
10
29
  .filter((entry) => entry.isDirectory() && existsSync(`src/apps/${entry.name}/views/app.js`))
11
30
  .map((entry) => entry.name);
@@ -13,10 +32,14 @@ const apps = readdirSync('src/apps', { withFileTypes: true })
13
32
  export default defineConfig({
14
33
  base: '/build/',
15
34
  publicDir: false,
16
- plugins: [vue()],
35
+ plugins: [vue({ script: { fs: vueTypeFiles } }), dokebiInertia()],
17
36
  build: {
18
37
  outDir: 'dist',
19
- emptyOutDir: true,
38
+ // A rolling deploy serves two builds at once: keep the chunks of the previous build
39
+ // (@dokebi/template-inertia serves every hashed file of dist/assets). Remove old ones with
40
+ // pruneBuildFiles of @dokebi/template-inertia/prune (keeps every file the current manifest
41
+ // names; template-inertia AI.md §4), not by age alone.
42
+ emptyOutDir: false,
20
43
  manifest: true,
21
44
  rollupOptions: {
22
45
  input: Object.fromEntries(apps.map((app) => [app, `src/apps/${app}/views/app.js`])),
@@ -1,22 +1,32 @@
1
1
  // Server build of every Inertia app that renders its first HTML on the server (D-0039):
2
2
  // src/apps/<app>/views/ssr.js becomes dist/ssr/<app>/ssr.js, which the app names in
3
- // `inertia.ssr.bundle`. Runs after the browser build (`npm run build`), whose emptyOutDir clears
4
- // dist/ first. dist/ssr/ is not served: @dokebi/template-inertia serves only the manifest's
5
- // files. Written once by `dokebi app add --inertia --ssr`; this file is yours to change.
6
- import { existsSync, readdirSync } from 'node:fs';
3
+ // `inertia.ssr.bundle`. Runs after the browser build (`npm run build`). dist/ssr/ is not served:
4
+ // @dokebi/template-inertia serves only the files of the manifest's folders (dist/assets).
5
+ // Written once by `dokebi app add --inertia --ssr`; this file is yours to change.
6
+ import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
7
7
  import vue from '@vitejs/plugin-vue';
8
8
  import { defineConfig } from 'vite';
9
9
 
10
+ // The Vue compiler reads the props types a page imports (defineProps<ImportedProps>()) from files:
11
+ // with TypeScript 7 it has no file access of its own, so `vite build` would fail without this.
12
+ const vueTypeFiles = {
13
+ fileExists: (file: string) => existsSync(file),
14
+ readFile: (file: string) => readFileSync(file, 'utf8'),
15
+ realpath: (file: string) => realpathSync(file),
16
+ };
17
+
10
18
  const apps = readdirSync('src/apps', { withFileTypes: true })
11
19
  .filter((entry) => entry.isDirectory() && existsSync(`src/apps/${entry.name}/views/ssr.js`))
12
20
  .map((entry) => entry.name);
13
21
 
14
22
  export default defineConfig({
15
23
  publicDir: false,
16
- plugins: [vue()],
24
+ plugins: [vue({ script: { fs: vueTypeFiles } })],
17
25
  build: {
18
26
  outDir: 'dist/ssr',
19
- emptyOutDir: true,
27
+ // Kept like the browser build: a worker started before this build still imports the lazy
28
+ // chunks of its own SSR bundle (a dynamic import) from here until it is replaced.
29
+ emptyOutDir: false,
20
30
  ssr: true,
21
31
  rollupOptions: {
22
32
  input: Object.fromEntries(apps.map((app) => [app, `src/apps/${app}/views/ssr.js`])),