@supabase/pg-delta 1.0.0-alpha.7 → 1.0.0-alpha.8
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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Plan creation - the main entry point for creating migration plans.
|
|
3
3
|
*/
|
|
4
4
|
import type { Pool } from "pg";
|
|
5
|
-
import { Catalog } from "../catalog.model.ts";
|
|
5
|
+
import type { Catalog } from "../catalog.model.ts";
|
|
6
6
|
import type { Change } from "../change.types.ts";
|
|
7
7
|
import type { DiffContext } from "../context.ts";
|
|
8
8
|
import type { CreatePlanOptions, Plan } from "./types.ts";
|
package/dist/core/plan/create.js
CHANGED
|
@@ -3,13 +3,29 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { escapeIdentifier } from "pg";
|
|
5
5
|
import { diffCatalogs } from "../catalog.diff.js";
|
|
6
|
-
import {
|
|
6
|
+
import { createEmptyCatalog, extractCatalog } from "../catalog.model.js";
|
|
7
7
|
import { buildPlanScopeFingerprint, hashStableIds } from "../fingerprint.js";
|
|
8
8
|
import { compileFilterDSL, } from "../integrations/filter/dsl.js";
|
|
9
9
|
import { compileSerializeDSL, } from "../integrations/serialize/dsl.js";
|
|
10
10
|
import { createManagedPool, endPool } from "../postgres-config.js";
|
|
11
11
|
import { sortChanges } from "../sort/sort-changes.js";
|
|
12
12
|
import { classifyChangesRisk } from "./risk.js";
|
|
13
|
+
/**
|
|
14
|
+
* Bundle-safe catalog detection: treat input as a resolved Catalog when it has
|
|
15
|
+
* the catalog shape and is not a pg Pool. Deserialized or cross-bundle Catalog
|
|
16
|
+
* instances may fail `instanceof Catalog` but pass this guard.
|
|
17
|
+
*/
|
|
18
|
+
function isResolvedCatalog(input) {
|
|
19
|
+
return (typeof input === "object" &&
|
|
20
|
+
input !== null &&
|
|
21
|
+
typeof input.query !== "function" &&
|
|
22
|
+
"version" in input &&
|
|
23
|
+
"currentUser" in input &&
|
|
24
|
+
"depends" in input &&
|
|
25
|
+
"schemas" in input &&
|
|
26
|
+
"tables" in input &&
|
|
27
|
+
"views" in input);
|
|
28
|
+
}
|
|
13
29
|
/**
|
|
14
30
|
* Create a migration plan by comparing two catalog states.
|
|
15
31
|
*
|
|
@@ -42,7 +58,7 @@ export async function createPlan(source, target, options = {}) {
|
|
|
42
58
|
* Resolve a CatalogInput to a Catalog, tracking pools that need cleanup.
|
|
43
59
|
*/
|
|
44
60
|
const resolveCatalog = async (input, label, pools) => {
|
|
45
|
-
if (input
|
|
61
|
+
if (isResolvedCatalog(input)) {
|
|
46
62
|
return input;
|
|
47
63
|
}
|
|
48
64
|
const resolved = await resolvePool(input, label);
|
package/package.json
CHANGED
|
@@ -289,6 +289,19 @@ describe("catalog snapshot serde", () => {
|
|
|
289
289
|
expect(result).toBeNull();
|
|
290
290
|
});
|
|
291
291
|
|
|
292
|
+
test("createPlan accepts catalog-shaped plain object (bundle-boundary regression)", async () => {
|
|
293
|
+
const { createPlan } = await import("./plan/create.ts");
|
|
294
|
+
|
|
295
|
+
const sourceCatalog = await createEmptyCatalog(160000, "postgres");
|
|
296
|
+
const targetCatalog = await createEmptyCatalog(160000, "postgres");
|
|
297
|
+
const source = { ...sourceCatalog };
|
|
298
|
+
|
|
299
|
+
expect(source instanceof Catalog).toBe(false);
|
|
300
|
+
|
|
301
|
+
const result = await createPlan(source as Catalog, targetCatalog);
|
|
302
|
+
expect(result).toBeNull();
|
|
303
|
+
});
|
|
304
|
+
|
|
292
305
|
test("createPlan with null source produces plan when target has objects", async () => {
|
|
293
306
|
const { createPlan } = await import("./plan/create.ts");
|
|
294
307
|
|
package/src/core/plan/create.ts
CHANGED
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
import type { Pool } from "pg";
|
|
6
6
|
import { escapeIdentifier } from "pg";
|
|
7
7
|
import { diffCatalogs } from "../catalog.diff.ts";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
createEmptyCatalog,
|
|
11
|
-
extractCatalog,
|
|
12
|
-
} from "../catalog.model.ts";
|
|
8
|
+
import type { Catalog } from "../catalog.model.ts";
|
|
9
|
+
import { createEmptyCatalog, extractCatalog } from "../catalog.model.ts";
|
|
13
10
|
import type { Change } from "../change.types.ts";
|
|
14
11
|
import type { DiffContext } from "../context.ts";
|
|
15
12
|
import { buildPlanScopeFingerprint, hashStableIds } from "../fingerprint.ts";
|
|
@@ -38,6 +35,25 @@ import type { CreatePlanOptions, Plan } from "./types.ts";
|
|
|
38
35
|
*/
|
|
39
36
|
export type CatalogInput = string | Pool | Catalog;
|
|
40
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Bundle-safe catalog detection: treat input as a resolved Catalog when it has
|
|
40
|
+
* the catalog shape and is not a pg Pool. Deserialized or cross-bundle Catalog
|
|
41
|
+
* instances may fail `instanceof Catalog` but pass this guard.
|
|
42
|
+
*/
|
|
43
|
+
function isResolvedCatalog(input: CatalogInput): input is Catalog {
|
|
44
|
+
return (
|
|
45
|
+
typeof input === "object" &&
|
|
46
|
+
input !== null &&
|
|
47
|
+
typeof (input as { query?: unknown }).query !== "function" &&
|
|
48
|
+
"version" in input &&
|
|
49
|
+
"currentUser" in input &&
|
|
50
|
+
"depends" in input &&
|
|
51
|
+
"schemas" in input &&
|
|
52
|
+
"tables" in input &&
|
|
53
|
+
"views" in input
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
41
57
|
/**
|
|
42
58
|
* Create a migration plan by comparing two catalog states.
|
|
43
59
|
*
|
|
@@ -82,7 +98,7 @@ export async function createPlan(
|
|
|
82
98
|
label: "source" | "target",
|
|
83
99
|
pools: Array<{ pool: Pool; shouldClose: boolean }>,
|
|
84
100
|
): Promise<Catalog> => {
|
|
85
|
-
if (input
|
|
101
|
+
if (isResolvedCatalog(input)) {
|
|
86
102
|
return input;
|
|
87
103
|
}
|
|
88
104
|
const resolved = await resolvePool(input, label);
|