@crvouga/mockingbird-service-postgres 1.3.1 → 1.5.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.
@@ -21,6 +21,11 @@ export type ConnectionOptions = {
21
21
  parameters: Record<string, string>;
22
22
  faults: ServerFaults;
23
23
  onLog?: (entry: ServerLog) => void;
24
+ /**
25
+ * When set, a startup packet that names a different database is fatal `3D000`.
26
+ * Unset accepts any database name.
27
+ */
28
+ database?: string;
24
29
  };
25
30
  /**
26
31
  * One client connection: the protocol state machine over the shared {@link Cluster}.
@@ -44,12 +44,27 @@ export type ServeOptions = {
44
44
  parameters?: Record<string, string>;
45
45
  /** Per-statement log sink, for tests and debugging. */
46
46
  onLog?: (entry: ServerLog) => void;
47
+ /**
48
+ * `postgres://` or `postgresql://` URL. User, password, host, port, and database name
49
+ * fill the fields above when those fields are omitted. An omitted port means `5432`;
50
+ * pass port `0` in the URL (`postgres://postgres@127.0.0.1:0/app`) for an ephemeral port.
51
+ */
52
+ url?: string;
53
+ /**
54
+ * Database name clients must request in the startup packet. A different name is
55
+ * SQLSTATE `3D000`. Set from `url` when the path is non-empty. Unset accepts any name.
56
+ */
57
+ databaseName?: string;
58
+ /** Role shown in `connectionString`. A URI's username fills this. Default `postgres`. */
59
+ user?: string;
47
60
  };
48
61
  export type PostgresServer = {
49
62
  /** The bound port. */
50
63
  readonly port: number;
51
64
  /** The bound host. */
52
65
  readonly host: string;
66
+ /** `postgres://` URL for the bound address, including the database name. */
67
+ readonly connectionString: string;
53
68
  /** The shared engine, for seeding, snapshotting or asserting from the test process. */
54
69
  readonly database: Database;
55
70
  /** The underlying `net.Server`. */
@@ -63,7 +78,8 @@ export type PostgresServer = {
63
78
  /** Stop listening and close every connection. */
64
79
  close(): Promise<void>;
65
80
  };
66
- /** Start a server and resolve once it is listening. */
67
- export declare const serve: (options?: ServeOptions) => Promise<PostgresServer>;
81
+ export type ServeInput = ServeOptions | string;
82
+ /** Start a server and resolve once it is listening. A string argument is a `postgres://` URI. */
83
+ export declare const serve: (input?: ServeInput) => Promise<PostgresServer>;
68
84
  export { Cluster } from "./cluster.js";
69
85
  export type { ServerFaults, ServerLog } from "./connection.js";