@gaonjs/config 0.9.1 → 0.10.0

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { defineConfig, defineAppConfig, type GaonConfig, type AppConfig, type AppSessionConfig, type DbConfig, type RedisConfig, type NatsConfig, type HubConfig, type MailConfig, type StorageConfig, type StorageDiskConfig, type I18nConfig, type WebConfig, } from './types.js';
2
2
  export { loadGaonConfig, findConfigPath } from './load.js';
3
3
  export { resolveApps, toAppSpec, type DiscoveredApp, } from './apps.js';
4
- export { wireGaon, type WiredGaon } from './wire.js';
4
+ export { wireGaon, wireDomain, type WiredGaon, type WiredDomain } from './wire.js';
5
5
  export { connectTestDatabase, type TestDbHandle } from './testkit.js';
package/dist/index.js CHANGED
@@ -9,6 +9,6 @@
9
9
  export { defineConfig, defineAppConfig, } from './types.js';
10
10
  export { loadGaonConfig, findConfigPath } from './load.js';
11
11
  export { resolveApps, toAppSpec, } from './apps.js';
12
- export { wireGaon } from './wire.js';
12
+ export { wireGaon, wireDomain } from './wire.js';
13
13
  // 테스트 DB 배선 (결정 111 · gaon test 격리)
14
14
  export { connectTestDatabase } from './testkit.js';
package/dist/wire.d.ts CHANGED
@@ -13,6 +13,20 @@ export interface WiredGaon {
13
13
  /** graceful 종료 — Fastify · NATS · Redis · DB 를 순서대로 닫는다. */
14
14
  close(): Promise<void>;
15
15
  }
16
+ /** 도메인 배터리 배선 결과 — serve·work 가 공유한다. closeDomain() 으로 뒤집는다. */
17
+ export interface WiredDomain {
18
+ readonly config: GaonConfig;
19
+ /** DB 커넥션 파기 · storage/i18n 리셋(배선 역순). */
20
+ closeDomain(): Promise<void>;
21
+ }
22
+ /**
23
+ * gaon.config.ts 의 **프로세스 전역 도메인 배터리**(DB 커넥션·메일·스토리지·
24
+ * i18n)를 배선한다. serve(웹)와 work(워커)가 함께 태우는 공통 경로다 — 잡
25
+ * 핸들러가 모델을 읽고(registerConnection) 메일을 보내려면(configureMailer)
26
+ * work 프로세스에도 같은 배선이 있어야 한다(결정 129). 웹 전용 배선(Redis
27
+ * 세션·NATS 잡 발행·Fastify)은 여기 두지 않는다 — wireGaon 이 이 위에 얹는다.
28
+ */
29
+ export declare function wireDomain(config: GaonConfig, cwd?: string): Promise<WiredDomain>;
16
30
  /**
17
31
  * gaon.config.ts + apps/ 를 바탕으로 배터리를 배선하고 Fastify 앱을 만든다.
18
32
  *
package/dist/wire.js CHANGED
@@ -17,41 +17,22 @@ import { resolveApps, toAppSpec } from './apps.js';
17
17
  import { existsSync } from 'node:fs';
18
18
  import { resolve as resolvePath, join } from 'node:path';
19
19
  /**
20
- * gaon.config.ts + apps/ 바탕으로 배터리를 배선하고 Fastify 앱을 만든다.
21
- *
22
- * 배선 순서(의존):
23
- * 1) DB 다른 배터리가 이미 configureX 시점에 커넥션을 만지지는 않지만,
24
- * 사용 시점(모델 조회) 필요. 실패는 즉시 던진다.
25
- * 2) Redis — 세션 배터리가 쓴다. redis 인스턴스는 앱 스펙 조립 시 주입.
26
- * 3) NATS — 실시간(웹) · 비동기 잡(work)이 공유. 여기서는 웹만 배선.
27
- * 4) mail · storage · i18n — 프로세스 전역 configureX() 호출.
28
- * 5) createApp — 위에서 만든 세션·realtime 설정을 담아 Fastify 인스턴스 생성.
20
+ * gaon.config.ts **프로세스 전역 도메인 배터리**(DB 커넥션·메일·스토리지·
21
+ * i18n)를 배선한다. serve(웹)와 work(워커)가 함께 태우는 공통 경로다 — 잡
22
+ * 핸들러가 모델을 읽고(registerConnection) 메일을 보내려면(configureMailer)
23
+ * work 프로세스에도 같은 배선이 있어야 한다(결정 129). 전용 배선(Redis
24
+ * 세션·NATS 잡 발행·Fastify) 여기 두지 않는다 — wireGaon 이 이 위에 얹는다.
29
25
  */
