@cedarjs/pg 0.1.0-alpha.0 → 0.2.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/README.md +281 -30
- package/dist/cli.cjs +62 -16
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +61 -15
- package/dist/cli.mjs.map +1 -1
- package/dist/{constants-B7sCf4fg.cjs → constants-Ct8myrEn.cjs} +4 -4
- package/dist/constants-Ct8myrEn.cjs.map +1 -0
- package/dist/{constants-YnHDwShD.mjs → constants-NLR0U4NR.mjs} +4 -4
- package/dist/constants-NLR0U4NR.mjs.map +1 -0
- package/dist/dev-env.cjs +12 -0
- package/dist/dev-env.cjs.map +1 -0
- package/dist/dev-env.d.cts +1 -0
- package/dist/dev-env.d.mts +1 -0
- package/dist/dev-env.mjs +14 -0
- package/dist/dev-env.mjs.map +1 -0
- package/dist/index.cjs +50 -10
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +168 -82
- package/dist/index.d.mts +168 -82
- package/dist/index.mjs +32 -2
- package/dist/index.mjs.map +1 -0
- package/dist/jest-teardown.cjs +18 -0
- package/dist/jest-teardown.cjs.map +1 -0
- package/dist/jest-teardown.d.cts +13 -0
- package/dist/jest-teardown.d.mts +14 -0
- package/dist/jest-teardown.mjs +18 -0
- package/dist/jest-teardown.mjs.map +1 -0
- package/dist/jest-template.cjs +41 -0
- package/dist/jest-template.cjs.map +1 -0
- package/dist/jest-template.d.cts +28 -0
- package/dist/jest-template.d.mts +28 -0
- package/dist/jest-template.mjs +35 -0
- package/dist/jest-template.mjs.map +1 -0
- package/dist/jest.cjs +12 -15
- package/dist/jest.cjs.map +1 -1
- package/dist/jest.d.cts +10 -7
- package/dist/jest.d.mts +10 -6
- package/dist/jest.mjs +12 -10
- package/dist/jest.mjs.map +1 -1
- package/dist/lease-B3TuX92y.d.mts +24 -0
- package/dist/lease-BSBBpaR4.mjs +201 -0
- package/dist/lease-BSBBpaR4.mjs.map +1 -0
- package/dist/lease-Bq9wKwQa.cjs +272 -0
- package/dist/lease-Bq9wKwQa.cjs.map +1 -0
- package/dist/lease-t4I9JahV.d.cts +24 -0
- package/dist/lifecycle-BOo6xBjD.mjs +684 -0
- package/dist/lifecycle-BOo6xBjD.mjs.map +1 -0
- package/dist/lifecycle-DEJ4GgWV.cjs +856 -0
- package/dist/lifecycle-DEJ4GgWV.cjs.map +1 -0
- package/dist/load-dev-env-7UjMHhw7.mjs +10 -0
- package/dist/load-dev-env-7UjMHhw7.mjs.map +1 -0
- package/dist/load-dev-env-cII6N4ZP.cjs +15 -0
- package/dist/load-dev-env-cII6N4ZP.cjs.map +1 -0
- package/dist/load-mode-env-B0qO9DZx.cjs +39 -0
- package/dist/load-mode-env-B0qO9DZx.cjs.map +1 -0
- package/dist/load-mode-env-C8gy4v9V.mjs +28 -0
- package/dist/load-mode-env-C8gy4v9V.mjs.map +1 -0
- package/dist/load-test-env-C34wpkIX.mjs +18 -0
- package/dist/load-test-env-C34wpkIX.mjs.map +1 -0
- package/dist/load-test-env-CkdUjTpV.cjs +23 -0
- package/dist/load-test-env-CkdUjTpV.cjs.map +1 -0
- package/dist/naming-C2nGVxPk.d.cts +39 -0
- package/dist/naming-C2nGVxPk.d.mts +39 -0
- package/dist/nx.cjs +26 -17
- package/dist/nx.cjs.map +1 -1
- package/dist/nx.d.cts +9 -20
- package/dist/nx.d.mts +9 -20
- package/dist/nx.mjs +20 -18
- package/dist/nx.mjs.map +1 -1
- package/dist/tasks-Caud9yHr.cjs +67 -0
- package/dist/tasks-Caud9yHr.cjs.map +1 -0
- package/dist/tasks-CjaZRi_G.d.mts +19 -0
- package/dist/tasks-DdQoP9We.d.cts +19 -0
- package/dist/tasks-KherHLac.mjs +38 -0
- package/dist/tasks-KherHLac.mjs.map +1 -0
- package/dist/template-CGw3C1Ob.mjs +88 -0
- package/dist/template-CGw3C1Ob.mjs.map +1 -0
- package/dist/template-D0gJ_MS2.cjs +105 -0
- package/dist/template-D0gJ_MS2.cjs.map +1 -0
- package/dist/template-mode-BkEs9LnY.cjs +91 -0
- package/dist/template-mode-BkEs9LnY.cjs.map +1 -0
- package/dist/template-mode-CcxV_Iju.d.cts +28 -0
- package/dist/template-mode-CcxV_Iju.d.mts +28 -0
- package/dist/template-mode-IjlFOG4O.mjs +80 -0
- package/dist/template-mode-IjlFOG4O.mjs.map +1 -0
- package/dist/test-env.cjs +16 -0
- package/dist/test-env.cjs.map +1 -0
- package/dist/test-env.d.cts +1 -0
- package/dist/test-env.d.mts +1 -0
- package/dist/test-env.mjs +18 -0
- package/dist/test-env.mjs.map +1 -0
- package/dist/vite-plus.cjs +8 -33
- package/dist/vite-plus.cjs.map +1 -1
- package/dist/vite-plus.d.cts +4 -48
- package/dist/vite-plus.d.mts +4 -48
- package/dist/vite-plus.mjs +5 -30
- package/dist/vite-plus.mjs.map +1 -1
- package/dist/vitest-template.cjs +48 -0
- package/dist/vitest-template.cjs.map +1 -0
- package/dist/vitest-template.d.cts +31 -0
- package/dist/vitest-template.d.mts +31 -0
- package/dist/vitest-template.mjs +42 -0
- package/dist/vitest-template.mjs.map +1 -0
- package/dist/vitest.cjs +10 -10
- package/dist/vitest.cjs.map +1 -1
- package/dist/vitest.d.cts +7 -3
- package/dist/vitest.d.mts +7 -2
- package/dist/vitest.mjs +10 -5
- package/dist/vitest.mjs.map +1 -1
- package/package.json +37 -13
- package/scripts/autopg-version +1 -0
- package/scripts/ci-install-autopg.sh +73 -0
- package/scripts/postinstall.js +39 -13
- package/dist/constants-B7sCf4fg.cjs.map +0 -1
- package/dist/constants-YnHDwShD.mjs.map +0 -1
- package/dist/lifecycle-D10usEjM.cjs +0 -743
- package/dist/lifecycle-D10usEjM.cjs.map +0 -1
- package/dist/lifecycle-PbTXNC2Z.mjs +0 -577
- package/dist/lifecycle-PbTXNC2Z.mjs.map +0 -1
- package/dist/tasks-CW2D0n46.mjs +0 -16
- package/dist/tasks-CW2D0n46.mjs.map +0 -1
- package/dist/tasks-DZ7hMmGJ.cjs +0 -21
- package/dist/tasks-DZ7hMmGJ.cjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,59 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
1
|
+
import { a as WorktreeIdentity, i as buildRoleName, n as buildCloneDatabaseName, o as resolveRoot, r as buildDatabaseName, s as resolveWorktreeIdentity, t as DbMode } from "./naming-C2nGVxPk.cjs";
|
|
2
|
+
import { a as readLease, i as parseLease, n as envFilePath, r as isOrphanLease, t as Lease } from "./lease-t4I9JahV.cjs";
|
|
52
3
|
//#region src/core/policy.d.ts
|
|
53
4
|
/**
|
|
54
|
-
* Shared
|
|
5
|
+
* Shared acquire skip policy for test-runner adapters and Cedar CLI bridges.
|
|
55
6
|
*/
|
|
56
|
-
type
|
|
7
|
+
type AcquireSkip = {
|
|
57
8
|
skip: false;
|
|
58
9
|
} | {
|
|
59
10
|
skip: true;
|
|
@@ -63,45 +14,55 @@ type EnsureSkip = {
|
|
|
63
14
|
reason: "external-url";
|
|
64
15
|
databaseUrl: string;
|
|
65
16
|
};
|
|
66
|
-
type
|
|
17
|
+
type ResolveAcquireSkipInput = {
|
|
67
18
|
/** Candidate URL (TEST_DATABASE_URL for tests, DATABASE_URL for dev). */
|
|
68
19
|
url?: string;
|
|
69
20
|
/** When true, never skip (CEDAR_PG_FORCE=1). */
|
|
70
21
|
force?: boolean;
|
|
71
22
|
/**
|
|
72
|
-
* When true, skip
|
|
23
|
+
* When true, skip acquire entirely.
|
|
73
24
|
* Defaults from CEDAR_PG=0|false (opt-out adapters). Pass `false` for Cedar opt-in flows.
|
|
74
25
|
*/
|
|
75
26
|
disabled?: boolean;
|
|
76
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Inject DATABASE_URL (and TEST_DATABASE_URL for test mode) from a resolved URL.
|
|
30
|
+
* Single env path for acquire, clone, and external-url skip.
|
|
31
|
+
*/
|
|
32
|
+
declare function applyDatabaseUrlEnv(databaseUrl: string, options?: {
|
|
33
|
+
mode?: "dev" | "test";
|
|
34
|
+
}): void;
|
|
77
35
|
/**
|
|
78
36
|
* True when the URL looks like a cedarpg provisioned database (`cpg_*` name/role).
|
|
79
|
-
* These must never be treated as an external escape hatch
|
|
37
|
+
* These must never be treated as an external escape hatch; always re-acquire so
|
|
80
38
|
* disposed/stale shell env cannot skip provisioning.
|
|
81
39
|
*/
|
|
82
40
|
declare function isCedarPgManagedUrl(url: string | undefined): boolean;
|
|
83
41
|
/**
|
|
84
|
-
* True when `url` is a real external database and
|
|
85
|
-
* Sqlite `file:` URLs
|
|
42
|
+
* True when `url` is a real external database and acquire should be skipped.
|
|
43
|
+
* Sqlite `file:` URLs, cedarpg `cpg_*` URLs, and unset template placeholders
|
|
44
|
+
* are not external.
|
|
86
45
|
*/
|
|
87
46
|
declare function isExternalDatabaseEscapeHatch(url: string | undefined): boolean;
|
|
88
47
|
/**
|
|
89
|
-
* Decide whether
|
|
48
|
+
* Decide whether acquire should run.
|
|
90
49
|
* Adapters may call with no args (env defaults). Cedar opt-in should pass `disabled: false`
|
|
91
50
|
* and the relevant `url` (`DATABASE_URL` or `TEST_DATABASE_URL`).
|
|
92
51
|
*/
|
|
93
|
-
declare function
|
|
52
|
+
declare function resolveAcquireSkip(input?: ResolveAcquireSkipInput): AcquireSkip;
|
|
94
53
|
//#endregion
|
|
95
54
|
//#region src/core/lifecycle.d.ts
|
|
96
55
|
declare function urlFromLease(lease: Lease): string;
|
|
97
|
-
type
|
|
56
|
+
type AcquireOptions = {
|
|
98
57
|
root?: string;
|
|
99
58
|
mode: DbMode;
|
|
100
59
|
/** Inject DATABASE_URL / TEST_DATABASE_URL into process.env (default true). */
|
|
101
60
|
setEnv?: boolean;
|
|
102
61
|
};
|
|
103
|
-
type
|
|
62
|
+
type AcquireResult = {
|
|
104
63
|
databaseUrl: string;
|
|
64
|
+
/** Superuser URL for privileged DDL (mark template, CREATE DATABASE … TEMPLATE). */
|
|
65
|
+
adminUrl: string;
|
|
105
66
|
databaseName: string;
|
|
106
67
|
roleName: string;
|
|
107
68
|
repoSlug: string;
|
|
@@ -113,14 +74,14 @@ type EnsureResult = {
|
|
|
113
74
|
dispose: () => Promise<void>;
|
|
114
75
|
};
|
|
115
76
|
/**
|
|
116
|
-
*
|
|
77
|
+
* Acquire a worktree-scoped database and return connection info.
|
|
117
78
|
*
|
|
118
79
|
* - `dev`: keep DB across restarts.
|
|
119
80
|
* - `test`: DROP when `dispose()` is awaited (callers / test runners own teardown).
|
|
120
81
|
*/
|
|
121
|
-
declare function
|
|
122
|
-
type
|
|
123
|
-
type
|
|
82
|
+
declare function acquire(options: AcquireOptions): Promise<AcquireResult>;
|
|
83
|
+
type AcquireIfNeededOptions = AcquireOptions & ResolveAcquireSkipInput;
|
|
84
|
+
type AcquireIfNeededResult = {
|
|
124
85
|
status: "skipped";
|
|
125
86
|
reason: "disabled";
|
|
126
87
|
} | {
|
|
@@ -128,13 +89,13 @@ type EnsureIfNeededResult = {
|
|
|
128
89
|
reason: "external-url";
|
|
129
90
|
databaseUrl: string;
|
|
130
91
|
} | ({
|
|
131
|
-
status: "
|
|
132
|
-
} &
|
|
92
|
+
status: "acquired";
|
|
93
|
+
} & AcquireResult);
|
|
133
94
|
/**
|
|
134
|
-
* Resolve skip policy then
|
|
135
|
-
* On external-url skip,
|
|
95
|
+
* Resolve skip policy then acquire. Single entry for hosts (Cedar CLI, Jest, Vitest).
|
|
96
|
+
* On external-url skip, applies DATABASE_URL / TEST_DATABASE_URL when `setEnv` is not false.
|
|
136
97
|
*/
|
|
137
|
-
declare function
|
|
98
|
+
declare function acquireIfNeeded(options: AcquireIfNeededOptions): Promise<AcquireIfNeededResult>;
|
|
138
99
|
type DisposeOptions = {
|
|
139
100
|
root?: string;
|
|
140
101
|
mode?: DbMode;
|
|
@@ -142,24 +103,150 @@ type DisposeOptions = {
|
|
|
142
103
|
type DisposeResult = {
|
|
143
104
|
dropped: true;
|
|
144
105
|
databaseName: string;
|
|
106
|
+
droppedDatabases: string[];
|
|
145
107
|
} | {
|
|
146
108
|
dropped: false;
|
|
147
109
|
reason: "no-lease" | "host-unavailable";
|
|
148
110
|
};
|
|
149
111
|
/**
|
|
150
|
-
* DROP
|
|
151
|
-
*
|
|
112
|
+
* Role-scoped suite teardown: DROP every database owned by the lease role
|
|
113
|
+
* (TEMPLATE + clones), then DROP ROLE and forget the lease. Unsets `IS_TEMPLATE`
|
|
114
|
+
* as needed. This is not per-clone cleanup — use `CloneResult.dropClone` for that.
|
|
115
|
+
* No-ops without a valid lease; never invents a DROP target beyond role ownership.
|
|
152
116
|
* If the host is unavailable, leaves the lease so dispose/gc can retry.
|
|
153
117
|
*/
|
|
154
118
|
declare function dispose(options?: DisposeOptions): Promise<DisposeResult>;
|
|
155
119
|
/**
|
|
156
120
|
* Drop databases whose registered worktree root no longer exists on disk.
|
|
157
|
-
* Registry entries are removed only after a successful DROP.
|
|
121
|
+
* Registry entries are removed only after a successful DROP (owned DBs + lease DB).
|
|
158
122
|
*/
|
|
159
123
|
declare function gc(): Promise<{
|
|
160
124
|
dropped: string[];
|
|
161
125
|
}>;
|
|
162
126
|
//#endregion
|
|
127
|
+
//#region src/core/template.d.ts
|
|
128
|
+
type MarkTemplateOptions = {
|
|
129
|
+
root?: string;
|
|
130
|
+
mode: DbMode;
|
|
131
|
+
/** Superuser URL from `acquire`; when omitted, discovers/starts the host. */
|
|
132
|
+
adminUrl?: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* After migrations, mark the leased DB as a PostgreSQL TEMPLATE so workers can clone it.
|
|
136
|
+
* Requires a lease from `acquire` (no datname override).
|
|
137
|
+
*/
|
|
138
|
+
declare function markTemplate(options: MarkTemplateOptions): Promise<{
|
|
139
|
+
databaseName: string;
|
|
140
|
+
adminUrl: string;
|
|
141
|
+
}>;
|
|
142
|
+
type CloneFromTemplateOptions = {
|
|
143
|
+
root?: string;
|
|
144
|
+
mode: DbMode;
|
|
145
|
+
/** Superuser URL from `acquire`; when omitted, discovers/starts the host. */
|
|
146
|
+
adminUrl?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Suffix for the clone datname (e.g. Jest worker id).
|
|
149
|
+
* Defaults to `<pid>_<base36 time>`.
|
|
150
|
+
*/
|
|
151
|
+
name?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Inject DATABASE_URL / TEST_DATABASE_URL for this clone (default false).
|
|
154
|
+
* Host `cloneFromTemplateIfNeeded` defaults true; worker adapters pass true explicitly.
|
|
155
|
+
*/
|
|
156
|
+
setEnv?: boolean;
|
|
157
|
+
};
|
|
158
|
+
type CloneResult = {
|
|
159
|
+
databaseUrl: string;
|
|
160
|
+
adminUrl: string;
|
|
161
|
+
databaseName: string;
|
|
162
|
+
roleName: string;
|
|
163
|
+
templateName: string;
|
|
164
|
+
port: number;
|
|
165
|
+
/**
|
|
166
|
+
* DROP this clone only (leaves TEMPLATE + role if still owned elsewhere).
|
|
167
|
+
* Not suite teardown — use role-scoped `dispose` for that.
|
|
168
|
+
*/
|
|
169
|
+
dropClone: () => Promise<void>;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Clone the leased TEMPLATE database via admin (`CREATE DATABASE … TEMPLATE`).
|
|
173
|
+
* Reuses the template role so `databaseUrl` passwords stay valid (scheme v2).
|
|
174
|
+
* Provider rejects when the leased DB is not marked TEMPLATE.
|
|
175
|
+
* Port comes from the lease; admin URL is passed through or rediscovered.
|
|
176
|
+
*/
|
|
177
|
+
declare function cloneFromTemplate(options: CloneFromTemplateOptions): Promise<CloneResult>;
|
|
178
|
+
type CloneFromTemplateIfNeededOptions = CloneFromTemplateOptions & ResolveAcquireSkipInput;
|
|
179
|
+
type CloneFromTemplateIfNeededResult = {
|
|
180
|
+
status: "skipped";
|
|
181
|
+
reason: "disabled";
|
|
182
|
+
} | {
|
|
183
|
+
status: "skipped";
|
|
184
|
+
reason: "external-url";
|
|
185
|
+
databaseUrl: string;
|
|
186
|
+
} | ({
|
|
187
|
+
status: "cloned";
|
|
188
|
+
} & CloneResult);
|
|
189
|
+
/**
|
|
190
|
+
* Resolve skip policy then clone. Host entry for worker adapters (same skip
|
|
191
|
+
* semantics as `acquireIfNeeded`). Defaults `setEnv` on for skip and clone paths.
|
|
192
|
+
*/
|
|
193
|
+
declare function cloneFromTemplateIfNeeded(options: CloneFromTemplateIfNeededOptions): Promise<CloneFromTemplateIfNeededResult>;
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/core/constants.d.ts
|
|
196
|
+
/**
|
|
197
|
+
* Product identity vs frozen crypto.
|
|
198
|
+
*
|
|
199
|
+
* State dirs follow the CLI name (`.cedarpg`): product-owned, not nested under
|
|
200
|
+
* autopg's `~/.autopg/` (host owns that) and not a generic `.pg` (collision-prone).
|
|
201
|
+
* Password salt is an opaque crypto constant; bump ROLE_PASSWORD_SCHEME to change it.
|
|
202
|
+
*/
|
|
203
|
+
/** User-facing CLI binary (`package.json` bin) and log prefix */
|
|
204
|
+
declare const CLI_NAME = "cedarpg";
|
|
205
|
+
/**
|
|
206
|
+
* Worktree-local state dir and home-registry parent (`~/.cedarpg/registry`).
|
|
207
|
+
* Frozen for lease/gc discovery after first alpha consumers appear.
|
|
208
|
+
*/
|
|
209
|
+
declare const STATE_DIRNAME = ".cedarpg";
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/adapters/load-mode-env.d.ts
|
|
212
|
+
type LoadModeEnvOptions = {
|
|
213
|
+
root?: string;
|
|
214
|
+
/** Overwrite existing `process.env` keys (default: only fill undefined). */
|
|
215
|
+
overwrite?: boolean;
|
|
216
|
+
};
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/adapters/load-test-env.d.ts
|
|
219
|
+
type LoadTestEnvOptions = LoadModeEnvOptions;
|
|
220
|
+
/**
|
|
221
|
+
* Load `.cedarpg/test.env` into `process.env` (worker-side).
|
|
222
|
+
*
|
|
223
|
+
* Jest (and optional Vitest `setupFiles`) run tests in a different process than
|
|
224
|
+
* `globalSetup`, so `setEnv` in acquire does not reach workers — the env file does.
|
|
225
|
+
*
|
|
226
|
+
* No-ops unless a matching `test.json` lease exists, so a leftover env after dispose
|
|
227
|
+
* cannot inject a dropped DATABASE_URL.
|
|
228
|
+
*/
|
|
229
|
+
declare function loadTestEnv(rootOrOptions?: string | LoadTestEnvOptions): void;
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/adapters/load-dev-env.d.ts
|
|
232
|
+
type LoadDevEnvOptions = LoadModeEnvOptions;
|
|
233
|
+
/** Load `.cedarpg/dev.env` into `process.env`. Use `{ overwrite: true }` to beat `.env`. */
|
|
234
|
+
declare function loadDevEnv(rootOrOptions?: string | LoadDevEnvOptions): void;
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/adapters/acquire-task.d.ts
|
|
237
|
+
type AcquireTaskContext = Pick<AcquireResult, "databaseUrl" | "adminUrl" | "databaseName" | "roleName" | "root" | "mode" | "port">;
|
|
238
|
+
type CreateAcquireTaskOptions = {
|
|
239
|
+
mode: DbMode;
|
|
240
|
+
root?: string;
|
|
241
|
+
/** Ignore external-URL escape hatch (`CEDAR_PG_FORCE=1` also works). */
|
|
242
|
+
force?: boolean;
|
|
243
|
+
setEnv?: boolean;
|
|
244
|
+
/** App-owned migrate/seed after a successful acquire. */
|
|
245
|
+
afterAcquire?: (ctx: AcquireTaskContext) => void | Promise<void>;
|
|
246
|
+
};
|
|
247
|
+
/** Run acquireIfNeeded, then optional afterAcquire (migrate / db:ready). */
|
|
248
|
+
declare function createAcquireTask(options: CreateAcquireTaskOptions): () => Promise<void>;
|
|
249
|
+
//#endregion
|
|
163
250
|
//#region src/providers/autopg.d.ts
|
|
164
251
|
type AutopgDiscovery = {
|
|
165
252
|
port: number;
|
|
@@ -167,8 +254,8 @@ type AutopgDiscovery = {
|
|
|
167
254
|
bin: string;
|
|
168
255
|
};
|
|
169
256
|
declare const INSTALL_HINT: string;
|
|
170
|
-
/** Password scheme
|
|
171
|
-
declare const ROLE_PASSWORD_SCHEME: "
|
|
257
|
+
/** Password scheme v2: sha256(PASSWORD_SALT_PREFIX + "\\0" + roleName) hex[:32]. Frozen for URL rebuild. */
|
|
258
|
+
declare const ROLE_PASSWORD_SCHEME: "v2";
|
|
172
259
|
declare function resolveAutopgBin(): string | null;
|
|
173
260
|
declare function requireAutopgBin(): string;
|
|
174
261
|
/**
|
|
@@ -181,15 +268,14 @@ declare function parseHostStatus(json: string): {
|
|
|
181
268
|
* Discover a live autopg host via `autopg status --json`. Throws if the host is not proven live.
|
|
182
269
|
*/
|
|
183
270
|
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
271
|
/**
|
|
189
272
|
* Deterministic local-only password for an app role (Prisma/TCP need it;
|
|
190
273
|
* autopg hba uses `password` for 127.0.0.1).
|
|
274
|
+
*
|
|
275
|
+
* Keyed by `roleName` (not databaseName) so TEMPLATE clones that reuse the
|
|
276
|
+
* same role keep working when `buildDatabaseUrl` is called with a new database.
|
|
191
277
|
*/
|
|
192
|
-
declare function rolePasswordFor(
|
|
278
|
+
declare function rolePasswordFor(roleName: string): string;
|
|
193
279
|
declare function buildDatabaseUrl(opts: {
|
|
194
280
|
port: number;
|
|
195
281
|
databaseName: string;
|
|
@@ -197,5 +283,5 @@ declare function buildDatabaseUrl(opts: {
|
|
|
197
283
|
password?: string;
|
|
198
284
|
}): string;
|
|
199
285
|
//#endregion
|
|
200
|
-
export { type
|
|
286
|
+
export { type AcquireIfNeededOptions, type AcquireIfNeededResult, type AcquireOptions, type AcquireResult, type AcquireSkip, type AcquireTaskContext, type AutopgDiscovery, CLI_NAME, type CloneFromTemplateIfNeededOptions, type CloneFromTemplateIfNeededResult, type CloneFromTemplateOptions, type CloneResult, type CreateAcquireTaskOptions, type DbMode, type DisposeOptions, type DisposeResult, INSTALL_HINT, type Lease, type LoadDevEnvOptions, type LoadTestEnvOptions, type MarkTemplateOptions, ROLE_PASSWORD_SCHEME, type ResolveAcquireSkipInput, STATE_DIRNAME, type WorktreeIdentity, acquire, acquireIfNeeded, applyDatabaseUrlEnv, buildCloneDatabaseName, buildDatabaseName, buildDatabaseUrl, buildRoleName, cloneFromTemplate, cloneFromTemplateIfNeeded, createAcquireTask, discoverHost, dispose, envFilePath, gc, isCedarPgManagedUrl, isExternalDatabaseEscapeHatch, isOrphanLease, loadDevEnv, loadTestEnv, markTemplate, parseHostStatus, parseLease, readLease, requireAutopgBin, resolveAcquireSkip, resolveAutopgBin, resolveRoot, resolveWorktreeIdentity, rolePasswordFor, urlFromLease };
|
|
201
287
|
//# sourceMappingURL=index.d.cts.map
|