@shivaedev/server 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +2 -0
- package/dist/appDatabase.d.ts +2 -1
- package/dist/appDatabase.d.ts.map +1 -1
- package/dist/appDatabase.js +5 -4
- package/dist/appDatabase.js.map +1 -1
- package/package.json +7 -7
- package/src/appDatabase.ts +8 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.15.0 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Accept `config.clock` on `appDatabase` and `appHost` for stories that explicitly exercise database lifecycle timers with their test clock. Application handlers and jobs keep their application clock.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Run application database pool maintenance and change-listener heartbeats, deadlines and renewal on the live clock so a running host can advance its story clock by days while retaining database access, worker writes and change hints.
|
|
12
|
+
|
|
13
|
+
### Breaking
|
|
14
|
+
|
|
15
|
+
- Database lifecycle timers use the live clock instead of the caller's clock by default. Stories that advance time to exercise pool expiry, listener renewal or heartbeat deadlines must pass their native `yield* Clock.Clock` as `config.clock` to `appDatabase` or `appHost`.
|
|
16
|
+
|
|
3
17
|
## 0.14.0 - 2026-10-31
|
|
4
18
|
|
|
5
19
|
### Added
|
package/README.md
CHANGED
|
@@ -174,6 +174,8 @@ Set `config.maxConnections` on `appDatabase` or a migrated `appHost` to bound th
|
|
|
174
174
|
|
|
175
175
|
The host defaults to `config.connectionTTL: "10 minutes"` and `config.idleTimeout: "1 minute"`. Both accept native Effect durations; `config.minConnections` controls the idle floor. Lifetime expiry replaces a query connection on its next checkout, allowing active queries and transactions to finish. The reserved change listener renews on the same lifetime, resynchronizes live subscribers across renewal and resumes committed hints, including with a separate listener URL. No PostgreSQL `idle_session_timeout` is set: an idle LISTEN session must stay alive until its owner renews it.
|
|
176
176
|
|
|
177
|
+
Database pool maintenance and change-listener heartbeats, deadlines, retries and renewal use the live clock. A story can advance its application clock by days while the host and job worker keep running; handlers and jobs still see the advanced application time. For stories about database lifecycle timers, pass the story's native `Clock.Clock` service as `config.clock` on `appDatabase` or `appHost`. This option applies to both application and separate listener pools; it does not change the application clock or migration wait timers.
|
|
178
|
+
|
|
177
179
|
For a deployment behind a proxy, set `HOST=0.0.0.0` and `TRUSTED_PROXY` to a comma-separated list of proxy peer IPs or CIDR ranges (IPv4 or IPv6), or use `config.host` and `config.trustedProxy`. Only matching peers may supply `X-Forwarded-Host` and `X-Forwarded-Proto` (`http` or `https`) for the guard's same-origin check; the proxy must overwrite both headers and preserve Origin. A single authority is required, and comma-separated forwarding chains are refused. IPv4-mapped IPv6 peers match their IPv4 address. A session host bound to a non-loopback address refuses to boot without `TRUSTED_PROXY` or `config.trustedProxy`, with a typed `TrustedProxyRequired` error from `@shivaedev/server/TrustedProxyRequired.ts` naming both settings and how to supply proxy peer addresses or CIDR ranges. Local loopback hosts keep working without proxy trust; `policy: "loopback"` does not use proxy trust. Malformed addresses or ranges fail `appHost` startup with a typed `ConfigError`. The starter's Railway deployment works out of the box: its web configuration supplies `TRUSTED_PROXY=100.64.0.0/10` and `AUTH_CLIENT_IP_HEADER=x-real-ip`, so matching peers supply forwarded client IPs for auth and the HTTPS authority for RPC origin checks. Set `PUBLIC_URL` to the app's HTTPS URL for secure session cookies. NDJSON and the application's session Origin policy still apply. See the [deployment quickstart](https://github.com/ShivaeDev/platform/blob/main/docs/framework/quickstart.md#deploy).
|
|
178
180
|
|
|
179
181
|
Build application handlers with `Api.application.toLayer(...)` (and `Api.application.of(...)` for an Effect-built handler map), then pass the full `Api` to the host and client. `Api.application` is the native RPC group without the reserved `$changes` stream; the host supplies that handler. The explicit `Api.omit("<namespace>.$changes")` form also works.
|
package/dist/appDatabase.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as PgClient from "@effect/sql-pg/PgClient";
|
|
2
|
-
import { Config, Layer, Redacted } from "effect";
|
|
2
|
+
import { Clock, Config, Layer, Redacted } from "effect";
|
|
3
3
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
4
4
|
import { Migrator } from "effect/sql";
|
|
5
5
|
import { type PostgresChangesOptions } from "@shivaedev/sql/postgresChanges.ts";
|
|
@@ -7,6 +7,7 @@ import { type PostgresOptions } from "@shivaedev/sql/postgresLayer.ts";
|
|
|
7
7
|
import type { AppDatabaseOptions } from "#appHost.ts";
|
|
8
8
|
export interface DatabaseConfig extends PostgresOptions {
|
|
9
9
|
readonly changes?: Partial<Omit<PostgresChangesOptions, "client" | "listenerClient" | "connectionSetting" | "connectionTTL" | "resync">>;
|
|
10
|
+
readonly clock?: Clock.Clock;
|
|
10
11
|
readonly databaseUrl?: Redacted.Redacted<string>;
|
|
11
12
|
readonly listenDatabaseUrl?: Redacted.Redacted<string>;
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appDatabase.d.ts","sourceRoot":"","sources":["../src/appDatabase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAoC,KAAK,EAAU,QAAQ,EAAY,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"appDatabase.d.ts","sourceRoot":"","sources":["../src/appDatabase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAoC,KAAK,EAAU,QAAQ,EAAY,MAAM,QAAQ,CAAC;AAC5G,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMtC,OAAO,EAAE,KAAK,sBAAsB,EAAmB,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,iCAAiC,CAAC;AAEtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,cAAe,SAAQ,eAAe;IACtD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,QAAQ,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,eAAe,GAAG,QAAQ,CAAC,CAAC,CAAC;IACzI,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjD,QAAQ,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CACvD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,shBAmD1E"}
|
package/dist/appDatabase.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import * as PgClient from "@effect/sql-pg/PgClient";
|
|
3
|
-
import { Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
|
|
3
|
+
import { Clock, Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
|
|
4
4
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
5
5
|
import { Migrator } from "effect/sql";
|
|
6
6
|
import { LiveServer } from "@shivaedev/contract/LiveServer.ts";
|
|
@@ -17,7 +17,8 @@ export function appDatabase(options) {
|
|
|
17
17
|
"connectionTTL": options.config?.connectionTTL ?? "10 minutes",
|
|
18
18
|
idleTimeout: options.config?.idleTimeout ?? "1 minute",
|
|
19
19
|
};
|
|
20
|
-
const
|
|
20
|
+
const clock = Layer.succeed(Clock.Clock, config.clock ?? Clock.Clock.defaultValue());
|
|
21
|
+
const pool = Layer.unwrap(Effect.map(options.config?.databaseUrl === undefined ? Config.Redacted("DATABASE_URL") : Effect.succeed(options.config.databaseUrl), (url) => postgresLayer(url, config).pipe(Layer.provide(clock))));
|
|
21
22
|
const prepared = Layer.effectDiscard(prepareMigrations(options.migrations)).pipe(Layer.provideMerge(pool));
|
|
22
23
|
const live = LiveServer.layer.pipe(Layer.provideMerge(Reactivity.layer));
|
|
23
24
|
const migrations = options.migrations;
|
|
@@ -35,7 +36,7 @@ export function appDatabase(options) {
|
|
|
35
36
|
const listenUrl = options.config?.listenDatabaseUrl ?? Option.getOrUndefined(yield* Config.Redacted("LISTEN_DATABASE_URL").pipe(Config.option));
|
|
36
37
|
const listenerClient = listenUrl === undefined
|
|
37
38
|
? client
|
|
38
|
-
: yield* Effect.map(Layer.build(postgresLayer(listenUrl, { ...config, maxConnections: 1, minConnections: 0 })), (context) => Context.get(context, PgClient.PgClient));
|
|
39
|
+
: yield* Effect.map(Layer.build(postgresLayer(listenUrl, { ...config, maxConnections: 1, minConnections: 0 }).pipe(Layer.provide(clock))), (context) => Context.get(context, PgClient.PgClient));
|
|
39
40
|
let connectionSetting = options.config?.databaseUrl === undefined ? "DATABASE_URL" : "config.databaseUrl";
|
|
40
41
|
if (listenUrl !== undefined) {
|
|
41
42
|
connectionSetting = options.config?.listenDatabaseUrl === undefined ? "LISTEN_DATABASE_URL" : "config.listenDatabaseUrl";
|
|
@@ -48,7 +49,7 @@ export function appDatabase(options) {
|
|
|
48
49
|
"connectionTTL": config.connectionTTL,
|
|
49
50
|
listenerClient,
|
|
50
51
|
resync: hints.resync(),
|
|
51
|
-
});
|
|
52
|
+
}).pipe(Layer.provide(clock));
|
|
52
53
|
})).pipe(Layer.provideMerge(base));
|
|
53
54
|
}
|
|
54
55
|
function prepareMigrations(migrations) {
|
package/dist/appDatabase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appDatabase.js","sour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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "The Effect application host: HTTP and RPC serving, health, OTLP export, database and migrations, and development mode",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -49,21 +49,21 @@
|
|
|
49
49
|
"@shivaedev/contract": "0.30.0",
|
|
50
50
|
"@shivaedev/errors": "0.4.0",
|
|
51
51
|
"@shivaedev/http": "0.3.1",
|
|
52
|
-
"@shivaedev/identity": "0.
|
|
52
|
+
"@shivaedev/identity": "0.14.0",
|
|
53
53
|
"@shivaedev/local-postgres": "0.8.0",
|
|
54
|
-
"@shivaedev/sql": "0.
|
|
54
|
+
"@shivaedev/sql": "0.29.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@effect/platform-node": "4.0.6",
|
|
58
58
|
"@effect/sql-pg": "4.0.6",
|
|
59
59
|
"@effect/vitest": "4.0.6",
|
|
60
60
|
"@shivaedev/access": "0.3.4",
|
|
61
|
-
"@shivaedev/admin": "0.16.
|
|
62
|
-
"@shivaedev/jobs": "0.28.
|
|
61
|
+
"@shivaedev/admin": "0.16.1",
|
|
62
|
+
"@shivaedev/jobs": "0.28.2",
|
|
63
63
|
"@shivaedev/quality": "0.52.0",
|
|
64
64
|
"@shivaedev/test": "0.12.0",
|
|
65
|
-
"@shivaedev/test-sql": "0.15.
|
|
66
|
-
"@shivaedev/test-story": "0.31.
|
|
65
|
+
"@shivaedev/test-sql": "0.15.2",
|
|
66
|
+
"@shivaedev/test-story": "0.31.2",
|
|
67
67
|
"@types/node": "24.19.2",
|
|
68
68
|
"better-auth": "1.7.12",
|
|
69
69
|
"effect": "4.0.6",
|
package/src/appDatabase.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import * as PgClient from "@effect/sql-pg/PgClient";
|
|
3
|
-
import { Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
|
|
3
|
+
import { Clock, Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
|
|
4
4
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
5
5
|
import { Migrator } from "effect/sql";
|
|
6
6
|
import { LiveServer } from "@shivaedev/contract/LiveServer.ts";
|
|
@@ -15,6 +15,7 @@ import type { AppDatabaseOptions } from "#appHost.ts";
|
|
|
15
15
|
|
|
16
16
|
export interface DatabaseConfig extends PostgresOptions {
|
|
17
17
|
readonly changes?: Partial<Omit<PostgresChangesOptions, "client" | "listenerClient" | "connectionSetting" | "connectionTTL" | "resync">>;
|
|
18
|
+
readonly clock?: Clock.Clock;
|
|
18
19
|
readonly databaseUrl?: Redacted.Redacted<string>;
|
|
19
20
|
readonly listenDatabaseUrl?: Redacted.Redacted<string>;
|
|
20
21
|
}
|
|
@@ -25,9 +26,10 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
|
|
|
25
26
|
"connectionTTL": options.config?.connectionTTL ?? "10 minutes",
|
|
26
27
|
idleTimeout: options.config?.idleTimeout ?? "1 minute",
|
|
27
28
|
} satisfies DatabaseConfig;
|
|
29
|
+
const clock = Layer.succeed(Clock.Clock, config.clock ?? Clock.Clock.defaultValue());
|
|
28
30
|
const pool = Layer.unwrap(
|
|
29
31
|
Effect.map(options.config?.databaseUrl === undefined ? Config.Redacted("DATABASE_URL") : Effect.succeed(options.config.databaseUrl), (url) =>
|
|
30
|
-
postgresLayer(url, config),
|
|
32
|
+
postgresLayer(url, config).pipe(Layer.provide(clock)),
|
|
31
33
|
),
|
|
32
34
|
);
|
|
33
35
|
const prepared = Layer.effectDiscard(prepareMigrations(options.migrations)).pipe(Layer.provideMerge(pool));
|
|
@@ -50,8 +52,9 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
|
|
|
50
52
|
const listenerClient =
|
|
51
53
|
listenUrl === undefined
|
|
52
54
|
? client
|
|
53
|
-
: yield* Effect.map(
|
|
54
|
-
|
|
55
|
+
: yield* Effect.map(
|
|
56
|
+
Layer.build(postgresLayer(listenUrl, { ...config, maxConnections: 1, minConnections: 0 }).pipe(Layer.provide(clock))),
|
|
57
|
+
(context) => Context.get(context, PgClient.PgClient),
|
|
55
58
|
);
|
|
56
59
|
let connectionSetting = options.config?.databaseUrl === undefined ? "DATABASE_URL" : "config.databaseUrl";
|
|
57
60
|
if (listenUrl !== undefined) {
|
|
@@ -65,7 +68,7 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
|
|
|
65
68
|
"connectionTTL": config.connectionTTL,
|
|
66
69
|
listenerClient,
|
|
67
70
|
resync: hints.resync(),
|
|
68
|
-
});
|
|
71
|
+
}).pipe(Layer.provide(clock));
|
|
69
72
|
}),
|
|
70
73
|
).pipe(Layer.provideMerge(base));
|
|
71
74
|
}
|