@spfn/core 0.2.0-beta.2 → 0.2.0-beta.4
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/README.md +91 -6
- package/dist/{boss-D-fGtVgM.d.ts → boss-BO8ty33K.d.ts} +45 -5
- package/dist/config/index.d.ts +36 -0
- package/dist/config/index.js +15 -6
- package/dist/config/index.js.map +1 -1
- package/dist/env/index.d.ts +29 -3
- package/dist/env/index.js +13 -13
- package/dist/env/index.js.map +1 -1
- package/dist/env/loader.d.ts +87 -0
- package/dist/env/loader.js +70 -0
- package/dist/env/loader.js.map +1 -0
- package/dist/event/index.d.ts +3 -70
- package/dist/event/index.js +10 -1
- package/dist/event/index.js.map +1 -1
- package/dist/event/sse/client.d.ts +82 -0
- package/dist/event/sse/client.js +115 -0
- package/dist/event/sse/client.js.map +1 -0
- package/dist/event/sse/index.d.ts +40 -0
- package/dist/event/sse/index.js +92 -0
- package/dist/event/sse/index.js.map +1 -0
- package/dist/job/index.d.ts +34 -3
- package/dist/job/index.js +18 -9
- package/dist/job/index.js.map +1 -1
- package/dist/middleware/index.d.ts +102 -11
- package/dist/middleware/index.js +2 -2
- package/dist/middleware/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +2 -2
- package/dist/nextjs/index.js +1 -1
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/server.d.ts +2 -2
- package/dist/nextjs/server.js +4 -1
- package/dist/nextjs/server.js.map +1 -1
- package/dist/route/index.d.ts +72 -13
- package/dist/route/index.js +82 -27
- package/dist/route/index.js.map +1 -1
- package/dist/route/types.d.ts +2 -31
- package/dist/router-Di7ENoah.d.ts +151 -0
- package/dist/server/index.d.ts +82 -6
- package/dist/server/index.js +175 -14
- package/dist/server/index.js.map +1 -1
- package/dist/types-B-e_f2dQ.d.ts +121 -0
- package/dist/{types-DRG2XMTR.d.ts → types-D_N_U-Py.d.ts} +76 -3
- package/package.json +18 -3
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Full-stack type-safe framework for building Next.js + Node.js applications with
|
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
|
|
9
|
-
> **
|
|
9
|
+
> **Beta Release**: SPFN is currently in beta. Core APIs are stable but may have minor changes before 1.0.
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
@@ -200,7 +200,7 @@ route.get('/users/:id')
|
|
|
200
200
|
|-- Type Inference: RouteDef<TInput, TResponse>
|
|
201
201
|
|-- Validation: TypeBox schema
|
|
202
202
|
|-- Middleware: Skip control per route
|
|
203
|
-
|-- Response: c.
|
|
203
|
+
|-- Response: Direct return / c.json() / helpers
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
**Key Components**:
|
|
@@ -431,6 +431,57 @@ Return NextResponse
|
|
|
431
431
|
|
|
432
432
|
---
|
|
433
433
|
|
|
434
|
+
### 9. Job System (`src/job/`)
|
|
435
|
+
|
|
436
|
+
**Purpose**: Background job processing with pg-boss
|
|
437
|
+
|
|
438
|
+
**Architecture**:
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
job('send-email')
|
|
442
|
+
.input(schema)
|
|
443
|
+
.options({ retryLimit: 3 })
|
|
444
|
+
.cron('0 9 * * *')
|
|
445
|
+
.on(eventDef)
|
|
446
|
+
.handler(async (input) => { ... })
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
**Key Components**:
|
|
450
|
+
|
|
451
|
+
- `job()`: Fluent job builder
|
|
452
|
+
- `defineJobRouter()`: Group jobs for registration
|
|
453
|
+
- Job types: Standard, Cron, RunOnce, Event-driven
|
|
454
|
+
- `initBoss()`, `registerJobs()`: pg-boss lifecycle
|
|
455
|
+
|
|
456
|
+
**Design Pattern**: Builder pattern (same as routes)
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
### 10. Event System (`src/event/`)
|
|
461
|
+
|
|
462
|
+
**Purpose**: Decoupled pub/sub event system
|
|
463
|
+
|
|
464
|
+
**Architecture**:
|
|
465
|
+
|
|
466
|
+
```
|
|
467
|
+
defineEvent('user.created', schema)
|
|
468
|
+
→ emit(payload)
|
|
469
|
+
→ handlers (in-memory)
|
|
470
|
+
→ job queues (pg-boss)
|
|
471
|
+
→ cache pub/sub (multi-instance)
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
**Key Components**:
|
|
475
|
+
|
|
476
|
+
- `defineEvent()`: Define typed events
|
|
477
|
+
- `event.emit()`: Emit event to all subscribers
|
|
478
|
+
- `event.subscribe()`: In-memory subscription
|
|
479
|
+
- `event.useCache()`: Multi-instance pub/sub via Redis
|
|
480
|
+
|
|
481
|
+
**Integration**: `job().on(event)` for event-driven jobs
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
434
485
|
## Type System
|
|
435
486
|
|
|
436
487
|
### End-to-End Type Safety Flow
|
|
@@ -469,8 +520,8 @@ export const getUser = route.get('/users/:id')
|
|
|
469
520
|
const user = await findOne(users, { id: params.id });
|
|
470
521
|
// ^? User | null
|
|
471
522
|
|
|
472
|
-
return
|
|
473
|
-
//
|
|
523
|
+
return user;
|
|
524
|
+
// ^? Response type inferred from return value
|
|
474
525
|
});
|
|
475
526
|
|
|
476
527
|
// 3. Router Type Export
|
|
@@ -884,7 +935,7 @@ export const getUser = route.get('/users/:id')
|
|
|
884
935
|
})
|
|
885
936
|
.handler(async (c) => {
|
|
886
937
|
const { params } = await c.data();
|
|
887
|
-
return
|
|
938
|
+
return { id: params.id, name: 'John' };
|
|
888
939
|
});
|
|
889
940
|
|
|
890
941
|
// router.ts
|
|
@@ -1076,6 +1127,40 @@ import {
|
|
|
1076
1127
|
import { env, envSchema } from '@spfn/core/config';
|
|
1077
1128
|
```
|
|
1078
1129
|
|
|
1130
|
+
### Job System
|
|
1131
|
+
|
|
1132
|
+
```typescript
|
|
1133
|
+
import {
|
|
1134
|
+
job,
|
|
1135
|
+
defineJobRouter,
|
|
1136
|
+
registerJobs,
|
|
1137
|
+
initBoss,
|
|
1138
|
+
getBoss,
|
|
1139
|
+
stopBoss,
|
|
1140
|
+
} from '@spfn/core/job';
|
|
1141
|
+
|
|
1142
|
+
import type {
|
|
1143
|
+
JobDef,
|
|
1144
|
+
JobRouter,
|
|
1145
|
+
JobOptions,
|
|
1146
|
+
BossOptions,
|
|
1147
|
+
InferJobInput,
|
|
1148
|
+
} from '@spfn/core/job';
|
|
1149
|
+
```
|
|
1150
|
+
|
|
1151
|
+
### Event System
|
|
1152
|
+
|
|
1153
|
+
```typescript
|
|
1154
|
+
import { defineEvent } from '@spfn/core/event';
|
|
1155
|
+
|
|
1156
|
+
import type {
|
|
1157
|
+
EventDef,
|
|
1158
|
+
EventHandler,
|
|
1159
|
+
InferEventPayload,
|
|
1160
|
+
PubSubCache,
|
|
1161
|
+
} from '@spfn/core/event';
|
|
1162
|
+
```
|
|
1163
|
+
|
|
1079
1164
|
---
|
|
1080
1165
|
|
|
1081
1166
|
## Quick Reference
|
|
@@ -1133,7 +1218,7 @@ export const getUser = route.get('/users/:id')
|
|
|
1133
1218
|
.input({ params: Type.Object({ id: Type.String() }) })
|
|
1134
1219
|
.handler(async (c) => {
|
|
1135
1220
|
const { params } = await c.data();
|
|
1136
|
-
return
|
|
1221
|
+
return { id: params.id, name: 'John' };
|
|
1137
1222
|
});
|
|
1138
1223
|
```
|
|
1139
1224
|
|
|
@@ -134,39 +134,79 @@ type InferJobInput<TJob> = TJob extends JobDef<infer TInput> ? TInput : never;
|
|
|
134
134
|
*/
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
* pg-boss
|
|
137
|
+
* Options for pg-boss initialization
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* await initBoss({
|
|
142
|
+
* connectionString: process.env.DATABASE_URL,
|
|
143
|
+
* schema: 'spfn_queue',
|
|
144
|
+
* clearOnStart: process.env.NODE_ENV === 'development',
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
138
147
|
*/
|
|
139
|
-
interface
|
|
148
|
+
interface BossOptions {
|
|
140
149
|
/**
|
|
141
150
|
* PostgreSQL connection string
|
|
151
|
+
*
|
|
152
|
+
* @example 'postgresql://user:password@localhost:5432/mydb'
|
|
142
153
|
*/
|
|
143
154
|
connectionString: string;
|
|
144
155
|
/**
|
|
145
156
|
* Schema name for pg-boss tables
|
|
157
|
+
*
|
|
158
|
+
* pg-boss creates its own tables in this schema.
|
|
159
|
+
*
|
|
146
160
|
* @default 'spfn_queue'
|
|
147
161
|
*/
|
|
148
162
|
schema?: string;
|
|
149
163
|
/**
|
|
150
164
|
* Maintenance interval in seconds
|
|
165
|
+
*
|
|
166
|
+
* pg-boss runs maintenance tasks (cleanup, archiving) at this interval.
|
|
167
|
+
*
|
|
151
168
|
* @default 120
|
|
152
169
|
*/
|
|
153
170
|
maintenanceIntervalSeconds?: number;
|
|
154
171
|
/**
|
|
155
172
|
* Monitor state changes interval in seconds
|
|
173
|
+
*
|
|
174
|
+
* When set, pg-boss emits state change events at this interval.
|
|
175
|
+
*
|
|
156
176
|
* @default undefined (disabled)
|
|
157
177
|
*/
|
|
158
178
|
monitorIntervalSeconds?: number;
|
|
159
179
|
/**
|
|
160
180
|
* Clear all pending/scheduled jobs on startup
|
|
161
|
-
*
|
|
181
|
+
*
|
|
182
|
+
* Useful for development mode to start with a clean queue.
|
|
183
|
+
* Should be false in production.
|
|
184
|
+
*
|
|
162
185
|
* @default false
|
|
163
186
|
*/
|
|
164
187
|
clearOnStart?: boolean;
|
|
165
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Use BossOptions instead
|
|
191
|
+
*/
|
|
192
|
+
type BossConfig = BossOptions;
|
|
166
193
|
/**
|
|
167
194
|
* Initialize pg-boss with the given configuration
|
|
195
|
+
*
|
|
196
|
+
* Must be called before registerJobs(). Typically handled by defineServerConfig().
|
|
197
|
+
*
|
|
198
|
+
* @param options - pg-boss configuration options
|
|
199
|
+
* @returns The pg-boss instance
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const boss = await initBoss({
|
|
204
|
+
* connectionString: process.env.DATABASE_URL!,
|
|
205
|
+
* schema: 'spfn_queue',
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
168
208
|
*/
|
|
169
|
-
declare function initBoss(
|
|
209
|
+
declare function initBoss(options: BossOptions): Promise<PgBoss>;
|
|
170
210
|
/**
|
|
171
211
|
* Get the current pg-boss instance
|
|
172
212
|
*/
|
|
@@ -184,4 +224,4 @@ declare function isBossRunning(): boolean;
|
|
|
184
224
|
*/
|
|
185
225
|
declare function shouldClearOnStart(): boolean;
|
|
186
226
|
|
|
187
|
-
export { type
|
|
227
|
+
export { type BossOptions as B, type InferJobInput as I, type JobRouter as J, type JobOptions as a, type JobHandler as b, type JobDef as c, type JobRouterEntry as d, type JobSendOptions as e, isBossRunning as f, getBoss as g, shouldClearOnStart as h, initBoss as i, type BossConfig as j, stopBoss as s };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -388,15 +388,27 @@ declare const coreEnvSchema: {
|
|
|
388
388
|
SPFN_API_URL: {
|
|
389
389
|
description: string;
|
|
390
390
|
required: boolean;
|
|
391
|
+
nextjs: boolean;
|
|
391
392
|
examples: string[];
|
|
392
393
|
} & {
|
|
393
394
|
type: "url";
|
|
394
395
|
} & {
|
|
395
396
|
key: "SPFN_API_URL";
|
|
396
397
|
};
|
|
398
|
+
NEXT_PUBLIC_SPFN_API_URL: {
|
|
399
|
+
description: string;
|
|
400
|
+
required: boolean;
|
|
401
|
+
nextjs: boolean;
|
|
402
|
+
examples: string[];
|
|
403
|
+
} & {
|
|
404
|
+
type: "url";
|
|
405
|
+
} & {
|
|
406
|
+
key: "NEXT_PUBLIC_SPFN_API_URL";
|
|
407
|
+
};
|
|
397
408
|
SPFN_APP_URL: {
|
|
398
409
|
description: string;
|
|
399
410
|
required: boolean;
|
|
411
|
+
nextjs: boolean;
|
|
400
412
|
examples: string[];
|
|
401
413
|
} & {
|
|
402
414
|
type: "url";
|
|
@@ -783,15 +795,27 @@ declare const registry: _spfn_core_env.EnvRegistry<{
|
|
|
783
795
|
SPFN_API_URL: {
|
|
784
796
|
description: string;
|
|
785
797
|
required: boolean;
|
|
798
|
+
nextjs: boolean;
|
|
786
799
|
examples: string[];
|
|
787
800
|
} & {
|
|
788
801
|
type: "url";
|
|
789
802
|
} & {
|
|
790
803
|
key: "SPFN_API_URL";
|
|
791
804
|
};
|
|
805
|
+
NEXT_PUBLIC_SPFN_API_URL: {
|
|
806
|
+
description: string;
|
|
807
|
+
required: boolean;
|
|
808
|
+
nextjs: boolean;
|
|
809
|
+
examples: string[];
|
|
810
|
+
} & {
|
|
811
|
+
type: "url";
|
|
812
|
+
} & {
|
|
813
|
+
key: "NEXT_PUBLIC_SPFN_API_URL";
|
|
814
|
+
};
|
|
792
815
|
SPFN_APP_URL: {
|
|
793
816
|
description: string;
|
|
794
817
|
required: boolean;
|
|
818
|
+
nextjs: boolean;
|
|
795
819
|
examples: string[];
|
|
796
820
|
} & {
|
|
797
821
|
type: "url";
|
|
@@ -1171,15 +1195,27 @@ declare const env: _spfn_core_env.InferEnvType<{
|
|
|
1171
1195
|
SPFN_API_URL: {
|
|
1172
1196
|
description: string;
|
|
1173
1197
|
required: boolean;
|
|
1198
|
+
nextjs: boolean;
|
|
1174
1199
|
examples: string[];
|
|
1175
1200
|
} & {
|
|
1176
1201
|
type: "url";
|
|
1177
1202
|
} & {
|
|
1178
1203
|
key: "SPFN_API_URL";
|
|
1179
1204
|
};
|
|
1205
|
+
NEXT_PUBLIC_SPFN_API_URL: {
|
|
1206
|
+
description: string;
|
|
1207
|
+
required: boolean;
|
|
1208
|
+
nextjs: boolean;
|
|
1209
|
+
examples: string[];
|
|
1210
|
+
} & {
|
|
1211
|
+
type: "url";
|
|
1212
|
+
} & {
|
|
1213
|
+
key: "NEXT_PUBLIC_SPFN_API_URL";
|
|
1214
|
+
};
|
|
1180
1215
|
SPFN_APP_URL: {
|
|
1181
1216
|
description: string;
|
|
1182
1217
|
required: boolean;
|
|
1218
|
+
nextjs: boolean;
|
|
1183
1219
|
examples: string[];
|
|
1184
1220
|
} & {
|
|
1185
1221
|
type: "url";
|
package/dist/config/index.js
CHANGED
|
@@ -7,7 +7,8 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
7
7
|
// ========================================================================
|
|
8
8
|
NODE_ENV: envEnum(["local", "development", "production", "test"], {
|
|
9
9
|
description: "Node.js runtime environment",
|
|
10
|
-
default: "local"
|
|
10
|
+
default: "local",
|
|
11
|
+
nextjs: true
|
|
11
12
|
}),
|
|
12
13
|
// ========================================================================
|
|
13
14
|
// Database - Connection
|
|
@@ -241,17 +242,25 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
241
242
|
examples: [1e4, 3e4, 6e4]
|
|
242
243
|
}),
|
|
243
244
|
// ========================================================================
|
|
244
|
-
// Next.js
|
|
245
|
+
// Next.js Integration
|
|
245
246
|
// ========================================================================
|
|
246
247
|
SPFN_API_URL: envUrl({
|
|
247
|
-
description: "
|
|
248
|
+
description: "SPFN API URL (used by Next.js to call backend)",
|
|
248
249
|
required: true,
|
|
249
|
-
|
|
250
|
+
nextjs: true,
|
|
251
|
+
examples: ["http://localhost:8790", "https://api.your-app.com"]
|
|
252
|
+
}),
|
|
253
|
+
NEXT_PUBLIC_SPFN_API_URL: envUrl({
|
|
254
|
+
description: "SPFN API URL (used by Next.js to call backend)",
|
|
255
|
+
required: true,
|
|
256
|
+
nextjs: true,
|
|
257
|
+
examples: ["http://localhost:8790", "https://api.your-app.com"]
|
|
250
258
|
}),
|
|
251
259
|
SPFN_APP_URL: envUrl({
|
|
252
|
-
description: "Next.js application URL (
|
|
260
|
+
description: "Next.js application URL (used by SPFN server)",
|
|
253
261
|
required: false,
|
|
254
|
-
|
|
262
|
+
nextjs: true,
|
|
263
|
+
examples: ["http://localhost:3790", "https://your-app.com"]
|
|
255
264
|
})
|
|
256
265
|
});
|
|
257
266
|
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/schema.ts","../../src/config/index.ts"],"names":[],"mappings":";;;AAsCO,IAAM,gBAAgB,eAAA,CAAgB;AAAA;AAAA;AAAA;AAAA,EAKzC,UAAU,OAAA,CAAQ,CAAC,SAAS,aAAA,EAAe,YAAA,EAAc,MAAM,CAAA,EAAY;AAAA,IACvE,WAAA,EAAa,6BAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACZ,CAAA;AAAA;AAAA;AAAA;AAAA,EAMD,cAAc,SAAA,CAAU;AAAA,IACpB,WAAA,EAAa,iCAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IACV,SAAA,EAAW,IAAA;AAAA,IACX,SAAA,EAAW,gBAAA;AAAA,IACX,QAAA,EAAU,CAAC,kDAAkD;AAAA,GAChE,CAAA;AAAA,EAED,oBAAoB,SAAA,CAAU;AAAA,IAC1B,WAAA,EAAa,6CAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IACV,SAAA,EAAW,IAAA;AAAA,IACX,SAAA,EAAW,gBAAA;AAAA,IACX,QAAA,EAAU,CAAC,+CAA+C;AAAA,GAC7D,CAAA;AAAA,EAED,mBAAmB,SAAA,CAAU;AAAA,IACzB,WAAA,EAAa,4CAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IACV,SAAA,EAAW,IAAA;AAAA,IACX,SAAA,EAAW,gBAAA;AAAA,IACX,QAAA,EAAU,CAAC,gDAAgD;AAAA,GAC9D,CAAA;AAAA;AAAA;AAAA;AAAA,EAOD,aAAa,SAAA,CAAU;AAAA,IACnB,WAAA,EAAa,gDAAA;AAAA,IACb,OAAA,EAAS,EAAA;AAAA,IACT,QAAA,EAAU,CAAC,EAAA,EAAI,EAAA,EAAI,EAAE;AAAA,GACxB,CAAA;AAAA,EAED,sBAAsB,SAAA,CAAU;AAAA,IAC5B,WAAA,EAAa,6CAAA;AAAA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SAAA,CAAU;AAAA,IACtB,WAAA,EAAa,iCAAA;AAAA,IACb,OAAA,EAAS,IAAA;AAAA,IACT,QAAA,EAAU,CAAC,GAAA,EAAO,IAAA,EAAQ,GAAM;AAAA,GACnC,CAAA;AAAA,EAED,0BAA0B,SAAA,CAAU;AAAA,IAChC,WAAA,EAAa,oCAAA;AAAA,IACb,OAAA,EAAS,IAAA;AAAA,IACT,QAAA,EAAU,CAAC,GAAA,EAAO,IAAA,EAAO,IAAM;AAAA,GAClC,CAAA;AAAA,EAED,wBAAwB,SAAA,CAAU;AAAA,IAC9B,WAAA,EAAa,iCAAA;AAAA,IACb,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU,CAAC,GAAA,EAAO,GAAA,EAAO,IAAM;AAAA,GAClC,CAAA;AAAA,EAED,kBAAkB,SAAA,CAAU;AAAA,IACxB,WAAA,EAAa,2CAAA;AAAA,IACb,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU,CAAC,GAAA,EAAO,GAAA,EAAO,GAAK;AAAA,GACjC,CAAA;AAAA;AAAA;AAAA;AAAA,EAKD,cAAc,MAAA,CAAO;AAAA,IACjB,WAAA,EAAa,sDAAA;AAAA,IACb,QAAA,EAAU,IAAA;AAAA,IACV,QAAA,EAAU,CAAC,uBAAA,EAAyB,sBAAsB;AAAA,GAC7D,CAAA;AAAA,EAED,cAAc,MAAA,CAAO;AAAA,IACjB,WAAA,EAAa,8DAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IACV,QAAA,EAAU,CAAC,uBAAA,EAAyB,sBAAsB;AAAA,GAC7D;AACL,CAAC;;;ACvTM,IAAM,QAAA,GAAW,kBAAkB,aAAa;AAKhD,IAAM,GAAA,GAAM,SAAS,QAAA","file":"index.js","sourcesContent":["/**\n * Core Package Environment Variable Schema\n *\n * Centralized schema definition for all environment variables used in @spfn/core.\n * This provides type safety, validation, and documentation for environment configuration.\n *\n * @module config/schema\n */\n\nimport {\n defineEnvSchema,\n envEnum,\n envNumber,\n envBoolean,\n envUrl,\n envString,\n parsePostgresUrl,\n parseRedisUrl,\n} from '@spfn/core/env';\n\n/**\n * Core package environment variable schema\n *\n * Defines all environment variables with:\n * - Type information\n * - Default values\n * - Validation rules\n * - Documentation\n *\n * @example\n * ```typescript\n * import { coreEnvSchema } from '@spfn/core/config';\n *\n * // Access schema information\n * console.log(coreEnvSchema.DB_POOL_MAX.description);\n * console.log(coreEnvSchema.DB_POOL_MAX.default);\n * ```\n */\nexport const coreEnvSchema = defineEnvSchema({\n // ========================================================================\n // Core Environment\n // ========================================================================\n\n NODE_ENV: envEnum(['local', 'development', 'production', 'test'] as const, {\n description: 'Node.js runtime environment',\n default: 'local',\n }),\n\n // ========================================================================\n // Database - Connection\n // ========================================================================\n\n DATABASE_URL: envString({\n description: 'Primary database connection URL',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@localhost:5432/dbname'],\n }),\n\n DATABASE_WRITE_URL: envString({\n description: 'Write database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@master:5432/dbname'],\n }),\n\n DATABASE_READ_URL: envString({\n description: 'Read database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@replica:5432/dbname'],\n }),\n\n\n // ========================================================================\n // Database - Connection Pool\n // ========================================================================\n\n DB_POOL_MAX: envNumber({\n description: 'Maximum number of database connections in pool',\n default: 10,\n examples: [10, 20, 50],\n }),\n\n DB_POOL_IDLE_TIMEOUT: envNumber({\n description: 'Database connection idle timeout in seconds',\n default: 30,\n examples: [20, 30, 60],\n }),\n\n // ========================================================================\n // Database - Retry Configuration\n // ========================================================================\n\n DB_RETRY_MAX: envNumber({\n description: 'Maximum number of database connection retry attempts',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_RETRY_INITIAL_DELAY: envNumber({\n description: 'Initial delay between database retry attempts (milliseconds)',\n default: 100,\n examples: [50, 100, 200],\n }),\n\n DB_RETRY_MAX_DELAY: envNumber({\n description: 'Maximum delay cap for database retry attempts (milliseconds)',\n default: 10000,\n examples: [5000, 10000, 30000],\n }),\n\n DB_RETRY_FACTOR: envNumber({\n description: 'Exponential backoff factor for database retry delays',\n default: 2,\n examples: [2, 1.5, 3],\n }),\n\n // ========================================================================\n // Database - Health Check\n // ========================================================================\n\n DB_HEALTH_CHECK_ENABLED: envBoolean({\n description: 'Enable periodic database health checks',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_INTERVAL: envNumber({\n description: 'Database health check interval (milliseconds)',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n DB_HEALTH_CHECK_RECONNECT: envBoolean({\n description: 'Reconnect to database on health check failure',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_MAX_RETRIES: envNumber({\n description: 'Maximum health check retry attempts before marking as failed',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_HEALTH_CHECK_RETRY_INTERVAL: envNumber({\n description: 'Interval between health check retry attempts (milliseconds)',\n default: 5000,\n examples: [5000, 10000, 15000],\n }),\n\n // ========================================================================\n // Database - Monitoring\n // ========================================================================\n\n DB_MONITORING_ENABLED: envBoolean({\n description: 'Enable database query performance monitoring',\n default: false,\n examples: [true, false],\n }),\n\n DB_MONITORING_SLOW_THRESHOLD: envNumber({\n description: 'Slow query threshold for monitoring (milliseconds)',\n default: 1000,\n examples: [500, 1000, 2000],\n }),\n\n DB_MONITORING_LOG_QUERIES: envBoolean({\n description: 'Log all database queries (not just slow queries)',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Transaction\n // ========================================================================\n\n TRANSACTION_TIMEOUT: envNumber({\n description: 'Transaction timeout in milliseconds',\n default: 30000,\n examples: [10000, 30000, 60000],\n }),\n\n // ========================================================================\n // Database - Development\n // ========================================================================\n\n DB_DEBUG_TRACE: envBoolean({\n description: 'Enable detailed debug tracing for database operations',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Drizzle ORM\n // ========================================================================\n\n DRIZZLE_SCHEMA_PATH: envString({\n description: 'Path to Drizzle schema configuration',\n required: false,\n default: './src/server/entities/config.ts',\n examples: ['./src/db/schema.ts', './src/server/entities/config.ts'],\n }),\n\n DRIZZLE_OUT_DIR: envString({\n description: 'Output directory for Drizzle migrations',\n required: false,\n default: './drizzle',\n examples: ['./drizzle', './migrations'],\n }),\n\n // ========================================================================\n // Logger - Core\n // ========================================================================\n\n SPFN_LOG_LEVEL: envEnum(['debug', 'info', 'warn', 'error', 'fatal'] as const, {\n description: 'Minimum log level to output',\n default: 'info'\n }),\n\n // ========================================================================\n // Cache (Redis/Valkey)\n // ========================================================================\n\n CACHE_URL: envString({\n description: 'Single Redis/Valkey instance URL',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://localhost:6379', 'rediss://secure.cache.com:6380'],\n }),\n\n CACHE_WRITE_URL: envString({\n description: 'Master Redis/Valkey URL for writes (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://master:6379'],\n }),\n\n CACHE_READ_URL: envString({\n description: 'Replica Redis/Valkey URL for reads (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://replica:6379'],\n }),\n\n CACHE_SENTINEL_HOSTS: envString({\n description: 'Comma-separated Redis Sentinel hosts',\n required: false,\n examples: ['sentinel1:26379,sentinel2:26379'],\n }),\n\n CACHE_CLUSTER_NODES: envString({\n description: 'Comma-separated Redis Cluster nodes',\n required: false,\n examples: ['node1:6379,node2:6379,node3:6379'],\n }),\n\n CACHE_MASTER_NAME: envString({\n description: 'Redis Sentinel master name',\n required: false,\n examples: ['mymaster'],\n }),\n\n CACHE_PASSWORD: envString({\n description: 'Redis/Valkey authentication password',\n required: false,\n sensitive: true,\n examples: ['your-redis-password'],\n }),\n\n CACHE_TLS_REJECT_UNAUTHORIZED: envBoolean({\n description: 'Verify TLS certificates for secure Redis connections',\n default: true,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Server - Core\n // ========================================================================\n\n PORT: envNumber({\n description: 'Server port number',\n default: 4000,\n examples: [3000, 4000, 8080],\n }),\n\n HOST: envString({\n description: 'Server hostname',\n default: 'localhost',\n required: false,\n examples: ['localhost', '0.0.0.0', '127.0.0.1'],\n }),\n\n // ========================================================================\n // Server - Timeout\n // ========================================================================\n\n SERVER_TIMEOUT: envNumber({\n description: 'Request timeout in milliseconds',\n default: 120000,\n examples: [60000, 120000, 300000],\n }),\n\n SERVER_KEEPALIVE_TIMEOUT: envNumber({\n description: 'Keep-alive timeout in milliseconds',\n default: 65000,\n examples: [30000, 65000, 120000],\n }),\n\n SERVER_HEADERS_TIMEOUT: envNumber({\n description: 'Headers timeout in milliseconds',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n SHUTDOWN_TIMEOUT: envNumber({\n description: 'Graceful shutdown timeout in milliseconds',\n default: 30000,\n examples: [10000, 30000, 60000],\n }),\n\n // ========================================================================\n // Next.js Client\n // ========================================================================\n SPFN_API_URL: envUrl({\n description: 'Next.js API URL (required for client-side API calls)',\n required: true,\n examples: ['http://localhost:3000', 'https://your-app.com'],\n }),\n\n SPFN_APP_URL: envUrl({\n description: 'Next.js application URL (required for server-side API calls)',\n required: false,\n examples: ['http://localhost:3000', 'https://your-app.com'],\n }),\n});","/**\n * Core Package Configuration\n *\n * @example\n * ```typescript\n * import { registry } from '@spfn/core/config';\n *\n * const env = registry.validate();\n * console.log(env.DB_POOL_MAX);\n * ```\n *\n * @module config\n */\n\nimport { createEnvRegistry } from '@spfn/core/env';\nimport { coreEnvSchema } from './schema';\n\n/**\n * Core environment schema\n */\nexport { coreEnvSchema as envSchema } from './schema';\n\n/**\n * Environment registry\n *\n * @example\n * ```typescript\n * // Reset for testing\n * registry.reset();\n * ```\n */\nexport const registry = createEnvRegistry(coreEnvSchema);\n\n/**\n * Validated environment configuration\n */\nexport const env = registry.validate();"]}
|
|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,QAAA,GAAW,kBAAkB,aAAa;AAKhD,IAAM,GAAA,GAAM,SAAS,QAAA","file":"index.js","sourcesContent":["/**\n * Core Package Environment Variable Schema\n *\n * Centralized schema definition for all environment variables used in @spfn/core.\n * This provides type safety, validation, and documentation for environment configuration.\n *\n * @module config/schema\n */\n\nimport {\n defineEnvSchema,\n envEnum,\n envNumber,\n envBoolean,\n envUrl,\n envString,\n parsePostgresUrl,\n parseRedisUrl,\n} from '@spfn/core/env';\n\n/**\n * Core package environment variable schema\n *\n * Defines all environment variables with:\n * - Type information\n * - Default values\n * - Validation rules\n * - Documentation\n *\n * @example\n * ```typescript\n * import { coreEnvSchema } from '@spfn/core/config';\n *\n * // Access schema information\n * console.log(coreEnvSchema.DB_POOL_MAX.description);\n * console.log(coreEnvSchema.DB_POOL_MAX.default);\n * ```\n */\nexport const coreEnvSchema = defineEnvSchema({\n // ========================================================================\n // Core Environment\n // ========================================================================\n\n NODE_ENV: envEnum(['local', 'development', 'production', 'test'] as const, {\n description: 'Node.js runtime environment',\n default: 'local',\n nextjs: true,\n }),\n\n // ========================================================================\n // Database - Connection\n // ========================================================================\n\n DATABASE_URL: envString({\n description: 'Primary database connection URL',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@localhost:5432/dbname'],\n }),\n\n DATABASE_WRITE_URL: envString({\n description: 'Write database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@master:5432/dbname'],\n }),\n\n DATABASE_READ_URL: envString({\n description: 'Read database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@replica:5432/dbname'],\n }),\n\n\n // ========================================================================\n // Database - Connection Pool\n // ========================================================================\n\n DB_POOL_MAX: envNumber({\n description: 'Maximum number of database connections in pool',\n default: 10,\n examples: [10, 20, 50],\n }),\n\n DB_POOL_IDLE_TIMEOUT: envNumber({\n description: 'Database connection idle timeout in seconds',\n default: 30,\n examples: [20, 30, 60],\n }),\n\n // ========================================================================\n // Database - Retry Configuration\n // ========================================================================\n\n DB_RETRY_MAX: envNumber({\n description: 'Maximum number of database connection retry attempts',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_RETRY_INITIAL_DELAY: envNumber({\n description: 'Initial delay between database retry attempts (milliseconds)',\n default: 100,\n examples: [50, 100, 200],\n }),\n\n DB_RETRY_MAX_DELAY: envNumber({\n description: 'Maximum delay cap for database retry attempts (milliseconds)',\n default: 10000,\n examples: [5000, 10000, 30000],\n }),\n\n DB_RETRY_FACTOR: envNumber({\n description: 'Exponential backoff factor for database retry delays',\n default: 2,\n examples: [2, 1.5, 3],\n }),\n\n // ========================================================================\n // Database - Health Check\n // ========================================================================\n\n DB_HEALTH_CHECK_ENABLED: envBoolean({\n description: 'Enable periodic database health checks',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_INTERVAL: envNumber({\n description: 'Database health check interval (milliseconds)',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n DB_HEALTH_CHECK_RECONNECT: envBoolean({\n description: 'Reconnect to database on health check failure',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_MAX_RETRIES: envNumber({\n description: 'Maximum health check retry attempts before marking as failed',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_HEALTH_CHECK_RETRY_INTERVAL: envNumber({\n description: 'Interval between health check retry attempts (milliseconds)',\n default: 5000,\n examples: [5000, 10000, 15000],\n }),\n\n // ========================================================================\n // Database - Monitoring\n // ========================================================================\n\n DB_MONITORING_ENABLED: envBoolean({\n description: 'Enable database query performance monitoring',\n default: false,\n examples: [true, false],\n }),\n\n DB_MONITORING_SLOW_THRESHOLD: envNumber({\n description: 'Slow query threshold for monitoring (milliseconds)',\n default: 1000,\n examples: [500, 1000, 2000],\n }),\n\n DB_MONITORING_LOG_QUERIES: envBoolean({\n description: 'Log all database queries (not just slow queries)',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Transaction\n // ========================================================================\n\n TRANSACTION_TIMEOUT: envNumber({\n description: 'Transaction timeout in milliseconds',\n default: 30000,\n examples: [10000, 30000, 60000],\n }),\n\n // ========================================================================\n // Database - Development\n // ========================================================================\n\n DB_DEBUG_TRACE: envBoolean({\n description: 'Enable detailed debug tracing for database operations',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Drizzle ORM\n // ========================================================================\n\n DRIZZLE_SCHEMA_PATH: envString({\n description: 'Path to Drizzle schema configuration',\n required: false,\n default: './src/server/entities/config.ts',\n examples: ['./src/db/schema.ts', './src/server/entities/config.ts'],\n }),\n\n DRIZZLE_OUT_DIR: envString({\n description: 'Output directory for Drizzle migrations',\n required: false,\n default: './drizzle',\n examples: ['./drizzle', './migrations'],\n }),\n\n // ========================================================================\n // Logger - Core\n // ========================================================================\n\n SPFN_LOG_LEVEL: envEnum(['debug', 'info', 'warn', 'error', 'fatal'] as const, {\n description: 'Minimum log level to output',\n default: 'info'\n }),\n\n // ========================================================================\n // Cache (Redis/Valkey)\n // ========================================================================\n\n CACHE_URL: envString({\n description: 'Single Redis/Valkey instance URL',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://localhost:6379', 'rediss://secure.cache.com:6380'],\n }),\n\n CACHE_WRITE_URL: envString({\n description: 'Master Redis/Valkey URL for writes (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://master:6379'],\n }),\n\n CACHE_READ_URL: envString({\n description: 'Replica Redis/Valkey URL for reads (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://replica:6379'],\n }),\n\n CACHE_SENTINEL_HOSTS: envString({\n description: 'Comma-separated Redis Sentinel hosts',\n required: false,\n examples: ['sentinel1:26379,sentinel2:26379'],\n }),\n\n CACHE_CLUSTER_NODES: envString({\n description: 'Comma-separated Redis Cluster nodes',\n required: false,\n examples: ['node1:6379,node2:6379,node3:6379'],\n }),\n\n CACHE_MASTER_NAME: envString({\n description: 'Redis Sentinel master name',\n required: false,\n examples: ['mymaster'],\n }),\n\n CACHE_PASSWORD: envString({\n description: 'Redis/Valkey authentication password',\n required: false,\n sensitive: true,\n examples: ['your-redis-password'],\n }),\n\n CACHE_TLS_REJECT_UNAUTHORIZED: envBoolean({\n description: 'Verify TLS certificates for secure Redis connections',\n default: true,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Server - Core\n // ========================================================================\n\n PORT: envNumber({\n description: 'Server port number',\n default: 4000,\n examples: [3000, 4000, 8080],\n }),\n\n HOST: envString({\n description: 'Server hostname',\n default: 'localhost',\n required: false,\n examples: ['localhost', '0.0.0.0', '127.0.0.1'],\n }),\n\n // ========================================================================\n // Server - Timeout\n // ========================================================================\n\n SERVER_TIMEOUT: envNumber({\n description: 'Request timeout in milliseconds',\n default: 120000,\n examples: [60000, 120000, 300000],\n }),\n\n SERVER_KEEPALIVE_TIMEOUT: envNumber({\n description: 'Keep-alive timeout in milliseconds',\n default: 65000,\n examples: [30000, 65000, 120000],\n }),\n\n SERVER_HEADERS_TIMEOUT: envNumber({\n description: 'Headers timeout in milliseconds',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n SHUTDOWN_TIMEOUT: envNumber({\n description: 'Graceful shutdown timeout in milliseconds',\n default: 30000,\n examples: [10000, 30000, 60000],\n }),\n\n // ========================================================================\n // Next.js Integration\n // ========================================================================\n\n SPFN_API_URL: envUrl({\n description: 'SPFN API URL (used by Next.js to call backend)',\n required: true,\n nextjs: true,\n examples: ['http://localhost:8790', 'https://api.your-app.com'],\n }),\n\n NEXT_PUBLIC_SPFN_API_URL: envUrl({\n description: 'SPFN API URL (used by Next.js to call backend)',\n required: true,\n nextjs: true,\n examples: ['http://localhost:8790', 'https://api.your-app.com'],\n }),\n\n SPFN_APP_URL: envUrl({\n description: 'Next.js application URL (used by SPFN server)',\n required: false,\n nextjs: true,\n examples: ['http://localhost:3790', 'https://your-app.com'],\n }),\n});","/**\n * Core Package Configuration\n *\n * @example\n * ```typescript\n * import { registry } from '@spfn/core/config';\n *\n * const env = registry.validate();\n * console.log(env.DB_POOL_MAX);\n * ```\n *\n * @module config\n */\n\nimport { createEnvRegistry } from '@spfn/core/env';\nimport { coreEnvSchema } from './schema';\n\n/**\n * Core environment schema\n */\nexport { coreEnvSchema as envSchema } from './schema';\n\n/**\n * Environment registry\n *\n * @example\n * ```typescript\n * // Reset for testing\n * registry.reset();\n * ```\n */\nexport const registry = createEnvRegistry(coreEnvSchema);\n\n/**\n * Validated environment configuration\n */\nexport const env = registry.validate();"]}
|
package/dist/env/index.d.ts
CHANGED
|
@@ -473,6 +473,15 @@ interface EnvVarSchema<T = string> {
|
|
|
473
473
|
sensitive?: boolean;
|
|
474
474
|
/** 예시 값들 (타입과 일치해야 함) */
|
|
475
475
|
examples?: T[];
|
|
476
|
+
/**
|
|
477
|
+
* Next.js 프로세스에서 사용 여부
|
|
478
|
+
*
|
|
479
|
+
* - true: .env.local에 존재해야 함 (Next.js 서버 컴포넌트에서 접근 가능)
|
|
480
|
+
* - false: .env.server.local에만 존재해야 함 (SPFN 서버에서만 접근)
|
|
481
|
+
*
|
|
482
|
+
* @default NEXT_PUBLIC_* 이면 true, 아니면 false
|
|
483
|
+
*/
|
|
484
|
+
nextjs?: boolean;
|
|
476
485
|
}
|
|
477
486
|
/**
|
|
478
487
|
* 스키마 컬렉션 타입
|
|
@@ -672,6 +681,24 @@ declare function isClientAccessible(key: string): boolean;
|
|
|
672
681
|
* ```
|
|
673
682
|
*/
|
|
674
683
|
declare function isServerOnly(key: string): boolean;
|
|
684
|
+
/**
|
|
685
|
+
* 스키마의 nextjs 옵션 값 결정
|
|
686
|
+
*
|
|
687
|
+
* 명시적으로 지정되지 않은 경우:
|
|
688
|
+
* - NEXT_PUBLIC_* → true
|
|
689
|
+
* - 그 외 → false
|
|
690
|
+
*
|
|
691
|
+
* @param schema - 환경변수 스키마
|
|
692
|
+
* @returns Next.js 프로세스에서 사용 가능 여부
|
|
693
|
+
*/
|
|
694
|
+
declare function isNextjsAccessible(schema: EnvVarSchema): boolean;
|
|
695
|
+
/**
|
|
696
|
+
* 스키마가 SPFN 서버 전용인지 확인
|
|
697
|
+
*
|
|
698
|
+
* @param schema - 환경변수 스키마
|
|
699
|
+
* @returns SPFN 서버에서만 사용되면 true
|
|
700
|
+
*/
|
|
701
|
+
declare function isSpfnServerOnly(schema: EnvVarSchema): boolean;
|
|
675
702
|
|
|
676
703
|
/**
|
|
677
704
|
* Environment Variable Registry
|
|
@@ -700,7 +727,6 @@ declare function isServerOnly(key: string): boolean;
|
|
|
700
727
|
declare class EnvRegistry<T extends EnvSchemaCollection = EnvSchemaCollection> {
|
|
701
728
|
private schemas;
|
|
702
729
|
private hasValidated;
|
|
703
|
-
private valueCache;
|
|
704
730
|
constructor(schemas?: T);
|
|
705
731
|
/**
|
|
706
732
|
* 스키마 등록
|
|
@@ -711,7 +737,7 @@ declare class EnvRegistry<T extends EnvSchemaCollection = EnvSchemaCollection> {
|
|
|
711
737
|
*/
|
|
712
738
|
registerMultiple(schemas: EnvSchemaCollection): void;
|
|
713
739
|
/**
|
|
714
|
-
*
|
|
740
|
+
* 검증 상태 리셋 (테스트용)
|
|
715
741
|
*/
|
|
716
742
|
reset(): void;
|
|
717
743
|
/**
|
|
@@ -776,4 +802,4 @@ declare function createEnvRegistry<T extends EnvSchemaCollection>(schemas: T): E
|
|
|
776
802
|
*/
|
|
777
803
|
type NodeEnv = 'local' | 'development' | 'staging' | 'production' | 'test';
|
|
778
804
|
|
|
779
|
-
export { EnvRegistry, type EnvSchemaCollection, type EnvVarSchema, type InferEnvType, type NodeEnv, type Parser, chain, createArrayParser, createEnumParser, createEnvRegistry, createJsonParser, createNumberParser, createPasswordParser, createSecureSecretParser, createStringParser, createUrlParser, defineEnvSchema, envBoolean, envEnum, envJson, envNumber, envString, envUrl, isClientAccessible, isServerOnly, optional, parseArray, parseBoolean, parseDecimal, parseEnum, parseInteger, parseJson, parseNumber, parsePostgresUrl, parseRedisUrl, parseString, parseUrl, withFallback };
|
|
805
|
+
export { EnvRegistry, type EnvSchemaCollection, type EnvVarSchema, type InferEnvType, type NodeEnv, type Parser, chain, createArrayParser, createEnumParser, createEnvRegistry, createJsonParser, createNumberParser, createPasswordParser, createSecureSecretParser, createStringParser, createUrlParser, defineEnvSchema, envBoolean, envEnum, envJson, envNumber, envString, envUrl, isClientAccessible, isNextjsAccessible, isServerOnly, isSpfnServerOnly, optional, parseArray, parseBoolean, parseDecimal, parseEnum, parseInteger, parseJson, parseNumber, parsePostgresUrl, parseRedisUrl, parseString, parseUrl, withFallback };
|
package/dist/env/index.js
CHANGED
|
@@ -346,11 +346,19 @@ function isClientAccessible(key) {
|
|
|
346
346
|
function isServerOnly(key) {
|
|
347
347
|
return !isClientAccessible(key);
|
|
348
348
|
}
|
|
349
|
+
function isNextjsAccessible(schema) {
|
|
350
|
+
if (schema.nextjs !== void 0) {
|
|
351
|
+
return schema.nextjs;
|
|
352
|
+
}
|
|
353
|
+
return isClientAccessible(schema.key);
|
|
354
|
+
}
|
|
355
|
+
function isSpfnServerOnly(schema) {
|
|
356
|
+
return !isNextjsAccessible(schema);
|
|
357
|
+
}
|
|
349
358
|
var envLogger = logger.child("@spfn/core:env-registry");
|
|
350
359
|
var EnvRegistry = class {
|
|
351
360
|
schemas = /* @__PURE__ */ new Map();
|
|
352
361
|
hasValidated = false;
|
|
353
|
-
valueCache = /* @__PURE__ */ new Map();
|
|
354
362
|
constructor(schemas) {
|
|
355
363
|
if (schemas) {
|
|
356
364
|
this.registerMultiple(schemas);
|
|
@@ -371,10 +379,9 @@ var EnvRegistry = class {
|
|
|
371
379
|
}
|
|
372
380
|
}
|
|
373
381
|
/**
|
|
374
|
-
*
|
|
382
|
+
* 검증 상태 리셋 (테스트용)
|
|
375
383
|
*/
|
|
376
384
|
reset() {
|
|
377
|
-
this.valueCache.clear();
|
|
378
385
|
this.hasValidated = false;
|
|
379
386
|
}
|
|
380
387
|
/**
|
|
@@ -430,9 +437,6 @@ var EnvRegistry = class {
|
|
|
430
437
|
* @internal
|
|
431
438
|
*/
|
|
432
439
|
getAndValidate(key) {
|
|
433
|
-
if (this.valueCache.has(key)) {
|
|
434
|
-
return this.valueCache.get(key);
|
|
435
|
-
}
|
|
436
440
|
const schema = this.schemas.get(key);
|
|
437
441
|
if (!schema) {
|
|
438
442
|
return void 0;
|
|
@@ -446,9 +450,7 @@ var EnvRegistry = class {
|
|
|
446
450
|
throw new Error("Environment validation failed");
|
|
447
451
|
}
|
|
448
452
|
if (!value) {
|
|
449
|
-
|
|
450
|
-
this.valueCache.set(key, result);
|
|
451
|
-
return result;
|
|
453
|
+
return schema.default;
|
|
452
454
|
}
|
|
453
455
|
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
454
456
|
const errorMsg = `${key} must be at least ${schema.minLength} characters long (current: ${value.length})`;
|
|
@@ -457,9 +459,7 @@ var EnvRegistry = class {
|
|
|
457
459
|
throw new Error("Environment validation failed");
|
|
458
460
|
}
|
|
459
461
|
try {
|
|
460
|
-
|
|
461
|
-
this.valueCache.set(key, result);
|
|
462
|
-
return result;
|
|
462
|
+
return this.applyValidator(value, schema);
|
|
463
463
|
} catch (error) {
|
|
464
464
|
const errorMsg = `${key} validation failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
465
465
|
envLogger.error(`Environment validation failed:
|
|
@@ -513,6 +513,6 @@ function createEnvRegistry(schemas) {
|
|
|
513
513
|
return new EnvRegistry(schemas);
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
-
export { EnvRegistry, chain, createArrayParser, createEnumParser, createEnvRegistry, createJsonParser, createNumberParser, createPasswordParser, createSecureSecretParser, createStringParser, createUrlParser, defineEnvSchema, envBoolean, envEnum, envJson, envNumber, envString, envUrl, isClientAccessible, isServerOnly, optional, parseArray, parseBoolean, parseDecimal, parseEnum, parseInteger, parseJson, parseNumber, parsePostgresUrl, parseRedisUrl, parseString, parseUrl, withFallback };
|
|
516
|
+
export { EnvRegistry, chain, createArrayParser, createEnumParser, createEnvRegistry, createJsonParser, createNumberParser, createPasswordParser, createSecureSecretParser, createStringParser, createUrlParser, defineEnvSchema, envBoolean, envEnum, envJson, envNumber, envString, envUrl, isClientAccessible, isNextjsAccessible, isServerOnly, isSpfnServerOnly, optional, parseArray, parseBoolean, parseDecimal, parseEnum, parseInteger, parseJson, parseNumber, parsePostgresUrl, parseRedisUrl, parseString, parseUrl, withFallback };
|
|
517
517
|
//# sourceMappingURL=index.js.map
|
|
518
518
|
//# sourceMappingURL=index.js.map
|