@shivaedev/local-postgres 0.10.0 → 0.12.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +48 -10
  3. package/dist/server/AppPostgresVersionMismatch.d.ts +11 -0
  4. package/dist/server/AppPostgresVersionMismatch.d.ts.map +1 -0
  5. package/dist/server/AppPostgresVersionMismatch.js +11 -0
  6. package/dist/server/AppPostgresVersionMismatch.js.map +1 -0
  7. package/dist/server/PostgresBinaries.d.ts +11 -0
  8. package/dist/server/PostgresBinaries.d.ts.map +1 -0
  9. package/dist/server/PostgresBinaries.js +4 -0
  10. package/dist/server/PostgresBinaries.js.map +1 -0
  11. package/dist/server/PostgresSettingError.d.ts +11 -0
  12. package/dist/server/PostgresSettingError.d.ts.map +1 -0
  13. package/dist/server/PostgresSettingError.js +11 -0
  14. package/dist/server/PostgresSettingError.js.map +1 -0
  15. package/dist/server/{clientConnection.d.ts → adapters/clientConnection.d.ts} +2 -2
  16. package/dist/server/adapters/clientConnection.d.ts.map +1 -0
  17. package/dist/server/{clientConnection.js → adapters/clientConnection.js} +1 -1
  18. package/dist/server/adapters/clientConnection.js.map +1 -0
  19. package/dist/server/adapters/docker.d.ts +8 -0
  20. package/dist/server/adapters/docker.d.ts.map +1 -0
  21. package/dist/server/{localDocker.js → adapters/docker.js} +3 -3
  22. package/dist/server/adapters/docker.js.map +1 -0
  23. package/dist/server/adapters/ensureConnections.d.ts +11 -0
  24. package/dist/server/adapters/ensureConnections.d.ts.map +1 -0
  25. package/dist/server/{localConnections.js → adapters/ensureConnections.js} +5 -13
  26. package/dist/server/adapters/ensureConnections.js.map +1 -0
  27. package/dist/server/adapters/hostPostgresBinaries.d.ts +4 -0
  28. package/dist/server/adapters/hostPostgresBinaries.d.ts.map +1 -0
  29. package/dist/server/adapters/hostPostgresBinaries.js +20 -0
  30. package/dist/server/adapters/hostPostgresBinaries.js.map +1 -0
  31. package/dist/server/{localContainer.d.ts → adapters/localContainer.d.ts} +4 -4
  32. package/dist/server/adapters/localContainer.d.ts.map +1 -0
  33. package/dist/server/{localContainer.js → adapters/localContainer.js} +3 -3
  34. package/dist/server/adapters/localContainer.js.map +1 -0
  35. package/dist/server/adapters/localSql.d.ts +6 -0
  36. package/dist/server/adapters/localSql.d.ts.map +1 -0
  37. package/dist/server/adapters/localSql.js +15 -0
  38. package/dist/server/adapters/localSql.js.map +1 -0
  39. package/dist/server/{runCommand.d.ts → adapters/runCommand.d.ts} +1 -1
  40. package/dist/server/adapters/runCommand.d.ts.map +1 -0
  41. package/dist/server/{runCommand.js → adapters/runCommand.js} +1 -1
  42. package/dist/server/adapters/runCommand.js.map +1 -0
  43. package/dist/server/appPostgres.d.ts +22 -0
  44. package/dist/server/appPostgres.d.ts.map +1 -0
  45. package/dist/server/appPostgres.js +50 -0
  46. package/dist/server/appPostgres.js.map +1 -0
  47. package/dist/server/assertLocalDatabase.d.ts +1 -1
  48. package/dist/server/assertLocalDatabase.d.ts.map +1 -1
  49. package/dist/server/assertLocalDatabase.js +1 -1
  50. package/dist/server/assertLocalDatabase.js.map +1 -1
  51. package/dist/server/dockerEnvironment.d.ts +10 -0
  52. package/dist/server/dockerEnvironment.d.ts.map +1 -0
  53. package/dist/server/dockerEnvironment.js +6 -0
  54. package/dist/server/dockerEnvironment.js.map +1 -0
  55. package/dist/server/localPostgres.d.ts +5 -5
  56. package/dist/server/localPostgres.d.ts.map +1 -1
  57. package/dist/server/localPostgres.js +7 -16
  58. package/dist/server/localPostgres.js.map +1 -1
  59. package/dist/server/migrateAppPostgres.d.ts +6 -0
  60. package/dist/server/migrateAppPostgres.d.ts.map +1 -0
  61. package/dist/server/migrateAppPostgres.js +31 -0
  62. package/dist/server/migrateAppPostgres.js.map +1 -0
  63. package/dist/server/prepareAppPostgresData.d.ts +6 -0
  64. package/dist/server/prepareAppPostgresData.d.ts.map +1 -0
  65. package/dist/server/prepareAppPostgresData.js +35 -0
  66. package/dist/server/prepareAppPostgresData.js.map +1 -0
  67. package/package.json +6 -6
  68. package/src/server/AppPostgresVersionMismatch.ts +11 -0
  69. package/src/server/PostgresBinaries.ts +9 -0
  70. package/src/server/PostgresSettingError.ts +11 -0
  71. package/src/server/{clientConnection.ts → adapters/clientConnection.ts} +2 -2
  72. package/src/server/{localDocker.ts → adapters/docker.ts} +3 -4
  73. package/src/server/{localConnections.ts → adapters/ensureConnections.ts} +7 -16
  74. package/src/server/adapters/hostPostgresBinaries.ts +27 -0
  75. package/src/server/{localContainer.ts → adapters/localContainer.ts} +5 -5
  76. package/src/server/adapters/localSql.ts +20 -0
  77. package/src/server/{runCommand.ts → adapters/runCommand.ts} +1 -1
  78. package/src/server/appPostgres.ts +80 -0
  79. package/src/server/assertLocalDatabase.ts +1 -1
  80. package/src/server/dockerEnvironment.ts +8 -0
  81. package/src/server/localPostgres.ts +9 -21
  82. package/src/server/migrateAppPostgres.ts +35 -0
  83. package/src/server/prepareAppPostgresData.ts +35 -0
  84. package/dist/server/clientConnection.d.ts.map +0 -1
  85. package/dist/server/clientConnection.js.map +0 -1
  86. package/dist/server/localConnections.d.ts +0 -18
  87. package/dist/server/localConnections.d.ts.map +0 -1
  88. package/dist/server/localConnections.js.map +0 -1
  89. package/dist/server/localContainer.d.ts.map +0 -1
  90. package/dist/server/localContainer.js.map +0 -1
  91. package/dist/server/localDocker.d.ts +0 -12
  92. package/dist/server/localDocker.d.ts.map +0 -1
  93. package/dist/server/localDocker.js.map +0 -1
  94. package/dist/server/runCommand.d.ts.map +0 -1
  95. package/dist/server/runCommand.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0 - 2026-11-03
