@cedarjs/pg 0.1.0-alpha.1 → 0.2.0-beta.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 +361 -89
- package/dist/cli.cjs +131 -35
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +118 -22
- package/dist/cli.mjs.map +1 -1
- 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 +51 -10
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +198 -84
- package/dist/index.d.mts +198 -84
- 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 +44 -0
- package/dist/jest-template.cjs.map +1 -0
- package/dist/jest-template.d.cts +31 -0
- package/dist/jest-template.d.mts +31 -0
- package/dist/jest-template.mjs +38 -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-DS1SX8U_.mjs +221 -0
- package/dist/lease-DS1SX8U_.mjs.map +1 -0
- package/dist/lease-WlmOnNDi.cjs +310 -0
- package/dist/lease-WlmOnNDi.cjs.map +1 -0
- package/dist/lease-t4I9JahV.d.cts +24 -0
- package/dist/lifecycle-BbrvFQvg.cjs +953 -0
- package/dist/lifecycle-BbrvFQvg.cjs.map +1 -0
- package/dist/lifecycle-BvIx0xqq.mjs +781 -0
- package/dist/lifecycle-BvIx0xqq.mjs.map +1 -0
- package/dist/load-dev-env-BULkXyen.mjs +10 -0
- package/dist/load-dev-env-BULkXyen.mjs.map +1 -0
- package/dist/load-dev-env-Bl6Ddv1U.cjs +15 -0
- package/dist/load-dev-env-Bl6Ddv1U.cjs.map +1 -0
- package/dist/load-mode-env-CX9vd56X.cjs +39 -0
- package/dist/load-mode-env-CX9vd56X.cjs.map +1 -0
- package/dist/load-mode-env-Ce9ujisN.mjs +28 -0
- package/dist/load-mode-env-Ce9ujisN.mjs.map +1 -0
- package/dist/load-test-env-BqtA6V-d.mjs +18 -0
- package/dist/load-test-env-BqtA6V-d.mjs.map +1 -0
- package/dist/load-test-env-Dcgh6YHV.cjs +23 -0
- package/dist/load-test-env-Dcgh6YHV.cjs.map +1 -0
- package/dist/naming-C2nGVxPk.d.cts +39 -0
- package/dist/naming-C2nGVxPk.d.mts +39 -0
- package/dist/nx.cjs +25 -18
- 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 +18 -18
- package/dist/nx.mjs.map +1 -1
- package/dist/status-4Uz6A3LB.cjs +31 -0
- package/dist/status-4Uz6A3LB.cjs.map +1 -0
- package/dist/status-Dcnpgnlz.mjs +26 -0
- package/dist/status-Dcnpgnlz.mjs.map +1 -0
- package/dist/studio-DIFw1qWC.mjs +173 -0
- package/dist/studio-DIFw1qWC.mjs.map +1 -0
- package/dist/studio-oJE30_PO.cjs +208 -0
- package/dist/studio-oJE30_PO.cjs.map +1 -0
- package/dist/tasks-CNHvvlsN.cjs +67 -0
- package/dist/tasks-CNHvvlsN.cjs.map +1 -0
- package/dist/tasks-CjaZRi_G.d.mts +19 -0
- package/dist/tasks-D5iWIdlo.mjs +38 -0
- package/dist/tasks-D5iWIdlo.mjs.map +1 -0
- package/dist/tasks-DdQoP9We.d.cts +19 -0
- package/dist/template-BiJ-0TIF.mjs +88 -0
- package/dist/template-BiJ-0TIF.mjs.map +1 -0
- package/dist/template-CXMpODzK.cjs +105 -0
- package/dist/template-CXMpODzK.cjs.map +1 -0
- package/dist/template-mode-BTUsdBtA.mjs +94 -0
- package/dist/template-mode-BTUsdBtA.mjs.map +1 -0
- package/dist/template-mode-CzyVwHsi.d.cts +31 -0
- package/dist/template-mode-CzyVwHsi.d.mts +31 -0
- package/dist/template-mode-JTOxrEgE.cjs +105 -0
- package/dist/template-mode-JTOxrEgE.cjs.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 +113 -35
- package/dist/vite-plus.cjs.map +1 -1
- package/dist/vite-plus.d.cts +26 -46
- package/dist/vite-plus.d.mts +26 -46
- package/dist/vite-plus.mjs +110 -32
- 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 +46 -13
- package/scripts/autopg-version +1 -0
- package/scripts/ci-install-autopg.sh +73 -0
- package/scripts/postinstall.js +35 -9
- package/dist/constants-BY97wXjA.mjs +0 -24
- package/dist/constants-BY97wXjA.mjs.map +0 -1
- package/dist/constants-CNZn5Xro.cjs +0 -41
- package/dist/constants-CNZn5Xro.cjs.map +0 -1
- package/dist/lifecycle-BGYtVXtx.cjs +0 -743
- package/dist/lifecycle-BGYtVXtx.cjs.map +0 -1
- package/dist/lifecycle-CT_8AWPv.mjs +0 -577
- package/dist/lifecycle-CT_8AWPv.mjs.map +0 -1
- package/dist/tasks-13P6tMth.mjs +0 -16
- package/dist/tasks-13P6tMth.mjs.map +0 -1
- package/dist/tasks-B8ryV9xo.cjs +0 -21
- package/dist/tasks-B8ryV9xo.cjs.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { n as setupTemplateMode, t as cloneWorkerDatabase } from "./template-mode-BTUsdBtA.mjs";
|
|
2
|
+
//#region src/adapters/jest-template.ts
|
|
3
|
+
/**
|
|
4
|
+
* Jest globalSetup (template mode).
|
|
5
|
+
*
|
|
6
|
+
* ```js
|
|
7
|
+
* // jest.cedar-global.cjs
|
|
8
|
+
* const { createGlobalSetup } = require("@cedarjs/pg/jest/template");
|
|
9
|
+
* module.exports = createGlobalSetup({ migrate: async ({ databaseUrl }) => {} });
|
|
10
|
+
*
|
|
11
|
+
* // jest.config.cjs
|
|
12
|
+
* // When .env has a real TEST_DATABASE_URL, set once here (inherits to workers):
|
|
13
|
+
* // process.env.CEDAR_PG_FORCE = "1";
|
|
14
|
+
* globalSetup: "<rootDir>/jest.cedar-global.cjs",
|
|
15
|
+
* globalTeardown: require.resolve("@cedarjs/pg/jest-teardown"),
|
|
16
|
+
* // Prefer setupFilesAfterEnv + beforeAll; setupFiles also works (memo is process-scoped).
|
|
17
|
+
* setupFilesAfterEnv: ["<rootDir>/jest.cedar-worker.cjs"],
|
|
18
|
+
*
|
|
19
|
+
* // jest.cedar-worker.cjs
|
|
20
|
+
* const { cloneWorkerDatabase } = require("@cedarjs/pg/jest/template");
|
|
21
|
+
* beforeAll(() => cloneWorkerDatabase());
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Stock `@cedarjs/pg/jest` is one shared test DB only.
|
|
25
|
+
*/
|
|
26
|
+
function createGlobalSetup(options) {
|
|
27
|
+
return async () => {
|
|
28
|
+
await setupTemplateMode(options);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** String `require.resolve` without a migrate hook is unsupported — use `createGlobalSetup`. */
|
|
32
|
+
async function globalSetup() {
|
|
33
|
+
throw new Error("@cedarjs/pg/jest/template requires createGlobalSetup({ migrate }). Point globalSetup at a local module that exports createGlobalSetup({ migrate }).");
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { cloneWorkerDatabase, createGlobalSetup, globalSetup as default };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=jest-template.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest-template.mjs","names":[],"sources":["../src/adapters/jest-template.ts"],"sourcesContent":["import {\n cloneWorkerDatabase,\n setupTemplateMode,\n type SetupTemplateModeOptions,\n} from \"./template-mode.ts\";\n\nexport { cloneWorkerDatabase };\nexport type {\n SetupTemplateModeOptions,\n TemplateMigrateFn,\n TemplateMigrateContext,\n} from \"./template-mode.ts\";\n\n/**\n * Jest globalSetup (template mode).\n *\n * ```js\n * // jest.cedar-global.cjs\n * const { createGlobalSetup } = require(\"@cedarjs/pg/jest/template\");\n * module.exports = createGlobalSetup({ migrate: async ({ databaseUrl }) => {} });\n *\n * // jest.config.cjs\n * // When .env has a real TEST_DATABASE_URL, set once here (inherits to workers):\n * // process.env.CEDAR_PG_FORCE = \"1\";\n * globalSetup: \"<rootDir>/jest.cedar-global.cjs\",\n * globalTeardown: require.resolve(\"@cedarjs/pg/jest-teardown\"),\n * // Prefer setupFilesAfterEnv + beforeAll; setupFiles also works (memo is process-scoped).\n * setupFilesAfterEnv: [\"<rootDir>/jest.cedar-worker.cjs\"],\n *\n * // jest.cedar-worker.cjs\n * const { cloneWorkerDatabase } = require(\"@cedarjs/pg/jest/template\");\n * beforeAll(() => cloneWorkerDatabase());\n * ```\n *\n * Stock `@cedarjs/pg/jest` is one shared test DB only.\n */\nexport function createGlobalSetup(options: SetupTemplateModeOptions) {\n return async () => {\n await setupTemplateMode(options);\n };\n}\n\n/** String `require.resolve` without a migrate hook is unsupported — use `createGlobalSetup`. */\nexport default async function globalSetup(): Promise<void> {\n throw new Error(\n \"@cedarjs/pg/jest/template requires createGlobalSetup({ migrate }). \" +\n \"Point globalSetup at a local module that exports createGlobalSetup({ migrate }).\",\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,kBAAkB,SAAmC;CACnE,OAAO,YAAY;EACjB,MAAM,kBAAkB,OAAO;CACjC;AACF;;AAGA,eAA8B,cAA6B;CACzD,MAAM,IAAI,MACR,qJAEF;AACF"}
|
package/dist/jest.cjs
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_lifecycle = require("./lifecycle-BGYtVXtx.cjs");
|
|
1
|
+
const require_lifecycle = require("./lifecycle-BbrvFQvg.cjs");
|
|
6
2
|
//#region src/adapters/jest.ts
|
|
7
3
|
/**
|
|
8
|
-
* Jest globalSetup
|
|
4
|
+
* Jest globalSetup for a single shared test DB (`acquireIfNeeded` + dispose).
|
|
5
|
+
* Not a migrate-once / per-worker TEMPLATE runner — use `@cedarjs/pg/jest/template`.
|
|
6
|
+
*
|
|
9
7
|
* ```js
|
|
10
|
-
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
8
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest'),
|
|
9
|
+
* globalTeardown: require.resolve('@cedarjs/pg/jest-teardown'),
|
|
10
|
+
* setupFiles: [require.resolve('@cedarjs/pg/test-env')],
|
|
11
11
|
* ```
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
|
+
* `setupFiles` is required: Jest runs globalSetup in a separate process, so
|
|
14
|
+
* `DATABASE_URL` reaches workers via `.cedarpg/test.env`.
|
|
13
15
|
*/
|
|
14
16
|
async function globalSetup() {
|
|
15
|
-
await require_lifecycle.
|
|
17
|
+
await require_lifecycle.acquireIfNeeded({
|
|
16
18
|
mode: "test",
|
|
17
19
|
setEnv: true
|
|
18
20
|
});
|
|
19
21
|
}
|
|
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
22
|
//#endregion
|
|
25
|
-
exports
|
|
26
|
-
exports.teardown = teardown;
|
|
23
|
+
module.exports = globalSetup;
|
|
27
24
|
|
|
28
25
|
//# sourceMappingURL=jest.cjs.map
|
package/dist/jest.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.cjs","names":["
|
|
1
|
+
{"version":3,"file":"jest.cjs","names":["acquireIfNeeded"],"sources":["../src/adapters/jest.ts"],"sourcesContent":["import { acquireIfNeeded } from \"../core/lifecycle.ts\";\n\n/**\n * Jest globalSetup for a single shared test DB (`acquireIfNeeded` + dispose).\n * Not a migrate-once / per-worker TEMPLATE runner — use `@cedarjs/pg/jest/template`.\n *\n * ```js\n * globalSetup: require.resolve('@cedarjs/pg/jest'),\n * globalTeardown: require.resolve('@cedarjs/pg/jest-teardown'),\n * setupFiles: [require.resolve('@cedarjs/pg/test-env')],\n * ```\n *\n * `setupFiles` is required: Jest runs globalSetup in a separate process, so\n * `DATABASE_URL` reaches workers via `.cedarpg/test.env`.\n */\nexport default async function globalSetup(): Promise<void> {\n await acquireIfNeeded({\n mode: \"test\",\n setEnv: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,eAA8B,cAA6B;CACzD,MAAMA,kBAAAA,gBAAgB;EACpB,MAAM;EACN,QAAQ;CACV,CAAC;AACH"}
|
package/dist/jest.d.cts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
//#region src/adapters/jest.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Jest globalSetup
|
|
3
|
+
* Jest globalSetup for a single shared test DB (`acquireIfNeeded` + dispose).
|
|
4
|
+
* Not a migrate-once / per-worker TEMPLATE runner — use `@cedarjs/pg/jest/template`.
|
|
5
|
+
*
|
|
4
6
|
* ```js
|
|
5
|
-
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
7
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest'),
|
|
8
|
+
* globalTeardown: require.resolve('@cedarjs/pg/jest-teardown'),
|
|
9
|
+
* setupFiles: [require.resolve('@cedarjs/pg/test-env')],
|
|
6
10
|
* ```
|
|
7
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* `setupFiles` is required: Jest runs globalSetup in a separate process, so
|
|
13
|
+
* `DATABASE_URL` reaches workers via `.cedarpg/test.env`.
|
|
8
14
|
*/
|
|
9
15
|
declare function globalSetup(): Promise<void>;
|
|
10
|
-
|
|
11
|
-
declare function teardown(): Promise<void>;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { globalSetup as default, teardown };
|
|
16
|
+
export = globalSetup;
|
|
14
17
|
//# sourceMappingURL=jest.d.cts.map
|
package/dist/jest.d.mts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
//#region src/adapters/jest.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Jest globalSetup
|
|
3
|
+
* Jest globalSetup for a single shared test DB (`acquireIfNeeded` + dispose).
|
|
4
|
+
* Not a migrate-once / per-worker TEMPLATE runner — use `@cedarjs/pg/jest/template`.
|
|
5
|
+
*
|
|
4
6
|
* ```js
|
|
5
|
-
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
7
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest'),
|
|
8
|
+
* globalTeardown: require.resolve('@cedarjs/pg/jest-teardown'),
|
|
9
|
+
* setupFiles: [require.resolve('@cedarjs/pg/test-env')],
|
|
6
10
|
* ```
|
|
7
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* `setupFiles` is required: Jest runs globalSetup in a separate process, so
|
|
13
|
+
* `DATABASE_URL` reaches workers via `.cedarpg/test.env`.
|
|
8
14
|
*/
|
|
9
15
|
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
16
|
//#endregion
|
|
13
|
-
export { globalSetup as default
|
|
17
|
+
export { globalSetup as default };
|
|
14
18
|
//# sourceMappingURL=jest.d.mts.map
|
package/dist/jest.mjs
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as acquireIfNeeded } from "./lifecycle-BvIx0xqq.mjs";
|
|
2
2
|
//#region src/adapters/jest.ts
|
|
3
3
|
/**
|
|
4
|
-
* Jest globalSetup
|
|
4
|
+
* Jest globalSetup for a single shared test DB (`acquireIfNeeded` + dispose).
|
|
5
|
+
* Not a migrate-once / per-worker TEMPLATE runner — use `@cedarjs/pg/jest/template`.
|
|
6
|
+
*
|
|
5
7
|
* ```js
|
|
6
|
-
* globalSetup: require.resolve('@cedarjs/pg/jest')
|
|
8
|
+
* globalSetup: require.resolve('@cedarjs/pg/jest'),
|
|
9
|
+
* globalTeardown: require.resolve('@cedarjs/pg/jest-teardown'),
|
|
10
|
+
* setupFiles: [require.resolve('@cedarjs/pg/test-env')],
|
|
7
11
|
* ```
|
|
8
|
-
*
|
|
12
|
+
*
|
|
13
|
+
* `setupFiles` is required: Jest runs globalSetup in a separate process, so
|
|
14
|
+
* `DATABASE_URL` reaches workers via `.cedarpg/test.env`.
|
|
9
15
|
*/
|
|
10
16
|
async function globalSetup() {
|
|
11
|
-
await
|
|
17
|
+
await acquireIfNeeded({
|
|
12
18
|
mode: "test",
|
|
13
19
|
setEnv: true
|
|
14
20
|
});
|
|
15
21
|
}
|
|
16
|
-
/** Lease-gated dispose; no skip re-check (env may flip mid-suite). */
|
|
17
|
-
async function teardown() {
|
|
18
|
-
await dispose({ mode: "test" });
|
|
19
|
-
}
|
|
20
22
|
//#endregion
|
|
21
|
-
export { globalSetup as default
|
|
23
|
+
export { globalSetup as default };
|
|
22
24
|
|
|
23
25
|
//# sourceMappingURL=jest.mjs.map
|
package/dist/jest.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.mjs","names":[],"sources":["../src/adapters/jest.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"jest.mjs","names":[],"sources":["../src/adapters/jest.ts"],"sourcesContent":["import { acquireIfNeeded } from \"../core/lifecycle.ts\";\n\n/**\n * Jest globalSetup for a single shared test DB (`acquireIfNeeded` + dispose).\n * Not a migrate-once / per-worker TEMPLATE runner — use `@cedarjs/pg/jest/template`.\n *\n * ```js\n * globalSetup: require.resolve('@cedarjs/pg/jest'),\n * globalTeardown: require.resolve('@cedarjs/pg/jest-teardown'),\n * setupFiles: [require.resolve('@cedarjs/pg/test-env')],\n * ```\n *\n * `setupFiles` is required: Jest runs globalSetup in a separate process, so\n * `DATABASE_URL` reaches workers via `.cedarpg/test.env`.\n */\nexport default async function globalSetup(): Promise<void> {\n await acquireIfNeeded({\n mode: \"test\",\n setEnv: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,eAA8B,cAA6B;CACzD,MAAM,gBAAgB;EACpB,MAAM;EACN,QAAQ;CACV,CAAC;AACH"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { t as DbMode } from "./naming-C2nGVxPk.mjs";
|
|
2
|
+
//#region src/core/lease.d.ts
|
|
3
|
+
type Lease = {
|
|
4
|
+
schemaVersion: 1;
|
|
5
|
+
mode: DbMode;
|
|
6
|
+
root: string;
|
|
7
|
+
repoSlug: string;
|
|
8
|
+
worktreeSlug: string;
|
|
9
|
+
pathHash: string;
|
|
10
|
+
databaseName: string;
|
|
11
|
+
roleName: string;
|
|
12
|
+
port: number;
|
|
13
|
+
pid: number;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
};
|
|
16
|
+
/** Narrow-parse a lease; reject incomplete or wrong-version records. */
|
|
17
|
+
declare function parseLease(raw: unknown): Lease | null;
|
|
18
|
+
/** Absolute `.cedarpg/<mode>.env` path (resolves root when omitted). */
|
|
19
|
+
declare function envFilePath(root: string | undefined, mode: DbMode): string;
|
|
20
|
+
declare function readLease(root: string, mode: DbMode): Lease | null;
|
|
21
|
+
declare function isOrphanLease(lease: Lease): boolean;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { readLease as a, parseLease as i, envFilePath as n, isOrphanLease as r, Lease as t };
|
|
24
|
+
//# sourceMappingURL=lease-B3TuX92y.d.mts.map
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
//#region src/core/constants.ts
|
|
7
|
+
/**
|
|
8
|
+
* Product identity vs frozen crypto.
|
|
9
|
+
*
|
|
10
|
+
* State dirs follow the CLI name (`.cedarpg`): product-owned, not nested under
|
|
11
|
+
* autopg's `~/.autopg/` (host owns that) and not a generic `.pg` (collision-prone).
|
|
12
|
+
* Password salt is an opaque crypto constant; bump ROLE_PASSWORD_SCHEME to change it.
|
|
13
|
+
*/
|
|
14
|
+
/** User-facing CLI binary (`package.json` bin) and log prefix */
|
|
15
|
+
const CLI_NAME = "cedarpg";
|
|
16
|
+
/**
|
|
17
|
+
* Worktree-local state dir and home-registry parent (`~/.cedarpg/registry`).
|
|
18
|
+
* Frozen for lease/gc discovery after first alpha consumers appear.
|
|
19
|
+
*/
|
|
20
|
+
const STATE_DIRNAME = ".cedarpg";
|
|
21
|
+
/**
|
|
22
|
+
* Password scheme v2 salt prefix: sha256(`${PASSWORD_SALT_PREFIX}\0` + roleName).
|
|
23
|
+
* Opaque; independent of STATE_DIRNAME / CLI_NAME. Bump ROLE_PASSWORD_SCHEME to change.
|
|
24
|
+
*/
|
|
25
|
+
const PASSWORD_SALT_PREFIX = "cedar-pg";
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/core/worktree.ts
|
|
28
|
+
function git(args, cwd) {
|
|
29
|
+
try {
|
|
30
|
+
return execFileSync("git", args, {
|
|
31
|
+
cwd,
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
stdio: [
|
|
34
|
+
"ignore",
|
|
35
|
+
"pipe",
|
|
36
|
+
"ignore"
|
|
37
|
+
]
|
|
38
|
+
}).trim();
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function sanitizeSlug(input) {
|
|
44
|
+
return input.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve the project / worktree root.
|
|
48
|
+
* Explicit `root` wins (app project path). Otherwise prefer git toplevel, then cwd.
|
|
49
|
+
*/
|
|
50
|
+
function resolveRoot(root) {
|
|
51
|
+
if (root) return resolve(root);
|
|
52
|
+
const start = resolve(process.cwd());
|
|
53
|
+
const toplevel = git(["rev-parse", "--show-toplevel"], start);
|
|
54
|
+
if (toplevel) return toplevel;
|
|
55
|
+
return start;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Identify repo + worktree for observable DB naming.
|
|
59
|
+
*/
|
|
60
|
+
function resolveWorktreeIdentity(root) {
|
|
61
|
+
const absRoot = resolveRoot(root);
|
|
62
|
+
const pathHash = createHash("sha256").update(absRoot).digest("hex").slice(0, 8);
|
|
63
|
+
const commonDir = git(["rev-parse", "--git-common-dir"], absRoot);
|
|
64
|
+
let repoSlug = sanitizeSlug(basename(absRoot));
|
|
65
|
+
if (commonDir) {
|
|
66
|
+
const commonAbs = resolve(absRoot, commonDir);
|
|
67
|
+
const mainRoot = basename(commonAbs) === ".git" ? dirname(commonAbs) : commonAbs;
|
|
68
|
+
const fromGit = sanitizeSlug(basename(basename(mainRoot) === ".git" ? dirname(mainRoot) : mainRoot));
|
|
69
|
+
if (fromGit) repoSlug = fromGit;
|
|
70
|
+
}
|
|
71
|
+
let worktreeSlug = sanitizeSlug(basename(absRoot));
|
|
72
|
+
const gitFile = resolve(absRoot, ".git");
|
|
73
|
+
if (existsSync(gitFile)) try {
|
|
74
|
+
const match = readFileSync(gitFile, "utf8").trim().match(/gitdir:\s*(.+)$/m);
|
|
75
|
+
if (match?.[1]) {
|
|
76
|
+
const parts = resolve(absRoot, match[1].trim()).split(/[/\\]/);
|
|
77
|
+
const wtIdx = parts.lastIndexOf("worktrees");
|
|
78
|
+
if (wtIdx >= 0 && parts[wtIdx + 1]) {
|
|
79
|
+
const fromWt = sanitizeSlug(parts[wtIdx + 1]);
|
|
80
|
+
if (fromWt) worktreeSlug = fromWt;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch {}
|
|
84
|
+
if (!repoSlug) repoSlug = "repo";
|
|
85
|
+
if (!worktreeSlug) worktreeSlug = "wt";
|
|
86
|
+
return {
|
|
87
|
+
root: absRoot,
|
|
88
|
+
repoSlug,
|
|
89
|
+
worktreeSlug,
|
|
90
|
+
pathHash
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/core/lease.ts
|
|
95
|
+
function isDbMode(value) {
|
|
96
|
+
return value === "dev" || value === "test";
|
|
97
|
+
}
|
|
98
|
+
function isNonEmptyString(value) {
|
|
99
|
+
return typeof value === "string" && value.length > 0;
|
|
100
|
+
}
|
|
101
|
+
/** Narrow-parse a lease; reject incomplete or wrong-version records. */
|
|
102
|
+
function parseLease(raw) {
|
|
103
|
+
if (!raw || typeof raw !== "object") return null;
|
|
104
|
+
const o = raw;
|
|
105
|
+
if (o.schemaVersion !== 1) return null;
|
|
106
|
+
if (!isDbMode(o.mode)) return null;
|
|
107
|
+
if (!isNonEmptyString(o.root)) return null;
|
|
108
|
+
if (!isNonEmptyString(o.repoSlug)) return null;
|
|
109
|
+
if (!isNonEmptyString(o.worktreeSlug)) return null;
|
|
110
|
+
if (!isNonEmptyString(o.pathHash)) return null;
|
|
111
|
+
if (!isNonEmptyString(o.databaseName)) return null;
|
|
112
|
+
if (!isNonEmptyString(o.roleName)) return null;
|
|
113
|
+
if (typeof o.port !== "number") return null;
|
|
114
|
+
if (typeof o.pid !== "number") return null;
|
|
115
|
+
if (!isNonEmptyString(o.createdAt)) return null;
|
|
116
|
+
return {
|
|
117
|
+
schemaVersion: 1,
|
|
118
|
+
mode: o.mode,
|
|
119
|
+
root: o.root,
|
|
120
|
+
repoSlug: o.repoSlug,
|
|
121
|
+
worktreeSlug: o.worktreeSlug,
|
|
122
|
+
pathHash: o.pathHash,
|
|
123
|
+
databaseName: o.databaseName,
|
|
124
|
+
roleName: o.roleName,
|
|
125
|
+
port: o.port,
|
|
126
|
+
pid: o.pid,
|
|
127
|
+
createdAt: o.createdAt
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function leaseDir(root) {
|
|
131
|
+
return join(root, STATE_DIRNAME);
|
|
132
|
+
}
|
|
133
|
+
function leasePath(root, mode) {
|
|
134
|
+
return join(leaseDir(root), `${mode}.json`);
|
|
135
|
+
}
|
|
136
|
+
function envPath(root, mode) {
|
|
137
|
+
return join(leaseDir(root), `${mode}.env`);
|
|
138
|
+
}
|
|
139
|
+
/** Absolute `.cedarpg/<mode>.env` path (resolves root when omitted). */
|
|
140
|
+
function envFilePath(root, mode) {
|
|
141
|
+
return envPath(resolveRoot(root), mode);
|
|
142
|
+
}
|
|
143
|
+
/** Best-effort delete worktree lease JSON + mode env (missing is fine). */
|
|
144
|
+
function unlinkWorktreeArtifacts(root, mode) {
|
|
145
|
+
for (const file of [leasePath(root, mode), envPath(root, mode)]) try {
|
|
146
|
+
unlinkSync(file);
|
|
147
|
+
} catch {}
|
|
148
|
+
}
|
|
149
|
+
/** Durable registry outside worktrees so GC can find orphans after a checkout is deleted. */
|
|
150
|
+
function registryDir() {
|
|
151
|
+
return process.env.CEDAR_PG_REGISTRY_DIR || join(homedir(), ".cedarpg", "registry");
|
|
152
|
+
}
|
|
153
|
+
function registryPath(databaseName) {
|
|
154
|
+
return join(registryDir(), `${databaseName}.json`);
|
|
155
|
+
}
|
|
156
|
+
function writeJsonAtomic(file, value) {
|
|
157
|
+
mkdirSync(dirname(file), {
|
|
158
|
+
recursive: true,
|
|
159
|
+
mode: 448
|
|
160
|
+
});
|
|
161
|
+
const tmp = `${file}.tmp.${process.pid}`;
|
|
162
|
+
writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\n`, { mode: 384 });
|
|
163
|
+
renameSync(tmp, file);
|
|
164
|
+
}
|
|
165
|
+
function registerLease(lease) {
|
|
166
|
+
writeJsonAtomic(registryPath(lease.databaseName), lease);
|
|
167
|
+
}
|
|
168
|
+
function unregisterLease(databaseName) {
|
|
169
|
+
try {
|
|
170
|
+
unlinkSync(registryPath(databaseName));
|
|
171
|
+
} catch {}
|
|
172
|
+
}
|
|
173
|
+
function readLease(root, mode) {
|
|
174
|
+
const file = leasePath(root, mode);
|
|
175
|
+
if (!existsSync(file)) return null;
|
|
176
|
+
try {
|
|
177
|
+
return parseLease(JSON.parse(readFileSync(file, "utf8")));
|
|
178
|
+
} catch {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Persist lease. Registry is written first (GC source of truth), then the worktree cache.
|
|
184
|
+
*/
|
|
185
|
+
function writeLease(lease) {
|
|
186
|
+
registerLease(lease);
|
|
187
|
+
mkdirSync(leaseDir(lease.root), {
|
|
188
|
+
recursive: true,
|
|
189
|
+
mode: 448
|
|
190
|
+
});
|
|
191
|
+
writeJsonAtomic(leasePath(lease.root, lease.mode), lease);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Remove registry entry by databaseName and best-effort delete worktree lease + env.
|
|
195
|
+
* Call only after a successful DROP (or when intentionally abandoning tracking).
|
|
196
|
+
*/
|
|
197
|
+
function forgetLease(lease) {
|
|
198
|
+
unregisterLease(lease.databaseName);
|
|
199
|
+
unlinkWorktreeArtifacts(lease.root, lease.mode);
|
|
200
|
+
}
|
|
201
|
+
/** All registry entries (used by gc). */
|
|
202
|
+
function listRegistryLeases() {
|
|
203
|
+
const dir = registryDir();
|
|
204
|
+
if (!existsSync(dir)) return [];
|
|
205
|
+
const out = [];
|
|
206
|
+
for (const name of readdirSync(dir)) {
|
|
207
|
+
if (!name.endsWith(".json")) continue;
|
|
208
|
+
try {
|
|
209
|
+
const lease = parseLease(JSON.parse(readFileSync(join(dir, name), "utf8")));
|
|
210
|
+
if (lease) out.push(lease);
|
|
211
|
+
} catch {}
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
function isOrphanLease(lease) {
|
|
216
|
+
return !existsSync(lease.root);
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
export { leaseDir as a, parseLease as c, resolveRoot as d, resolveWorktreeIdentity as f, STATE_DIRNAME as h, isOrphanLease as i, readLease as l, PASSWORD_SALT_PREFIX as m, envPath as n, leasePath as o, CLI_NAME as p, forgetLease as r, listRegistryLeases as s, envFilePath as t, writeLease as u };
|
|
220
|
+
|
|
221
|
+
//# sourceMappingURL=lease-DS1SX8U_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease-DS1SX8U_.mjs","names":[],"sources":["../src/core/constants.ts","../src/core/worktree.ts","../src/core/lease.ts"],"sourcesContent":["/**\n * Product identity vs frozen crypto.\n *\n * State dirs follow the CLI name (`.cedarpg`): product-owned, not nested under\n * autopg's `~/.autopg/` (host owns that) and not a generic `.pg` (collision-prone).\n * Password salt is an opaque crypto constant; bump ROLE_PASSWORD_SCHEME to change it.\n */\n\n/** User-facing CLI binary (`package.json` bin) and log prefix */\nexport const CLI_NAME = \"cedarpg\";\n\n/**\n * Worktree-local state dir and home-registry parent (`~/.cedarpg/registry`).\n * Frozen for lease/gc discovery after first alpha consumers appear.\n */\nexport const STATE_DIRNAME = \".cedarpg\";\n\n/**\n * Password scheme v2 salt prefix: sha256(`${PASSWORD_SALT_PREFIX}\\0` + roleName).\n * Opaque; independent of STATE_DIRNAME / CLI_NAME. Bump ROLE_PASSWORD_SCHEME to change.\n */\nexport const PASSWORD_SALT_PREFIX = \"cedar-pg\";\n","import { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { basename, dirname, resolve } from \"node:path\";\nimport { execFileSync } from \"node:child_process\";\n\nexport type WorktreeIdentity = {\n /** Absolute path to the worktree / project root. */\n root: string;\n /** Basename of the git common dir / main checkout (e.g. `cedar`). */\n repoSlug: string;\n /** Basename of this worktree directory (e.g. `feat-auth`). */\n worktreeSlug: string;\n /** First 8 hex chars of sha256(absolute root). */\n pathHash: string;\n};\n\nfunction git(args: string[], cwd: string): string | null {\n try {\n return execFileSync(\"git\", args, {\n cwd,\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n }).trim();\n } catch {\n return null;\n }\n}\n\nfunction sanitizeSlug(input: string): string {\n return input\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/_+/g, \"_\")\n .replace(/^_|_$/g, \"\");\n}\n\n/**\n * Resolve the project / worktree root.\n * Explicit `root` wins (app project path). Otherwise prefer git toplevel, then cwd.\n */\nexport function resolveRoot(root?: string): string {\n if (root) return resolve(root);\n const start = resolve(process.cwd());\n const toplevel = git([\"rev-parse\", \"--show-toplevel\"], start);\n if (toplevel) return toplevel;\n return start;\n}\n\n/**\n * Identify repo + worktree for observable DB naming.\n */\nexport function resolveWorktreeIdentity(root?: string): WorktreeIdentity {\n const absRoot = resolveRoot(root);\n const pathHash = createHash(\"sha256\").update(absRoot).digest(\"hex\").slice(0, 8);\n\n const commonDir = git([\"rev-parse\", \"--git-common-dir\"], absRoot);\n let repoSlug = sanitizeSlug(basename(absRoot));\n if (commonDir) {\n // common-dir is often `<main>/.git` or an absolute path to the main .git\n const commonAbs = resolve(absRoot, commonDir);\n // If commonAbs ends with `.git`, parent is main worktree root\n const mainRoot = basename(commonAbs) === \".git\" ? dirname(commonAbs) : commonAbs;\n // For linked worktrees, common-dir may be `.../main/.git`\n const candidate = basename(mainRoot) === \".git\" ? dirname(mainRoot) : mainRoot;\n const fromGit = sanitizeSlug(basename(candidate));\n if (fromGit) repoSlug = fromGit;\n }\n\n // Prefer gitdir worktree name when present (`.git` file pointing at worktrees/<name>)\n let worktreeSlug = sanitizeSlug(basename(absRoot));\n const gitFile = resolve(absRoot, \".git\");\n if (existsSync(gitFile)) {\n try {\n const content = readFileSync(gitFile, \"utf8\").trim();\n const match = content.match(/gitdir:\\s*(.+)$/m);\n if (match?.[1]) {\n const gitdir = resolve(absRoot, match[1].trim());\n // .../.git/worktrees/<name>\n const parts = gitdir.split(/[/\\\\]/);\n const wtIdx = parts.lastIndexOf(\"worktrees\");\n if (wtIdx >= 0 && parts[wtIdx + 1]) {\n const fromWt = sanitizeSlug(parts[wtIdx + 1]!);\n if (fromWt) worktreeSlug = fromWt;\n }\n }\n } catch {\n // keep basename slug\n }\n }\n\n if (!repoSlug) repoSlug = \"repo\";\n if (!worktreeSlug) worktreeSlug = \"wt\";\n\n return { root: absRoot, repoSlug, worktreeSlug, pathHash };\n}\n","import {\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n renameSync,\n unlinkSync,\n writeFileSync,\n} from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { STATE_DIRNAME } from \"./constants.ts\";\nimport type { DbMode } from \"./naming.ts\";\nimport { resolveRoot } from \"./worktree.ts\";\n\nexport type Lease = {\n schemaVersion: 1;\n mode: DbMode;\n root: string;\n repoSlug: string;\n worktreeSlug: string;\n pathHash: string;\n databaseName: string;\n roleName: string;\n port: number;\n pid: number;\n createdAt: string;\n};\n\nfunction isDbMode(value: unknown): value is DbMode {\n return value === \"dev\" || value === \"test\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\n/** Narrow-parse a lease; reject incomplete or wrong-version records. */\nexport function parseLease(raw: unknown): Lease | null {\n if (!raw || typeof raw !== \"object\") return null;\n const o = raw as Record<string, unknown>;\n if (o.schemaVersion !== 1) return null;\n if (!isDbMode(o.mode)) return null;\n if (!isNonEmptyString(o.root)) return null;\n if (!isNonEmptyString(o.repoSlug)) return null;\n if (!isNonEmptyString(o.worktreeSlug)) return null;\n if (!isNonEmptyString(o.pathHash)) return null;\n if (!isNonEmptyString(o.databaseName)) return null;\n if (!isNonEmptyString(o.roleName)) return null;\n if (typeof o.port !== \"number\") return null;\n if (typeof o.pid !== \"number\") return null;\n if (!isNonEmptyString(o.createdAt)) return null;\n return {\n schemaVersion: 1,\n mode: o.mode,\n root: o.root,\n repoSlug: o.repoSlug,\n worktreeSlug: o.worktreeSlug,\n pathHash: o.pathHash,\n databaseName: o.databaseName,\n roleName: o.roleName,\n port: o.port,\n pid: o.pid,\n createdAt: o.createdAt,\n };\n}\n\nexport function leaseDir(root: string): string {\n return join(root, STATE_DIRNAME);\n}\n\nexport function leasePath(root: string, mode: DbMode): string {\n return join(leaseDir(root), `${mode}.json`);\n}\n\nexport function envPath(root: string, mode: DbMode): string {\n return join(leaseDir(root), `${mode}.env`);\n}\n\n/** Absolute `.cedarpg/<mode>.env` path (resolves root when omitted). */\nexport function envFilePath(root: string | undefined, mode: DbMode): string {\n return envPath(resolveRoot(root), mode);\n}\n\n/** Best-effort delete worktree lease JSON + mode env (missing is fine). */\nfunction unlinkWorktreeArtifacts(root: string, mode: DbMode): void {\n for (const file of [leasePath(root, mode), envPath(root, mode)]) {\n try {\n unlinkSync(file);\n } catch {\n // root or file may already be gone\n }\n }\n}\n\n/** Durable registry outside worktrees so GC can find orphans after a checkout is deleted. */\nexport function registryDir(): string {\n return process.env.CEDAR_PG_REGISTRY_DIR || join(homedir(), STATE_DIRNAME, \"registry\");\n}\n\nfunction registryPath(databaseName: string): string {\n return join(registryDir(), `${databaseName}.json`);\n}\n\nfunction writeJsonAtomic(file: string, value: unknown): void {\n mkdirSync(dirname(file), { recursive: true, mode: 0o700 });\n const tmp = `${file}.tmp.${process.pid}`;\n writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\\n`, { mode: 0o600 });\n renameSync(tmp, file);\n}\n\nfunction registerLease(lease: Lease): void {\n writeJsonAtomic(registryPath(lease.databaseName), lease);\n}\n\nfunction unregisterLease(databaseName: string): void {\n try {\n unlinkSync(registryPath(databaseName));\n } catch {\n // missing is fine\n }\n}\n\nfunction peekDatabaseName(root: string, mode: DbMode): string | undefined {\n const file = leasePath(root, mode);\n if (!existsSync(file)) return undefined;\n try {\n const raw = JSON.parse(readFileSync(file, \"utf8\")) as { databaseName?: unknown };\n return typeof raw.databaseName === \"string\" && raw.databaseName ? raw.databaseName : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function readLease(root: string, mode: DbMode): Lease | null {\n const file = leasePath(root, mode);\n if (!existsSync(file)) return null;\n try {\n return parseLease(JSON.parse(readFileSync(file, \"utf8\")));\n } catch {\n return null;\n }\n}\n\n/**\n * Persist lease. Registry is written first (GC source of truth), then the worktree cache.\n */\nexport function writeLease(lease: Lease): void {\n registerLease(lease);\n const dir = leaseDir(lease.root);\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n writeJsonAtomic(leasePath(lease.root, lease.mode), lease);\n}\n\n/**\n * Remove registry entry by databaseName and best-effort delete worktree lease + env.\n * Call only after a successful DROP (or when intentionally abandoning tracking).\n */\nexport function forgetLease(lease: Pick<Lease, \"root\" | \"mode\" | \"databaseName\">): void {\n unregisterLease(lease.databaseName);\n unlinkWorktreeArtifacts(lease.root, lease.mode);\n}\n\n/**\n * Clear worktree lease + env + registry. Unregisters by databaseName even when the local\n * file fails full parse (peeks databaseName from raw JSON).\n */\nexport function clearLease(root: string, mode: DbMode): void {\n const existing = readLease(root, mode);\n if (existing) {\n forgetLease(existing);\n return;\n }\n const databaseName = peekDatabaseName(root, mode);\n unlinkWorktreeArtifacts(root, mode);\n if (databaseName) {\n unregisterLease(databaseName);\n }\n}\n\n/** All registry entries (used by gc). */\nexport function listRegistryLeases(): Lease[] {\n const dir = registryDir();\n if (!existsSync(dir)) return [];\n const out: Lease[] = [];\n for (const name of readdirSync(dir)) {\n if (!name.endsWith(\".json\")) continue;\n try {\n const lease = parseLease(JSON.parse(readFileSync(join(dir, name), \"utf8\")));\n if (lease) out.push(lease);\n } catch {\n // skip corrupt\n }\n }\n return out;\n}\n\nexport function isOrphanLease(lease: Lease): boolean {\n return !existsSync(lease.root);\n}\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAa,WAAW;;;;;AAMxB,MAAa,gBAAgB;;;;;AAM7B,MAAa,uBAAuB;;;ACLpC,SAAS,IAAI,MAAgB,KAA4B;CACvD,IAAI;EACF,OAAO,aAAa,OAAO,MAAM;GAC/B;GACA,UAAU;GACV,OAAO;IAAC;IAAU;IAAQ;GAAQ;EACpC,CAAC,CAAC,CAAC,KAAK;CACV,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,aAAa,OAAuB;CAC3C,OAAO,MACJ,YAAY,CAAC,CACb,QAAQ,eAAe,GAAG,CAAC,CAC3B,QAAQ,OAAO,GAAG,CAAC,CACnB,QAAQ,UAAU,EAAE;AACzB;;;;;AAMA,SAAgB,YAAY,MAAuB;CACjD,IAAI,MAAM,OAAO,QAAQ,IAAI;CAC7B,MAAM,QAAQ,QAAQ,QAAQ,IAAI,CAAC;CACnC,MAAM,WAAW,IAAI,CAAC,aAAa,iBAAiB,GAAG,KAAK;CAC5D,IAAI,UAAU,OAAO;CACrB,OAAO;AACT;;;;AAKA,SAAgB,wBAAwB,MAAiC;CACvE,MAAM,UAAU,YAAY,IAAI;CAChC,MAAM,WAAW,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC;CAE9E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