diff --git a/README.md b/README.md index d9acbb6..e8960b8 100644 --- a/README.md +++ b/README.md @@ -116,11 +116,11 @@ This repository documents what is specific to the PostgreSQL backend: -| Package | Supported | Tested with | -| ---------------------------------------- | ---------------- | ----------- | -| `@antelopejs/interface-core` | `>=0.5.0 <0.6.0` | `0.5.1` | -| `@antelopejs/interface-database` | `>=0.4.1 <0.5.0` | `0.4.1` | -| `@antelopejs/interface-database-catalog` | `>=0.1.0 <0.2.0` | `0.1.0` | +| Package | Supported | Tested with | +| ---------------------------------------- | ------------------------ | ------------------------ | +| `@antelopejs/interface-core` | `>=0.5.0 <0.6.0` | `0.5.1` | +| `@antelopejs/interface-database` | `>=0.4.1 <0.5.0` | `0.4.1` | +| `@antelopejs/interface-database-catalog` | `0.1.1-next.44.gee21aa3` | `0.1.1-next.44.gee21aa3` | diff --git a/package.json b/package.json index 9b1b7e1..6fe6f53 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "dependencies": { "@antelopejs/interface-core": ">=0.5.0 <0.6.0", "@antelopejs/interface-database": ">=0.4.1 <0.5.0", - "@antelopejs/interface-database-catalog": ">=0.1.0 <0.2.0", + "@antelopejs/interface-database-catalog": "0.1.1-next.44.gee21aa3", "pg": "^8.22.0", "pg-connection-string": "^2.14.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e8ff4e..4ea18e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,8 +15,8 @@ importers: specifier: '>=0.4.1 <0.5.0' version: 0.4.1(@antelopejs/interface-core@0.5.1) '@antelopejs/interface-database-catalog': - specifier: '>=0.1.0 <0.2.0' - version: 0.1.0(@antelopejs/interface-core@0.5.1) + specifier: 0.1.1-next.44.gee21aa3 + version: 0.1.1-next.44.gee21aa3(@antelopejs/interface-core@0.5.1) pg: specifier: ^8.22.0 version: 8.22.0 @@ -95,8 +95,8 @@ packages: '@antelopejs/interface-core@0.5.1': resolution: {integrity: sha512-ON/7TYA1yyT8UznzKi6vnwyjRU3byNE0OcFXBmf8dE/dqp8hKjeWHVyA2EUPOngmEimCLw4idZqOS5DJqMJx3g==} - '@antelopejs/interface-database-catalog@0.1.0': - resolution: {integrity: sha512-R5SL72JKD7u63UwBumWt18YsGXVnnWfKbBVwc323CgKvDcLS7Qfz+Eo/ko2ybr8wHq7Izi7maSTPhJn3fp91ug==} + '@antelopejs/interface-database-catalog@0.1.1-next.44.gee21aa3': + resolution: {integrity: sha512-lzROCQM6E01kNvubEZqxzIVJ28avLZ/aLv1lY4qUIs5HLBi5GVrbQMrthKCCSu13Z14Ka709B2nwGNJjX2eRsg==} peerDependencies: '@antelopejs/interface-core': '>=0.5.0 <0.6.0' @@ -3106,7 +3106,7 @@ snapshots: dependencies: reflect-metadata: 0.2.2 - '@antelopejs/interface-database-catalog@0.1.0(@antelopejs/interface-core@0.5.1)': + '@antelopejs/interface-database-catalog@0.1.1-next.44.gee21aa3(@antelopejs/interface-core@0.5.1)': dependencies: '@antelopejs/interface-core': 0.5.1 diff --git a/src/test-external/ranges.test.ts b/src/test-external/ranges.test.ts index 9a4e265..9a30a1a 100644 --- a/src/test-external/ranges.test.ts +++ b/src/test-external/ranges.test.ts @@ -1,24 +1,56 @@ import { expect } from "chai"; +import { z } from "zod"; import { type ColumnProfile, Profile, + type RelationProfile, } from "@antelopejs/interface-database-catalog"; +import { + AssertNoRareValue, + type FixtureCount, + type ResultValue, +} from "@antelopejs/interface-database-catalog/testing"; import { Received } from "./received"; /** The labels of `sales.grade` as the relation's description reads them from `pg_enum`. */ const DECLARED_GRADES = '["bronze","silver","gold","platinum"]'; +/** The rows of `sales.grades` that hold each value of its `grade` and `level` columns. */ +const GRADE_COUNTS = { + grade: [ + { value: "bronze", rows: 4 }, + { value: "silver", rows: 5 }, + { value: "gold", rows: 8 }, + { value: "platinum", rows: 1 }, + ], + level: [ + { value: 7001, rows: 4 }, + { value: 7002, rows: 5 }, + { value: 7008, rows: 5 }, + { value: 7009, rows: 4 }, + ], +} satisfies Record; + async function ProfiledColumn( column: string, relation = "sales.grades", -): Promise<{ profile: ColumnProfile | undefined; results: string }> { +): Promise<{ + profile: ColumnProfile | undefined; + relationProfile: RelationProfile; + results: string; + received: ResultValue[]; +}> { const { answer, results } = await Received(() => Profile({ relation, columns: [column] }), ); return { profile: answer.columns.find((profiled) => profiled.name === column), + relationProfile: answer, results: results.join("\n"), + received: results + .filter((result) => !result.includes(DECLARED_GRADES)) + .map((result): ResultValue => z.json().parse(JSON.parse(result))), }; } @@ -26,16 +58,18 @@ describe("the range of an external column", function () { this.timeout(120_000); it("ends an enum column at labels seen at least 5 times, so no result set holds a rarer one but the declared labels", async () => { - const { profile, results } = await ProfiledColumn("grade"); + const { profile, results, relationProfile, received } = + await ProfiledColumn("grade"); expect(profile?.range).to.deep.equal({ status: "ok", value: { min: "silver", max: "gold" }, }); expect(results).to.include(DECLARED_GRADES); - const measured = results.replaceAll(DECLARED_GRADES, ""); - expect(measured).to.include('"silver"'); - expect(measured).to.not.include("bronze"); - expect(measured).to.not.include("platinum"); + AssertNoRareValue({ + profile: relationProfile, + results: received, + counts: GRADE_COUNTS, + }); }); it("ends a column typed as a domain over an enum like an enum column, and counts its nulls", async () => { @@ -48,14 +82,18 @@ describe("the range of an external column", function () { }); it("ends an integer column at values seen 5 times, past values seen 4 times", async () => { - const { profile, results } = await ProfiledColumn("level"); + const { profile, results, relationProfile, received } = + await ProfiledColumn("level"); expect(profile?.range).to.deep.equal({ status: "ok", value: { min: 7002, max: 7008 }, }); expect(results).to.include("7002"); - expect(results).to.not.include("7001"); - expect(results).to.not.include("7009"); + AssertNoRareValue({ + profile: relationProfile, + results: received, + counts: GRADE_COUNTS, + }); }); it("answers empty for an integer column whose every value is seen once", async () => { diff --git a/tsconfig.json b/tsconfig.json index 1497f02..780570c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,11 @@ "noImplicitAny": true, "esModuleInterop": true, "resolveJsonModule": true, + "paths": { + "@antelopejs/interface-database-catalog/testing": [ + "./node_modules/@antelopejs/interface-database-catalog/dist/testing.d.ts" + ] + }, "removeComments": true, "preserveConstEnums": true, "experimentalDecorators": true,