@dokebi/app 0.1.1 → 0.1.2

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
@@ -1,4 +1,4 @@
1
- # AI 작업 안내 — @dokebi/app 0.1.1
1
+ # AI 작업 안내 — @dokebi/app 0.1.2
2
2
 
3
3
  한 프로젝트에 앱을 여러 개 두고, **요청 도메인으로 앱과 템플릿을 고르는** 플러그인이다(D-0030). 앱 하나는 `src/apps/<앱>/` 폴더 하나이고 `defineApp`으로 정의한다. Node >=24.0.0, core ^0.2.0. 사람용 설명은 [README](README.md)다.
4
4
 
@@ -97,7 +97,9 @@ export default defineApp({
97
97
 
98
98
  ## 6. 시작 때 거절되는 것
99
99
 
100
- 없는 앱을 가리키는 도메인, 등록 안 된 앱, `views` 폴더나 `views/default/`·도메인이 고른 `views/<템플릿>/` 누락, `defineApp`의 모르는 필드, 잘못된 모듈 접두사, `defineModule`로 만들지 않은 모듈.
100
+ 없는 앱을 가리키는 도메인, 등록 안 된 앱, `views` 폴더나 `views/default/`·도메인이 고른 `views/<템플릿>/` 누락(원래 파일 오류는 `cause`), `defineApp`의 모르는 필드, 잘못된 모듈 접두사, `defineModule`로 만들지 않은 모듈.
101
+
102
+ debug 로그(D-0047): `App domains configured`(도메인 → 앱/템플릿, 64개까지)·`App set up`(requires·템플릿·inertia·모듈·라우트·소켓 수·ms)·`App start finished`·`App drain finished`, 요청마다는 설정에 없는 호스트일 때만 `App domain not configured`(debug가 켜졌을 때만 만든다).
101
103
 
102
104
  ## 7. 주의 사항
103
105
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @dokebi/app 0.1.1
1
+ # @dokebi/app 0.1.2
2
2
 
3
3
  한 프로젝트 안에 여러 앱을 두고, 요청 도메인으로 앱과 템플릿을 고르는 선택 플러그인이다. Node >=24.0.0, core ^0.2.0의 선택 패키지다(npm 공개). 설계는 [D-0030](../../docs/decisions/D-0030-multi-app-and-domains.md)이다.
4
4
 
package/dist/index.js CHANGED
@@ -133,7 +133,10 @@ const inertia = optionalDependency({
133
133
  name: 'dokebi-template-inertia',
134
134
  version: '^0.1.0',
135
135
  });
136
- const websocket = optionalDependency({ name: 'dokebi-websocket', version: '^0.1.0' });
136
+ const websocket = optionalDependency({
137
+ name: 'dokebi-websocket',
138
+ version: '^0.1.0 || ^0.2.0',
139
+ });
137
140
  const descriptors = new WeakMap();
138
141
  /** Stable descriptor per requirement, so declared and runtime lookups use the same object. */
139
142
  function requirement(value) {
@@ -192,6 +195,15 @@ class AppRuntime {
192
195
  if (!this.apps.has(target.app))
193
196
  throw new Error(`Domain ${host} points to app ${target.app}, which is not registered`);
194
197
  const http = context.getDependency(web);
198
+ const logger = context.logger;
199
+ logger.log('debug', 'App domains configured', {
200
+ apps: [...this.apps.keys()],
201
+ domains: [...this.options.domains]
202
+ .slice(0, 64)
203
+ .map(([domain, target]) => `${domain} -> ${target.app}/${target.template}`),
204
+ count: this.options.domains.size,
205
+ unknownDomain: this.options.unknownDomain ?? 'reject',
206
+ });
195
207
  // Behind a trusted proxy (dokebi-web trustProxy) the forwarded host picks the app.
196
208
  const host = (request) => withoutPort(http.requestHost(request));
197
209
  http.constraint({
@@ -205,7 +217,14 @@ class AppRuntime {
205
217
  },
206
218
  };
207
219
  },
208
- deriveConstraint: (request) => this.resolve(host(request))?.name,
220
+ deriveConstraint: (request) => {
221
+ const requested = host(request);
222
+ const name = this.resolve(requested)?.name;
223
+ // Per request: only built when debug is on (D-0047).
224
+ if (name === undefined && logger.isEnabled('debug'))
225
+ logger.log('debug', 'App domain not configured', { host: requested.slice(0, 253) });
226
+ return name;
227
+ },
209
228
  // Requests of a known app may still reach shared (unconstrained) routes.
210
229
  mustMatchWhenDerived: false,
211
230
  });
@@ -213,6 +232,9 @@ class AppRuntime {
213
232
  const sockets = context.getOptionalDependency(websocket);
214
233
  for (const [name, definition] of this.apps) {
215
234
  context.signal.throwIfAborted();
235
+ const begin = performance.now();
236
+ let routeCount = 0;
237
+ let socketCount = 0;
216
238
  const allowed = new Set([...(definition.requires ?? []), ...Object.values(definition.modules ?? {})].map((item) => requirement(item).name));
217
239
  let controllers;
218
240
  const appContext = Object.freeze({
@@ -334,6 +356,7 @@ class AppRuntime {
334
356
  const routerFor = (page, base) => {
335
357
  const add = (options) => {
336
358
  const { handler, ...rest } = options;
359
+ routeCount++;
337
360
  http.route({
338
361
  ...rest,
339
362
  url: joinPath(base, rest.url),
@@ -357,6 +380,7 @@ class AppRuntime {
357
380
  for (const route of routes) {
358
381
  if (!sockets)
359
382
  throw new Error(`${owner} has sockets; add @dokebi/websocket`);
383
+ socketCount++;
360
384
  sockets.route({
361
385
  ...route,
362
386
  path: joinPath(base, route.path),
@@ -384,6 +408,17 @@ class AppRuntime {
384
408
  ((await mount.sockets?.(module)) ?? []), base, `Module ${mount.name} (app ${name})`);
385
409
  }
386
410
  this.#mounted.push({ name, definition, context: appContext });
411
+ logger.log('debug', 'App set up', {
412
+ app: name,
413
+ requires: [...allowed],
414
+ controllers: definition.controllers?.length ?? 0,
415
+ templates: [...templates],
416
+ inertia: Boolean(inertiaApi),
417
+ modules: Object.entries(definition.modules ?? {}).map(([prefix, plugin]) => `${prefix} -> ${mountOf(plugin).name}`),
418
+ routes: routeCount,
419
+ sockets: socketCount,
420
+ ms: Math.round(performance.now() - begin),
421
+ });
387
422
  }
388
423
  return Object.freeze({
389
424
  names: Object.freeze([...this.apps.keys()]),
@@ -398,18 +433,40 @@ class AppRuntime {
398
433
  wanted.add(target.template);
399
434
  for (const template of wanted) {
400
435
  const folder = fileURLToPath(new URL(`${template}/`, views));
401
- const info = await stat(folder).catch(() => undefined);
436
+ // A missing folder and an unreadable one both stop setup; the stat error is the cause.
437
+ let failure;
438
+ const info = await stat(folder).catch((cause) => {
439
+ failure = cause;
440
+ return undefined;
441
+ });
402
442
  if (!info?.isDirectory())
403
- throw new Error(`App ${name} has no views/${template}/ folder`);
443
+ throw new Error(`App ${name} has no views/${template}/ folder`, failure === undefined ? undefined : { cause: failure });
404
444
  found.add(template);
405
445
  }
406
446
  }
407
447
  async start() {
408
- for (const { definition, context } of this.#mounted)
409
- await definition.start?.(context);
448
+ for (const { name, definition, context } of this.#mounted) {
449
+ if (!definition.start)
450
+ continue;
451
+ const begin = performance.now();
452
+ await definition.start(context);
453
+ context.logger.log('debug', 'App start finished', {
454
+ app: name,
455
+ ms: Math.round(performance.now() - begin),
456
+ });
457
+ }
410
458
  }
411
459
  async drain() {
412
- await Promise.all(this.#mounted.map(({ definition, context }) => definition.drain?.(context)));
460
+ await Promise.all(this.#mounted.map(async ({ name, definition, context }) => {
461
+ if (!definition.drain)
462
+ return;
463
+ const begin = performance.now();
464
+ await definition.drain(context);
465
+ context.logger.log('debug', 'App drain finished', {
466
+ app: name,
467
+ ms: Math.round(performance.now() - begin),
468
+ });
469
+ }));
413
470
  }
414
471
  }
415
472
  function missingViews(name) {
@@ -421,7 +478,7 @@ function missingViews(name) {
421
478
  }
422
479
  export const createPlugin = definePlugin({
423
480
  name: 'dokebi-app',
424
- version: '0.1.1',
481
+ version: '0.1.2',
425
482
  core: '^0.2.0',
426
483
  options: parseOptions,
427
484
  entry: parseEntry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/app",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "@dokebi/template-ejs": "^0.1.0",
36
36
  "@dokebi/template-inertia": "^0.1.0",
37
37
  "@dokebi/web": "^0.1.0",
38
- "@dokebi/websocket": "^0.1.0",
38
+ "@dokebi/websocket": "^0.1.0 || ^0.2.0",
39
39
  "fastify": "^5.12.7"
40
40
  },
41
41
  "peerDependenciesMeta": {
@@ -52,7 +52,7 @@
52
52
  "devDependencies": {
53
53
  "@dokebi/module": "^0.1.0",
54
54
  "@dokebi/template-inertia": "^0.1.0",
55
- "@dokebi/websocket": "^0.1.0"
55
+ "@dokebi/websocket": "^0.1.0 || ^0.2.0"
56
56
  },
57
57
  "dokebi": {
58
58
  "schemaVersion": 2,
@@ -81,7 +81,7 @@
81
81
  },
82
82
  {
83
83
  "name": "dokebi-websocket",
84
- "version": "^0.1.0",
84
+ "version": "^0.1.0 || ^0.2.0",
85
85
  "optional": true
86
86
  }
87
87
  ],