4
+
5
+ ### Added
6
+
7
+ - App-owned PostgreSQL instances initialize and preserve application data, run as scoped children with private Unix sockets and no TCP listener, and refuse incompatible data major versions with `AppPostgresVersionMismatch`.
8
+ - Migration Effects run after a `pg_dump` backup, with configurable retention of completed backups. `PostgresBinaries` separates binary sourcing from lifecycle management; `hostPostgresBinaries` supplies host-installed executables.
9
+
10
+ ## 0.11.0 - 2026-11-03
11
+
12
+ ### Added
13
+
14
+ - Read Docker settings through Effect Config with `dockerEnvironment` from `@shivaedev/local-postgres/server/dockerEnvironment.ts`.
15
+
16
+ ### Breaking
17
+
18
+ - Import `PostgresSettingError` from `@shivaedev/local-postgres/server/PostgresSettingError.ts` and `ensureConnections` from `server/adapters/ensureConnections.ts` instead of `server/localConnections.ts`.
19
+ - Import `DockerEnvironment` from `@shivaedev/local-postgres/server/dockerEnvironment.ts` and `docker` from `server/adapters/docker.ts` instead of `server/localDocker.ts`. Import `localContainer`, `runCommand` and `clientConnection` modules from `server/adapters/` instead of `server/`; their exported names stay the same.
20
+
3
21
  ## 0.10.0 - 2026-11-02
4
22
 
5
23
  ### Breaking
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @shivaedev/local-postgres
2
2
 
3
- Make development and integration tests share one persistent local PostgreSQL service. Repeat setup without rebuilding the database contents, and keep each application's database names and schema preparation in its own setup script.
3
+ Make development and integration tests share one persistent local PostgreSQL service, or let a local application own a private instance. Keep data across starts and leave schema preparation with the application.
4
4
 
5
5
  ## Why you want this
6
6
 
@@ -40,15 +40,13 @@ When database names come from the application's configured URLs, pass those URLs
40
40
 
41
41
  ```ts
42
42
  import { Config, Effect } from "effect";
43
+ import { dockerEnvironment } from "@shivaedev/local-postgres/server/dockerEnvironment.ts";
43
44
  import { LOCAL_SERVER, localPostgres } from "@shivaedev/local-postgres/server/localPostgres.ts";
44
45
 
45
46
  const setup = Effect.gen(function* () {
46
47
  const development = yield* Config.String("DATABASE_URL").pipe(Config.withDefault(`${LOCAL_SERVER}/example_dev`));
47
48
  const tests = yield* Config.String("TEST_DATABASE_URL").pipe(Config.withDefault(`${LOCAL_SERVER}/example_test`));
48
- const environment = yield* Config.all({
49
- "DOCKER_CONTEXT": Config.String("DOCKER_CONTEXT").pipe(Config.withDefault("")),
50
- "DOCKER_HOST": Config.String("DOCKER_HOST").pipe(Config.withDefault("")),
51
- });
49
+ const environment = yield* dockerEnvironment;
52
50
  yield* localPostgres(environment).prepareDatabases([development, tests]);
53
51
  });
54
52
  ```
@@ -95,7 +93,7 @@ Run these setup Effects at a Node entry point with `NodeRuntime.runMain(setup.pi
95
93
 
96
94
  `startPostgres(connection)` prepares the service without choosing an application database to create. Its connection defaults to `LOCAL_SERVER`. Prefer `prepareDatabases` when the setup script needs named databases as well.
97
95
 
98
- On each start, setup reads `SHOW max_connections`. Native servers retain their configured limit. When the running managed container publishes port 55432 and allows fewer than 500 connections, setup applies `ALTER SYSTEM SET max_connections = 500`, restarts that same container, waits for readiness and confirms the setting. Existing data stays in place. A limit of 500 or higher causes no setting change or restart. If the setting cannot be applied, setup fails with `PostgresSettingError` from `@shivaedev/local-postgres/server/localConnections.ts`, with `_tag`, `container`, `setting` and the original `cause`.
96
+ On each start, setup reads `SHOW max_connections`. Native servers retain their configured limit. When the running managed container publishes port 55432 and allows fewer than 500 connections, setup applies `ALTER SYSTEM SET max_connections = 500`, restarts that same container, waits for readiness and confirms the setting. Existing data stays in place. A limit of 500 or higher causes no setting change or restart. If the setting cannot be applied, setup fails with `PostgresSettingError` from `@shivaedev/local-postgres/server/PostgresSettingError.ts`, with `_tag`, `container`, `setting` and the original `cause`.
99
97
 
100
98
  ### API
101
99
 
@@ -112,14 +110,54 @@ Import service preparation from `@shivaedev/local-postgres/server/localPostgres.
112
110
 
113
111
  The last three functions are members of the object returned by `localPostgres`, not module-level exports. They fail in the typed error channel. `PostgresCommandError` carries the command, diagnostic message and exit code or platform cause; `LocalPostgresError` describes local-target and image refusals, and malformed URL password escapes. Exhausted readiness checks retain their final failure; a version mismatch always names a version the service returned.
114
112
 