30
- export async function wireGaon(config, cwd = process.cwd()) {
26
+ export async function wireDomain(config, cwd = process.cwd()) {
31
27
  const root = resolvePath(cwd);
32
- // 1) DB 커넥션 — 키별로 등록.연결 검증은 첫 쿼리에서(pool lazy).
28
+ // 1) DB 커넥션 — 키별로 등록(main + 명명 커넥션 · §4.5). 연결은 첫 쿼리에서(pool lazy).
33
29
  if (config.db) {
34
30
  for (const [key, cfg] of Object.entries(config.db)) {
35
31
  const db = createDb(cfg);
36
32
  registerConnection(key, db, cfg.adapter);
37
33
  }
38
34
  }
39
- // 2) Redis세션 스토어. 스펙 조립 시 세션 옵션에 주입한다.
40
- let redis;
41
- if (config.redis) {
42
- redis = new Redis(config.redis.url, { lazyConnect: false, maxRetriesPerRequest: 3 });
43
- }
44
- // 3) NATS — 웹 프로세스도 채널·잡 publish 를 위해 연결한다.
45
- // 연결만으로는 부족하다 — 잡 전송 런타임(configureJobs)까지 배선해야
46
- // 컨트롤러의 `.later()` 가 실제로 publish 된다. 이걸 빠뜨리면 웹에서
47
- // 잡 발행 시 "잡 전송이 설정되지 않았습니다" 로 깨진다(work 는 runWork
48
- // 가 이미 설정하지만 serve 는 여기서 해야 한다).
49
- let nats;
50
- if (config.nats) {
51
- nats = await connectNats({ servers: config.nats.url, name: config.nats.name ?? 'gaon-serve' });
52
- configureJobs(nats);
53
- }
54
- // 4) mail — SMTP 전송(개발은 MailPit, 운영은 실 SMTP).
35
+ // 2) mailSMTP 전송(개발은 MailPit, 운영은 SMTP).
55
36
  if (config.mail) {
56
37
  const m = config.mail;
57
38
  configureMailer({
@@ -64,7 +45,7 @@ export async function wireGaon(config, cwd = process.cwd()) {
64
45
  defaultFrom: m.defaultFrom,
65
46
  });
66
47
  }
67
- // 4') storage — 로컬(기본) 또는 S3.
48
+ // 3) storage — 로컬(기본) 또는 S3.
68
49
  if (config.storage) {
69
50
  const disks = {};
70
51
  for (const [name, d] of Object.entries(config.storage.disks)) {
@@ -88,7 +69,7 @@ export async function wireGaon(config, cwd = process.cwd()) {
88
69
  }
89
70
  configureStorage({ default: config.storage.default, disks });
90
71
  }
91
- // 4'') i18n — locales/ 로드 후 초기화.
72
+ // 4) i18n — locales/ 로드 후 초기화.
92
73
  if (config.i18n) {
93
74
  const dir = config.i18n.dir ?? 'locales';
94
75
  const abs = dir.startsWith('/') ? dir : join(root, dir);
@@ -99,6 +80,46 @@ export async function wireGaon(config, cwd = process.cwd()) {
99
80
  supportedLngs: config.i18n.supportedLngs,
100
81
  });
101
82
  }
83
+ return {
84
+ config,
85
+ async closeDomain() {
86
+ await destroyAllConnections();
87
+ resetStorage();
88
+ resetI18n();
89
+ },
90
+ };
91
+ }
92
+ /**
93
+ * gaon.config.ts + apps/ 를 바탕으로 배터리를 배선하고 Fastify 앱을 만든다.
94
+ *
95
+ * 배선 순서(의존):
96
+ * 1) DB — 다른 배터리가 이미 configureX 시점에 커넥션을 만지지는 않지만,
97
+ * 사용 시점(모델 조회)에 필요. 실패는 즉시 던진다.
98
+ * 2) Redis — 세션 배터리가 쓴다. redis 인스턴스는 앱 스펙 조립 시 주입.
99
+ * 3) NATS — 실시간(웹) · 비동기 잡(work)이 공유. 여기서는 웹만 배선.
100
+ * 4) mail · storage · i18n — 프로세스 전역 configureX() 호출.
101
+ * 5) createApp — 위에서 만든 세션·realtime 설정을 담아 Fastify 인스턴스 생성.
102
+ */
103
+ export async function wireGaon(config, cwd = process.cwd()) {
104
+ const root = resolvePath(cwd);
105
+ // 1) 도메인 배터리(DB 커넥션·메일·스토리지·i18n) — serve·work 공통 경로(결정 129).
106
+ // 잡 핸들러가 모델·메일을 쓰려면 work 도 같은 배선을 태워야 한다.
107
+ const domain = await wireDomain(config, cwd);
108
+ // 2) Redis — 세션 스토어. 앱 스펙 조립 시 세션 옵션에 주입한다.
109
+ let redis;
110
+ if (config.redis) {
111
+ redis = new Redis(config.redis.url, { lazyConnect: false, maxRetriesPerRequest: 3 });
112
+ }
113
+ // 3) NATS — 웹 프로세스도 채널·잡 publish 를 위해 연결한다.
114
+ // 연결만으로는 부족하다 — 잡 전송 런타임(configureJobs)까지 배선해야
115
+ // 컨트롤러의 `.later()` 가 실제로 publish 된다. 이걸 빠뜨리면 웹에서
116
+ // 잡 발행 시 "잡 전송이 설정되지 않았습니다" 로 깨진다(work 는 runWork
117
+ // 가 이미 설정하지만 serve 는 여기서 해야 한다).
118
+ let nats;
119
+ if (config.nats) {
120
+ nats = await connectNats({ servers: config.nats.url, name: config.nats.name ?? 'gaon-serve' });
121
+ configureJobs(nats);
122
+ }
102
123
  // 5) 앱 스캔 · createApp.
103
124
  const apps = await resolveApps(root);
104
125
  const specs = apps.map((a) => {
@@ -170,9 +191,7 @@ export async function wireGaon(config, cwd = process.cwd()) {
170
191
  await nats.close();
171
192
  if (redis)
172
193
  redis.disconnect();
173
- await destroyAllConnections();
174
- resetStorage();
175
- resetI18n();
194
+ await domain.closeDomain();
176
195
  },
177
196
  };
178
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaonjs/config",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Gaon 루트 설정 로더·자동 배선 (gaon.config.ts · §3.3 · M9-A)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,13 +25,13 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "ioredis": "^5.4.1",
28
- "@gaonjs/async": "0.7.0",
29
- "@gaonjs/core": "0.2.1",
30
- "@gaonjs/data": "0.13.1",
28
+ "@gaonjs/async": "0.8.0",
31
29
  "@gaonjs/i18n": "0.1.2",
30
+ "@gaonjs/data": "0.13.1",
32
31
  "@gaonjs/mail": "0.1.3",
32
+ "@gaonjs/core": "0.2.1",
33
33
  "@gaonjs/storage": "0.1.2",
34
- "@gaonjs/web": "0.12.0"
34
+ "@gaonjs/web": "0.13.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "fastify": "^5.0.0"