@spfn/core 0.3.0-beta.1 → 0.3.0-beta.3
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 +84 -21
- package/dist/app-config/index.d.ts +96 -0
- package/dist/app-config/index.js +58 -0
- package/dist/app-config/index.js.map +1 -0
- package/dist/config/index.d.ts +0 -63
- package/dist/config/index.js +11 -11
- package/dist/config/index.js.map +1 -1
- package/dist/contract/index.d.ts +4 -4
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/{define-middleware-DfDP39Nq.d.ts → define-middleware-CVKgqo8S.d.ts} +1 -1
- package/dist/middleware/index.d.ts +6 -2
- package/dist/middleware/index.js +1 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/ops/index.d.ts +54 -9
- package/dist/ops/index.js +38 -14
- package/dist/ops/index.js.map +1 -1
- package/dist/route/index.d.ts +3 -3
- package/dist/route/index.js +1 -1
- package/dist/route/index.js.map +1 -1
- package/dist/{router-ukNdAZcN.d.ts → router-Cy7rAfmj.d.ts} +8 -8
- package/dist/server/index.d.ts +56 -8
- package/dist/server/index.js +173 -30
- package/dist/server/index.js.map +1 -1
- package/dist/{types-Bvvig_tT.d.ts → types-CfYVhIQ9.d.ts} +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -292,8 +292,8 @@ export default defineServerConfig()
|
|
|
292
292
|
|
|
293
293
|
All three log the pending list as a warning rather than silently continuing.
|
|
294
294
|
|
|
295
|
-
**A readiness probe sees the same thing.** When detailed health is on,
|
|
296
|
-
carries a `migrations` object beside `services`:
|
|
295
|
+
**A readiness probe sees the same thing.** When detailed health is on,
|
|
296
|
+
`GET /_core/health` carries a `migrations` object beside `services`:
|
|
297
297
|
|
|
298
298
|
```json
|
|
299
299
|
{
|
|
@@ -320,6 +320,45 @@ The serverless path (`createServerlessApp`) has no boot to gate — run
|
|
|
320
320
|
|
|
321
321
|
---
|
|
322
322
|
|
|
323
|
+
## Which path does the health endpoint answer on?
|
|
324
|
+
|
|
325
|
+
`/_core/health`. That is the whole answer — `@spfn/core` registers nothing on `/health`.
|
|
326
|
+
|
|
327
|
+
`/_core/` belongs to `@spfn/core` the way `/_auth/` belongs to `@spfn/auth`: the endpoints
|
|
328
|
+
in it are registered before your routes, so no route you declare can take one. That is
|
|
329
|
+
what makes `/_core/health` the right target for a readiness probe, a Dockerfile
|
|
330
|
+
`HEALTHCHECK` or an uptime monitor — the answer does not depend on what your app defines.
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
// the endpoint answers at /_core/health, and nowhere else
|
|
334
|
+
export default defineServerConfig().build();
|
|
335
|
+
|
|
336
|
+
// an additional address, for a probe path you cannot change
|
|
337
|
+
export default defineServerConfig().healthCheck({ path: '/health' }).build();
|
|
338
|
+
|
|
339
|
+
// off → nothing answers anywhere
|
|
340
|
+
export default defineServerConfig().healthCheck({ enabled: false }).build();
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
`healthCheck.path` adds a second address. It never moves `/_core/health`, and it is
|
|
344
|
+
registered before your routes like the canonical one — so an app route on the same path
|
|
345
|
+
will not run, and the server says so at boot.
|
|
346
|
+
|
|
347
|
+
**`/health` is yours now.** Declare `GET /health` and it behaves like any other route of
|
|
348
|
+
yours. Declare nothing there and, for one release, a `GET` answers **410** naming
|
|
349
|
+
`/_core/health`, and the server warns once the first time it is hit — a readiness probe
|
|
350
|
+
failure shows an operator neither a response body nor a status text, so a bare 404 would
|
|
351
|
+
leave them nothing to search for. Upgrading an existing deployment?
|
|
352
|
+
[docs/guides/migration/health-endpoint.md](../../docs/guides/migration/health-endpoint.md).
|
|
353
|
+
|
|
354
|
+
Every built-in health address is registered before the `lifecycle.beforeRoutes` hook, and
|
|
355
|
+
a Hono middleware only wraps handlers registered after it. So a global guard your app adds
|
|
356
|
+
in that hook — which is what the hook is documented for — cannot close the endpoint a
|
|
357
|
+
probe depends on, and a probe reaches it unauthenticated. An app with `src/server/app.ts`
|
|
358
|
+
(level 3) wires its own server and gets no health endpoint at all.
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
323
362
|
## Can I deploy this to Vercel?
|
|
324
363
|
|
|
325
364
|
Yes, and it is a first-class target rather than a workaround. From your app:
|
|
@@ -369,11 +408,10 @@ path: `spfn build && spfn start`, or the generated Docker files.
|
|
|
369
408
|
Put the contract in a file and let the agent read it, instead of describing the
|
|
370
409
|
architecture again in every prompt.
|
|
371
410
|
|
|
372
|
-
|
|
411
|
+
The SPFN repository states it in `CONTRIBUTING.md`: what the repo is, the commands, the
|
|
373
412
|
vertical-slice pattern, and the rules that are not negotiable — never hand-edit generated
|
|
374
|
-
files, migrations come from the schema.
|
|
375
|
-
|
|
376
|
-
apart. Projects created by `spfn create` get the same arrangement.
|
|
413
|
+
files, migrations come from the schema. One file answers to people and agents alike, so
|
|
414
|
+
there is no second copy to drift apart from the first.
|
|
377
415
|
|
|
378
416
|
Each module README under `src/` is written for the same reader. When an agent is working
|
|
379
417
|
on database code, `src/db/README.md` is the page to give it.
|
|
@@ -389,12 +427,11 @@ vertical slice whose path lives under `/_ops/`.
|
|
|
389
427
|
```typescript
|
|
390
428
|
// src/server/ops.ts
|
|
391
429
|
import { Type } from '@sinclair/typebox';
|
|
392
|
-
import {
|
|
393
|
-
import { createOpsRouter } from '@spfn/core/ops';
|
|
430
|
+
import { createOpsRouter, opsRoute } from '@spfn/core/ops';
|
|
394
431
|
import { opsTokenAuth, requireOpsScope } from '@spfn/auth/server';
|
|
395
432
|
|
|
396
433
|
export const opsRouter = createOpsRouter({
|
|
397
|
-
listSignups:
|
|
434
|
+
listSignups: opsRoute.get('/signups') // GET /_ops/signups
|
|
398
435
|
.use([requireOpsScope('waitlist:read')])
|
|
399
436
|
.input({ query: Type.Object({ limit: Type.Optional(Type.Number()) }) })
|
|
400
437
|
.handler(async (c) => signupsRepository.list((await c.data()).query.limit)),
|
|
@@ -404,16 +441,41 @@ export const opsRouter = createOpsRouter({
|
|
|
404
441
|
export const appRouter = defineRouter({ ... }).packages([opsRouter]);
|
|
405
442
|
```
|
|
406
443
|
|
|
407
|
-
`
|
|
408
|
-
|
|
409
|
-
|
|
444
|
+
`opsRoute` is `route` with the `/_ops` namespace applied, so a definition carries only the
|
|
445
|
+
path this app owns — what that path looks like, how it nests, which segments are
|
|
446
|
+
parameters are the app's decisions. It exists from `@spfn/core` **0.3.0-beta.2**.
|
|
447
|
+
`createOpsRouter` injects the auth middleware into every route (there is no
|
|
448
|
+
unauthenticated variant) and serves `GET /_ops/_manifest` — the self-description the CLI
|
|
449
|
+
reads, with each command's TypeBox schemas as JSON Schema.
|
|
450
|
+
|
|
451
|
+
The manifest is registered ahead of the ops routes, so none of them can take its URL even
|
|
452
|
+
when one is a pattern like `/_ops/:name`. That ordering does not reach outside the ops
|
|
453
|
+
router: routes an app declares in its own router are registered before any package router,
|
|
454
|
+
so a pattern there that covers `/_ops/_manifest` — a `/*` catch-all, say — shadows the
|
|
455
|
+
manifest, exactly as it shadows every other package route.
|
|
410
456
|
|
|
411
457
|
Routes may be grouped in nested `defineRouter`s, and a group's own `.use()` middlewares
|
|
412
|
-
apply to its routes
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
458
|
+
apply to its routes — always after the injected auth, so a group-wide guard reads a
|
|
459
|
+
request that has already been authenticated. A group-level middleware must be a named one;
|
|
460
|
+
wrap a factory to give it a name:
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
const requireAdmin = defineMiddleware('opsAdminScope', requireOpsScope('admin:read'));
|
|
464
|
+
|
|
465
|
+
export const opsRouter = createOpsRouter({
|
|
466
|
+
admin: defineRouter({ getStats, reindex }).use([requireAdmin]),
|
|
467
|
+
}, { auth: opsTokenAuth });
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
Note that a group's `.use()` middleware carries its `skips` into every route in the group,
|
|
471
|
+
suppressing that server-level middleware there.
|
|
472
|
+
|
|
473
|
+
Three things are refused when the surface is defined, rather than discovered in
|
|
474
|
+
production: a route built with `route` instead of `opsRoute` (it would carry no
|
|
475
|
+
namespace), two routes sharing a command name (the manifest flattens nested groups into
|
|
476
|
+
one list, so the CLI could not tell them apart), and a group mounting `.packages()` (those
|
|
477
|
+
routes register with neither the namespace nor the auth injection). The command name
|
|
478
|
+
`getOpsManifest` and the path `/_ops/_manifest` are reserved.
|
|
417
479
|
|
|
418
480
|
```bash
|
|
419
481
|
spfn ops list --app https://api.example.com # discover commands
|
|
@@ -422,10 +484,11 @@ spfn ops call listSignups --describe # print its usage (--json
|
|
|
422
484
|
```
|
|
423
485
|
|
|
424
486
|
Authentication is an ops token from [`@spfn/auth`](../auth/README.md#ops-tokens-spfn-ops):
|
|
425
|
-
scoped, revocable, hash-stored, issued with `spfn ops token issue`
|
|
426
|
-
|
|
427
|
-
token in the keychain (`spfn ops token store`), and resolution order is
|
|
428
|
-
`SPFN_OPS_TOKEN` → keychain.
|
|
487
|
+
scoped, revocable, hash-stored, issued with `spfn ops token issue` against the running app
|
|
488
|
+
— the CLI signs in as an administrator, so issuance needs no database access. On macOS the
|
|
489
|
+
CLI keeps the token in the keychain (`spfn ops token store`), and resolution order is
|
|
490
|
+
`--token` → `SPFN_OPS_TOKEN` → keychain. The `--app` URL must be https, since every command
|
|
491
|
+
carries a secret; `http` is accepted only against a loopback host.
|
|
429
492
|
|
|
430
493
|
---
|
|
431
494
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `spfn.config.js` — the app's serving shape, read by both the CLI and the server.
|
|
3
|
+
*
|
|
4
|
+
* The file has existed since `spfn init` started writing it, and until now
|
|
5
|
+
* nothing read it back. It is the one committed place that describes how an app
|
|
6
|
+
* is served, which makes it the right home for the ports: an app that wants a
|
|
7
|
+
* different port says so once here instead of repeating the number across its
|
|
8
|
+
* `server.config.ts`, Dockerfile, compose file, `next.config.ts` and env
|
|
9
|
+
* example, where nothing checks that the copies still agree.
|
|
10
|
+
*
|
|
11
|
+
* This module is deliberately free of side effects. `@spfn/core/config`
|
|
12
|
+
* validates the whole environment schema the moment it is imported, which is
|
|
13
|
+
* fine inside a server and wrong inside a CLI that has not been handed an
|
|
14
|
+
* app's environment yet.
|
|
15
|
+
*
|
|
16
|
+
* @module app-config
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Ports the app is served on.
|
|
20
|
+
*
|
|
21
|
+
* Two names because two processes are started. Next.js reads `PORT` as its own,
|
|
22
|
+
* so the SPFN server cannot claim that name without the two colliding whenever
|
|
23
|
+
* they run together.
|
|
24
|
+
*/
|
|
25
|
+
interface SpfnPorts {
|
|
26
|
+
/** Next.js frontend. Passed to `next` as `-p`. */
|
|
27
|
+
next?: number;
|
|
28
|
+
/** SPFN API server. */
|
|
29
|
+
server?: number;
|
|
30
|
+
}
|
|
31
|
+
interface SpfnAppConfig {
|
|
32
|
+
ports?: SpfnPorts;
|
|
33
|
+
/** Host the SPFN API server binds. */
|
|
34
|
+
host?: string;
|
|
35
|
+
/** Deployment settings — untouched by this module, kept so the type is whole. */
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The single place each default exists.
|
|
40
|
+
*
|
|
41
|
+
* Defaults live at the bottom of the chain and nowhere else. A default declared
|
|
42
|
+
* at an input layer — a commander option, a generated entry file, an env schema
|
|
43
|
+
* — cannot be told apart from a value someone supplied, so it silently outranks
|
|
44
|
+
* whatever is below it. Three separate defects in this repository came from
|
|
45
|
+
* exactly that, including an env schema default that forced the environment to
|
|
46
|
+
* be consulted last and made an injected port unreachable.
|
|
47
|
+
*/
|
|
48
|
+
declare const PORT_DEFAULTS: {
|
|
49
|
+
readonly next: 3790;
|
|
50
|
+
readonly server: 8790;
|
|
51
|
+
};
|
|
52
|
+
declare const HOST_DEFAULT = "localhost";
|
|
53
|
+
/**
|
|
54
|
+
* Read `spfn.config.js` from an app directory.
|
|
55
|
+
*
|
|
56
|
+
* Returns an empty object when there is no file, and also when the file cannot
|
|
57
|
+
* be imported — a malformed deployment config must not stop a server from
|
|
58
|
+
* booting. The caller decides whether the absence is worth reporting.
|
|
59
|
+
*/
|
|
60
|
+
declare function loadAppConfig(cwd?: string): Promise<SpfnAppConfig>;
|
|
61
|
+
/**
|
|
62
|
+
* The port each process binds, given a loaded config and the environment.
|
|
63
|
+
*
|
|
64
|
+
* Three layers, in this order, and no more: environment variable, then
|
|
65
|
+
* `spfn.config.js`, then the default.
|
|
66
|
+
*/
|
|
67
|
+
declare function resolvePorts(config: SpfnAppConfig, env?: NodeJS.ProcessEnv): {
|
|
68
|
+
next: number;
|
|
69
|
+
server: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The host the SPFN server binds, on the same three layers.
|
|
73
|
+
*
|
|
74
|
+
* `localhost` by default: a container states `SPFN_HOST=0.0.0.0` in its own
|
|
75
|
+
* files, where that decision belongs, rather than every developer machine
|
|
76
|
+
* publishing a dev server to its network.
|
|
77
|
+
*/
|
|
78
|
+
declare function resolveHost(config: SpfnAppConfig, env?: NodeJS.ProcessEnv): string;
|
|
79
|
+
/**
|
|
80
|
+
* Where the SPFN server binds, including the address a server config may still
|
|
81
|
+
* carry through `.port()` / `.host()`.
|
|
82
|
+
*
|
|
83
|
+
* Those two are deprecated and sit between `spfn.config.js` and the default for
|
|
84
|
+
* one release, so an app that has not moved yet keeps the address it had. Once
|
|
85
|
+
* they are removed this collapses back to {@link resolvePorts} and
|
|
86
|
+
* {@link resolveHost}.
|
|
87
|
+
*/
|
|
88
|
+
declare function resolveServerAddress(config: SpfnAppConfig, deprecated?: {
|
|
89
|
+
port?: number;
|
|
90
|
+
host?: string;
|
|
91
|
+
}, env?: NodeJS.ProcessEnv): {
|
|
92
|
+
port: number;
|
|
93
|
+
host: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export { HOST_DEFAULT, PORT_DEFAULTS, type SpfnAppConfig, type SpfnPorts, loadAppConfig, resolveHost, resolvePorts, resolveServerAddress };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
// src/app-config/index.ts
|
|
6
|
+
var PORT_DEFAULTS = {
|
|
7
|
+
next: 3790,
|
|
8
|
+
server: 8790
|
|
9
|
+
};
|
|
10
|
+
var HOST_DEFAULT = "localhost";
|
|
11
|
+
var CONFIG_FILE_NAMES = [
|
|
12
|
+
"spfn.config.js",
|
|
13
|
+
"spfn.config.mjs"
|
|
14
|
+
];
|
|
15
|
+
async function loadAppConfig(cwd = process.cwd()) {
|
|
16
|
+
for (const fileName of CONFIG_FILE_NAMES) {
|
|
17
|
+
const fullPath = join(cwd, fileName);
|
|
18
|
+
if (!existsSync(fullPath)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const module = await import(pathToFileURL(fullPath).href);
|
|
23
|
+
return module.default ?? {};
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.warn(
|
|
26
|
+
`\u26A0\uFE0F ${fileName} could not be imported \u2014 falling back to defaults for ports and host. ${error instanceof Error ? error.message : String(error)}`
|
|
27
|
+
);
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
function resolvePorts(config, env = process.env) {
|
|
34
|
+
return {
|
|
35
|
+
next: readPort(env.NEXT_PORT) ?? config.ports?.next ?? PORT_DEFAULTS.next,
|
|
36
|
+
server: readPort(env.SPFN_PORT) ?? config.ports?.server ?? PORT_DEFAULTS.server
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function resolveHost(config, env = process.env) {
|
|
40
|
+
return env.SPFN_HOST || config.host || HOST_DEFAULT;
|
|
41
|
+
}
|
|
42
|
+
function resolveServerAddress(config, deprecated = {}, env = process.env) {
|
|
43
|
+
return {
|
|
44
|
+
port: readPort(env.SPFN_PORT) ?? config.ports?.server ?? deprecated.port ?? PORT_DEFAULTS.server,
|
|
45
|
+
host: env.SPFN_HOST || config.host || deprecated.host || HOST_DEFAULT
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function readPort(value) {
|
|
49
|
+
if (!value) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
const port = Number(value);
|
|
53
|
+
return Number.isInteger(port) && port > 0 && port < 65536 ? port : void 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { HOST_DEFAULT, PORT_DEFAULTS, loadAppConfig, resolveHost, resolvePorts, resolveServerAddress };
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/app-config/index.ts"],"names":[],"mappings":";;;;;AA2DO,IAAM,aAAA,GAAgB;AAAA,EACzB,IAAA,EAAM,IAAA;AAAA,EACN,MAAA,EAAQ;AACZ;AAEO,IAAM,YAAA,GAAe;AAE5B,IAAM,iBAAA,GAAoB;AAAA,EACtB,gBAAA;AAAA,EACA;AACJ,CAAA;AASA,eAAsB,aAAA,CAAc,GAAA,GAAc,OAAA,CAAQ,GAAA,EAAI,EAC9D;AACI,EAAA,KAAA,MAAW,YAAY,iBAAA,EACvB;AACI,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,GAAA,EAAK,QAAQ,CAAA;AAEnC,IAAA,IAAI,CAAC,UAAA,CAAW,QAAQ,CAAA,EACxB;AACI,MAAA;AAAA,IACJ;AAEA,IAAA,IACA;AAGI,MAAA,MAAM,MAAA,GAAS,MAAM,OAAO,aAAA,CAAc,QAAQ,CAAA,CAAE,IAAA,CAAA;AAEpD,MAAA,OAAQ,MAAA,CAAO,WAAW,EAAC;AAAA,IAC/B,SACO,KAAA,EACP;AAQI,MAAA,OAAA,CAAQ,IAAA;AAAA,QACJ,CAAA,cAAA,EAAO,QAAQ,CAAA,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ACvE","file":"index.js","sourcesContent":["/**\n * `spfn.config.js` — the app's serving shape, read by both the CLI and the server.\n *\n * The file has existed since `spfn init` started writing it, and until now\n * nothing read it back. It is the one committed place that describes how an app\n * is served, which makes it the right home for the ports: an app that wants a\n * different port says so once here instead of repeating the number across its\n * `server.config.ts`, Dockerfile, compose file, `next.config.ts` and env\n * example, where nothing checks that the copies still agree.\n *\n * This module is deliberately free of side effects. `@spfn/core/config`\n * validates the whole environment schema the moment it is imported, which is\n * fine inside a server and wrong inside a CLI that has not been handed an\n * app's environment yet.\n *\n * @module app-config\n */\n\nimport { existsSync } from 'fs';\nimport { pathToFileURL } from 'url';\nimport { join } from 'path';\n\n/**\n * Ports the app is served on.\n *\n * Two names because two processes are started. Next.js reads `PORT` as its own,\n * so the SPFN server cannot claim that name without the two colliding whenever\n * they run together.\n */\nexport interface SpfnPorts\n{\n /** Next.js frontend. Passed to `next` as `-p`. */\n next?: number;\n\n /** SPFN API server. */\n server?: number;\n}\n\nexport interface SpfnAppConfig\n{\n ports?: SpfnPorts;\n\n /** Host the SPFN API server binds. */\n host?: string;\n\n /** Deployment settings — untouched by this module, kept so the type is whole. */\n [key: string]: unknown;\n}\n\n/**\n * The single place each default exists.\n *\n * Defaults live at the bottom of the chain and nowhere else. A default declared\n * at an input layer — a commander option, a generated entry file, an env schema\n * — cannot be told apart from a value someone supplied, so it silently outranks\n * whatever is below it. Three separate defects in this repository came from\n * exactly that, including an env schema default that forced the environment to\n * be consulted last and made an injected port unreachable.\n */\nexport const PORT_DEFAULTS = {\n next: 3790,\n server: 8790,\n} as const;\n\nexport const HOST_DEFAULT = 'localhost';\n\nconst CONFIG_FILE_NAMES = [\n 'spfn.config.js',\n 'spfn.config.mjs',\n] as const;\n\n/**\n * Read `spfn.config.js` from an app directory.\n *\n * Returns an empty object when there is no file, and also when the file cannot\n * be imported — a malformed deployment config must not stop a server from\n * booting. The caller decides whether the absence is worth reporting.\n */\nexport async function loadAppConfig(cwd: string = process.cwd()): Promise<SpfnAppConfig>\n{\n for (const fileName of CONFIG_FILE_NAMES)\n {\n const fullPath = join(cwd, fileName);\n\n if (!existsSync(fullPath))\n {\n continue;\n }\n\n try\n {\n // A file URL, not a path: on Windows an absolute path is not a\n // valid ESM specifier, and this file is imported at runtime.\n const module = await import(pathToFileURL(fullPath).href);\n\n return (module.default ?? {}) as SpfnAppConfig;\n }\n catch (error)\n {\n // Falling back to defaults, and saying so. A file that exists and\n // cannot be imported is a typo, not an absence — silence would send\n // the server to port 8790 while its own config named another, and\n // the only symptom would be a port nobody chose.\n //\n // console, not the server logger: this runs inside the CLI too,\n // before any logger is configured.\n console.warn(\n `⚠️ ${fileName} could not be imported — falling back to defaults `\n + `for ports and host. ${error instanceof Error ? error.message : String(error)}`,\n );\n\n return {};\n }\n }\n\n return {};\n}\n\n/**\n * The port each process binds, given a loaded config and the environment.\n *\n * Three layers, in this order, and no more: environment variable, then\n * `spfn.config.js`, then the default.\n */\nexport function resolvePorts(\n config: SpfnAppConfig,\n env: NodeJS.ProcessEnv = process.env,\n): { next: number; server: number }\n{\n return {\n next: readPort(env.NEXT_PORT) ?? config.ports?.next ?? PORT_DEFAULTS.next,\n server: readPort(env.SPFN_PORT) ?? config.ports?.server ?? PORT_DEFAULTS.server,\n };\n}\n\n/**\n * The host the SPFN server binds, on the same three layers.\n *\n * `localhost` by default: a container states `SPFN_HOST=0.0.0.0` in its own\n * files, where that decision belongs, rather than every developer machine\n * publishing a dev server to its network.\n */\nexport function resolveHost(\n config: SpfnAppConfig,\n env: NodeJS.ProcessEnv = process.env,\n): string\n{\n return env.SPFN_HOST || config.host || HOST_DEFAULT;\n}\n\n/**\n * Where the SPFN server binds, including the address a server config may still\n * carry through `.port()` / `.host()`.\n *\n * Those two are deprecated and sit between `spfn.config.js` and the default for\n * one release, so an app that has not moved yet keeps the address it had. Once\n * they are removed this collapses back to {@link resolvePorts} and\n * {@link resolveHost}.\n */\nexport function resolveServerAddress(\n config: SpfnAppConfig,\n deprecated: { port?: number; host?: string } = {},\n env: NodeJS.ProcessEnv = process.env,\n): { port: number; host: string }\n{\n return {\n port: readPort(env.SPFN_PORT)\n ?? config.ports?.server\n ?? deprecated.port\n ?? PORT_DEFAULTS.server,\n host: env.SPFN_HOST\n || config.host\n || deprecated.host\n || HOST_DEFAULT,\n };\n}\n\nfunction readPort(value: string | undefined): number | undefined\n{\n if (!value)\n {\n return undefined;\n }\n\n const port = Number(value);\n\n return Number.isInteger(port) && port > 0 && port < 65536 ? port : undefined;\n}\n"]}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -407,27 +407,6 @@ declare const coreEnvSchema: {
|
|
|
407
407
|
} & {
|
|
408
408
|
key: "DB_MAX_ROWS";
|
|
409
409
|
};
|
|
410
|
-
PORT: {
|
|
411
|
-
description: string;
|
|
412
|
-
default: number;
|
|
413
|
-
examples: number[];
|
|
414
|
-
} & {
|
|
415
|
-
type: "number";
|
|
416
|
-
validator: (value: string) => number;
|
|
417
|
-
} & {
|
|
418
|
-
key: "PORT";
|
|
419
|
-
};
|
|
420
|
-
HOST: {
|
|
421
|
-
description: string;
|
|
422
|
-
default: string;
|
|
423
|
-
required: boolean;
|
|
424
|
-
examples: string[];
|
|
425
|
-
} & {
|
|
426
|
-
type: "string";
|
|
427
|
-
validator: (value: string) => string;
|
|
428
|
-
} & {
|
|
429
|
-
key: "HOST";
|
|
430
|
-
};
|
|
431
410
|
SERVER_TIMEOUT: {
|
|
432
411
|
description: string;
|
|
433
412
|
default: number;
|
|
@@ -1017,27 +996,6 @@ declare const registry: _spfn_core_env.EnvRegistry<{
|
|
|
1017
996
|
} & {
|
|
1018
997
|
key: "DB_MAX_ROWS";
|
|
1019
998
|
};
|
|
1020
|
-
PORT: {
|
|
1021
|
-
description: string;
|
|
1022
|
-
default: number;
|
|
1023
|
-
examples: number[];
|
|
1024
|
-
} & {
|
|
1025
|
-
type: "number";
|
|
1026
|
-
validator: (value: string) => number;
|
|
1027
|
-
} & {
|
|
1028
|
-
key: "PORT";
|
|
1029
|
-
};
|
|
1030
|
-
HOST: {
|
|
1031
|
-
description: string;
|
|
1032
|
-
default: string;
|
|
1033
|
-
required: boolean;
|
|
1034
|
-
examples: string[];
|
|
1035
|
-
} & {
|
|
1036
|
-
type: "string";
|
|
1037
|
-
validator: (value: string) => string;
|
|
1038
|
-
} & {
|
|
1039
|
-
key: "HOST";
|
|
1040
|
-
};
|
|
1041
999
|
SERVER_TIMEOUT: {
|
|
1042
1000
|
description: string;
|
|
1043
1001
|
default: number;
|
|
@@ -1620,27 +1578,6 @@ declare const env: _spfn_core_env.InferEnvType<{
|
|
|
1620
1578
|
} & {
|
|
1621
1579
|
key: "DB_MAX_ROWS";
|
|
1622
1580
|
};
|
|
1623
|
-
PORT: {
|
|
1624
|
-
description: string;
|
|
1625
|
-
default: number;
|
|
1626
|
-
examples: number[];
|
|
1627
|
-
} & {
|
|
1628
|
-
type: "number";
|
|
1629
|
-
validator: (value: string) => number;
|
|
1630
|
-
} & {
|
|
1631
|
-
key: "PORT";
|
|
1632
|
-
};
|
|
1633
|
-
HOST: {
|
|
1634
|
-
description: string;
|
|
1635
|
-
default: string;
|
|
1636
|
-
required: boolean;
|
|
1637
|
-
examples: string[];
|
|
1638
|
-
} & {
|
|
1639
|
-
type: "string";
|
|
1640
|
-
validator: (value: string) => string;
|
|
1641
|
-
} & {
|
|
1642
|
-
key: "HOST";
|
|
1643
|
-
};
|
|
1644
1581
|
SERVER_TIMEOUT: {
|
|
1645
1582
|
description: string;
|
|
1646
1583
|
default: number;
|
package/dist/config/index.js
CHANGED
|
@@ -251,17 +251,17 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
251
251
|
// ========================================================================
|
|
252
252
|
// Server - Core
|
|
253
253
|
// ========================================================================
|
|
254
|
-
PORT
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
254
|
+
// PORT and HOST are deliberately absent.
|
|
255
|
+
//
|
|
256
|
+
// They were declared here with defaults of 4000 and 'localhost', and a
|
|
257
|
+
// schema default is indistinguishable from a value someone set — so
|
|
258
|
+
// `env.PORT` was never undefined, and the resolution order had to consult
|
|
259
|
+
// the environment last to avoid it winning every time. That is what made an
|
|
260
|
+
// injected port unreachable. The server's address now resolves through
|
|
261
|
+
// `@spfn/core/app-config`: SPFN_PORT, then spfn.config.js, then the
|
|
262
|
+
// default, with the default existing in exactly one place.
|
|
263
|
+
//
|
|
264
|
+
// `PORT` is also Next.js's own variable, and two processes are started.
|
|
265
265
|
// ========================================================================
|
|
266
266
|
// Server - Timeout
|
|
267
267
|
// ========================================================================
|
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,QAAA,EAAU,QAAQ,CAAC,OAAA,EAAS,eAAe,SAAA,EAAW,YAAA,EAAc,MAAM,CAAA,EAAY;AAAA,IAClF,WAAA,EAAa,6BAAA;AAAA,IACb,OAAA,EAAS,OAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,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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AA;AAAA,EAMD,8BAA8B,UAAA,CAAW;AAAA,IACrC,WAAA,EAAa,0TAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACZ;AACL,CAAC;;;ACldM,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', 'staging', '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 // 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_READ_MAX: envNumber({\n description: 'Maximum connections for the read-replica pool. Defaults to DB_POOL_MAX. Set lower so write.max + read.max stays under the server max_connections (each process otherwise opens up to 2 × DB_POOL_MAX when a replica is configured).',\n required: false,\n examples: [5, 10, 20],\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 TRANSACTION_IDLE_TIMEOUT: envNumber({\n description: 'Max time (ms) a transaction may sit idle (no running query) before Postgres terminates it and reclaims the pooled connection. Guards against external I/O held inside a transaction starving the connection pool. 0 disables.',\n default: 30000,\n examples: [10000, 30000, 0],\n }),\n\n // ========================================================================\n // Jobs (pg-boss)\n // ========================================================================\n\n JOB_POLLING_INTERVAL_SECONDS: envNumber({\n description: 'How often each pg-boss worker polls the DB for new jobs (seconds). Lower = faster pickup, more idle SELECT load; higher = less DB chatter, slower pickup. Per-job override via job options.',\n default: 2,\n examples: [1, 2, 10],\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 // Database - Migrations\n // ========================================================================\n\n SPFN_ALLOW_PENDING_MIGRATIONS: envBoolean({\n description: 'Start the server even when a function package or the project has migrations the database has not applied. Off by default: a server booted with pending migrations fails only at request time, as an opaque 500. The flag equivalent is `spfn dev --allow-pending-migrations`.',\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 CACHE_MAX_RETRIES_PER_REQUEST: envNumber({\n description: 'Max ioredis retries per command before it rejects (fail fast instead of hanging on a cache outage). ioredis default is 20.',\n default: 3,\n examples: [1, 3, 20],\n }),\n\n CACHE_ENABLE_OFFLINE_QUEUE: envBoolean({\n description: 'Queue commands while the cache is disconnected (true) vs reject immediately for strict fail-fast (false). Default true keeps resilience to brief blips.',\n default: true,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Query limits\n // ========================================================================\n\n DB_MAX_ROWS: envNumber({\n description: 'Safety ceiling for rows returned by repository findMany (0 = unlimited). When >0, an unbounded query is capped and an explicit limit is clamped, guarding against accidentally loading a whole large table.',\n default: 0,\n examples: [0, 1000, 10000],\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 (must be less than k8s terminationGracePeriodSeconds minus preStop sleep, with safety margin)',\n default: 280000,\n examples: [30000, 120000, 280000],\n }),\n\n // ========================================================================\n // Fetch (Node.js undici) - outbound HTTP request timeout\n // ========================================================================\n\n FETCH_CONNECT_TIMEOUT: envNumber({\n description: 'Fetch TCP connection timeout in milliseconds (time to establish socket connection to upstream server)',\n default: 10000,\n examples: [5000, 10000, 30000],\n }),\n\n FETCH_HEADERS_TIMEOUT: envNumber({\n description: 'Fetch headers timeout in milliseconds (time to receive response headers after request sent)',\n default: 300000,\n examples: [120000, 300000, 600000],\n }),\n\n FETCH_BODY_TIMEOUT: envNumber({\n description: 'Fetch body timeout in milliseconds (time between body data chunks from upstream server)',\n default: 300000,\n examples: [120000, 300000, 600000],\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 RPC_PROXY_TIMEOUT: envNumber({\n description: 'RPC proxy request timeout in milliseconds (AbortController timeout for proxied requests to backend, should be shorter than FETCH_HEADERS_TIMEOUT)',\n default: 120000,\n nextjs: true,\n examples: [60000, 120000, 280000],\n }),\n\n // ========================================================================\n // Proxy → Backend trust (HMAC signing)\n // ========================================================================\n\n SPFN_PROXY_SECRET: envString({\n description: 'Shared secret for signing proxy→backend requests (HMAC-SHA256). Read by BOTH processes — the Next.js proxy (to sign) and the SPFN backend (to verify) — so it belongs in .env.local (loaded by both; the backend reads it via loadEnv, Next.js reads it server-side without exposing it to the browser). Set the SAME value on both. Leave unset to disable proxy-guard signing.',\n required: false,\n sensitive: true,\n nextjs: true,\n examples: ['<32+ byte random hex>', 'v2:<32+ byte random hex>'],\n }),\n\n SPFN_PROXY_SECRET_PREVIOUS: envString({\n description: 'Previous (grace) proxy keys still accepted for verification during rotation — comma-separated <keyId>:<secret>. The proxy never signs with these; they only keep requests signed with the prior key verifying until a rollout settles. Backend-only (verification), so it belongs in .env.server, NOT exposed to the Next.js process.',\n required: false,\n sensitive: true,\n nextjs: false,\n examples: ['v1:<old secret>', 'v1:<old>,v0:<older>'],\n }),\n\n TRUSTED_PROXY_HOPS: envNumber({\n description: 'Number of trusted reverse proxies in front of the Next.js proxy (e.g. cloud LB + nginx = 2). Read by the proxy to extract the real client IP from the inbound X-Forwarded-For (counting from the right, which your own infra appends and a client cannot spoof) and forward it to the backend for rate limiting. Set it to your actual hop count; too low trusts a client-spoofable entry, too high collapses users behind a shared proxy IP.',\n default: 1,\n nextjs: true,\n examples: [1, 2, 3],\n }),\n\n // ========================================================================\n // Rate limiting (global default limiter)\n // ========================================================================\n\n RATE_LIMIT_MODE: envEnum(['off', 'on'] as const, {\n description: 'Global default rate limiter. \"off\": only routes tagged with rateLimitPolicy() are limited. \"on\": every named-middleware route gets the default limit too (opt out per route with .skip([\\'rateLimit\\'])). Health/SSE/WebSocket endpoints are always exempt. Overridden by defineServerConfig().rateLimit({ mode }).',\n default: 'off',\n }),\n\n RATE_LIMIT_DEFAULT_LIMIT: envNumber({\n description: 'Max requests per window for the global default limiter (RATE_LIMIT_MODE=on), counted per route and per client IP.',\n default: 100,\n examples: [60, 100, 300],\n }),\n\n RATE_LIMIT_DEFAULT_WINDOW_MS: envNumber({\n description: 'Window length in milliseconds for the global default limiter.',\n default: 60000,\n examples: [1000, 60000],\n }),\n\n RATE_LIMIT_FAIL_CLOSED: envBoolean({\n description: 'When the cache (Redis/Valkey) backing the limiter is unavailable, reject with 429 instead of counting in-process. Default false: the limiter falls back to per-process counters, so limits still apply — but the effective limit multiplies by the instance count, since each process counts alone. Set true only where a shared count is required and refusing traffic is preferable to a looser one.',\n default: false,\n }),\n\n // ========================================================================\n // Outbound request safety (SSRF)\n // ========================================================================\n\n SAFE_FETCH_BLOCK_PRIVATE_IPS: envBoolean({\n description: 'Default for safeFetch (@spfn/core/security): block outbound requests that resolve to private/reserved IP ranges, including the cloud metadata address. Keep true in production; set false only for trusted internal-network calls in development. Overridden by defineServerConfig().outboundFetch({ blockPrivateIps }).',\n default: true,\n }),\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();\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/schema.ts","../../src/config/index.ts"],"names":[],"mappings":";;;AAsCO,IAAM,gBAAgB,eAAA,CAAgB;AAAA;AAAA;AAAA;AAAA,EAKzC,QAAA,EAAU,QAAQ,CAAC,OAAA,EAAS,eAAe,SAAA,EAAW,YAAA,EAAc,MAAM,CAAA,EAAY;AAAA,IAClF,WAAA,EAAa,6BAAA;AAAA,IACb,OAAA,EAAS,OAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,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,IAC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EAED,oBAAoB,SAAA,CAAU;AAAA,IAC1B,WAAA,EAAa,+aAAA;AAAA,IACb,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,IAAA;AAAA,IACR,QAAA,EAAU,CAAC,CAAA,EAAG,CAAA,EAAG,CAAC;AAAA,GACrB,CAAA;AAAA;AAAA;AAAA;AAAA,EAMD,eAAA,EAAiB,OAAA,CAAQ,CAAC,KAAA,EAAO,IAAI,CAAA,EAAY;AAAA,IAC7C,WAAA,EAAa,CAAA,iTAAA,CAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACZ,CAAA;AAAA,EAED,0BAA0B,SAAA,CAAU;AAAA,IAChC,WAAA,EAAa,mHAAA;AAAA,IACb,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU,CAAC,EAAA,EAAI,GAAA,EAAK,GAAG;AAAA,GAC1B,CAAA;AAAA,EAED,8BAA8B,SAAA,CAAU;AAAA,IACpC,WAAA,EAAa,+DAAA;AAAA,IACb,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU,CAAC,GAAA,EAAM,GAAK;AAAA,GACzB,CAAA;AAAA,EAED,wBAAwB,UAAA,CAAW;AAAA,IAC/B,WAAA,EAAa,6YAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACZ,CAAA;AAAA;AAAA;AAAA;AAAA,EAMD,8BAA8B,UAAA,CAAW;AAAA,IACrC,WAAA,EAAa,0TAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACZ;AACL,CAAC;;;ACjdM,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', 'staging', '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 // 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_READ_MAX: envNumber({\n description: 'Maximum connections for the read-replica pool. Defaults to DB_POOL_MAX. Set lower so write.max + read.max stays under the server max_connections (each process otherwise opens up to 2 × DB_POOL_MAX when a replica is configured).',\n required: false,\n examples: [5, 10, 20],\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 TRANSACTION_IDLE_TIMEOUT: envNumber({\n description: 'Max time (ms) a transaction may sit idle (no running query) before Postgres terminates it and reclaims the pooled connection. Guards against external I/O held inside a transaction starving the connection pool. 0 disables.',\n default: 30000,\n examples: [10000, 30000, 0],\n }),\n\n // ========================================================================\n // Jobs (pg-boss)\n // ========================================================================\n\n JOB_POLLING_INTERVAL_SECONDS: envNumber({\n description: 'How often each pg-boss worker polls the DB for new jobs (seconds). Lower = faster pickup, more idle SELECT load; higher = less DB chatter, slower pickup. Per-job override via job options.',\n default: 2,\n examples: [1, 2, 10],\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 // Database - Migrations\n // ========================================================================\n\n SPFN_ALLOW_PENDING_MIGRATIONS: envBoolean({\n description: 'Start the server even when a function package or the project has migrations the database has not applied. Off by default: a server booted with pending migrations fails only at request time, as an opaque 500. The flag equivalent is `spfn dev --allow-pending-migrations`.',\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 CACHE_MAX_RETRIES_PER_REQUEST: envNumber({\n description: 'Max ioredis retries per command before it rejects (fail fast instead of hanging on a cache outage). ioredis default is 20.',\n default: 3,\n examples: [1, 3, 20],\n }),\n\n CACHE_ENABLE_OFFLINE_QUEUE: envBoolean({\n description: 'Queue commands while the cache is disconnected (true) vs reject immediately for strict fail-fast (false). Default true keeps resilience to brief blips.',\n default: true,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Query limits\n // ========================================================================\n\n DB_MAX_ROWS: envNumber({\n description: 'Safety ceiling for rows returned by repository findMany (0 = unlimited). When >0, an unbounded query is capped and an explicit limit is clamped, guarding against accidentally loading a whole large table.',\n default: 0,\n examples: [0, 1000, 10000],\n }),\n\n // ========================================================================\n // Server - Core\n // ========================================================================\n\n // PORT and HOST are deliberately absent.\n //\n // They were declared here with defaults of 4000 and 'localhost', and a\n // schema default is indistinguishable from a value someone set — so\n // `env.PORT` was never undefined, and the resolution order had to consult\n // the environment last to avoid it winning every time. That is what made an\n // injected port unreachable. The server's address now resolves through\n // `@spfn/core/app-config`: SPFN_PORT, then spfn.config.js, then the\n // default, with the default existing in exactly one place.\n //\n // `PORT` is also Next.js's own variable, and two processes are started.\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 (must be less than k8s terminationGracePeriodSeconds minus preStop sleep, with safety margin)',\n default: 280000,\n examples: [30000, 120000, 280000],\n }),\n\n // ========================================================================\n // Fetch (Node.js undici) - outbound HTTP request timeout\n // ========================================================================\n\n FETCH_CONNECT_TIMEOUT: envNumber({\n description: 'Fetch TCP connection timeout in milliseconds (time to establish socket connection to upstream server)',\n default: 10000,\n examples: [5000, 10000, 30000],\n }),\n\n FETCH_HEADERS_TIMEOUT: envNumber({\n description: 'Fetch headers timeout in milliseconds (time to receive response headers after request sent)',\n default: 300000,\n examples: [120000, 300000, 600000],\n }),\n\n FETCH_BODY_TIMEOUT: envNumber({\n description: 'Fetch body timeout in milliseconds (time between body data chunks from upstream server)',\n default: 300000,\n examples: [120000, 300000, 600000],\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 RPC_PROXY_TIMEOUT: envNumber({\n description: 'RPC proxy request timeout in milliseconds (AbortController timeout for proxied requests to backend, should be shorter than FETCH_HEADERS_TIMEOUT)',\n default: 120000,\n nextjs: true,\n examples: [60000, 120000, 280000],\n }),\n\n // ========================================================================\n // Proxy → Backend trust (HMAC signing)\n // ========================================================================\n\n SPFN_PROXY_SECRET: envString({\n description: 'Shared secret for signing proxy→backend requests (HMAC-SHA256). Read by BOTH processes — the Next.js proxy (to sign) and the SPFN backend (to verify) — so it belongs in .env.local (loaded by both; the backend reads it via loadEnv, Next.js reads it server-side without exposing it to the browser). Set the SAME value on both. Leave unset to disable proxy-guard signing.',\n required: false,\n sensitive: true,\n nextjs: true,\n examples: ['<32+ byte random hex>', 'v2:<32+ byte random hex>'],\n }),\n\n SPFN_PROXY_SECRET_PREVIOUS: envString({\n description: 'Previous (grace) proxy keys still accepted for verification during rotation — comma-separated <keyId>:<secret>. The proxy never signs with these; they only keep requests signed with the prior key verifying until a rollout settles. Backend-only (verification), so it belongs in .env.server, NOT exposed to the Next.js process.',\n required: false,\n sensitive: true,\n nextjs: false,\n examples: ['v1:<old secret>', 'v1:<old>,v0:<older>'],\n }),\n\n TRUSTED_PROXY_HOPS: envNumber({\n description: 'Number of trusted reverse proxies in front of the Next.js proxy (e.g. cloud LB + nginx = 2). Read by the proxy to extract the real client IP from the inbound X-Forwarded-For (counting from the right, which your own infra appends and a client cannot spoof) and forward it to the backend for rate limiting. Set it to your actual hop count; too low trusts a client-spoofable entry, too high collapses users behind a shared proxy IP.',\n default: 1,\n nextjs: true,\n examples: [1, 2, 3],\n }),\n\n // ========================================================================\n // Rate limiting (global default limiter)\n // ========================================================================\n\n RATE_LIMIT_MODE: envEnum(['off', 'on'] as const, {\n description: 'Global default rate limiter. \"off\": only routes tagged with rateLimitPolicy() are limited. \"on\": every named-middleware route gets the default limit too (opt out per route with .skip([\\'rateLimit\\'])). Health/SSE/WebSocket endpoints are always exempt. Overridden by defineServerConfig().rateLimit({ mode }).',\n default: 'off',\n }),\n\n RATE_LIMIT_DEFAULT_LIMIT: envNumber({\n description: 'Max requests per window for the global default limiter (RATE_LIMIT_MODE=on), counted per route and per client IP.',\n default: 100,\n examples: [60, 100, 300],\n }),\n\n RATE_LIMIT_DEFAULT_WINDOW_MS: envNumber({\n description: 'Window length in milliseconds for the global default limiter.',\n default: 60000,\n examples: [1000, 60000],\n }),\n\n RATE_LIMIT_FAIL_CLOSED: envBoolean({\n description: 'When the cache (Redis/Valkey) backing the limiter is unavailable, reject with 429 instead of counting in-process. Default false: the limiter falls back to per-process counters, so limits still apply — but the effective limit multiplies by the instance count, since each process counts alone. Set true only where a shared count is required and refusing traffic is preferable to a looser one.',\n default: false,\n }),\n\n // ========================================================================\n // Outbound request safety (SSRF)\n // ========================================================================\n\n SAFE_FETCH_BLOCK_PRIVATE_IPS: envBoolean({\n description: 'Default for safeFetch (@spfn/core/security): block outbound requests that resolve to private/reserved IP ranges, including the cloud metadata address. Keep true in production; set false only for trusted internal-network calls in development. Overridden by defineServerConfig().outboundFetch({ blockPrivateIps }).',\n default: true,\n }),\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();\n"]}
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as Router } from '../router-
|
|
2
|
-
import { C as ContractDocument, a as ContractViolation, b as ContractOperation, c as ContractSnapshot } from '../types-
|
|
3
|
-
export { d as CompatibilityPolicy, e as ContractRequest, f as ContractViolationKind, J as JsonSchema } from '../types-
|
|
4
|
-
import '../define-middleware-
|
|
1
|
+
import { R as Router } from '../router-Cy7rAfmj.js';
|
|
2
|
+
import { C as ContractDocument, a as ContractViolation, b as ContractOperation, c as ContractSnapshot } from '../types-CfYVhIQ9.js';
|
|
3
|
+
export { d as CompatibilityPolicy, e as ContractRequest, f as ContractViolationKind, J as JsonSchema } from '../types-CfYVhIQ9.js';
|
|
4
|
+
import '../define-middleware-CVKgqo8S.js';
|
|
5
5
|
import 'hono';
|
|
6
6
|
import '@sinclair/typebox';
|
|
7
7
|
import 'hono/utils/http-status';
|
package/dist/db/index.d.ts
CHANGED
|
@@ -246,7 +246,7 @@ declare function getDatabase<TDatabase extends DrizzleDatabase = DefaultDatabase
|
|
|
246
246
|
* // Set custom database instances (testing)
|
|
247
247
|
* const writeClient = postgres('postgresql://primary:5432/mydb');
|
|
248
248
|
* const readClient = postgres('postgresql://replica:5432/mydb');
|
|
249
|
-
* setDatabase(drizzle(writeClient), drizzle(readClient));
|
|
249
|
+
* setDatabase(drizzle({ client: writeClient }), drizzle({ client: readClient }));
|
|
250
250
|
*
|
|
251
251
|
* // Clear instances (not recommended - use closeDatabase() instead)
|
|
252
252
|
* setDatabase(undefined, undefined);
|