115
- The module export pattern also exposes the lower-level Docker and container command functions in `@shivaedev/local-postgres/server/localDocker.ts` and `@shivaedev/local-postgres/server/localContainer.ts`. Use `@shivaedev/local-postgres/server/localPostgres.ts` for application preparation.
113
+ The module export pattern also exposes the lower-level Docker and container command functions in `@shivaedev/local-postgres/server/adapters/docker.ts` and `@shivaedev/local-postgres/server/adapters/localContainer.ts`. Use `@shivaedev/local-postgres/server/localPostgres.ts` for application preparation.
114
+
115
+ ### An instance owned by a local application
116
+
117
+ `appPostgres` from `@shivaedev/local-postgres/server/appPostgres.ts` initializes a cluster in `dataDirectory` and starts PostgreSQL as a child in the current Effect scope. Closing the scope sends a fast-shutdown signal and waits for the child to exit. The data directory survives; the temporary socket directory is removed. Keep the scope open for the application's lifetime:
118
+
119
+ ```ts
120
+ import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
121
+ import * as NodeServices from "@effect/platform-node/NodeServices";
122
+ import { Effect } from "effect";
123
+ import { hostPostgresBinaries } from "@shivaedev/local-postgres/server/adapters/hostPostgresBinaries.ts";
124
+ import { appPostgres } from "@shivaedev/local-postgres/server/appPostgres.ts";
125
+
126
+ const app = Effect.scoped(
127
+ Effect.gen(function* () {
128
+ const postgres = yield* appPostgres({ dataDirectory: "/path/to/app/data", backupsToKeep: 3 });
129
+ yield* Effect.log(postgres.connectionUrl);
130
+ yield* Effect.never;
131
+ }),
132
+ );
133
+
134
+ NodeRuntime.runMain(app.pipe(Effect.provide(hostPostgresBinaries()), Effect.provide(NodeServices.layer)));
135
+ ```
136
+
137
+ The instance listens on a Unix socket in a directory with permissions `0700` and opens no TCP listener. `connectionUrl` selects the `postgres` database and role through that socket. Use it with the application's PostgreSQL client. App-owned mode is separate from the shared development service on port 55432.
138
+
139
+ Before migrations, yield `migrateAppPostgres(instance, migrations)` from `@shivaedev/local-postgres/server/migrateAppPostgres.ts`. `migrations` is the application's Effect, such as its `@shivaedev/sql` migration entry point. The wrapper finishes a custom-format `pg_dump` before evaluating that Effect. A backup failure prevents the migration from running. Completed dumps live in `dataDirectory/backups`; `backupsToKeep` defaults to five and must be a positive integer. After each completed backup, only the newest configured number of dumps remain. The same module exports `backupAppPostgres(instance)` for an explicit backup; it returns the completed dump's path.
140
+
141
+ The instance reads its binaries from the `PostgresBinaries` port in `@shivaedev/local-postgres/server/PostgresBinaries.ts`. `hostPostgresBinaries(directory?)` supplies host executables: either from the supplied directory, from `PATH`, or from `pg_config --bindir` when `postgres` is absent from `PATH`. It checks `initdb`, `postgres` and `pg_dump`. Another adapter can supply the port's `initdb`, `postgres` and `pgDump` paths without changing instance management.
142
+
143
+ Before starting an existing cluster, the instance compares `PG_VERSION` with the server binary's major version. A mismatch fails with `AppPostgresVersionMismatch` from `@shivaedev/local-postgres/server/AppPostgresVersionMismatch.ts`, carrying `dataDirectory`, `expectedMajor` and `observedMajor`. It does not initialize or upgrade that data directory. Choose upgrades and restores outside this package.
144
+
145
+ App-owned mode needs host PostgreSQL server and client binaries and a Unix-socket-capable system. Its real-instance stories skip with a diagnostic when those binaries are absent; set `PLATFORM_LOCAL_POSTGRES_BIN_DIRECTORY` to run them with a particular installed binary directory.
116
146
 
117
147
  ### Install and machine setup
118
148
 
149
+ For shared development and test setup tooling:
150
+
119
151
  ```sh
120
152
  pnpm add --save-dev @shivaedev/local-postgres @effect/platform-node effect
121
153
  ```
122
154
 
155
+ For an app-owned instance, install these as runtime dependencies:
156
+
157
+ ```sh
158
+ pnpm add @shivaedev/local-postgres @effect/platform-node effect
159
+ ```
160
+
123
161
  The package requires Node 24 or later and uses Effect as a peer dependency. It needs host `psql` or a local Docker installation. SQL uses host `psql` when available and falls back to the container's client when the host executable is missing. Both clients receive the connection password through `PGPASSWORD`, outside the command line. Query failures retain PostgreSQL's diagnostics and command failure details (and a platform `cause` when a process cannot start) without exposing the connection password.
124
162
 
125
163
  The shared baseline is PostgreSQL 18.6 on loopback port 55432. Docker preparation uses container and volume name `development-postgres`, loopback publication `127.0.0.1:55432:5432`, and this image:
@@ -130,12 +168,12 @@ postgres:18.6-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f
130
168
 
131
169
  A newly created container uses username and password `postgres`; connection URLs supply credentials for client commands. Setup accepts native PostgreSQL 18.6 version strings with distribution suffixes, such as `18.6 (Debian 18.6-1.pgdg13+2)`, without requiring a managed container or Docker installation. Setup refuses a running release other than 18.6 with `PostgresVersionMismatch` from `@shivaedev/local-postgres/server/PostgresVersionMismatch.ts`. The error carries `_tag: "PostgresVersionMismatch"`, `expectedVersion` and `observedVersion`. A running PostgreSQL 17 service is refused without losing its existing rows; upgrading it while preserving its data is your job. Container preparation and container-client fallback also check the managed image; a successful host-`psql` version probe does not inspect that image.
132
170
 
