@cedarjs/pg 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/cli.cjs +139 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +140 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/constants-B7sCf4fg.cjs +41 -0
- package/dist/constants-B7sCf4fg.cjs.map +1 -0
- package/dist/constants-YnHDwShD.mjs +24 -0
- package/dist/constants-YnHDwShD.mjs.map +1 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.mts +201 -0
- package/dist/index.mjs +2 -0
- package/dist/jest.cjs +28 -0
- package/dist/jest.cjs.map +1 -0
- package/dist/jest.d.cts +14 -0
- package/dist/jest.d.mts +14 -0
- package/dist/jest.mjs +23 -0
- package/dist/jest.mjs.map +1 -0
- package/dist/lifecycle-D10usEjM.cjs +743 -0
- package/dist/lifecycle-D10usEjM.cjs.map +1 -0
- package/dist/lifecycle-PbTXNC2Z.mjs +577 -0
- package/dist/lifecycle-PbTXNC2Z.mjs.map +1 -0
- package/dist/nx.cjs +35 -0
- package/dist/nx.cjs.map +1 -0
- package/dist/nx.d.cts +26 -0
- package/dist/nx.d.mts +26 -0
- package/dist/nx.mjs +34 -0
- package/dist/nx.mjs.map +1 -0
- package/dist/tasks-CW2D0n46.mjs +16 -0
- package/dist/tasks-CW2D0n46.mjs.map +1 -0
- package/dist/tasks-DZ7hMmGJ.cjs +21 -0
- package/dist/tasks-DZ7hMmGJ.cjs.map +1 -0
- package/dist/vite-plus.cjs +65 -0
- package/dist/vite-plus.cjs.map +1 -0
- package/dist/vite-plus.d.cts +51 -0
- package/dist/vite-plus.d.mts +51 -0
- package/dist/vite-plus.mjs +61 -0
- package/dist/vite-plus.mjs.map +1 -0
- package/dist/vitest.cjs +33 -0
- package/dist/vitest.cjs.map +1 -0
- package/dist/vitest.d.cts +17 -0
- package/dist/vitest.d.mts +17 -0
- package/dist/vitest.mjs +28 -0
- package/dist/vitest.mjs.map +1 -0
- package/package.json +96 -0
- package/scripts/postinstall.js +61 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
//#region src/core/worktree.d.ts
|
|
2
|
+
type WorktreeIdentity = {
|
|
3
|
+
/** Absolute path to the worktree / project root. */
|
|
4
|
+
root: string;
|
|
5
|
+
/** Basename of the git common dir / main checkout (e.g. `cedar`). */
|
|
6
|
+
repoSlug: string;
|
|
7
|
+
/** Basename of this worktree directory (e.g. `feat-auth`). */
|
|
8
|
+
worktreeSlug: string;
|
|
9
|
+
/** First 8 hex chars of sha256(absolute root). */
|
|
10
|
+
pathHash: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the project / worktree root.
|
|
14
|
+
* Explicit `root` wins (app project path). Otherwise prefer git toplevel, then cwd.
|
|
15
|
+
*/
|
|
16
|
+
declare function resolveRoot(root?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Identify repo + worktree for observable DB naming.
|
|
19
|
+
*/
|
|
20
|
+
declare function resolveWorktreeIdentity(root?: string): WorktreeIdentity;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/core/naming.d.ts
|
|
23
|
+
type DbMode = "dev" | "test";
|
|
24
|
+
/**
|
|
25
|
+
* Build an observable Postgres database name:
|
|
26
|
+
* cpg_<repoSlug>_<worktreeSlug>_<mode>_<pathHash8>
|
|
27
|
+
*
|
|
28
|
+
* Never drops `mode` or `pathHash`. Truncates slugs to fit ≤63 chars.
|
|
29
|
+
*/
|
|
30
|
+
declare function buildDatabaseName(identity: WorktreeIdentity, mode: DbMode): string;
|
|
31
|
+
declare function buildRoleName(databaseName: string): string;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/core/lease.d.ts
|
|
34
|
+
type Lease = {
|
|
35
|
+
schemaVersion: 1;
|
|
36
|
+
mode: DbMode;
|
|
37
|
+
root: string;
|
|
38
|
+
repoSlug: string;
|
|
39
|
+
worktreeSlug: string;
|
|
40
|
+
pathHash: string;
|
|
41
|
+
databaseName: string;
|
|
42
|
+
roleName: string;
|
|
43
|
+
port: number;
|
|
44
|
+
pid: number;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
};
|
|
47
|
+
/** Narrow-parse a lease; reject incomplete or wrong-version records. */
|
|
48
|
+
declare function parseLease(raw: unknown): Lease | null;
|
|
49
|
+
declare function readLease(root: string, mode: DbMode): Lease | null;
|
|
50
|
+
declare function isOrphanLease(lease: Lease): boolean;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/core/policy.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* Shared ensure skip policy for test-runner adapters and Cedar CLI bridges.
|
|
55
|
+
*/
|
|
56
|
+
type EnsureSkip = {
|
|
57
|
+
skip: false;
|
|
58
|
+
} | {
|
|
59
|
+
skip: true;
|
|
60
|
+
reason: "disabled";
|
|
61
|
+
} | {
|
|
62
|
+
skip: true;
|
|
63
|
+
reason: "external-url";
|
|
64
|
+
databaseUrl: string;
|
|
65
|
+
};
|
|
66
|
+
type ResolveEnsureSkipInput = {
|
|
67
|
+
/** Candidate URL (TEST_DATABASE_URL for tests, DATABASE_URL for dev). */
|
|
68
|
+
url?: string;
|
|
69
|
+
/** When true, never skip (CEDAR_PG_FORCE=1). */
|
|
70
|
+
force?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* When true, skip ensure entirely.
|
|
73
|
+
* Defaults from CEDAR_PG=0|false (opt-out adapters). Pass `false` for Cedar opt-in flows.
|
|
74
|
+
*/
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* True when the URL looks like a cedarpg provisioned database (`cpg_*` name/role).
|
|
79
|
+
* These must never be treated as an external escape hatch — always re-ensure so
|
|
80
|
+
* disposed/stale shell env cannot skip provisioning.
|
|
81
|
+
*/
|
|
82
|
+
declare function isCedarPgManagedUrl(url: string | undefined): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* True when `url` is a real external database and ensure should be skipped.
|
|
85
|
+
* Sqlite `file:` URLs and cedarpg `cpg_*` URLs are not external.
|
|
86
|
+
*/
|
|
87
|
+
declare function isExternalDatabaseEscapeHatch(url: string | undefined): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Decide whether ensure should run.
|
|
90
|
+
* Adapters may call with no args (env defaults). Cedar opt-in should pass `disabled: false`
|
|
91
|
+
* and the relevant `url` (`DATABASE_URL` or `TEST_DATABASE_URL`).
|
|
92
|
+
*/
|
|
93
|
+
declare function resolveEnsureSkip(input?: ResolveEnsureSkipInput): EnsureSkip;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/core/lifecycle.d.ts
|
|
96
|
+
declare function urlFromLease(lease: Lease): string;
|
|
97
|
+
type EnsureOptions = {
|
|
98
|
+
root?: string;
|
|
99
|
+
mode: DbMode;
|
|
100
|
+
/** Inject DATABASE_URL / TEST_DATABASE_URL into process.env (default true). */
|
|
101
|
+
setEnv?: boolean;
|
|
102
|
+
};
|
|
103
|
+
type EnsureResult = {
|
|
104
|
+
databaseUrl: string;
|
|
105
|
+
databaseName: string;
|
|
106
|
+
roleName: string;
|
|
107
|
+
repoSlug: string;
|
|
108
|
+
worktreeSlug: string;
|
|
109
|
+
pathHash: string;
|
|
110
|
+
root: string;
|
|
111
|
+
mode: DbMode;
|
|
112
|
+
port: number;
|
|
113
|
+
dispose: () => Promise<void>;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Ensure a worktree-scoped database exists and return connection info.
|
|
117
|
+
*
|
|
118
|
+
* - `dev`: keep DB across restarts.
|
|
119
|
+
* - `test`: DROP when `dispose()` is awaited (callers / test runners own teardown).
|
|
120
|
+
*/
|
|
121
|
+
declare function ensure(options: EnsureOptions): Promise<EnsureResult>;
|
|
122
|
+
type EnsureIfNeededOptions = EnsureOptions & ResolveEnsureSkipInput;
|
|
123
|
+
type EnsureIfNeededResult = {
|
|
124
|
+
status: "skipped";
|
|
125
|
+
reason: "disabled";
|
|
126
|
+
} | {
|
|
127
|
+
status: "skipped";
|
|
128
|
+
reason: "external-url";
|
|
129
|
+
databaseUrl: string;
|
|
130
|
+
} | ({
|
|
131
|
+
status: "ensured";
|
|
132
|
+
} & EnsureResult);
|
|
133
|
+
/**
|
|
134
|
+
* Resolve skip policy then ensure. Single entry for hosts (Cedar CLI, Jest, Vitest).
|
|
135
|
+
* On external-url skip, sets DATABASE_URL when `setEnv` is not false.
|
|
136
|
+
*/
|
|
137
|
+
declare function ensureIfNeeded(options: EnsureIfNeededOptions): Promise<EnsureIfNeededResult>;
|
|
138
|
+
type DisposeOptions = {
|
|
139
|
+
root?: string;
|
|
140
|
+
mode?: DbMode;
|
|
141
|
+
};
|
|
142
|
+
type DisposeResult = {
|
|
143
|
+
dropped: true;
|
|
144
|
+
databaseName: string;
|
|
145
|
+
} | {
|
|
146
|
+
dropped: false;
|
|
147
|
+
reason: "no-lease" | "host-unavailable";
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* DROP the worktree database for the given mode (default: test).
|
|
151
|
+
* No-ops without a valid lease (never invents a name to DROP).
|
|
152
|
+
* If the host is unavailable, leaves the lease so dispose/gc can retry.
|
|
153
|
+
*/
|
|
154
|
+
declare function dispose(options?: DisposeOptions): Promise<DisposeResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Drop databases whose registered worktree root no longer exists on disk.
|
|
157
|
+
* Registry entries are removed only after a successful DROP.
|
|
158
|
+
*/
|
|
159
|
+
declare function gc(): Promise<{
|
|
160
|
+
dropped: string[];
|
|
161
|
+
}>;
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/providers/autopg.d.ts
|
|
164
|
+
type AutopgDiscovery = {
|
|
165
|
+
port: number;
|
|
166
|
+
adminUrl: string;
|
|
167
|
+
bin: string;
|
|
168
|
+
};
|
|
169
|
+
declare const INSTALL_HINT: string;
|
|
170
|
+
/** Password scheme v1: sha256(PASSWORD_SALT_PREFIX + "\\0" + databaseName) hex[:32]. Frozen for URL rebuild. */
|
|
171
|
+
declare const ROLE_PASSWORD_SCHEME: "v1";
|
|
172
|
+
declare function resolveAutopgBin(): string | null;
|
|
173
|
+
declare function requireAutopgBin(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Parse `autopg status --json` output. Requires a numeric port and running !== false.
|
|
176
|
+
*/
|
|
177
|
+
declare function parseHostStatus(json: string): {
|
|
178
|
+
port: number;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Discover a live autopg host via `autopg status --json`. Throws if the host is not proven live.
|
|
182
|
+
*/
|
|
183
|
+
declare function discoverHost(bin?: string): AutopgDiscovery;
|
|
184
|
+
/**
|
|
185
|
+
* Ensure the host postmaster is up. Runs `autopg install` only after status fails, then re-discovers.
|
|
186
|
+
*/
|
|
187
|
+
declare function ensureHostRunning(bin?: string): AutopgDiscovery;
|
|
188
|
+
/**
|
|
189
|
+
* Deterministic local-only password for an app role (Prisma/TCP need it;
|
|
190
|
+
* autopg hba uses `password` for 127.0.0.1).
|
|
191
|
+
*/
|
|
192
|
+
declare function rolePasswordFor(databaseName: string): string;
|
|
193
|
+
declare function buildDatabaseUrl(opts: {
|
|
194
|
+
port: number;
|
|
195
|
+
databaseName: string;
|
|
196
|
+
roleName: string;
|
|
197
|
+
password?: string;
|
|
198
|
+
}): string;
|
|
199
|
+
//#endregion
|
|
200
|
+
export { type DbMode, type DisposeOptions, type DisposeResult, type EnsureIfNeededOptions, type EnsureIfNeededResult, type EnsureOptions, type EnsureResult, type EnsureSkip, INSTALL_HINT, type Lease, ROLE_PASSWORD_SCHEME, type ResolveEnsureSkipInput, type WorktreeIdentity, buildDatabaseName, buildDatabaseUrl, buildRoleName, discoverHost, dispose, ensure, ensureHostRunning, ensureIfNeeded, gc, isCedarPgManagedUrl, isExternalDatabaseEscapeHatch, isOrphanLease, parseHostStatus, parseLease, readLease, requireAutopgBin, resolveAutopgBin, resolveEnsureSkip, resolveRoot, resolveWorktreeIdentity, rolePasswordFor, urlFromLease };
|
|
201
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
//#region src/core/worktree.d.ts
|
|
2
|
+
type WorktreeIdentity = {
|
|
3
|
+
/** Absolute path to the worktree / project root. */
|
|
4
|
+
root: string;
|
|
5
|
+
/** Basename of the git common dir / main checkout (e.g. `cedar`). */
|
|
6
|
+
repoSlug: string;
|
|
7
|
+
/** Basename of this worktree directory (e.g. `feat-auth`). */
|
|
8
|
+
worktreeSlug: string;
|
|
9
|
+
/** First 8 hex chars of sha256(absolute root). */
|
|
10
|
+
pathHash: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the project / worktree root.
|
|
14
|
+
* Explicit `root` wins (app project path). Otherwise prefer git toplevel, then cwd.
|
|
15
|
+
*/
|
|
16
|
+
declare function resolveRoot(root?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Identify repo + worktree for observable DB naming.
|
|
19
|
+
*/
|
|
20
|
+
declare function resolveWorktreeIdentity(root?: string): WorktreeIdentity;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/core/naming.d.ts
|
|
23
|
+
type DbMode = "dev" | "test";
|
|
24
|
+
/**
|
|
25
|
+
* Build an observable Postgres database name:
|
|
26
|
+
* cpg_<repoSlug>_<worktreeSlug>_<mode>_<pathHash8>
|
|
27
|
+
*
|
|
28
|
+
* Never drops `mode` or `pathHash`. Truncates slugs to fit ≤63 chars.
|
|
29
|
+
*/
|
|
30
|
+
declare function buildDatabaseName(identity: WorktreeIdentity, mode: DbMode): string;
|
|
31
|
+
declare function buildRoleName(databaseName: string): string;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/core/lease.d.ts
|
|
34
|
+
type Lease = {
|
|
35
|
+
schemaVersion: 1;
|
|
36
|
+
mode: DbMode;
|
|
37
|
+
root: string;
|
|
38
|
+
repoSlug: string;
|
|
39
|
+
worktreeSlug: string;
|
|
40
|
+
pathHash: string;
|
|
41
|
+
databaseName: string;
|
|
42
|
+
roleName: string;
|
|
43
|
+
port: number;
|
|
44
|
+
pid: number;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
};
|
|
47
|
+
/** Narrow-parse a lease; reject incomplete or wrong-version records. */
|
|
48
|
+
declare function parseLease(raw: unknown): Lease | null;
|
|
49
|
+
declare function readLease(root: string, mode: DbMode): Lease | null;
|
|
50
|
+
declare function isOrphanLease(lease: Lease): boolean;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/core/policy.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* Shared ensure skip policy for test-runner adapters and Cedar CLI bridges.
|
|
55
|
+
*/
|
|
56
|
+
type EnsureSkip = {
|
|
57
|
+
skip: false;
|
|
58
|
+
} | {
|
|
59
|
+
skip: true;
|
|
60
|
+
reason: "disabled";
|
|
61
|
+
} | {
|
|
62
|
+
skip: true;
|
|
63
|
+
reason: "external-url";
|
|
64
|
+
databaseUrl: string;
|
|
65
|
+
};
|
|
66
|
+
type ResolveEnsureSkipInput = {
|
|
67
|
+
/** Candidate URL (TEST_DATABASE_URL for tests, DATABASE_URL for dev). */
|
|
68
|
+
url?: string;
|
|
69
|
+
/** When true, never skip (CEDAR_PG_FORCE=1). */
|
|
70
|
+
force?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* When true, skip ensure entirely.
|
|
73
|
+
* Defaults from CEDAR_PG=0|false (opt-out adapters). Pass `false` for Cedar opt-in flows.
|
|
74
|
+
*/
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* True when the URL looks like a cedarpg provisioned database (`cpg_*` name/role).
|
|
79
|
+
* These must never be treated as an external escape hatch — always re-ensure so
|
|
80
|
+
* disposed/stale shell env cannot skip provisioning.
|
|
81
|
+
*/
|
|
82
|
+
declare function isCedarPgManagedUrl(url: string | undefined): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* True when `url` is a real external database and ensure should be skipped.
|
|
85
|
+
* Sqlite `file:` URLs and cedarpg `cpg_*` URLs are not external.
|
|
86
|
+
*/
|
|
87
|
+
declare function isExternalDatabaseEscapeHatch(url: string | undefined): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Decide whether ensure should run.
|
|
90
|
+
* Adapters may call with no args (env defaults). Cedar opt-in should pass `disabled: false`
|
|
91
|
+
* and the relevant `url` (`DATABASE_URL` or `TEST_DATABASE_URL`).
|
|
92
|
+
*/
|
|
93
|
+
declare function resolveEnsureSkip(input?: ResolveEnsureSkipInput): EnsureSkip;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/core/lifecycle.d.ts
|
|
96
|
+
declare function urlFromLease(lease: Lease): string;
|
|
97
|
+
type EnsureOptions = {
|
|
98
|
+
root?: string;
|
|
99
|
+
mode: DbMode;
|
|
100
|
+
/** Inject DATABASE_URL / TEST_DATABASE_URL into process.env (default true). */
|
|
101
|
+
setEnv?: boolean;
|
|
102
|
+
};
|
|
103
|
+
type EnsureResult = {
|
|
104
|
+
databaseUrl: string;
|
|
105
|
+
databaseName: string;
|
|
106
|
+
roleName: string;
|
|
107
|
+
repoSlug: string;
|
|
108
|
+
worktreeSlug: string;
|
|
109
|
+
pathHash: string;
|
|
110
|
+
root: string;
|
|
111
|
+
mode: DbMode;
|
|
112
|
+
port: number;
|
|
113
|
+
dispose: () => Promise<void>;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Ensure a worktree-scoped database exists and return connection info.
|
|
117
|
+
*
|
|
118
|
+
* - `dev`: keep DB across restarts.
|
|
119
|
+
* - `test`: DROP when `dispose()` is awaited (callers / test runners own teardown).
|
|
120
|
+
*/
|
|
121
|
+
declare function ensure(options: EnsureOptions): Promise<EnsureResult>;
|
|
122
|
+
type EnsureIfNeededOptions = EnsureOptions & ResolveEnsureSkipInput;
|
|
123
|
+
type EnsureIfNeededResult = {
|
|
124
|
+
status: "skipped";
|
|
125
|
+
reason: "disabled";
|
|
126
|
+
} | {
|
|
127
|
+
status: "skipped";
|
|
128
|
+
reason: "external-url";
|
|
129
|
+
databaseUrl: string;
|
|
130
|
+
} | ({
|
|
131
|
+
status: "ensured";
|
|
132
|
+
} & EnsureResult);
|
|
133
|
+
/**
|
|
134
|
+
* Resolve skip policy then ensure. Single entry for hosts (Cedar CLI, Jest, Vitest).
|
|
135
|
+
* On external-url skip, sets DATABASE_URL when `setEnv` is not false.
|
|
136
|
+
*/
|
|
137
|
+
declare function ensureIfNeeded(options: EnsureIfNeededOptions): Promise<EnsureIfNeededResult>;
|
|
138
|
+
type DisposeOptions = {
|
|
139
|
+
root?: string;
|
|
140
|
+
mode?: DbMode;
|
|
141
|
+
};
|
|
142
|
+
type DisposeResult = {
|
|
143
|
+
dropped: true;
|
|
144
|
+
databaseName: string;
|
|
145
|
+
} | {
|
|
146
|
+
dropped: false;
|
|
147
|
+
reason: "no-lease" | "host-unavailable";
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* DROP the worktree database for the given mode (default: test).
|
|
151
|
+
* No-ops without a valid lease (never invents a name to DROP).
|
|
152
|
+
* If the host is unavailable, leaves the lease so dispose/gc can retry.
|
|
153
|
+
*/
|
|
154
|
+
declare function dispose(options?: DisposeOptions): Promise<DisposeResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Drop databases whose registered worktree root no longer exists on disk.
|
|
157
|
+
* Registry entries are removed only after a successful DROP.
|
|
158
|
+
*/
|
|
159
|
+
declare function gc(): Promise<{
|
|
160
|
+
dropped: string[];
|
|
161
|
+
}>;
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/providers/autopg.d.ts
|
|
164
|
+
type AutopgDiscovery = {
|
|
165
|
+
port: number;
|
|
166
|
+
adminUrl: string;
|
|
167
|
+
bin: string;
|
|
168
|
+
};
|
|
169
|
+
declare const INSTALL_HINT: string;
|
|
170
|
+
/** Password scheme v1: sha256(PASSWORD_SALT_PREFIX + "\\0" + databaseName) hex[:32]. Frozen for URL rebuild. */
|
|
171
|
+
declare const ROLE_PASSWORD_SCHEME: "v1";
|
|
172
|
+
declare function resolveAutopgBin(): string | null;
|
|
173
|
+
declare function requireAutopgBin(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Parse `autopg status --json` output. Requires a numeric port and running !== false.
|
|
176
|
+
*/
|
|
177
|
+
declare function parseHostStatus(json: string): {
|
|
178
|
+
port: number;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Discover a live autopg host via `autopg status --json`. Throws if the host is not proven live.
|
|
182
|
+
*/
|
|
183
|
+
declare function discoverHost(bin?: string): AutopgDiscovery;
|
|
184
|
+
/**
|
|
185
|
+
* Ensure the host postmaster is up. Runs `autopg install` only after status fails, then re-discovers.
|
|
186
|
+
*/
|
|
187
|
+
declare function ensureHostRunning(bin?: string): AutopgDiscovery;
|
|
188
|
+
/**
|
|
189
|
+
* Deterministic local-only password for an app role (Prisma/TCP need it;
|
|
190
|
+
* autopg hba uses `password` for 127.0.0.1).
|
|
191
|
+
*/
|
|
192
|
+
declare function rolePasswordFor(databaseName: string): string;
|
|
193
|
+
declare function buildDatabaseUrl(opts: {
|
|
194
|
+
port: number;
|
|
195
|
+
databaseName: string;
|
|
196
|
+
roleName: string;
|
|
197
|
+
password?: string;
|
|
198
|
+
}): string;
|
|
199
|
+
//#endregion
|
|
200
|
+
export { type DbMode, type DisposeOptions, type DisposeResult, type EnsureIfNeededOptions, type EnsureIfNeededResult, type EnsureOptions, type EnsureResult, type EnsureSkip, INSTALL_HINT, type Lease, ROLE_PASSWORD_SCHEME, type ResolveEnsureSkipInput, type WorktreeIdentity, buildDatabaseName, buildDatabaseUrl, buildRoleName, discoverHost, dispose, ensure, ensureHostRunning, ensureIfNeeded, gc, isCedarPgManagedUrl, isExternalDatabaseEscapeHatch, isOrphanLease, parseHostStatus, parseLease, readLease, requireAutopgBin, resolveAutopgBin, resolveEnsureSkip, resolveRoot, resolveWorktreeIdentity, rolePasswordFor, urlFromLease };
|
|
201
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as buildDatabaseName, S as readLease, _ as isCedarPgManagedUrl, a as urlFromLease, b as isOrphanLease, c as buildDatabaseUrl, d as parseHostStatus, f as requireAutopgBin, g as resolveWorktreeIdentity, h as resolveRoot, i as gc, l as discoverHost, m as rolePasswordFor, n as ensure, o as INSTALL_HINT, p as resolveAutopgBin, r as ensureIfNeeded, s as ROLE_PASSWORD_SCHEME, t as dispose, u as ensureHostRunning, v as isExternalDatabaseEscapeHatch, w as buildRoleName, x as parseLease, y as resolveEnsureSkip } from "./lifecycle-PbTXNC2Z.mjs";
|
|
2
|
+
export { INSTALL_HINT, ROLE_PASSWORD_SCHEME, buildDatabaseName, buildDatabaseUrl, buildRoleName, discoverHost, dispose, ensure, ensureHostRunning, ensureIfNeeded, gc, isCedarPgManagedUrl, isExternalDatabaseEscapeHatch, isOrphanLease, parseHostStatus, parseLease, readLease, requireAutopgBin, resolveAutopgBin, resolveEnsureSkip, resolveRoot, resolveWorktreeIdentity, rolePasswordFor, urlFromLease };
|
package/dist/jest.cjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_lifecycle = require("./lifecycle-D10usEjM.cjs");
|
|
6
|
+
//#region src/adapters/jest.ts
|
|
7
|
+
/**
|
|
8
|
+
* Jest globalSetup — call from jest config:
|
|
9
|
+
* ```js
|
|
10
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
11
|
+
* ```
|
|
12
|
+
* Pair with `teardown` from this module as globalTeardown.
|
|
13
|
+
*/
|
|
14
|
+
async function globalSetup() {
|
|
15
|
+
await require_lifecycle.ensureIfNeeded({
|
|
16
|
+
mode: "test",
|
|
17
|
+
setEnv: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** Lease-gated dispose — no skip re-check (env may flip mid-suite). */
|
|
21
|
+
async function teardown() {
|
|
22
|
+
await require_lifecycle.dispose({ mode: "test" });
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.default = globalSetup;
|
|
26
|
+
exports.teardown = teardown;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=jest.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.cjs","names":["ensureIfNeeded","dispose"],"sources":["../src/adapters/jest.ts"],"sourcesContent":["import { dispose, ensureIfNeeded } from \"../core/lifecycle.ts\";\n\n/**\n * Jest globalSetup — call from jest config:\n * ```js\n * globalSetup: require.resolve('@cedarjs/pg/jest')\n * ```\n * Pair with `teardown` from this module as globalTeardown.\n */\nexport default async function globalSetup(): Promise<void> {\n await ensureIfNeeded({\n mode: \"test\",\n setEnv: true,\n });\n}\n\n/** Lease-gated dispose — no skip re-check (env may flip mid-suite). */\nexport async function teardown(): Promise<void> {\n await dispose({ mode: \"test\" });\n}\n"],"mappings":";;;;;;;;;;;;;AASA,eAA8B,cAA6B;CACzD,MAAMA,kBAAAA,eAAe;EACnB,MAAM;EACN,QAAQ;CACV,CAAC;AACH;;AAGA,eAAsB,WAA0B;CAC9C,MAAMC,kBAAAA,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChC"}
|
package/dist/jest.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/adapters/jest.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Jest globalSetup — call from jest config:
|
|
4
|
+
* ```js
|
|
5
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
6
|
+
* ```
|
|
7
|
+
* Pair with `teardown` from this module as globalTeardown.
|
|
8
|
+
*/
|
|
9
|
+
declare function globalSetup(): Promise<void>;
|
|
10
|
+
/** Lease-gated dispose — no skip re-check (env may flip mid-suite). */
|
|
11
|
+
declare function teardown(): Promise<void>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { globalSetup as default, teardown };
|
|
14
|
+
//# sourceMappingURL=jest.d.cts.map
|
package/dist/jest.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/adapters/jest.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Jest globalSetup — call from jest config:
|
|
4
|
+
* ```js
|
|
5
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
6
|
+
* ```
|
|
7
|
+
* Pair with `teardown` from this module as globalTeardown.
|
|
8
|
+
*/
|
|
9
|
+
declare function globalSetup(): Promise<void>;
|
|
10
|
+
/** Lease-gated dispose — no skip re-check (env may flip mid-suite). */
|
|
11
|
+
declare function teardown(): Promise<void>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { globalSetup as default, teardown };
|
|
14
|
+
//# sourceMappingURL=jest.d.mts.map
|
package/dist/jest.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { r as ensureIfNeeded, t as dispose } from "./lifecycle-PbTXNC2Z.mjs";
|
|
2
|
+
//#region src/adapters/jest.ts
|
|
3
|
+
/**
|
|
4
|
+
* Jest globalSetup — call from jest config:
|
|
5
|
+
* ```js
|
|
6
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
7
|
+
* ```
|
|
8
|
+
* Pair with `teardown` from this module as globalTeardown.
|
|
9
|
+
*/
|
|
10
|
+
async function globalSetup() {
|
|
11
|
+
await ensureIfNeeded({
|
|
12
|
+
mode: "test",
|
|
13
|
+
setEnv: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Lease-gated dispose — no skip re-check (env may flip mid-suite). */
|
|
17
|
+
async function teardown() {
|
|
18
|
+
await dispose({ mode: "test" });
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { globalSetup as default, teardown };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=jest.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.mjs","names":[],"sources":["../src/adapters/jest.ts"],"sourcesContent":["import { dispose, ensureIfNeeded } from \"../core/lifecycle.ts\";\n\n/**\n * Jest globalSetup — call from jest config:\n * ```js\n * globalSetup: require.resolve('@cedarjs/pg/jest')\n * ```\n * Pair with `teardown` from this module as globalTeardown.\n */\nexport default async function globalSetup(): Promise<void> {\n await ensureIfNeeded({\n mode: \"test\",\n setEnv: true,\n });\n}\n\n/** Lease-gated dispose — no skip re-check (env may flip mid-suite). */\nexport async function teardown(): Promise<void> {\n await dispose({ mode: \"test\" });\n}\n"],"mappings":";;;;;;;;;AASA,eAA8B,cAA6B;CACzD,MAAM,eAAe;EACnB,MAAM;EACN,QAAQ;CACV,CAAC;AACH;;AAGA,eAAsB,WAA0B;CAC9C,MAAM,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChC"}
|