@shivaedev/server 0.29.1 → 0.30.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 +6 -0
- package/README.md +31 -24
- package/dist/AppHostInput.d.ts +2 -0
- package/dist/AppHostInput.d.ts.map +1 -1
- package/dist/appDatabase.d.ts +2 -0
- package/dist/appDatabase.d.ts.map +1 -1
- package/dist/appDatabase.js +2 -0
- package/dist/appDatabase.js.map +1 -1
- package/package.json +11 -11
- package/src/AppHostInput.ts +2 -0
- package/src/appDatabase.ts +3 -0
- package/dist/trimPostgresPageCache.d.ts +0 -10
- package/dist/trimPostgresPageCache.d.ts.map +0 -1
- package/dist/trimPostgresPageCache.js +0 -25
- package/dist/trimPostgresPageCache.js.map +0 -1
- package/src/trimPostgresPageCache.ts +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.30.0 - 2026-11-06
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- Declare `postgresSettings` explicitly when building `appDatabase`, a database-backed `appHost`, or `workerHost`; use `{}` to request no server changes. Startup applies differing PostgreSQL server settings outside migrations and warns about refused values and pending restarts. Drop calls and imports of the removed `trimPostgresPageCache`; page-cache trimming belongs in the PostgreSQL service start command.
|
|
8
|
+
|
|
3
9
|
## 0.29.1 - 2026-11-06
|
|
4
10
|
|
|
5
11
|
### Changed
|
package/README.md
CHANGED
|
@@ -15,7 +15,17 @@ import { appHost } from "@shivaedev/server/appDatabase.ts";
|
|
|
15
15
|
import { Api, Handlers, Services, migrations, sessions } from "./app.ts";
|
|
16
16
|
|
|
17
17
|
NodeRuntime.runMain(
|
|
18
|
-
Layer.launch(
|
|
18
|
+
Layer.launch(
|
|
19
|
+
appHost({
|
|
20
|
+
group: Api,
|
|
21
|
+
handlers: Handlers,
|
|
22
|
+
services: Services,
|
|
23
|
+
postgresSettings: {},
|
|
24
|
+
migrations: { loader: migrations },
|
|
25
|
+
sessions,
|
|
26
|
+
assets: "./public",
|
|
27
|
+
}),
|
|
28
|
+
),
|
|
19
29
|
);
|
|
20
30
|
```
|
|
21
31
|
|
|
@@ -86,8 +96,8 @@ import { notes, tasks, sessions } from "./app.ts";
|
|
|
86
96
|
const hosts = Effect.gen(function* () {
|
|
87
97
|
const modules = yield* appModules([notes, tasks]);
|
|
88
98
|
return {
|
|
89
|
-
server: appHost({ ...modules, sessions }),
|
|
90
|
-
worker: workerHost({ ...modules, migrations: { ...modules.migrations, mode: "wait" } }),
|
|
99
|
+
server: appHost({ ...modules, postgresSettings: {}, sessions }),
|
|
100
|
+
worker: workerHost({ ...modules, postgresSettings: {}, migrations: { ...modules.migrations, mode: "wait" } }),
|
|
91
101
|
};
|
|
92
102
|
});
|
|
93
103
|
```
|
|
@@ -110,6 +120,7 @@ const Server = appHost({
|
|
|
110
120
|
group: Api,
|
|
111
121
|
handlers: Handlers,
|
|
112
122
|
services: Services,
|
|
123
|
+
postgresSettings: {},
|
|
113
124
|
migrations: { loader: migrations },
|
|
114
125
|
sessions,
|
|
115
126
|
assets: "./public",
|
|
@@ -207,11 +218,12 @@ Supply `preflight: AppConfigLive` to `appHost` to build a native Layer before ch
|
|
|
207
218
|
|
|
208
219
|
Preflight logs pass through the host's redaction, including logged failure causes and annotations. The original typed failure remains available to callers. Direct hosts derive the policy from their RPC schemas and `config.sensitiveKeys`; deferred hosts use the default credential policy during preflight, before their application's schemas are available. Ordinary startup messages and annotations remain intact.
|
|
209
220
|
|
|
210
|
-
When construction itself touches the schema, use `appHost({ migrations, config, application })`. `application` is a native Effect that returns the HTTP host options (`group`, handler and service Layers, session policy, and optional HTTP config). The host first builds `appDatabase`, then evaluates this Effect in the host scope with SQL, Reactivity and `LiveServer` from `@shivaedev/contract/live-server/service.ts` available. A failed migration or schema-current check prevents construction. Initialization requirements and errors stay in the returned Layer's types, and acquired resources close with the host scope.
|
|
221
|
+
When construction itself touches the schema, use `appHost({ migrations, config, postgresSettings, application })`. `application` is a native Effect that returns the HTTP host options (`group`, handler and service Layers, session policy, and optional HTTP config). The host first builds `appDatabase`, then evaluates this Effect in the host scope with SQL, Reactivity and `LiveServer` from `@shivaedev/contract/live-server/service.ts` available. A failed migration or schema-current check prevents construction. Initialization requirements and errors stay in the returned Layer's types, and acquired resources close with the host scope.
|
|
211
222
|
|
|
212
223
|
```ts
|
|
213
224
|
const host = appHost({
|
|
214
225
|
config: { databaseUrl },
|
|
226
|
+
postgresSettings: {},
|
|
215
227
|
migrations: { loader: migrations, mode: "check" },
|
|
216
228
|
preflight: AppConfigLive,
|
|
217
229
|
application: Effect.gen(function* () {
|
|
@@ -284,7 +296,7 @@ Build application handlers with `Api.application.toLayer(...)` (and `Api.applica
|
|
|
284
296
|
|
|
285
297
|
Set `LISTEN_DATABASE_URL` to a direct or session-mode connection when `DATABASE_URL` uses a transaction pooler. `config.listenDatabaseUrl` overrides that setting; when neither is set, the listener shares the application pool. Both URLs must reach the same database. A separate listener pool reserves one connection; the application pool continues to own migrations, writes and heartbeat publication. Startup waits for the listener to receive its own heartbeat. A timeout fails the host with `PostgresListenerError` from `@shivaedev/sql/PostgresListenerError.ts`, naming the selected connection setting. Fix the URL before restarting; a startup timeout does not fall back to periodic reconnects. Established listeners retain their reconnect and Resync behavior.
|
|
286
298
|
|
|
287
|
-
Database-backed hosts enable PostgreSQL change delivery by default and serve each contract's reserved change stream under its middleware. After a command handler succeeds, its declared invalidation keys publish without repeating keys already announced by repository commits. The handler keeps ownership of its transactions and error mapping. `config.changes.channel` overrides the app-derived default, and heartbeat and retry settings remain optional. Use the same application name or channel across web and worker processes. A worker can provide `appDatabase({ migrations, config })` without starting HTTP. See [commit-bound changes](https://github.com/ShivaeDev/platform/blob/main/docs/framework/changes.md) for defaults and limits.
|
|
299
|
+
Database-backed hosts enable PostgreSQL change delivery by default and serve each contract's reserved change stream under its middleware. After a command handler succeeds, its declared invalidation keys publish without repeating keys already announced by repository commits. The handler keeps ownership of its transactions and error mapping. `config.changes.channel` overrides the app-derived default, and heartbeat and retry settings remain optional. Use the same application name or channel across web and worker processes. A worker can provide `appDatabase({ migrations, config, postgresSettings })` without starting HTTP. See [commit-bound changes](https://github.com/ShivaeDev/platform/blob/main/docs/framework/changes.md) for defaults and limits.
|
|
288
300
|
|
|
289
301
|
### Public client configuration
|
|
290
302
|
|
|
@@ -469,32 +481,27 @@ Wrap disposal of the host scope or runtime with `readouts.shutdown(dispose)`, th
|
|
|
469
481
|
|
|
470
482
|
To exercise PostgreSQL recovery, install the optional `@shivaedev/test-sql` peer and pass a redacted `databaseUrl` to `hostProcess`. The kit opens a `disconnectProxy` in its owning scope and gives the child its URL through `DATABASE_URL`; the child must use that setting. This mode uses the explicit `env` record plus the proxy's `DATABASE_URL` as the child's environment. Call `disconnectIdlePostgres()` once the host's database connections are idle. It cuts the proxy's existing connections while allowing new ones, so a following HTTP health request can exercise the host's PostgreSQL pool recovery.
|
|
471
483
|
|
|
472
|
-
###
|
|
473
|
-
|
|
474
|
-
Use sql's [opt-in preset](https://github.com/ShivaeDev/platform/tree/main/packages/sql#low-memory-postgresql-hosts) with the host's ten-minute connection lifetime and one-minute idle timeout. The preset bounds PostgreSQL shared memory and per-operation work; connection recycling releases backend memory, and a page-cache trim releases clean file pages charged to the container. A busy workload still needs memory for its working set.
|
|
484
|
+
### PostgreSQL server settings
|
|
475
485
|
|
|
476
|
-
|
|
486
|
+
Every `appDatabase`, database-backed `appHost` and `workerHost` requires `postgresSettings`. Omitting the declaration is a TypeScript error; `{}` explicitly requests no server changes. The declaration uses PostgreSQL names and string values, separate from client pool options such as `config.maxConnections`.
|
|
477
487
|
|
|
478
488
|
```ts
|
|
479
|
-
import
|
|
480
|
-
import { Config, Effect, Schedule } from "effect";
|
|
481
|
-
import { trimPostgresPageCache } from "@shivaedev/server/trimPostgresPageCache.ts";
|
|
482
|
-
|
|
483
|
-
const trim = Effect.gen(function* () {
|
|
484
|
-
const dataDirectory = yield* Config.String("PGDATA");
|
|
485
|
-
yield* trimPostgresPageCache(dataDirectory).pipe(Effect.repeat(Schedule.spaced("5 minutes")));
|
|
486
|
-
}).pipe(Effect.provide(NodeServices.layer));
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
The cadence starts with one trim, then waits five minutes between completed runs. Scope or interrupt the Effect with its owning process. For a PostgreSQL image without Node, schedule the equivalent command every five minutes using that image's scheduler, as its database OS user:
|
|
489
|
+
import { appDatabase } from "@shivaedev/server/appDatabase.ts";
|
|
490
490
|
|
|
491
|
-
|
|
492
|
-
|
|
491
|
+
const Database = appDatabase({
|
|
492
|
+
migrations: { loader: migrations },
|
|
493
|
+
postgresSettings: {
|
|
494
|
+
shared_buffers: "32MB",
|
|
495
|
+
max_connections: "50",
|
|
496
|
+
jit: "off",
|
|
497
|
+
idle_in_transaction_session_timeout: "10min",
|
|
498
|
+
},
|
|
499
|
+
});
|
|
493
500
|
```
|
|
494
501
|
|
|
495
|
-
The
|
|
502
|
+
The host applies the declaration on startup before listeners and migrations, outside any migration transaction. SQL's [settings applier](https://github.com/ShivaeDev/platform/tree/main/packages/sql#postgresql-server-settings) reads `pg_settings`, writes only differing values with `ALTER SYSTEM SET`, and requests a reload. Startup logs settings awaiting a PostgreSQL restart with the values they will take. In this example, `shared_buffers` and `max_connections` wait for the next PostgreSQL redeploy or image update. `idle_in_transaction_session_timeout` ends sessions left in an open transaction without terminating idle LISTEN connections.
|
|
496
503
|
|
|
497
|
-
|
|
504
|
+
Railway's template connects as the `postgres` superuser. Its wrapper appends `max_connections = 500` only when no such line exists in `postgresql.auto.conf`, so an `ALTER SYSTEM` value survives a restart. On a non-superuser deployment, or a refused setting, the host warns with the setting name, live value and wanted value and continues starting. The database operator must apply settings the app cannot change. Server settings apply to the entire PostgreSQL cluster; all apps sharing it must agree on the declaration.
|
|
498
505
|
|
|
499
506
|
### API
|
|
500
507
|
|
package/dist/AppHostInput.d.ts
CHANGED
|
@@ -11,11 +11,13 @@ export type AppHostInput<TRpcs extends Rpc.Any, THandlers, THandlerError, THandl
|
|
|
11
11
|
})));
|
|
12
12
|
export type AppHostOptions<TRpcs extends Rpc.Any = never, THandlers = never, THandlerError = never, THandlerRequirements = never, TServices = never, TServiceError = never, TServiceRequirements = never, TMigrations = never, TPreflight = never, TPreflightError = never, TPreflightRequirements = never, TRouteError = never, TRouteRequirements = HostRouteRequirements, TMigrationError = never, TRequestServices = never, TRequestRequirements = never> = HostPreflight<TPreflight, TPreflightError, TPreflightRequirements> & HostCoreOptions<TRpcs, THandlers, THandlerError, THandlerRequirements, TServices, TServiceError, TServiceRequirements, TRequestServices, TRequestRequirements> & HostRoutes<TRouteError, TRouteRequirements> & HostPolicy & {
|
|
13
13
|
readonly migrations: AppDatabaseOptions<TMigrations, TMigrationError>["migrations"];
|
|
14
|
+
readonly postgresSettings: AppDatabaseOptions["postgresSettings"];
|
|
14
15
|
readonly config?: AppDatabaseOptions["config"];
|
|
15
16
|
readonly policy?: undefined;
|
|
16
17
|
};
|
|
17
18
|
export type AppLocalHostOptions<TRpcs extends Rpc.Any = never, THandlers = never, THandlerError = never, THandlerRequirements = never, TServices = never, TServiceError = never, TServiceRequirements = never, TMigrations = never, TPreflight = never, TPreflightError = never, TPreflightRequirements = never, TRouteError = never, TRouteRequirements = HostRouteRequirements, TMigrationError = never, TRequestServices = never, TRequestRequirements = never> = HostPreflight<TPreflight, TPreflightError, TPreflightRequirements> & HostCoreOptions<TRpcs, THandlers, THandlerError, THandlerRequirements, TServices, TServiceError, TServiceRequirements, TRequestServices, TRequestRequirements> & HostRoutes<TRouteError, TRouteRequirements> & {
|
|
18
19
|
readonly migrations: AppDatabaseOptions<TMigrations, TMigrationError>["migrations"];
|
|
20
|
+
readonly postgresSettings: AppDatabaseOptions["postgresSettings"];
|
|
19
21
|
readonly config?: AppDatabaseOptions["config"];
|
|
20
22
|
readonly policy: "loopback";
|
|
21
23
|
readonly sessions?: never;
|
|
@@ -1 +1 @@
|
|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Q,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;CAC5B,CAAC;AAEH,MAAM,MAAM,mBAAmB,CAC9B,KAAK,SAAS,GAAG,CAAC,GAAG,GAAG,KAAK,EAC7B,SAAS,GAAG,KAAK,EACjB,aAAa,GAAG,KAAK,EACrB,oBAAoB,GAAG,KAAK,EAC5B,SAAS,GAAG,KAAK,EACjB,aAAa,GAAG,KAAK,EACrB,oBAAoB,GAAG,KAAK,EAC5B,WAAW,GAAG,KAAK,EACnB,UAAU,GAAG,KAAK,EAClB,eAAe,GAAG,KAAK,EACvB,sBAAsB,GAAG,KAAK,EAC9B,WAAW,GAAG,KAAK,EACnB,kBAAkB,GAAG,qBAAqB,EAC1C,eAAe,GAAG,KAAK,EACvB,gBAAgB,GAAG,KAAK,EACxB,oBAAoB,GAAG,KAAK,IACzB,aAAa,CAAC,UAAU,EAAE,eAAe,EAAE,sBAAsB,CAAC,GACrE,eAAe,CACd,KAAK,EACL,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,CACpB,GACD,UAAU,CAAC,WAAW,EAAE,kBAAkB,CAAC,GAAG;IAC7C,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,YAAY,CAAC,CAAC;IACpF,QAAQ,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IAClE,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;CAC1B,CAAC"}
|
package/dist/appDatabase.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ import { Digest } from "effect/crypto";
|
|
|
4
4
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
5
5
|
import { type PostgresChangesOptions } from "@shivaedev/sql/postgresChanges.ts";
|
|
6
6
|
import { type PostgresOptions } from "@shivaedev/sql/postgresLayer.ts";
|
|
7
|
+
import { type PostgresSettings } from "@shivaedev/sql/postgresSettings.ts";
|
|
7
8
|
import type { AppHostFactory } from "#AppHostFactory.ts";
|
|
8
9
|
import type { MigrationOptions } from "#MigrationOptions.ts";
|
|
9
10
|
export interface AppDatabaseOptions<R = never, E = never> {
|
|
10
11
|
readonly config?: DatabaseConfig;
|
|
11
12
|
readonly migrations: MigrationOptions<R, E>;
|
|
13
|
+
readonly postgresSettings: PostgresSettings;
|
|
12
14
|
}
|
|
13
15
|
export interface DatabaseConfig extends PostgresOptions {
|
|
14
16
|
readonly changes?: Partial<Omit<PostgresChangesOptions, "client" | "listenerClient" | "connectionSetting" | "connectionTTL" | "resync">>;
|
|
@@ -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,KAAK,EAAE,MAAM,EAAmB,KAAK,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAM3D,OAAO,EAAE,KAAK,sBAAsB,EAAmB,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,iCAAiC,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,EAAmB,KAAK,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO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SensitiveKey } from "@shivaedev/errors/sensitive.ts";
|
|
|
9
9
|
import { coordinateWorkerRelease } from "@shivaedev/sql/coordinateWorkerRelease.ts";
|
|
10
10
|
import { postgresChanges } from "@shivaedev/sql/postgresChanges.ts";
|
|
11
11
|
import { postgresLayer } from "@shivaedev/sql/postgresLayer.ts";
|
|
12
|
+
import { applyPostgresSettings } from "@shivaedev/sql/postgresSettings.ts";
|
|
12
13
|
import { WorkerRelease } from "@shivaedev/sql/worker-release/service.ts";
|
|
13
14
|
import { deferredHost, migratedHost } from "#appDatabaseHttp.ts";
|
|
14
15
|
import { appHostHttp } from "#appHostHttp.ts";
|
|
@@ -32,6 +33,7 @@ export function appDatabase(options) {
|
|
|
32
33
|
const changes = options.config?.changes;
|
|
33
34
|
const connected = Layer.unwrap(Effect.gen(function* () {
|
|
34
35
|
const client = yield* PgClient.PgClient;
|
|
36
|
+
yield* applyPostgresSettings(options.postgresSettings);
|
|
35
37
|
const hints = yield* LiveServer;
|
|
36
38
|
const url = options.config?.databaseUrl ?? (yield* Config.Redacted("DATABASE_URL"));
|
|
37
39
|
const name = yield* Config.String("APP_NAME").pipe(Config.withDefault(new URL(Redacted.value(url)).pathname));
|
package/dist/appDatabase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appDatabase.js","sourceRoot":"","sources":["../src/appDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAC;AAC/D,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OA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,CAAC,KAAK,CAAC,CAAC,CAAC;IACrI,CAAC;IACD,OAAO,OAAO,CAAC,UAAU,KAAK,SAAS;QACtC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3F,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,IAAI,CAC9H,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,EAC7B,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAC/B,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.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,23 +49,23 @@
|
|
|
49
49
|
"@shivaedev/contract": "0.42.0",
|
|
50
50
|
"@shivaedev/errors": "0.10.0",
|
|
51
51
|
"@shivaedev/http": "0.8.0",
|
|
52
|
-
"@shivaedev/identity": "0.29.
|
|
52
|
+
"@shivaedev/identity": "0.29.2",
|
|
53
53
|
"@shivaedev/local-postgres": "0.15.0",
|
|
54
|
-
"@shivaedev/sql": "0.
|
|
54
|
+
"@shivaedev/sql": "0.45.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@effect/platform-node": "4.1.0",
|
|
58
58
|
"@effect/sql-pg": "4.1.0",
|
|
59
59
|
"@effect/vitest": "4.1.0",
|
|
60
60
|
"@shivaedev/access": "0.6.0",
|
|
61
|
-
"@shivaedev/admin": "0.
|
|
62
|
-
"@shivaedev/jobs": "0.
|
|
63
|
-
"@shivaedev/quality": "0.
|
|
64
|
-
"@shivaedev/rate-limit": "0.6.
|
|
61
|
+
"@shivaedev/admin": "0.23.0",
|
|
62
|
+
"@shivaedev/jobs": "0.41.0",
|
|
63
|
+
"@shivaedev/quality": "0.69.1",
|
|
64
|
+
"@shivaedev/rate-limit": "0.6.3",
|
|
65
65
|
"@shivaedev/service": "0.8.0",
|
|
66
|
-
"@shivaedev/test-kits": "0.9.
|
|
67
|
-
"@shivaedev/test-sql": "0.24.
|
|
68
|
-
"@shivaedev/test-story": "0.44.
|
|
66
|
+
"@shivaedev/test-kits": "0.9.3",
|
|
67
|
+
"@shivaedev/test-sql": "0.24.3",
|
|
68
|
+
"@shivaedev/test-story": "0.44.2",
|
|
69
69
|
"@types/node": "24.19.2",
|
|
70
70
|
"better-auth": "1.7.14",
|
|
71
71
|
"effect": "4.1.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@effect/platform-node": "4.1.0",
|
|
78
78
|
"@effect/sql-pg": "4.1.0",
|
|
79
79
|
"@effect/vitest": "4.1.0",
|
|
80
|
-
"@shivaedev/admin": "0.
|
|
80
|
+
"@shivaedev/admin": "0.23.0",
|
|
81
81
|
"better-auth": "1.7.14",
|
|
82
82
|
"effect": "4.1.0"
|
|
83
83
|
},
|
package/src/AppHostInput.ts
CHANGED
|
@@ -96,6 +96,7 @@ export type AppHostOptions<
|
|
|
96
96
|
HostRoutes<TRouteError, TRouteRequirements> &
|
|
97
97
|
HostPolicy & {
|
|
98
98
|
readonly migrations: AppDatabaseOptions<TMigrations, TMigrationError>["migrations"];
|
|
99
|
+
readonly postgresSettings: AppDatabaseOptions["postgresSettings"];
|
|
99
100
|
readonly config?: AppDatabaseOptions["config"];
|
|
100
101
|
readonly policy?: undefined;
|
|
101
102
|
};
|
|
@@ -131,6 +132,7 @@ export type AppLocalHostOptions<
|
|
|
131
132
|
> &
|
|
132
133
|
HostRoutes<TRouteError, TRouteRequirements> & {
|
|
133
134
|
readonly migrations: AppDatabaseOptions<TMigrations, TMigrationError>["migrations"];
|
|
135
|
+
readonly postgresSettings: AppDatabaseOptions["postgresSettings"];
|
|
134
136
|
readonly config?: AppDatabaseOptions["config"];
|
|
135
137
|
readonly policy: "loopback";
|
|
136
138
|
readonly sessions?: never;
|
package/src/appDatabase.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { isSensitiveKey } from "@shivaedev/errors/sensitive.ts";
|
|
|
10
10
|
import { coordinateWorkerRelease } from "@shivaedev/sql/coordinateWorkerRelease.ts";
|
|
11
11
|
import { type PostgresChangesOptions, postgresChanges } from "@shivaedev/sql/postgresChanges.ts";
|
|
12
12
|
import { type PostgresOptions, postgresLayer } from "@shivaedev/sql/postgresLayer.ts";
|
|
13
|
+
import { applyPostgresSettings, type PostgresSettings } from "@shivaedev/sql/postgresSettings.ts";
|
|
13
14
|
import { WorkerRelease } from "@shivaedev/sql/worker-release/service.ts";
|
|
14
15
|
import type { AppHostFactory } from "#AppHostFactory.ts";
|
|
15
16
|
import type { AppHostInput } from "#AppHostInput.ts";
|
|
@@ -24,6 +25,7 @@ import { prepareMigrations } from "#prepareMigrations.ts";
|
|
|
24
25
|
export interface AppDatabaseOptions<R = never, E = never> {
|
|
25
26
|
readonly config?: DatabaseConfig;
|
|
26
27
|
readonly migrations: MigrationOptions<R, E>;
|
|
28
|
+
readonly postgresSettings: PostgresSettings;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export interface DatabaseConfig extends PostgresOptions {
|
|
@@ -56,6 +58,7 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
|
|
|
56
58
|
const connected = Layer.unwrap(
|
|
57
59
|
Effect.gen(function* () {
|
|
58
60
|
const client = yield* PgClient.PgClient;
|
|
61
|
+
yield* applyPostgresSettings(options.postgresSettings);
|
|
59
62
|
const hints = yield* LiveServer;
|
|
60
63
|
const url = options.config?.databaseUrl ?? (yield* Config.Redacted("DATABASE_URL"));
|
|
61
64
|
const name = yield* Config.String("APP_NAME").pipe(Config.withDefault(new URL(Redacted.value(url)).pathname));
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { ChildProcessSpawner } from "effect/process";
|
|
3
|
-
declare const PostgresPageCacheTrimError_base: Schema.Class<PostgresPageCacheTrimError, Schema.TaggedStruct<"PostgresPageCacheTrimError", {
|
|
4
|
-
readonly exitCode: Schema.Number;
|
|
5
|
-
}>, import("effect/Cause").YieldableError>;
|
|
6
|
-
export declare class PostgresPageCacheTrimError extends PostgresPageCacheTrimError_base {
|
|
7
|
-
}
|
|
8
|
-
export declare const trimPostgresPageCache: (dataDirectory: string) => Effect.Effect<undefined, import("effect/PlatformError").PlatformError | PostgresPageCacheTrimError, ChildProcessSpawner.ChildProcessSpawner>;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=trimPostgresPageCache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trimPostgresPageCache.d.ts","sourceRoot":"","sources":["../src/trimPostgresPageCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;;;;AAEnE,qBAAa,0BAA2B,SAAQ,+BAE9C;CAAG;AAEL,eAAO,MAAM,qBAAqB,yKAuBhC,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
3
|
-
export class PostgresPageCacheTrimError extends Schema.TaggedError()("PostgresPageCacheTrimError", {
|
|
4
|
-
exitCode: Schema.Number,
|
|
5
|
-
}) {
|
|
6
|
-
}
|
|
7
|
-
export const trimPostgresPageCache = Effect.fn("Server.trimPostgresPageCache")(function* (dataDirectory) {
|
|
8
|
-
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
9
|
-
const code = yield* spawner.exitCode(ChildProcess.make("find", [
|
|
10
|
-
dataDirectory,
|
|
11
|
-
"-type",
|
|
12
|
-
"f",
|
|
13
|
-
"-exec",
|
|
14
|
-
"sh",
|
|
15
|
-
"-c",
|
|
16
|
-
'for path do dd if="$path" iflag=nocache count=0 status=none || exit; done',
|
|
17
|
-
"sh",
|
|
18
|
-
"{}",
|
|
19
|
-
"+",
|
|
20
|
-
], { stderr: "inherit", stdout: "ignore" }));
|
|
21
|
-
if (code !== 0) {
|
|
22
|
-
return yield* new PostgresPageCacheTrimError({ exitCode: Number(code) });
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
//# sourceMappingURL=trimPostgresPageCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trimPostgresPageCache.js","sourceRoot":"","sources":["../src/trimPostgresPageCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnE,MAAM,OAAO,0BAA2B,SAAQ,MAAM,CAAC,WAAW,EAA8B,CAAC,4BAA4B,EAAE;IAC9H,QAAQ,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,EAAE,CAAC,8BAA8B,CAAC,CAAC,QAAQ,CAAC,EAAE,aAAqB;IAC9G,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,mBAAmB,CAAC;IAC/D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CACnC,YAAY,CAAC,IAAI,CAChB,MAAM,EACN;QACC,aAAa;QACb,OAAO;QACP,GAAG;QACH,OAAO;QACP,IAAI;QACJ,IAAI;QACJ,2EAA2E;QAC3E,IAAI;QACJ,IAAI;QACJ,GAAG;KACH,EACD,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CACvC,CACD,CAAC;IACF,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC,CAAC,IAAI,0BAA0B,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;AACF,CAAC,CAAC,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
3
|
-
|
|
4
|
-
export class PostgresPageCacheTrimError extends Schema.TaggedError<PostgresPageCacheTrimError>()("PostgresPageCacheTrimError", {
|
|
5
|
-
exitCode: Schema.Number,
|
|
6
|
-
}) {}
|
|
7
|
-
|
|
8
|
-
export const trimPostgresPageCache = Effect.fn("Server.trimPostgresPageCache")(function* (dataDirectory: string) {
|
|
9
|
-
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
10
|
-
const code = yield* spawner.exitCode(
|
|
11
|
-
ChildProcess.make(
|
|
12
|
-
"find",
|
|
13
|
-
[
|
|
14
|
-
dataDirectory,
|
|
15
|
-
"-type",
|
|
16
|
-
"f",
|
|
17
|
-
"-exec",
|
|
18
|
-
"sh",
|
|
19
|
-
"-c",
|
|
20
|
-
'for path do dd if="$path" iflag=nocache count=0 status=none || exit; done',
|
|
21
|
-
"sh",
|
|
22
|
-
"{}",
|
|
23
|
-
"+",
|
|
24
|
-
],
|
|
25
|
-
{ stderr: "inherit", stdout: "ignore" },
|
|
26
|
-
),
|
|
27
|
-
);
|
|
28
|
-
if (code !== 0) {
|
|
29
|
-
return yield* new PostgresPageCacheTrimError({ exitCode: Number(code) });
|
|
30
|
-
}
|
|
31
|
-
});
|