133
- Read Docker settings through Effect Config and pass them to `localPostgres`, as in the configuration example. With `DOCKER_CONTEXT`, endpoint validation uses that context and ignores `DOCKER_HOST`; otherwise it validates `DOCKER_HOST` or the active context. Remote endpoints are rejected before a Docker operation. Each operation pins `DOCKER_HOST` to the validated endpoint and clears `DOCKER_CONTEXT`. The lower-level `docker` function refuses command environment settings that conflict with the supplied `DOCKER_HOST` or `DOCKER_CONTEXT` before invoking Docker.
171
+ Yield `dockerEnvironment` from `@shivaedev/local-postgres/server/dockerEnvironment.ts` and pass its result to `localPostgres`, as in the configuration example. This reader uses Effect Config for `DOCKER_CONTEXT` and `DOCKER_HOST`, with empty defaults that let Docker use its active context. The same module exports the `DockerEnvironment` type. With `DOCKER_CONTEXT`, endpoint validation uses that context and ignores `DOCKER_HOST`; otherwise it validates `DOCKER_HOST` or the active context. Remote endpoints are rejected before a Docker operation. Each operation pins `DOCKER_HOST` to the validated endpoint and clears `DOCKER_CONTEXT`. The lower-level `docker` function refuses command environment settings that conflict with the supplied `DOCKER_HOST` or `DOCKER_CONTEXT` before invoking Docker.
134
172
 
135
173
  ### Limits
136
174
 
137
- - The service version, port, container name and volume name are fixed. Choose any upgrade and data-preservation procedure outside this package.
138
- - Keep commands in development and test setup tooling; setup never becomes an application request path.
175
+ - The shared service's version, port, container name and volume name are fixed. Choose any upgrade and data-preservation procedure outside this package.
176
+ - Keep shared-service commands in development and test setup tooling. App-owned mode manages the local child's lifetime; runtime queries belong to the application's SQL client.
139
177
  - Keep allowed names, schema changes, test isolation and cleanup in the application. Preparation is not a database reset.
140
178
  - A prepared database name has 1–63 lowercase letters, digits or underscores and starts with a letter. An allowlisted connection URL does not bypass this SQL-name constraint.
141
179
  - Concurrent creation of the same absent database is not supported. Prepare databases before parallel tests begin.
@@ -0,0 +1,11 @@
1
+ import { Schema } from "effect";
2
+ declare const AppPostgresVersionMismatch_base: Schema.Class<AppPostgresVersionMismatch, Schema.TaggedStruct<"AppPostgresVersionMismatch", {
3
+ readonly dataDirectory: Schema.String;
4
+ readonly expectedMajor: Schema.String;
5
+ readonly observedMajor: Schema.String;
6
+ }>, import("effect/Cause").YieldableError>;
7
+ export declare class AppPostgresVersionMismatch extends AppPostgresVersionMismatch_base {
8
+ get message(): string;
9
+ }
10
+ export {};
11
+ //# sourceMappingURL=AppPostgresVersionMismatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppPostgresVersionMismatch.d.ts","sourceRoot":"","sources":["../../src/server/AppPostgresVersionMismatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;AAEhC,qBAAa,0BAA2B,SAAQ,+BAI9C;IACD,IAAa,OAAO,WAEnB;CACD"}
@@ -0,0 +1,11 @@
1
+ import { Schema } from "effect";
2
+ export class AppPostgresVersionMismatch extends Schema.TaggedError()("AppPostgresVersionMismatch", {
3
+ dataDirectory: Schema.String,
4
+ expectedMajor: Schema.String,
5
+ observedMajor: Schema.String,
6
+ }) {
7
+ get message() {
8
+ return `PostgreSQL ${this.expectedMajor} cannot open ${this.dataDirectory}: its data belongs to PostgreSQL ${this.observedMajor}.`;
9
+ }
10
+ }
11
+ //# sourceMappingURL=AppPostgresVersionMismatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppPostgresVersionMismatch.js","sourceRoot":"","sources":["../../src/server/AppPostgresVersionMismatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,0BAA2B,SAAQ,MAAM,CAAC,WAAW,EAA8B,CAAC,4BAA4B,EAAE;IAC9H,aAAa,EAAE,MAAM,CAAC,MAAM;IAC5B,aAAa,EAAE,MAAM,CAAC,MAAM;IAC5B,aAAa,EAAE,MAAM,CAAC,MAAM;CAC5B,CAAC;IACD,IAAa,OAAO;QACnB,OAAO,cAAc,IAAI,CAAC,aAAa,gBAAgB,IAAI,CAAC,aAAa,oCAAoC,IAAI,CAAC,aAAa,GAAG,CAAC;IACpI,CAAC;CACD"}
@@ -0,0 +1,11 @@
1
+ import { Context } from "effect";
2
+ export interface PostgresExecutables {
3
+ readonly initdb: string;
4
+ readonly pgDump: string;
5
+ readonly postgres: string;
6
+ }
7
+ declare const PostgresBinaries_base: Context.ServiceClass<PostgresBinaries, "@shivaedev/local-postgres/PostgresBinaries", PostgresExecutables>;
8
+ export declare class PostgresBinaries extends PostgresBinaries_base {
9
+ }
10
+ export {};
11
+ //# sourceMappingURL=PostgresBinaries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresBinaries.d.ts","sourceRoot":"","sources":["../../src/server/PostgresBinaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;;AAED,qBAAa,gBAAiB,SAAQ,qBAAsG;CAAG"}
@@ -0,0 +1,4 @@
1
+ import { Context } from "effect";
2
+ export class PostgresBinaries extends Context.Service()("@shivaedev/local-postgres/PostgresBinaries") {
3
+ }
4
+ //# sourceMappingURL=PostgresBinaries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresBinaries.js","sourceRoot":"","sources":["../../src/server/PostgresBinaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAQjC,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,OAAO,EAAyC,CAAC,4CAA4C,CAAC;CAAG"}
@@ -0,0 +1,11 @@
1
+ import { Schema } from "effect";
2
+ declare const PostgresSettingError_base: Schema.Class<PostgresSettingError, Schema.TaggedStruct<"PostgresSettingError", {
3
+ readonly cause: Schema.Unknown;
4
+ readonly container: Schema.Literal<"development-postgres">;
5
+ readonly setting: Schema.Literal<"max_connections">;
6
+ }>, import("effect/Cause").YieldableError>;
7
+ export declare class PostgresSettingError extends PostgresSettingError_base {
8
+ get message(): string;
9
+ }
10
+ export {};
11
+ //# sourceMappingURL=PostgresSettingError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresSettingError.d.ts","sourceRoot":"","sources":["../../src/server/PostgresSettingError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;AAEhC,qBAAa,oBAAqB,SAAQ,yBAIxC;IACD,IAAa,OAAO,WAEnB;CACD"}
@@ -0,0 +1,11 @@
1
+ import { Schema } from "effect";
2
+ export class PostgresSettingError extends Schema.TaggedError()("PostgresSettingError", {
3
+ cause: Schema.Unknown,
4
+ container: Schema.Literal("development-postgres"),
5
+ setting: Schema.Literal("max_connections"),
6
+ }) {
7
+ get message() {
8
+ return "Could not set max_connections to at least 500 in container development-postgres.";
9
+ }
10
+ }
11
+ //# sourceMappingURL=PostgresSettingError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresSettingError.js","sourceRoot":"","sources":["../../src/server/PostgresSettingError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,WAAW,EAAwB,CAAC,sBAAsB,EAAE;IAC5G,KAAK,EAAE,MAAM,CAAC,OAAO;IACrB,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC;IACjD,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;CAC1C,CAAC;IACD,IAAa,OAAO;QACnB,OAAO,kFAAkF,CAAC;IAC3F,CAAC;CACD"}
@@ -1,6 +1,6 @@
1
1
  import { Effect } from "effect";
