@shivaedev/local-postgres 0.9.0 → 0.10.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 +3 -2
- package/dist/server/assertLocalDatabase.d.ts +4 -0
- package/dist/server/assertLocalDatabase.d.ts.map +1 -0
- package/dist/server/assertLocalDatabase.js +14 -0
- package/dist/server/assertLocalDatabase.js.map +1 -0
- package/dist/server/localPostgres.d.ts +0 -1
- package/dist/server/localPostgres.d.ts.map +1 -1
- package/dist/server/localPostgres.js +1 -11
- package/dist/server/localPostgres.js.map +1 -1
- package/package.json +3 -3
- package/src/server/assertLocalDatabase.ts +16 -0
- package/src/server/localPostgres.ts +1 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0 - 2026-11-02
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- Import `assertLocalDatabase` from `@shivaedev/local-postgres/server/assertLocalDatabase.ts` instead of `@shivaedev/local-postgres/server/localPostgres.ts`. The validator has its own module so validation stays independent of process execution; its validation behavior is unchanged.
|
|
8
|
+
|
|
3
9
|
## 0.9.0 - 2026-11-02
|
|
4
10
|
|
|
5
11
|
### Fixed
|
package/README.md
CHANGED
|
@@ -59,7 +59,8 @@ Use `assertLocalDatabase` when the setup script owns a fixed set of database nam
|
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
61
|
import { Effect } from "effect";
|
|
62
|
-
import { assertLocalDatabase
|
|
62
|
+
import { assertLocalDatabase } from "@shivaedev/local-postgres/server/assertLocalDatabase.ts";
|
|
63
|
+
import { LOCAL_SERVER, localPostgres } from "@shivaedev/local-postgres/server/localPostgres.ts";
|
|
63
64
|
|
|
64
65
|
const setup = Effect.gen(function* () {
|
|
65
66
|
const development = `${LOCAL_SERVER}/example_dev`;
|
|
@@ -98,7 +99,7 @@ On each start, setup reads `SHOW max_connections`. Native servers retain their c
|
|
|
98
99
|
|
|
99
100
|
### API
|
|
100
101
|
|
|
101
|
-
Import
|
|
102
|
+
Import service preparation from `@shivaedev/local-postgres/server/localPostgres.ts` and fixed-name validation from `@shivaedev/local-postgres/server/assertLocalDatabase.ts`:
|
|
102
103
|
|
|
103
104
|
| Export | Purpose |
|
|
104
105
|
| ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { LocalPostgresError } from "#LocalPostgresError.ts";
|
|
3
|
+
export declare const assertLocalDatabase: (value: string, names: readonly string[]) => Effect.Effect<import("url").URL, LocalPostgresError, never>;
|
|
4
|
+
//# sourceMappingURL=assertLocalDatabase.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { LocalPostgresError } from "#LocalPostgresError.ts";
|
|
3
|
+
export const assertLocalDatabase = Effect.fn("LocalPostgres.assertLocalDatabase")(function* (value, names) {
|
|
4
|
+
const message = `Use a local database on 127.0.0.1:55432 named ${names.join(" or ")}.`;
|
|
5
|
+
const url = yield* Effect.try({ catch: () => new LocalPostgresError({ message }), try: () => new URL(value) });
|
|
6
|
+
if (!(["postgres:", "postgresql:"].includes(url.protocol) && ["localhost", "127.0.0.1"].includes(url.hostname))
|
|
7
|
+
|| url.port !== "55432"
|
|
8
|
+
|| ["host", "hostaddr", "port", "dbname", "service"].some((key) => url.searchParams.has(key))
|
|
9
|
+
|| !names.includes(url.pathname.slice(1))) {
|
|
10
|
+
return yield* new LocalPostgresError({ message });
|
|
11
|
+
}
|
|
12
|
+
return url;
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=assertLocalDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertLocalDatabase.js","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,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,EAAE,CAAC,mCAAmC,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAa,EAAE,KAAwB;IACnI,MAAM,OAAO,GAAG,iDAAiD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACvF,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC/G,IACC,CAAC,CAAC,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;WACxG,GAAG,CAAC,IAAI,KAAK,OAAO;WACpB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;WAC1F,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACxC,CAAC;QACF,OAAO,KAAK,CAAC,CAAC,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC,CAAC"}
|
|
@@ -3,7 +3,6 @@ import { LocalPostgresError } from "#LocalPostgresError.ts";
|
|
|
3
3
|
import { type DockerEnvironment } from "#localDocker.ts";
|
|
4
4
|
import { PostgresVersionMismatch } from "#PostgresVersionMismatch.ts";
|
|
5
5
|
export declare const LOCAL_SERVER = "postgresql://postgres:postgres@127.0.0.1:55432";
|
|
6
|
-
export declare const assertLocalDatabase: (value: string, names: readonly string[]) => Effect.Effect<import("url").URL, LocalPostgresError, never>;
|
|
7
6
|
export interface ReadinessOptions {
|
|
8
7
|
readonly attempts?: number;
|
|
9
8
|
readonly delayMillis?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localPostgres.d.ts","sourceRoot":"","sources":["../../src/server/localPostgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"localPostgres.d.ts","sourceRoot":"","sources":["../../src/server/localPostgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAG5D,OAAO,EAAE,KAAK,iBAAiB,EAAU,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAGtE,eAAO,MAAM,YAAY,mDAAmD,CAAC;AAE7E,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,iBAAiB,EAAE,EAAE,QAAa,EAAE,WAAkB,EAAE,GAAE,gBAAqB;;;;EAuDzH"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect, Schedule } from "effect";
|
|
2
|
+
import { assertLocalDatabase } from "#assertLocalDatabase.ts";
|
|
2
3
|
import { clientConnection } from "#clientConnection.ts";
|
|
3
4
|
import { LocalPostgresError } from "#LocalPostgresError.ts";
|
|
4
5
|
import { ensureConnections } from "#localConnections.ts";
|
|
@@ -7,17 +8,6 @@ import { docker } from "#localDocker.ts";
|
|
|
7
8
|
import { PostgresVersionMismatch } from "#PostgresVersionMismatch.ts";
|
|
8
9
|
import { missingCommand, runCommand } from "#runCommand.ts";
|
|
9
10
|
export const LOCAL_SERVER = "postgresql://postgres:postgres@127.0.0.1:55432";
|
|
10
|
-
export const assertLocalDatabase = Effect.fn("LocalPostgres.assertLocalDatabase")(function* (value, names) {
|
|
11
|
-
const message = `Use a local database on 127.0.0.1:55432 named ${names.join(" or ")}.`;
|
|
12
|
-
const url = yield* Effect.try({ catch: () => new LocalPostgresError({ message }), try: () => new URL(value) });
|
|
13
|
-
if (!(["postgres:", "postgresql:"].includes(url.protocol) && ["localhost", "127.0.0.1"].includes(url.hostname))
|
|
14
|
-
|| url.port !== "55432"
|
|
15
|
-
|| ["host", "hostaddr", "port", "dbname", "service"].some((key) => url.searchParams.has(key))
|
|
16
|
-
|| !names.includes(url.pathname.slice(1))) {
|
|
17
|
-
return yield* new LocalPostgresError({ message });
|
|
18
|
-
}
|
|
19
|
-
return url;
|
|
20
|
-
});
|
|
21
11
|
export function localPostgres(environment, { attempts = 30, delayMillis = 1000 } = {}) {
|
|
22
12
|
function localDocker(args, options) {
|
|
23
13
|
return docker(environment, args, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localPostgres.js","sourceRoot":"","sources":["../../src/server/localPostgres.ts"],"names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AAC,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/local-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Repeatable local PostgreSQL preparation with one shared persistent service",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/local-postgres#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@effect/platform-node": "4.0.6",
|
|
44
|
-
"@shivaedev/quality": "0.
|
|
45
|
-
"@shivaedev/test-story": "0.
|
|
44
|
+
"@shivaedev/quality": "0.56.0",
|
|
45
|
+
"@shivaedev/test-story": "0.34.0",
|
|
46
46
|
"@types/node": "24.19.2",
|
|
47
47
|
"effect": "4.0.6",
|
|
48
48
|
"typescript": "7.0.2",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { LocalPostgresError } from "#LocalPostgresError.ts";
|
|
3
|
+
|
|
4
|
+
export const assertLocalDatabase = Effect.fn("LocalPostgres.assertLocalDatabase")(function* (value: string, names: readonly string[]) {
|
|
5
|
+
const message = `Use a local database on 127.0.0.1:55432 named ${names.join(" or ")}.`;
|
|
6
|
+
const url = yield* Effect.try({ catch: () => new LocalPostgresError({ message }), try: () => new URL(value) });
|
|
7
|
+
if (
|
|
8
|
+
!(["postgres:", "postgresql:"].includes(url.protocol) && ["localhost", "127.0.0.1"].includes(url.hostname))
|
|
9
|
+
|| url.port !== "55432"
|
|
10
|
+
|| ["host", "hostaddr", "port", "dbname", "service"].some((key) => url.searchParams.has(key))
|
|
11
|
+
|| !names.includes(url.pathname.slice(1))
|
|
12
|
+
) {
|
|
13
|
+
return yield* new LocalPostgresError({ message });
|
|
14
|
+
}
|
|
15
|
+
return url;
|
|
16
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect, Schedule } from "effect";
|
|
2
|
+
import { assertLocalDatabase } from "#assertLocalDatabase.ts";
|
|
2
3
|
import { clientConnection } from "#clientConnection.ts";
|
|
3
4
|
import { LocalPostgresError } from "#LocalPostgresError.ts";
|
|
4
5
|
import { ensureConnections } from "#localConnections.ts";
|
|
@@ -9,20 +10,6 @@ import { type CommandOptions, missingCommand, runCommand } from "#runCommand.ts"
|
|
|
9
10
|
|
|
10
11
|
export const LOCAL_SERVER = "postgresql://postgres:postgres@127.0.0.1:55432";
|
|
11
12
|
|
|
12
|
-
export const assertLocalDatabase = Effect.fn("LocalPostgres.assertLocalDatabase")(function* (value: string, names: readonly string[]) {
|
|
13
|
-
const message = `Use a local database on 127.0.0.1:55432 named ${names.join(" or ")}.`;
|
|
14
|
-
const url = yield* Effect.try({ catch: () => new LocalPostgresError({ message }), try: () => new URL(value) });
|
|
15
|
-
if (
|
|
16
|
-
!(["postgres:", "postgresql:"].includes(url.protocol) && ["localhost", "127.0.0.1"].includes(url.hostname))
|
|
17
|
-
|| url.port !== "55432"
|
|
18
|
-
|| ["host", "hostaddr", "port", "dbname", "service"].some((key) => url.searchParams.has(key))
|
|
19
|
-
|| !names.includes(url.pathname.slice(1))
|
|
20
|
-
) {
|
|
21
|
-
return yield* new LocalPostgresError({ message });
|
|
22
|
-
}
|
|
23
|
-
return url;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
13
|
export interface ReadinessOptions {
|
|
27
14
|
readonly attempts?: number;
|
|
28
15
|
readonly delayMillis?: number;
|