From 83449e6b92700453e9b84bd771f91e04db85e48c Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:00:46 +0000 Subject: [PATCH 1/2] test(catalog): run the shared fewer-than-5 profile check in the range tests --- package.json | 2 +- pnpm-lock.yaml | 13 ++++- src/test-external/ranges.test.ts | 84 +++++++++++++++++++++++--------- src/test-external/received.ts | 44 +++++++++++++++-- tsconfig.json | 5 ++ 5 files changed, 117 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 4b88faad..c9e6ea2e 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "dependencies": { "@antelopejs/interface-core": ">=0.5.1 <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", "mysql2": "^3.24.6" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b6f9acd9..e221fd16 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,8 +18,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) mysql2: specifier: ^3.24.6 version: 3.24.6(@types/node@22.20.5) @@ -125,6 +125,11 @@ packages: peerDependencies: '@antelopejs/interface-core': '>=0.5.0 <0.6.0' + '@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' + '@antelopejs/interface-database-decorators@0.5.2': resolution: {integrity: sha512-o89zRhY8MT6nXNLz+8G/Yj4f/hQsYqrVPZCMyTrttnQuMjGVEqbIANf9t/KmgNSUVagf34LZDpsfQ2LgeeQa9Q==} peerDependencies: @@ -2979,6 +2984,10 @@ snapshots: dependencies: '@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 + '@antelopejs/interface-database-decorators@0.5.2(@antelopejs/interface-api@0.3.3(@antelopejs/interface-core@0.5.1))(@antelopejs/interface-core@0.5.1)(@antelopejs/interface-database@0.4.1(@antelopejs/interface-core@0.5.1))': dependencies: '@antelopejs/interface-api': 0.3.3(@antelopejs/interface-core@0.5.1) diff --git a/src/test-external/ranges.test.ts b/src/test-external/ranges.test.ts index de112ff4..4586eb9b 100644 --- a/src/test-external/ranges.test.ts +++ b/src/test-external/ranges.test.ts @@ -1,51 +1,87 @@ import { expect } from "chai"; +import { + AssertNoRareValue, + type FixtureCount, + type ResultValue, +} from "@antelopejs/interface-database-catalog/testing"; import { type ColumnProfile, + type RelationProfile, Profile, } from "@antelopejs/interface-database-catalog"; import { Received } from "./received"; -/** The type of `sales.grades.grade` as the catalog lists it, which the contract allows to name every label. */ -const DECLARED_GRADES = "enum('bronze','silver','gold','platinum')"; +/** The rows of `sales.grades` and `sales.snowflakes` that hold each value, as the fixture inserts them. */ +const FIXTURE_COUNTS = new Map( + Object.entries({ + 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 }, + ], + ref: Array.from({ length: 5 }, (_, index) => ({ + value: 1500000000000000001n + BigInt(index) + "", + rows: 1, + })), + }), +); async function ProfiledColumn( column: string, relation = "sales.grades", -): Promise<{ profile: ColumnProfile | undefined; results: string }> { - const { answer, results } = await Received(() => +): Promise<{ + profile: ColumnProfile | undefined; + whole: RelationProfile; + sets: ResultValue[]; +}> { + const { answer, sets } = await Received(() => Profile({ relation, columns: [column] }), ); return { profile: answer.columns.find((profiled) => profiled.name === column), - results, + whole: answer, + sets, }; } +function AssertNoRare( + column: string, + { whole, sets }: { whole: RelationProfile; sets: ResultValue[] }, +): void { + AssertNoRareValue({ + profile: whole, + results: sets, + counts: { [column]: FIXTURE_COUNTS.get(column) ?? [] }, + }); +} + 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"); - expect(profile?.range).to.deep.equal({ + it("ends an enum column at labels seen at least 5 times, so no result set holds a rarer one beside the declared type", async () => { + const profiled = await ProfiledColumn("grade"); + expect(profiled.profile?.range).to.deep.equal({ status: "ok", value: { min: "gold", max: "silver" }, }); - const measured = results.replaceAll(DECLARED_GRADES, ""); - expect(measured).to.include('"silver"'); - expect(measured).to.not.include("bronze"); - expect(measured).to.not.include("platinum"); + AssertNoRare("grade", profiled); }); it("ends an integer column at values seen 5 times, past values seen 4 times", async () => { - const { profile, results } = await ProfiledColumn("level"); - expect(profile?.range).to.deep.equal({ + const profiled = await ProfiledColumn("level"); + expect(profiled.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"); + AssertNoRare("level", profiled); }); it("answers empty for an integer column whose every value is seen once", async () => { @@ -54,15 +90,15 @@ describe("the range of an external column", function () { }); it("counts bigint values one double cannot tell apart as distinct values, so five seen once each stay unnamed", async () => { - const { profile, results } = await ProfiledColumn( - "ref", - "sales.snowflakes", - ); - expect(profile?.range).to.deep.equal({ status: "error", code: "empty" }); - expect(profile?.categories).to.deep.equal({ + const profiled = await ProfiledColumn("ref", "sales.snowflakes"); + expect(profiled.profile?.range).to.deep.equal({ + status: "error", + code: "empty", + }); + expect(profiled.profile?.categories).to.deep.equal({ status: "ok", value: { values: [], other: 5 }, }); - expect(results).to.not.match(/15000000000000000\d\d/); + AssertNoRare("ref", profiled); }); }); diff --git a/src/test-external/received.ts b/src/test-external/received.ts index 2ae137e7..4ad71a19 100644 --- a/src/test-external/received.ts +++ b/src/test-external/received.ts @@ -1,5 +1,36 @@ +import type { ResultValue } from "@antelopejs/interface-database-catalog/testing"; +import { + IsBoolean, + IsDocument, + IsNumber, + IsString, +} from "../implementations/database/guards"; import { Connection, PoolConnection } from "mysql2/promise"; +/** Whether a parsed JSON value is one `ResultValue` spells, every nested element checked. */ +function IsResultValue(value: unknown): value is ResultValue { + if ( + value === null || + IsString(value) || + IsNumber(value) || + IsBoolean(value) + ) { + return true; + } + if (Array.isArray(value)) { + return value.every(IsResultValue); + } + return IsDocument(value) && Object.values(value).every(IsResultValue); +} + +function ParseResult(json: string): ResultValue { + const parsed: unknown = JSON.parse(json); + if (!IsResultValue(parsed)) { + throw new TypeError("A result set holds a value JSON cannot spell"); + } + return parsed; +} + /** * Every result set the module's pooled connections receive while `work` runs, as JSON: each * statement they run goes through the `execute` or `query` mysql2's promise `PoolConnection` @@ -7,14 +38,17 @@ import { Connection, PoolConnection } from "mysql2/promise"; */ export async function Received( work: () => Promise, -): Promise<{ answer: T; results: string }> { +): Promise<{ answer: T; results: string; sets: ResultValue[] }> { const results: string[] = []; + const sets: ResultValue[] = []; const tapped = PoolConnection.prototype; Object.defineProperty(tapped, "execute", { configurable: true, async value(this: Connection, ...args: Parameters) { const answer = await Connection.prototype.execute.call(this, ...args); - results.push(JSON.stringify(answer[0])); + const json = JSON.stringify(answer[0]); + results.push(json); + sets.push(ParseResult(json)); return answer; }, }); @@ -22,12 +56,14 @@ export async function Received( configurable: true, async value(this: Connection, ...args: Parameters) { const answer = await Connection.prototype.query.call(this, ...args); - results.push(JSON.stringify(answer[0])); + const json = JSON.stringify(answer[0]); + results.push(json); + sets.push(ParseResult(json)); return answer; }, }); try { - return { answer: await work(), results: results.join("\n") }; + return { answer: await work(), results: results.join("\n"), sets }; } finally { Reflect.deleteProperty(tapped, "execute"); Reflect.deleteProperty(tapped, "query"); diff --git a/tsconfig.json b/tsconfig.json index 10eb28c4..78ce4195 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,11 @@ "noEmitOnError": true, "sourceMap": true, "useDefineForClassFields": true, + "paths": { + "@antelopejs/interface-database-catalog/testing": [ + "./node_modules/@antelopejs/interface-database-catalog/dist/testing.d.ts" + ] + }, "types": ["chai", "mocha", "node"] }, "include": ["src/**/*.ts", "src/**/*.js"] From 028a52bc6122885f21fe5548fd79077f31e666ae Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:02:37 +0000 Subject: [PATCH 2/2] docs: sync the compatibility table with the pinned catalog preview --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55bcac97..c77e2751 100644 --- a/README.md +++ b/README.md @@ -128,11 +128,11 @@ This repository documents what is specific to the MySQL backend: -| Package | Supported | Tested with | -| ---------------------------------------- | ---------------- | ----------- | -| `@antelopejs/interface-core` | `>=0.5.1 <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.1 <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` |