2
- import { LocalPostgresError } from "#LocalPostgresError.ts";
3
- import type { CommandOptions } from "#runCommand.ts";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
+ import type { CommandOptions } from "./runCommand.ts";
4
4
  export declare const clientConnection: (value: URL, options?: CommandOptions | undefined) => Effect.Effect<{
5
5
  options: {
6
6
  env: {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientConnection.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/clientConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,eAAO,MAAM,gBAAgB;;;;;;;;6BAe3B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { LocalPostgresError } from "#LocalPostgresError.ts";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
3
  export const clientConnection = Effect.fn("LocalPostgres.clientConnection")(function* (value, options = {}) {
4
4
  const url = new URL(value);
5
5
  // libpq treats + literally in URI passwords.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientConnection.js","sourceRoot":"","sources":["../../../src/server/adapters/clientConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,EAAE,CAAC,gCAAg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Effect } from "effect";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
+ import { type CommandOptions } from "./runCommand.ts";
4
+ export declare const docker: (environment: Readonly<{
5
+ DOCKER_CONTEXT?: string | undefined;
6
+ DOCKER_HOST?: string | undefined;
7
+ }>, args: readonly string[], options?: CommandOptions | undefined) => Effect.Effect<string, LocalPostgresError | import("../PostgresCommandError.ts").PostgresCommandError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner>;
8
+ //# sourceMappingURL=docker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,KAAK,cAAc,EAAc,MAAM,iBAAiB,CAAC;AAElE,eAAO,MAAM,MAAM;;;6OA4BjB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Effect } from "effect";
2
- import { LocalPostgresError } from "#LocalPostgresError.ts";
3
- import { runCommand } from "#runCommand.ts";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
+ import { runCommand } from "./runCommand.js";
4
4
  export const docker = Effect.fn("LocalPostgres.docker")(function* (environment, args, options = {}) {
5
5
  const context = environment.DOCKER_CONTEXT;
6
6
  const host = environment.DOCKER_HOST;
@@ -21,4 +21,4 @@ export const docker = Effect.fn("LocalPostgres.docker")(function* (environment,
21
21
  }
22
22
  return yield* runCommand("docker", args, { ...settings, env: { ...settings.env, "DOCKER_CONTEXT": "", "DOCKER_HOST": endpoint } });
23
23
  });
24
- //# sourceMappingURL=localDocker.js.map
24
+ //# sourceMappingURL=docker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docker.js","sourceRoot":"","sources":["../../../src/server/adapters/docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAA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G,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC9I,IACC,CAAC,CACA,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;WACrF,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAC1F,EACA,CAAC;QACF,OAAO,KAAK,CAAC,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,qFAAqF,EAAE,CAAC,CAAC;IAC1I,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAC,GAAG,EAAE,gBAAgB,EAAE,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AACpI,CAAC,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Effect } from "effect";
2
+ import type { ChildProcessSpawner } from "effect/process";
3
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
4
+ import type { PostgresCommandError } from "#server/PostgresCommandError.ts";
5
+ import { PostgresSettingError } from "#server/PostgresSettingError.ts";
6
+ import type { PostgresVersionMismatch } from "#server/PostgresVersionMismatch.ts";
7
+ import type { docker as localDocker } from "./docker.ts";
8
+ type Query = (query: string) => Effect.Effect<string, LocalPostgresError | PostgresCommandError, ChildProcessSpawner.ChildProcessSpawner>;
9
+ export declare const ensureConnections: (docker: (args: readonly string[]) => ReturnType<typeof localDocker>, sql: Query, ready: () => Effect.Effect<void, LocalPostgresError | PostgresCommandError | PostgresVersionMismatch, ChildProcessSpawner.ChildProcessSpawner>) => Effect.Effect<void, PostgresSettingError, ChildProcessSpawner.ChildProcessSpawner>;
10
+ export {};
11
+ //# sourceMappingURL=ensureConnections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureConnections.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/ensureConnections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAGzD,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,oBAAoB,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE1I,eAAO,MAAM,iBAAiB,kBACd,SAAS,MAAM,EAAE,KAAK,UAAU,CAAC,OAAO,WAAW,CAAC,2BAEtD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,oBAAoB,GAAG,uBAAuB,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,uFA6B7I,CAAC"}
@@ -1,15 +1,7 @@
1
- import { Effect, Schema } from "effect";
2
- import { LocalPostgresError } from "#LocalPostgresError.ts";
3
- import { POSTGRES_IMAGE } from "#localContainer.ts";
4
- export class PostgresSettingError extends Schema.TaggedError()("PostgresSettingError", {
5
- cause: Schema.Unknown,
6
- container: Schema.Literal("development-postgres"),
7
- setting: Schema.Literal("max_connections"),
8
- }) {
9
- get message() {
10
- return "Could not set max_connections to at least 500 in container development-postgres.";
11
- }
12
- }
1
+ import { Effect } from "effect";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
+ import { PostgresSettingError } from "#server/PostgresSettingError.ts";
4
+ import { POSTGRES_IMAGE } from "./localContainer.js";
13
5
  export const ensureConnections = Effect.fn("LocalPostgres.ensureConnections")(function* (docker, sql, ready) {
14
6
  yield* Effect.gen(function* () {
15
7
  const current = Number(yield* sql("SHOW max_connections"));
@@ -37,4 +29,4 @@ export const ensureConnections = Effect.fn("LocalPostgres.ensureConnections")(fu
37
29
  }
38
30
  }).pipe(Effect.mapError((cause) => new PostgresSettingError({ cause, container: "development-postgres", setting: "max_connections" })));
39
31
  });
40
- //# sourceMappingURL=localConnections.js.map
32
+ //# sourceMappingURL=ensureConnections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureConnections.js","sourceRoot":"","sources":["../../../src/server/adapters/ensureConnections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,iCAAiC,CAAC,CAAC,QAAQ,CAAC,EACtF,MAAmE,EACnE,GAAU,EACV,KAA8I;IAE9I,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC1B,MAAM,OAAO,GAAG,MAAM,CAAC,K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D,OAAO,KAAK,CAAC,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,4DAA4D,EAAE,CAAC,CAAC;QACjH,CAAC;IACF,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;AACzI,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Layer, Path } from "effect";
2
+ import { PostgresBinaries } from "#server/PostgresBinaries.ts";
3
+ export declare function hostPostgresBinaries(directory?: string): Layer.Layer<PostgresBinaries, import("../PostgresCommandError.ts").PostgresCommandError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner | Path.Path>;
4
+ //# sourceMappingURL=hostPostgresBinaries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hostPostgresBinaries.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/hostPostgresBinaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAA4B,MAAM,6BAA6B,CAAC;AAEzF,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,0KAsBtD"}
@@ -0,0 +1,20 @@
1
+ import { Effect, Layer, Path } from "effect";
2
+ import { missingCommand, runCommand } from "#server/adapters/runCommand.ts";
3
+ import { PostgresBinaries } from "#server/PostgresBinaries.ts";
4
+ export function hostPostgresBinaries(directory) {
5
+ return Layer.effect(PostgresBinaries, Effect.gen(function* () {
6
+ const path = yield* Path.Path;
7
+ const bin = directory
8
+ ?? (yield* runCommand("postgres", ["--version"]).pipe(Effect.as(""), Effect.catchTag("PostgresCommandError", (error) => (missingCommand(error) ? runCommand("pg_config", ["--bindir"]) : Effect.fail(error)))));
9
+ const executables = {
10
+ initdb: bin ? path.join(bin, "initdb") : "initdb",
11
+ pgDump: bin ? path.join(bin, "pg_dump") : "pg_dump",
12
+ postgres: bin ? path.join(bin, "postgres") : "postgres",
13
+ };
14
+ for (const command of Object.values(executables)) {
15
+ yield* runCommand(command, ["--version"]);
16
+ }
17
+ return executables;
18
+ }));
19
+ }
20
+ //# sourceMappingURL=hostPostgresBinaries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hostPostgresBinaries.js","sourceRoot":"","sources":["../../../src/server/adapters/hostPostgresBinaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAA4B,MAAM,6BAA6B,CAAC;AAEzF,MAAM,UAAU,oBAAoB,CAAC,SAAkB;IACtD,OAAO,KAAK,CAAC,MAAM,CAClB,gBAAgB,EAChB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9B,MAAM,GAAG,GACR,SAAS;eACN,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CACpD,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EACb,MAAM,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CACxI,CAAC,CAAC;QACJ,MAAM,WAAW,GAAwB;YACxC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ;YACjD,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;YACnD,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU;SACvD,CAAC;QACF,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YAClD,KAAK,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,WAAW,CAAC;IACpB,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { Effect } from "effect";
2
- import { LocalPostgresError } from "#LocalPostgresError.ts";
3
- import type { docker as runDocker } from "#localDocker.ts";
4
- import { PostgresCommandError } from "#PostgresCommandError.ts";
5
- import type { CommandOptions } from "#runCommand.ts";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
+ import { PostgresCommandError } from "#server/PostgresCommandError.ts";
4
+ import type { docker as runDocker } from "./docker.ts";
5
+ import type { CommandOptions } from "./runCommand.ts";
6
6
  export declare const POSTGRES_IMAGE = "postgres:18.6-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873";
7
7
  type Docker = (args: readonly string[], options?: CommandOptions) => ReturnType<typeof runDocker>;
8
8
  export declare const sqlInContainer: (docker: Docker, url: URL, args: readonly string[], options: CommandOptions) => Effect.Effect<string, LocalPostgresError | PostgresCommandError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localContainer.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/localContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,KAAK,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,eAAO,MAAM,cAAc,iGAAiG,CAAC;AAE7H,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAElG,eAAO,MAAM,cAAc,oNAmBzB,CAAC;AAEH,eAAO,MAAM,cAAc,2JA2BzB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { Effect } from "effect";
2
- import { clientConnection } from "#clientConnection.ts";
3
- import { LocalPostgresError } from "#LocalPostgresError.ts";
4
- import { PostgresCommandError } from "#PostgresCommandError.ts";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
+ import { PostgresCommandError } from "#server/PostgresCommandError.ts";
4
+ import { clientConnection } from "./clientConnection.js";
5
5
  export const POSTGRES_IMAGE = "postgres:18.6-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873";
6
6
  const CONTAINER = "development-postgres";
7
7
  export const sqlInContainer = Effect.fn("LocalPostgres.sqlInContainer")(function* (docker, url, args, options) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localContainer.js","sourceRoot":"","sources":["../../../src/server/adapters/localContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAA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M,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;AACrH,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,8BAA8B,CAAC,CAAC,QAAQ,CAAC,EAAE,MAAc;IAChG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACxB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,SAAS,GAAG,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;IACxH,IAAI,QAAQ,EAAE,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE,CAAC;YACjG,OAAO,KAAK,CAAC,CAAC,IAAI,kBAAkB,CAAC;gBACpC,OAAO,EAAE,wGAAwG;aACjH,CAAC,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IACrC,CAAC;SAAM,CAAC;QACP,KAAK,CAAC,CAAC,MAAM,CAAC;YACb,KAAK;YACL,UAAU;YACV,QAAQ;YACR,SAAS;YACT,WAAW;YACX,sBAAsB;YACtB,OAAO;YACP,wBAAwB;YACxB,OAAO;YACP,4BAA4B;YAC5B,SAAS;YACT,8DAA8D;YAC9D,cAAc;SACd,CAAC,CAAC;IACJ,CAAC;AACF,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Effect } from "effect";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
+ import type { docker } from "./docker.ts";
4
+ import { type CommandOptions } from "./runCommand.ts";
5
+ export declare function localSql(localDocker: (args: readonly string[], options?: CommandOptions) => ReturnType<typeof docker>): (value: string | URL, query: string) => Effect.Effect<string, LocalPostgresError | import("../PostgresCommandError.ts").PostgresCommandError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner>;
6
+ //# sourceMappingURL=localSql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localSql.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/localSql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,KAAK,cAAc,EAA8B,MAAM,iBAAiB,CAAC;AAElF,wBAAgB,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,UAAU,CAAC,OAAO,MAAM,CAAC,mNAWrH"}
@@ -0,0 +1,15 @@
1
+ import { Effect } from "effect";
2
+ import { assertLocalDatabase } from "#server/assertLocalDatabase.ts";
3
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
4
+ import { clientConnection } from "./clientConnection.js";
5
+ import { sqlInContainer } from "./localContainer.js";
6
+ import { missingCommand, runCommand } from "./runCommand.js";
7
+ export function localSql(localDocker) {
8
+ return Effect.fn("LocalPostgres.sql")(function* (value, query) {
9
+ const parsed = yield* Effect.try({ catch: () => new LocalPostgresError({ message: "Invalid local database URL." }), try: () => new URL(value) });
10
+ const { url, options } = yield* clientConnection(yield* assertLocalDatabase(parsed.toString(), [parsed.pathname.slice(1)]));
11
+ const args = ["-X", "--set", "ON_ERROR_STOP=1", "-At", "-c", query];
12
+ return yield* runCommand("psql", [...args, "--dbname", url.toString()], options).pipe(Effect.catchTag("PostgresCommandError", (error) => missingCommand(error) ? sqlInContainer(localDocker, url, args, options) : Effect.fail(error)));
13
+ });
14
+ }
15
+ //# sourceMappingURL=localSql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localSql.js","sourceRoot":"","sources":["../../../src/server/adapters/localSql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAuB,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElF,MAAM,UAAU,QAAQ,CAAC,WAA6F;IACrH,OAAO,MAAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAmB,EAAE,KAAa;QAClF,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjJ,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5H,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACpE,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CACpF,MAAM,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,KAAK,EAAE,EAAE,CACjD,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAC5F,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Effect } from "effect";
2
2
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
3
- import { PostgresCommandError } from "#PostgresCommandError.ts";
3
+ import { PostgresCommandError } from "#server/PostgresCommandError.ts";
4
4
  export type CommandOptions = Pick<ChildProcess.CommandOptions, "env" | "extendEnv">;
5
5
  export declare const runCommand: (command: string, args: readonly string[], options?: CommandOptions | undefined) => Effect.Effect<string, PostgresCommandError, ChildProcessSpawner.ChildProcessSpawner>;
6
6
  export declare function missingCommand(error: PostgresCommandError): boolean;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCommand.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/runCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAyB,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,KAAK,GAAG,WAAW,CAAC,CAAC;AAEpF,eAAO,MAAM,UAAU,0KAoBrB,CAAC;AAEH,wBAAgB,cAAc,CAAC,KAAK,EAAE,oBAAoB,WAEzD"}
@@ -1,6 +1,6 @@
1
1
  import { Effect, PlatformError, Stream } from "effect";
2
2
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
3
- import { PostgresCommandError } from "#PostgresCommandError.ts";
3
+ import { PostgresCommandError } from "#server/PostgresCommandError.ts";
4
4
  export const runCommand = Effect.fn("LocalPostgres.runCommand")(function* (command, args, options = {}) {
5
5
  const label = command === "docker" ? `docker ${args[0] ?? ""}`.trim() : command;
6
6
  return yield* Effect.scoped(Effect.gen(function* () {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCommand.js","sourceRoot":"","sources":["../../../src/server/adapters/runCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAIvE,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC,0BAA0B,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAe,EAAE,IAAuB,EAAE,OAAO,GAAmB,EAAE;IAChJ,MAAM,KAAK,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAChF,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAC1B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnB,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,mBAAmB,CAAC;QAC/D,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QACtG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAC/C,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,EACpH,EAAE,WAAW,EAAE,WAAW,EAAE,CAC5B,CAAC;QACF,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YAChB,OAAO,KAAK,CAAC,CAAC,IAAI,oBAAoB,CAAC;gBACtC,OAAO,EAAE,KAAK;gBACd,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC;gBACtB,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,qBAAqB,IAAI,GAAG;aAChE,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC,CAAC,CACF,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,oBAAoB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/I,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,cAAc,CAAC,KAA2B;IACzD,OAAO,KAAK,CAAC,KAAK,YAAY,aAAa,CAAC,aAAa,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;AACrG,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { Effect, FileSystem, Path } from "effect";
2
+ import { ChildProcessSpawner } from "effect/process";
3
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
4
+ import { PostgresBinaries } from "#server/PostgresBinaries.ts";
5
+ import { PostgresCommandError } from "#server/PostgresCommandError.ts";
6
+ export interface AppPostgresOptions {
7
+ readonly backupsToKeep?: number;
8
+ readonly dataDirectory: string;
9
+ }
10
+ export interface AppPostgresInstance {
11
+ readonly backupsToKeep: number;
12
+ readonly connectionUrl: string;
13
+ readonly dataDirectory: string;
14
+ readonly socketDirectory: string;
15
+ }
16
+ export declare const appPostgres: (args_0: AppPostgresOptions) => Effect.Effect<{
17
+ backupsToKeep: number;
18
+ connectionUrl: string;
19
+ dataDirectory: string;
20
+ socketDirectory: string;
21
+ }, import("./AppPostgresVersionMismatch.ts").AppPostgresVersionMismatch | LocalPostgresError | import("effect/PlatformError").PlatformError | PostgresCommandError | import("effect/Cause").TimeoutError, ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path | PostgresBinaries | import("effect/Scope").Scope>;
22
+ //# sourceMappingURL=appPostgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appPostgres.d.ts","sourceRoot":"","sources":["../../src/server/appPostgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,UAAU,EAAE,IAAI,EAAU,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CACjC;AAED,eAAO,MAAM,WAAW;;;;;wUA4DtB,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { Deferred, Effect, FileSystem, Path, Stream } from "effect";
2
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
3
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
4
+ import { PostgresBinaries } from "#server/PostgresBinaries.ts";
5
+ import { PostgresCommandError } from "#server/PostgresCommandError.ts";
6
+ import { prepareAppPostgresData } from "#server/prepareAppPostgresData.ts";
7
+ export const appPostgres = Effect.fn("LocalPostgres.appPostgres")(function* ({ dataDirectory, backupsToKeep = 5 }) {
8
+ if (!Number.isSafeInteger(backupsToKeep) || backupsToKeep < 1) {
9
+ return yield* new LocalPostgresError({ message: "backupsToKeep must be a positive integer." });
10
+ }
11
+ const fs = yield* FileSystem.FileSystem;
12
+ const path = yield* Path.Path;
13
+ const binaries = yield* PostgresBinaries;
14
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
15
+ const directory = path.resolve(dataDirectory);
16
+ yield* prepareAppPostgresData(directory);
17
+ const socketDirectory = yield* fs.makeTempDirectoryScoped({ prefix: "app-postgres-" });
18
+ yield* fs.chmod(socketDirectory, 0o700);
19
+ const child = yield* spawner.spawn(ChildProcess.make(binaries.postgres, [
20
+ "-D",
21
+ directory,
22
+ "-h",
23
+ "",
24
+ "-k",
25
+ socketDirectory,
26
+ "-c",
27
+ "unix_socket_permissions=0700",
28
+ "-c",
29
+ "logging_collector=off",
30
+ "-c",
31
+ "log_destination=stderr",
32
+ "-c",
33
+ "lc_messages=C",
34
+ ], { env: { "LC_ALL": "C" }, extendEnv: true, killSignal: "SIGINT", stdin: "ignore", stdout: "ignore" }));
35
+ const ready = yield* Deferred.make();
36
+ let diagnostics = "";
37
+ yield* child.stderr.pipe(Stream.decodeText, Stream.splitLines, Stream.runForEach((line) => {
38
+ diagnostics = line;
39
+ return line.includes("database system is ready to accept connections") ? Deferred.succeed(ready, undefined) : Effect.void;
40
+ }), Effect.forkScoped);
41
+ yield* Effect.raceFirst(Deferred.await(ready), Effect.flatMap(child.exitCode, (code) => Effect.fail(new PostgresCommandError({
42
+ command: binaries.postgres,
43
+ exitCode: Number(code),
44
+ message: diagnostics || "PostgreSQL exited before becoming ready.",
45
+ })))).pipe(Effect.timeout("30 seconds"));
46
+ const connection = new URL("postgresql://postgres@localhost/postgres");
47
+ connection.searchParams.set("host", socketDirectory);
48
+ return { backupsToKeep, connectionUrl: connection.toString(), dataDirectory: directory, socketDirectory };
49
+ });
50
+ //# sourceMappingURL=appPostgres.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appPostgres.js","sourceRoot":"","sources":["../../src/server/appPostgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAc3E,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,aAAa,EAAE,aAAa,GAAG,CAAC,EAAsB;IACpI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,KAAK,CAAC,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,2CAA2C,EAAE,CAAC,CAAC;IACh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AAC,UAAU,EACjB,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,WAAW,GAAG,IAAI,CAAC;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,gDAAgD,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;IAC3H,CAAC,CAAC,EACF,MAAM,CAAC,UAAU,CACjB,CAAC;IACF,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,CACtB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EACrB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CACvC,MAAM,CAAC,IAAI,CACV,IAAI,oBAAoB,CAAC;QACxB,OAAO,EAAE,QAAQ,CAAC,QAAQ;QAC1B,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC;QACtB,OAAO,EAAE,WAAW,IAAI,0CAA0C;KAClE,CAAC,CACF,CACD,CACD,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,0CAA0C,CAAC,CAAC;IACvE,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACrD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAgC,CAAC;AACzI,CAAC,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import { Effect } from "effect";
2
- import { LocalPostgresError } from "#LocalPostgresError.ts";
2
+ import { LocalPostgresError } from "#server/LocalPostgresError.ts";
3
3
  export declare const assertLocalDatabase: (value: string, names: readonly string[]) => Effect.Effect<import("url").URL, LocalPostgresError, never>;
4
4
  //# sourceMappingURL=assertLocalDatabase.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertLocalDatabase.d.ts","sourceRoot":"","sources":["../../src/server/assertLocalDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,eAAO,MAAM,mBAAmB,0GAY9B,CAAC"}
1
+ {"version":3,"file":"assertLocalDatabase.d.ts","sourceRoot":"","sources":["../../src/server/assertLocalDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,eAAO,MAAM,mBAAmB,0GAY9B,CAAC"}