diff --git a/guardrails.suppressions.json b/guardrails.suppressions.json index c78bcc1..89787b1 100644 --- a/guardrails.suppressions.json +++ b/guardrails.suppressions.json @@ -2,7 +2,7 @@ "rules": { "anti-slop/no-unknown-parameters": 1 }, - "tsExpectError": 56, + "tsExpectError": 0, "tsIgnore": 0, "safety": 0, "config": {}, diff --git a/src/test/unit/config-fixture.ts b/src/test/unit/config-fixture.ts new file mode 100644 index 0000000..f3dcb3c --- /dev/null +++ b/src/test/unit/config-fixture.ts @@ -0,0 +1,10 @@ +/** The options `SetOptions` requires to be positive safe integers. */ +export const VALIDATED = [ + "cursorBatchSize", + "cursorIdleTimeoutMs", + "changeRetentionMs", + "changeBatchSize", + "changePollIntervalMs", +] as const; + +export type ValidatedOption = (typeof VALIDATED)[number]; diff --git a/src/test/unit/config.spec.ts b/src/test/unit/config.spec.ts index f5d86af..43407d5 100644 --- a/src/test/unit/config.spec.ts +++ b/src/test/unit/config.spec.ts @@ -1,6 +1,7 @@ import { expect } from "chai"; import { WithOptions } from "./spec-fixture"; +import { VALIDATED, type ValidatedOption } from "./config-fixture"; import { GetOptions, type Options, SetOptions } from "../../config"; const DEFAULT_CURSOR_BATCH_SIZE = 100; @@ -9,16 +10,6 @@ const DEFAULT_CHANGE_RETENTION_MS = 300_000; const DEFAULT_CHANGE_BATCH_SIZE = 256; const DEFAULT_CHANGE_POLL_INTERVAL_MS = 5_000; -const VALIDATED = [ - "cursorBatchSize", - "cursorIdleTimeoutMs", - "changeRetentionMs", - "changeBatchSize", - "changePollIntervalMs", -] as const; - -type ValidatedOption = (typeof VALIDATED)[number]; - const DEFAULTS: Record = { cursorBatchSize: DEFAULT_CURSOR_BATCH_SIZE, cursorIdleTimeoutMs: DEFAULT_CURSOR_IDLE_TIMEOUT_MS, @@ -27,20 +18,6 @@ const DEFAULTS: Record = { changePollIntervalMs: DEFAULT_CHANGE_POLL_INTERVAL_MS, }; -const REFUSED: readonly unknown[] = [ - 0, - -1, - 1.5, - Number.NaN, - Number.POSITIVE_INFINITY, - Number.NEGATIVE_INFINITY, - Number.MAX_SAFE_INTEGER + 2, - 1e21, - "100", - null, - {}, -]; - const EXTERNAL_REFUSED: readonly Options[] = [ { schemaPrefix: "app_" }, { migrations: "safe" }, @@ -68,16 +45,6 @@ describe("SetOptions", () => { expect(GetOptions()[option]).to.equal(DEFAULTS[option]); }); }); - - it(`refuses a ${option} that is not a positive safe integer`, () => { - for (const value of REFUSED) { - const options: Options = {}; - // @ts-expect-error REFUSED holds values that are not positive safe integers; SetOptions throws, naming the option and the value - options[option] = value; - expect(() => SetOptions(options)).to.throw(option); - expect(() => SetOptions(options)).to.throw(String(value)); - } - }); } it("leaves the configuration in place when it refuses", () => { @@ -111,13 +78,6 @@ describe("SetOptions", () => { }); }); - it("refuses a mode it does not know", () => { - expect(() => - // @ts-expect-error the unknown mode "readonly"; SetOptions throws, naming it - SetOptions({ mode: "readonly" }), - ).to.throw("readonly"); - }); - for (const refused of EXTERNAL_REFUSED) { const [option] = Object.keys(refused); it(`refuses ${option} in external mode, naming it`, () => { diff --git a/src/test/unit/config.untyped.spec.js b/src/test/unit/config.untyped.spec.js new file mode 100644 index 0000000..c5713a8 --- /dev/null +++ b/src/test/unit/config.untyped.spec.js @@ -0,0 +1,36 @@ +import { expect } from "chai"; + +import { VALIDATED } from "./config-fixture"; +import { SetOptions } from "../../config"; + +/** @type {readonly unknown[]} */ +const REFUSED = [ + 0, + -1, + 1.5, + Number.NaN, + Number.POSITIVE_INFINITY, + Number.NEGATIVE_INFINITY, + Number.MAX_SAFE_INTEGER + 2, + 1e21, + "100", + null, + {}, +]; + +describe("SetOptions", () => { + for (const option of VALIDATED) { + it(`refuses a ${option} that is not a positive safe integer`, () => { + for (const value of REFUSED) { + const options = {}; + options[option] = value; + expect(() => SetOptions(options)).to.throw(option); + expect(() => SetOptions(options)).to.throw(String(value)); + } + }); + } + + it("refuses a mode it does not know", () => { + expect(() => SetOptions({ mode: "readonly" })).to.throw("readonly"); + }); +}); diff --git a/src/test/unit/expression-array-walk.spec.ts b/src/test/unit/expression-array-walk.spec.ts index e943862..978a391 100644 --- a/src/test/unit/expression-array-walk.spec.ts +++ b/src/test/unit/expression-array-walk.spec.ts @@ -1,11 +1,7 @@ import { expect } from "chai"; -import { QueryStage } from "@antelopejs/interface-database/common"; - import { Occurrences } from "./spec-fixture"; -import { CompileExpression } from "../../implementations/database/expression"; - import { ArrayOf, FLOAT, @@ -14,8 +10,6 @@ import { TIMESTAMP, } from "../../implementations/database/types"; import { - ROW_ID, - NewContext, Compile, TAGS, EXTRA, @@ -113,16 +107,6 @@ describe("arr_map", () => { ); expect(Aliases(out.sql)).to.deep.equal(["t1", "t0"]); }); - - it("names the stage when the callback is absent", () => { - expect(() => - CompileExpression( - // @ts-expect-error no callback, which the arr_map stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_map")], - NewContext(), - ), - ).to.throw(/'arr_map'/); - }); }); describe("arr_filter", () => { @@ -147,16 +131,6 @@ describe("arr_filter", () => { const out = Compile((doc) => doc.key("scores").filter((score) => score)); expect(out.sql).to.contain(`WHERE (${AsNumber(Element("t0"))} <> 0)`); }); - - it("names the stage when the callback is absent", () => { - expect(() => - CompileExpression( - // @ts-expect-error no callback, which the arr_filter stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_filter")], - NewContext(), - ), - ).to.throw(/'arr_filter'/); - }); }); describe("a lambda body closing over the outer row", () => { diff --git a/src/test/unit/expression-array-walk.untyped.spec.js b/src/test/unit/expression-array-walk.untyped.spec.js new file mode 100644 index 0000000..5df2e99 --- /dev/null +++ b/src/test/unit/expression-array-walk.untyped.spec.js @@ -0,0 +1,27 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { CompileExpression } from "../../implementations/database/expression"; +import { ROW_ID, NewContext } from "./expression-array-fixture"; + +describe("arr_map", () => { + it("names the stage when the callback is absent", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_map")], + NewContext(), + ), + ).to.throw(/'arr_map'/); + }); +}); + +describe("arr_filter", () => { + it("names the stage when the callback is absent", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_filter")], + NewContext(), + ), + ).to.throw(/'arr_filter'/); + }); +}); diff --git a/src/test/unit/expression-array.spec.ts b/src/test/unit/expression-array.spec.ts index e74d835..fe7bda4 100644 --- a/src/test/unit/expression-array.spec.ts +++ b/src/test/unit/expression-array.spec.ts @@ -108,16 +108,6 @@ describe("arr_count and arr_empty", () => { Guarded(EXTRA, `((jsonb_array_length(${EXTRA}))::double precision)`), ); }); - - it("reads a scalar operand as jsonb so the guard nulls it", () => { - const age = `to_jsonb("t"."age")`; - expect( - // @ts-expect-error a number column where count reads an array; the SQL guards jsonb_array_length of the column read through to_jsonb - Compile((doc) => doc.key("age").count()).sql, - ).to.equal( - Guarded(age, `((jsonb_array_length(${age}))::double precision)`), - ); - }); }); describe("arr_index", () => { @@ -147,16 +137,6 @@ describe("arr_index", () => { expect(out.sql).to.contain("LEAST(GREATEST(trunc("); expect(out.sql).to.contain("-2147483648), 2147483647)::int)"); }); - - it("names the stage when the position is absent", () => { - expect(() => - CompileExpression( - // @ts-expect-error no position, which the arr_index stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_index")], - NewContext(), - ), - ).to.throw(/'arr_index'/); - }); }); describe("arr_includes", () => { @@ -176,24 +156,6 @@ describe("arr_includes", () => { Compile((doc) => doc.key("nope").includes([[1]])).sql, ).to.not.contain("CASE"); }); - - it("leaves a non-array operand to answer false, since @> cannot raise", () => { - const age = `to_jsonb("t"."age")`; - expect( - // @ts-expect-error a number column where includes reads an array; the SQL is an unguarded @> of the column read through to_jsonb - Compile((doc) => doc.key("age").includes("x")).sql, - ).to.equal(`(${age} @> jsonb_build_array(to_jsonb(($1::text))))`); - }); - - it("names the stage when the value is absent", () => { - expect(() => - CompileExpression( - // @ts-expect-error no value, which the arr_includes stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_includes")], - NewContext(), - ), - ).to.throw(/'arr_includes'/); - }); }); /** @@ -249,16 +211,6 @@ describe("arr_slice", () => { "COALESCE(jsonb_agg(", ); }); - - it("names the stage when the start is absent", () => { - expect(() => - CompileExpression( - // @ts-expect-error no start, which the arr_slice stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_slice")], - NewContext(), - ), - ).to.throw(/'arr_slice'/); - }); }); interface SliceBounds { diff --git a/src/test/unit/expression-array.untyped.spec.js b/src/test/unit/expression-array.untyped.spec.js new file mode 100644 index 0000000..12a7751 --- /dev/null +++ b/src/test/unit/expression-array.untyped.spec.js @@ -0,0 +1,59 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { CompileExpression } from "../../implementations/database/expression"; +import { + ROW_ID, + NewContext, + Compile, + Guarded, +} from "./expression-array-fixture"; + +describe("arr_count and arr_empty", () => { + it("reads a scalar operand as jsonb so the guard nulls it", () => { + const age = `to_jsonb("t"."age")`; + expect(Compile((doc) => doc.key("age").count()).sql).to.equal( + Guarded(age, `((jsonb_array_length(${age}))::double precision)`), + ); + }); +}); + +describe("arr_index", () => { + it("names the stage when the position is absent", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_index")], + NewContext(), + ), + ).to.throw(/'arr_index'/); + }); +}); + +describe("arr_includes", () => { + it("leaves a non-array operand to answer false, since @> cannot raise", () => { + const age = `to_jsonb("t"."age")`; + expect(Compile((doc) => doc.key("age").includes("x")).sql).to.equal( + `(${age} @> jsonb_build_array(to_jsonb(($1::text))))`, + ); + }); + + it("names the stage when the value is absent", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_includes")], + NewContext(), + ), + ).to.throw(/'arr_includes'/); + }); +}); + +describe("arr_slice", () => { + it("names the stage when the start is absent", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("arr_slice")], + NewContext(), + ), + ).to.throw(/'arr_slice'/); + }); +}); diff --git a/src/test/unit/expression-date.spec.ts b/src/test/unit/expression-date.spec.ts index 0159310..4cbc5a9 100644 --- a/src/test/unit/expression-date.spec.ts +++ b/src/test/unit/expression-date.spec.ts @@ -280,35 +280,6 @@ describe("date_with_timezone", () => { expect(stages).to.not.contain("date_with_timezone"); }); - it("names the stage when the zone is absent", () => { - expect(() => - CompileExpression( - [ - QueryStage("arg", undefined, ROW_ID), - // @ts-expect-error no zone, which the date_with_timezone stage refuses by naming itself - QueryStage("date_with_timezone"), - ], - NewContext(), - ), - ).to.throw(/'date_with_timezone'/); - }); - - it("names the stage when the zone is empty or is not a name", () => { - const dynamic = ValueProxy.arg(ROW_ID).key("name"); - for (const zone of ["", 5, dynamic]) { - expect(() => - CompileExpression( - [ - QueryStage("arg", undefined, ROW_ID), - // @ts-expect-error a number among the zones, which the date_with_timezone stage refuses by naming itself - QueryStage("date_with_timezone", undefined, zone), - ], - NewContext(), - ), - ).to.throw(/'date_with_timezone'/); - } - }); - it("is cleared by an unrelated stage between the zone and the part", () => { const context = NewContext(); const out = CompileIn(context, (doc) => @@ -396,19 +367,6 @@ describe("date_during", () => { `((${CREATED} >= ${FromEpoch("($1::double precision)")}) AND (${CREATED} < ${FromEpoch("($2::double precision)")}))`, ); }); - - it("names the stage when a bound is absent", () => { - expect(() => - CompileExpression( - [ - QueryStage("arg", undefined, ROW_ID), - // @ts-expect-error one bound, which the date_during stage refuses by naming itself - QueryStage("date_during", undefined, new Date(0)), - ], - NewContext(), - ), - ).to.throw(/'date_during'/); - }); }); describe("reading a value as a moment", () => { diff --git a/src/test/unit/expression-date.untyped.spec.js b/src/test/unit/expression-date.untyped.spec.js new file mode 100644 index 0000000..5c0ea3a --- /dev/null +++ b/src/test/unit/expression-date.untyped.spec.js @@ -0,0 +1,49 @@ +import { expect } from "chai"; +import { ValueProxy } from "@antelopejs/interface-database"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { CompileExpression } from "../../implementations/database/expression"; +import { ROW_ID, NewContext } from "./expression-fixture"; + +describe("date_with_timezone", () => { + it("names the stage when the zone is absent", () => { + expect(() => + CompileExpression( + [ + QueryStage("arg", undefined, ROW_ID), + QueryStage("date_with_timezone"), + ], + NewContext(), + ), + ).to.throw(/'date_with_timezone'/); + }); + + it("names the stage when the zone is empty or is not a name", () => { + const dynamic = ValueProxy.arg(ROW_ID).key("name"); + for (const zone of ["", 5, dynamic]) { + expect(() => + CompileExpression( + [ + QueryStage("arg", undefined, ROW_ID), + QueryStage("date_with_timezone", undefined, zone), + ], + NewContext(), + ), + ).to.throw(/'date_with_timezone'/); + } + }); +}); + +describe("date_during", () => { + it("names the stage when a bound is absent", () => { + expect(() => + CompileExpression( + [ + QueryStage("arg", undefined, ROW_ID), + QueryStage("date_during", undefined, new Date(0)), + ], + NewContext(), + ), + ).to.throw(/'date_during'/); + }); +}); diff --git a/src/test/unit/expression-numeric.spec.ts b/src/test/unit/expression-numeric.spec.ts index c57c9ae..179f1b1 100644 --- a/src/test/unit/expression-numeric.spec.ts +++ b/src/test/unit/expression-numeric.spec.ts @@ -129,30 +129,6 @@ describe("numeric stage dispatch", () => { ); expect(out.timezone).to.equal(undefined); }); - - it("names the stage when the second operand is absent", () => { - const binary = [ - "add", - "sub", - "mul", - "div", - "mod", - "bit_and", - "bit_or", - "bit_xor", - "bit_lshift", - "bit_rshift", - ]; - for (const name of binary) { - expect(() => - CompileExpression( - // @ts-expect-error a binary stage with no operand, which each stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage(name)], - NewContext(), - ), - ).to.throw(`'${name}'`); - } - }); }); describe("add", () => { @@ -198,15 +174,6 @@ describe("add", () => { expect(out.type).to.deep.equal(ArrayOf(TEXT)); }); - it("rejects two dates, naming the stage", () => { - expect(() => - // @ts-expect-error two dates, which the add stage refuses by naming itself - Compile((doc) => doc.key("createdAt").add(new Date())), - ).to.throw( - /Stage 'add' has no reading for a 'timestamp' and a 'timestamp'/, - ); - }); - it("pulls an undeclared key toward the kind of the other operand", () => { expect(Compile((doc) => doc.key("nope").add("x")).sql).to.equal( `(${AsText(Extra("nope"))} || ${TEXT_PARAM})`, diff --git a/src/test/unit/expression-numeric.untyped.spec.js b/src/test/unit/expression-numeric.untyped.spec.js new file mode 100644 index 0000000..285d6ec --- /dev/null +++ b/src/test/unit/expression-numeric.untyped.spec.js @@ -0,0 +1,41 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { CompileExpression } from "../../implementations/database/expression"; +import { ROW_ID, NewContext, Compile } from "./expression-fixture"; + +const BINARY_STAGES = [ + "add", + "sub", + "mul", + "div", + "mod", + "bit_and", + "bit_or", + "bit_xor", + "bit_lshift", + "bit_rshift", +]; + +describe("numeric stage dispatch", () => { + it("names the stage when the second operand is absent", () => { + for (const name of BINARY_STAGES) { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage(name)], + NewContext(), + ), + ).to.throw(`'${name}'`); + } + }); +}); + +describe("add", () => { + it("rejects two dates, naming the stage", () => { + expect(() => + Compile((doc) => doc.key("createdAt").add(new Date())), + ).to.throw( + /Stage 'add' has no reading for a 'timestamp' and a 'timestamp'/, + ); + }); +}); diff --git a/src/test/unit/expression-object.spec.ts b/src/test/unit/expression-object.spec.ts index b63713e..50a204a 100644 --- a/src/test/unit/expression-object.spec.ts +++ b/src/test/unit/expression-object.spec.ts @@ -205,16 +205,6 @@ describe("obj_merge", () => { expect(out.sql).to.contain(`AS "t0"`); expect(out.sql).to.contain(`AS "t1"`); }); - - it("names the stage when the other object is absent", () => { - expect(() => - CompileExpression( - // @ts-expect-error no other object, which the obj_merge stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("obj_merge")], - NewContext(), - ), - ).to.throw(/'obj_merge'/); - }); }); describe("obj_keys", () => { @@ -324,27 +314,4 @@ describe("obj_has", () => { const out = Compile((doc) => doc.key("age").hasfields("a")); expect(out.sql).to.equal(HasFields(age, `array['a']::text[]`)); }); - - it("names the stage when the field list is not a list", () => { - expect(() => - CompileExpression( - // @ts-expect-error no field list, which the obj_has stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("obj_has")], - NewContext(), - ), - ).to.throw(/'obj_has'/); - }); - - it("names the stage when a field name is not a string", () => { - expect(() => - CompileExpression( - [ - QueryStage("arg", undefined, ROW_ID), - // @ts-expect-error a field name that is not a string, which the obj_has stage refuses by naming itself - QueryStage("obj_has", undefined, [5]), - ], - NewContext(), - ), - ).to.throw(/'obj_has'/); - }); }); diff --git a/src/test/unit/expression-object.untyped.spec.js b/src/test/unit/expression-object.untyped.spec.js new file mode 100644 index 0000000..f5186a0 --- /dev/null +++ b/src/test/unit/expression-object.untyped.spec.js @@ -0,0 +1,39 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { CompileExpression } from "../../implementations/database/expression"; +import { ROW_ID, NewContext } from "./expression-fixture"; + +describe("obj_merge", () => { + it("names the stage when the other object is absent", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("obj_merge")], + NewContext(), + ), + ).to.throw(/'obj_merge'/); + }); +}); + +describe("obj_has", () => { + it("names the stage when the field list is not a list", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("obj_has")], + NewContext(), + ), + ).to.throw(/'obj_has'/); + }); + + it("names the stage when a field name is not a string", () => { + expect(() => + CompileExpression( + [ + QueryStage("arg", undefined, ROW_ID), + QueryStage("obj_has", undefined, [5]), + ], + NewContext(), + ), + ).to.throw(/'obj_has'/); + }); +}); diff --git a/src/test/unit/expression-string.spec.ts b/src/test/unit/expression-string.spec.ts index f790bfb..356c198 100644 --- a/src/test/unit/expression-string.spec.ts +++ b/src/test/unit/expression-string.spec.ts @@ -115,18 +115,6 @@ describe("string stage dispatch", () => { expect(out.timezone, call.stage).to.equal(undefined); } }); - - it("names the stage when the operand is absent", () => { - for (const name of ["str_concat", "str_match"]) { - expect(() => - CompileExpression( - // @ts-expect-error a string stage with no operand, which each stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage(name)], - NewContext(), - ), - ).to.throw(`'${name}'`); - } - }); }); describe("str_upcase and str_downcase", () => { diff --git a/src/test/unit/expression-string.untyped.spec.js b/src/test/unit/expression-string.untyped.spec.js new file mode 100644 index 0000000..f629d8d --- /dev/null +++ b/src/test/unit/expression-string.untyped.spec.js @@ -0,0 +1,18 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { CompileExpression } from "../../implementations/database/expression"; +import { ROW_ID, NewContext } from "./expression-fixture"; + +describe("string stage dispatch", () => { + it("names the stage when the operand is absent", () => { + for (const name of ["str_concat", "str_match"]) { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage(name)], + NewContext(), + ), + ).to.throw(`'${name}'`); + } + }); +}); diff --git a/src/test/unit/expression.spec.ts b/src/test/unit/expression.spec.ts index 87f276e..fa0327e 100644 --- a/src/test/unit/expression.spec.ts +++ b/src/test/unit/expression.spec.ts @@ -36,24 +36,6 @@ import { } from "./expression-fixture"; describe("CompileExpression dispatch", () => { - it("rejects a stage it does not know", () => { - expect(() => - // @ts-expect-error a stage outside the union, which the compiler refuses as unsupported - CompileExpression([QueryStage("not_a_stage")], NewContext()), - ).to.throw(/Unsupported expression stage 'not_a_stage'/); - }); - - it("does not dispatch a stage name inherited from Object.prototype", () => { - expect(() => - // @ts-expect-error a stage named after an inherited member, which the compiler refuses as unsupported - CompileExpression([QueryStage("constructor")], NewContext()), - ).to.throw(/Unsupported expression stage 'constructor'/); - expect(() => - // @ts-expect-error a stage named after an inherited member, which the compiler refuses as unsupported - CompileExpression([QueryStage("__proto__")], NewContext()), - ).to.throw(/Unsupported expression stage '__proto__'/); - }); - it("rejects an expression that never produced a value", () => { expect(() => CompileExpression([], NewContext())).to.throw( /Expression has no value/, @@ -139,23 +121,6 @@ describe("arg", () => { } }); - it("reads a text parameter id as unbound rather than refusing it", () => { - expect(() => - CompileExpression( - // @ts-expect-error a text parameter id, which the arg stage refuses as an unbound lambda parameter - [QueryStage("arg", undefined, "valueOf")], - NewContext(), - ), - ).to.throw("Unbound lambda parameter valueOf"); - }); - - it("reads an arg stage whose parameter id is neither a number nor a text as unbound", () => { - expect(() => - // @ts-expect-error a boolean parameter id, which the arg stage refuses as an unbound lambda parameter - CompileExpression([QueryStage("arg", undefined, true)], NewContext()), - ).to.throw("Unbound lambda parameter true"); - }); - it("clears a pending timezone", () => { const out = STAGES.arg( { timezone: "'UTC'" }, @@ -343,16 +308,6 @@ describe("boolean stages", () => { ); }); - it("rejects a missing operand naming the stage", () => { - expect(() => - CompileExpression( - // @ts-expect-error no operand, which the and stage refuses by naming itself - [QueryStage("arg", undefined, ROW_ID), QueryStage("and")], - NewContext(), - ), - ).to.throw(/'and'/); - }); - it("leaves a null operand null rather than reading it as false", () => { const truthy = `(("t"."_extra" -> 'missing') ${FALSEHOOD})`; expect(Compile((doc) => doc.key("missing").and(true)).sql).to.equal( diff --git a/src/test/unit/expression.untyped.spec.js b/src/test/unit/expression.untyped.spec.js new file mode 100644 index 0000000..48e9bd8 --- /dev/null +++ b/src/test/unit/expression.untyped.spec.js @@ -0,0 +1,50 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { CompileExpression } from "../../implementations/database/expression"; +import { ROW_ID, NewContext } from "./expression-fixture"; + +describe("CompileExpression dispatch", () => { + it("rejects a stage it does not know", () => { + expect(() => + CompileExpression([QueryStage("not_a_stage")], NewContext()), + ).to.throw(/Unsupported expression stage 'not_a_stage'/); + }); + + it("does not dispatch a stage name inherited from Object.prototype", () => { + expect(() => + CompileExpression([QueryStage("constructor")], NewContext()), + ).to.throw(/Unsupported expression stage 'constructor'/); + expect(() => + CompileExpression([QueryStage("__proto__")], NewContext()), + ).to.throw(/Unsupported expression stage '__proto__'/); + }); +}); + +describe("arg", () => { + it("reads a text parameter id as unbound rather than refusing it", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, "valueOf")], + NewContext(), + ), + ).to.throw("Unbound lambda parameter valueOf"); + }); + + it("reads an arg stage whose parameter id is neither a number nor a text as unbound", () => { + expect(() => + CompileExpression([QueryStage("arg", undefined, true)], NewContext()), + ).to.throw("Unbound lambda parameter true"); + }); +}); + +describe("boolean stages", () => { + it("rejects a missing operand naming the stage", () => { + expect(() => + CompileExpression( + [QueryStage("arg", undefined, ROW_ID), QueryStage("and")], + NewContext(), + ), + ).to.throw(/'and'/); + }); +}); diff --git a/src/test/unit/feeds-fixture.ts b/src/test/unit/feeds-fixture.ts new file mode 100644 index 0000000..a274e3c --- /dev/null +++ b/src/test/unit/feeds-fixture.ts @@ -0,0 +1,110 @@ +import type { QueryStage } from "@antelopejs/interface-database/common"; + +import { WhileConfigured } from "./spec-fixture"; +import type { TableOrigin } from "../../implementations/database/relation"; +import { + CloseOneFeed, + type FeedEnvironment, + type FeedReader, + type LoggedEvent, + ReadFeedEvent, +} from "../../implementations/database/feeds"; + +/** + * A feed that never opens against a live schema, driven entirely through the reader seam. + * + * These `reqId`s are negative because the interface's own counter starts at 0 + * and counts up, so a fixture using a positive id would collide with a lambda or a cursor the + * process allocated for something else. + */ +let nextReqId = -1000; +export const NewReqId = () => nextReqId--; + +export const SCHEMA_ID = "shop"; +export const TABLE_ID = "orders"; + +export const EPOCH = new Date("2026-08-12T09:00:00.000Z"); + +export function Stages(...between: QueryStage[]): QueryStage[] { + return [ + { stage: "schema", options: { id: SCHEMA_ID }, args: [] }, + { stage: "instance", options: { id: "default" }, args: [] }, + { stage: "table", options: { id: TABLE_ID }, args: [] }, + ...between, + { stage: "changes", args: [] }, + ]; +} + +interface Answer { + epoch?: Date; + high_water?: string | null; + scanned_to?: string | null; + events?: LoggedEvent[]; +} + +interface Asked { + sql: string; + params: unknown[]; +} + +/** + * A table with no declared fields, so every logged key reads out of the overflow document. + * + * `index` answers the name itself, which is `IndexFields`' own undeclared-field fallback — the + * feed's selection stages resolve through it exactly as the read path does. + */ +const FIELDLESS: TableOrigin = { + schemaId: SCHEMA_ID, + tableId: TABLE_ID, + model: { fields: {} }, + index: (name) => [name], +}; + +/** Answers each statement in turn, recording what it was asked; the last answer repeats. */ +export function Reader(answers: Answer[]) { + const asked: Asked[] = []; + const read: FeedReader = (sql, params) => { + asked.push({ sql, params }); + const answer = answers[Math.min(asked.length - 1, answers.length - 1)]; + return Promise.resolve({ + rows: [ + { + epoch: answer.epoch ?? EPOCH, + high_water: answer.high_water ?? null, + scanned_to: answer.scanned_to ?? null, + scanned_count: (answer.events ?? []).length, + events: answer.events ?? [], + }, + ], + }); + }; + return { + read: { + read, + install: () => Promise.resolve(), + origin: () => FIELDLESS, + listen: () => Promise.resolve(), + }, + asked, + }; +} + +/** + * Runs a feed spec with *a* configuration in place for the whole of it. + * + * `WithOptions` cannot serve here: it restores synchronously, and every generated name a feed reads + * — the physical schema and table it watches — is resolved one await later, inside the open. + */ +export function Feed(body: (reqId: number) => Promise) { + const reqId = NewReqId(); + return WhileConfigured(() => body(reqId)).finally(() => CloseOneFeed(reqId)); +} + +/** Reads one event, with the environment supplied so nothing touches a pool. */ +export function Step( + reqId: number, + read: FeedEnvironment, + ...between: QueryStage[] +) { + return ReadFeedEvent(reqId, Stages(...between), read); +} diff --git a/src/test/unit/feeds.spec.ts b/src/test/unit/feeds.spec.ts index c364c8a..d22fb79 100644 --- a/src/test/unit/feeds.spec.ts +++ b/src/test/unit/feeds.spec.ts @@ -3,99 +3,25 @@ import { expect } from "chai"; import { QueryStage } from "@antelopejs/interface-database/common"; import { WhileConfigured } from "./spec-fixture"; -import type { TableOrigin } from "../../implementations/database/relation"; import { CloseCursor, ReadCursor } from "../../implementations/database/query"; import { CloseAllFeeds, CloseOneFeed, - type FeedEnvironment, - type FeedReader, - type LoggedEvent, IsRegisteredFeed, - ReadFeedEvent, } from "../../implementations/database/feeds"; - -/** - * A feed that never opens against a live schema, driven entirely through the reader seam. - * - * These `reqId`s are negative because the interface's own counter starts at 0 - * and counts up, so a fixture using a positive id would collide with a lambda or a cursor the - * process allocated for something else. - */ -let nextReqId = -1000; -const NewReqId = () => nextReqId--; - -const SCHEMA_ID = "shop"; -const TABLE_ID = "orders"; - -const EPOCH = new Date("2026-08-12T09:00:00.000Z"); -const LATER_EPOCH = new Date("2026-08-12T10:00:00.000Z"); +import { + EPOCH, + Feed, + NewReqId, + Reader, + SCHEMA_ID, + Stages, + Step, + TABLE_ID, +} from "./feeds-fixture"; const SETTLE_MS = 60; - -function Stages(...between: QueryStage[]): QueryStage[] { - return [ - { stage: "schema", options: { id: SCHEMA_ID }, args: [] }, - { stage: "instance", options: { id: "default" }, args: [] }, - { stage: "table", options: { id: TABLE_ID }, args: [] }, - ...between, - { stage: "changes", args: [] }, - ]; -} - -interface Answer { - epoch?: Date; - high_water?: string | null; - scanned_to?: string | null; - events?: LoggedEvent[]; -} - -interface Asked { - sql: string; - params: unknown[]; -} - -/** - * A table with no declared fields, so every logged key reads out of the overflow document. - * - * `index` answers the name itself, which is `IndexFields`' own undeclared-field fallback — the - * feed's selection stages resolve through it exactly as the read path does. - */ -const FIELDLESS: TableOrigin = { - schemaId: SCHEMA_ID, - tableId: TABLE_ID, - model: { fields: {} }, - index: (name) => [name], -}; - -/** Answers each statement in turn, recording what it was asked; the last answer repeats. */ -function Reader(answers: Answer[]) { - const asked: Asked[] = []; - const read: FeedReader = (sql, params) => { - asked.push({ sql, params }); - const answer = answers[Math.min(asked.length - 1, answers.length - 1)]; - return Promise.resolve({ - rows: [ - { - epoch: answer.epoch ?? EPOCH, - high_water: answer.high_water ?? null, - scanned_to: answer.scanned_to ?? null, - scanned_count: (answer.events ?? []).length, - events: answer.events ?? [], - }, - ], - }); - }; - return { - read: { - read, - install: () => Promise.resolve(), - origin: () => FIELDLESS, - listen: () => Promise.resolve(), - }, - asked, - }; -} +const LATER_EPOCH = new Date("2026-08-12T10:00:00.000Z"); /** One side of an event as the laterals answer it: what it projected, and whether it matched. */ function Side(doc: Doc, matched = true) { @@ -104,22 +30,6 @@ function Side(doc: Doc, matched = true) { const ABSENT = Side(null, false); -/** - * Runs a feed spec with *a* configuration in place for the whole of it. - * - * `WithOptions` cannot serve here: it restores synchronously, and every generated name a feed reads - * — the physical schema and table it watches — is resolved one await later, inside the open. - */ -function Feed(body: (reqId: number) => Promise) { - const reqId = NewReqId(); - return WhileConfigured(() => body(reqId)).finally(() => CloseOneFeed(reqId)); -} - -/** Reads one event, with the environment supplied so nothing touches a pool. */ -function Step(reqId: number, read: FeedEnvironment, ...between: QueryStage[]) { - return ReadFeedEvent(reqId, Stages(...between), read); -} - describe("a change feed's refusals", () => { it("refuses a stage that needs an order, naming the stage and the position", async () => { const { read } = Reader([{}]); @@ -163,21 +73,6 @@ describe("a change feed's refusals", () => { }); }); - it("keeps the fold's own wording for a stage nothing knows, which is a typo", async () => { - const { read } = Reader([{}]); - await Feed(async (reqId) => { - // @ts-expect-error a stage outside the union, which the feed refuses by naming it - await Step(reqId, read, QueryStage("filtr")).then( - () => expect.fail("no such stage"), - (err: unknown) => { - assert(err instanceof Error, "the feed rejects with an Error"); - expect(err.message).to.contain("Unsupported query stage 'filtr'"); - expect(err.message).to.not.contain("'changes'"); - }, - ); - }); - }); - it("names the first unsupported stage rather than the last", async () => { const { read } = Reader([{}]); await Feed(async (reqId) => { diff --git a/src/test/unit/feeds.untyped.spec.js b/src/test/unit/feeds.untyped.spec.js new file mode 100644 index 0000000..c489240 --- /dev/null +++ b/src/test/unit/feeds.untyped.spec.js @@ -0,0 +1,21 @@ +import assert from "node:assert"; +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { Feed, Reader, Step } from "./feeds-fixture"; + +describe("a change feed's refusals", () => { + it("keeps the fold's own wording for a stage nothing knows, which is a typo", async () => { + const { read } = Reader([{}]); + await Feed(async (reqId) => { + await Step(reqId, read, QueryStage("filtr")).then( + () => expect.fail("no such stage"), + (/** @type {unknown} */ err) => { + assert(err instanceof Error, "the feed rejects with an Error"); + expect(err.message).to.contain("Unsupported query stage 'filtr'"); + expect(err.message).to.not.contain("'changes'"); + }, + ); + }); + }); +}); diff --git a/src/test/unit/fields.spec.ts b/src/test/unit/fields.spec.ts index 58d88a0..e37a8be 100644 --- a/src/test/unit/fields.spec.ts +++ b/src/test/unit/fields.spec.ts @@ -76,21 +76,6 @@ describe("ParseFieldType", () => { /Unsupported field type/, ); }); - - it("rejects a declaration that is neither a string, array nor object", () => { - expect(() => - // @ts-expect-error a null field declaration; ParseFieldType throws Unsupported field type - ParseFieldType(null, "t.f"), - ).to.throw(/Unsupported field type/); - expect(() => - // @ts-expect-error a number as a field declaration; ParseFieldType throws Unsupported field type - ParseFieldType(123, "t.f"), - ).to.throw(/Unsupported field type/); - expect(() => - // @ts-expect-error an undefined field declaration; ParseFieldType throws Unsupported field type - ParseFieldType(undefined, "t.f"), - ).to.throw(/Unsupported field type/); - }); }); describe("ParseTable", () => { diff --git a/src/test/unit/fields.untyped.spec.js b/src/test/unit/fields.untyped.spec.js new file mode 100644 index 0000000..c2d56c1 --- /dev/null +++ b/src/test/unit/fields.untyped.spec.js @@ -0,0 +1,15 @@ +import { expect } from "chai"; + +import { ParseFieldType } from "../../implementations/database/fields"; + +describe("ParseFieldType", () => { + it("rejects a declaration that is neither a string, array nor object", () => { + expect(() => ParseFieldType(null, "t.f")).to.throw( + /Unsupported field type/, + ); + expect(() => ParseFieldType(123, "t.f")).to.throw(/Unsupported field type/); + expect(() => ParseFieldType(undefined, "t.f")).to.throw( + /Unsupported field type/, + ); + }); +}); diff --git a/src/test/unit/pipeline-fold-fixture.ts b/src/test/unit/pipeline-fold-fixture.ts new file mode 100644 index 0000000..8a016ce --- /dev/null +++ b/src/test/unit/pipeline-fold-fixture.ts @@ -0,0 +1,62 @@ +import type { QueryStage } from "@antelopejs/interface-database/common"; + +import { RefusingCompilers } from "./spec-fixture"; +import { TEXT } from "../../implementations/database/types"; +import type { TableModel } from "../../implementations/database/fields"; +import { DecodingContext } from "../../implementations/database/context"; +import { + type Relation, + TableRelation, +} from "../../implementations/database/relation"; +import { + ApplyStages, + DEFERRED_STAGES, +} from "../../implementations/database/pipeline"; + +const VEHICLES: TableModel = { + fields: { + car: { column: "car", type: TEXT }, + }, +}; + +const TABLE = '"shop"."vehicles"'; +const ROOT_ALIAS = "t0"; + +export const REJECTED_STAGE = "changes"; + +/** + * A deferral installed by the spec rather than read off the map, which no longer carries one. + * + * Every stage the contract records is now dispatched or permanently declined, so the deferred + * branch is reachable only from a map this spec writes to — the same door the precedence case + * beside it already uses. + */ +export const DEFERRED_STAGE = "someStageThisBackendHasNotBuilt"; +export const DEFERRAL = + "The PostgreSQL backend does not implement something yet"; + +export function WithDeferral(name: string, read: () => T): T { + DEFERRED_STAGES[name] = DEFERRAL; + try { + return read(); + } finally { + delete DEFERRED_STAGES[name]; + } +} + +export function NewContext(): DecodingContext { + return new DecodingContext(RefusingCompilers()); +} + +export function NewTable(): Relation { + return TableRelation(TABLE, ROOT_ALIAS, { + schemaId: "shop", + tableId: "vehicles", + model: VEHICLES, + index: (name) => [name], + }); +} + +export function Apply(...stages: QueryStage[]): Relation { + return ApplyStages(NewTable(), stages, NewContext()); +} diff --git a/src/test/unit/pipeline-group.spec.ts b/src/test/unit/pipeline-group.spec.ts index 036dfeb..4cebc8e 100644 --- a/src/test/unit/pipeline-group.spec.ts +++ b/src/test/unit/pipeline-group.spec.ts @@ -13,7 +13,6 @@ import { BOOL } from "../../implementations/database/types"; import { Render } from "../../implementations/database/render"; import { type Applied, - ApplyRaw, ApplySubqueries, ReadParamLedger, Root, @@ -112,13 +111,6 @@ describe("the group stage", () => { expect(relation.single).to.equal(false); }); - it("names itself when the stage carries no index to group on", () => { - // @ts-expect-error no index or field, which the group stage refuses by naming itself - expect(() => ApplyRaw([QueryStage("group", {})])).to.throw( - "The 'group' stage is missing the index or field to group on", - ); - }); - it("binds no parameter for a mapper that reads the group alone", () => { expect(GroupedBy("age").context.params.all()).to.deep.equal([]); }); diff --git a/src/test/unit/pipeline-group.untyped.spec.js b/src/test/unit/pipeline-group.untyped.spec.js new file mode 100644 index 0000000..046c2bb --- /dev/null +++ b/src/test/unit/pipeline-group.untyped.spec.js @@ -0,0 +1,12 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { ApplyRaw } from "./pipeline-fixture"; + +describe("the group stage", () => { + it("names itself when the stage carries no index to group on", () => { + expect(() => ApplyRaw([QueryStage("group", {})])).to.throw( + "The 'group' stage is missing the index or field to group on", + ); + }); +}); diff --git a/src/test/unit/pipeline-lambda-ids.spec.ts b/src/test/unit/pipeline-lambda-ids.untyped.spec.js similarity index 58% rename from src/test/unit/pipeline-lambda-ids.spec.ts rename to src/test/unit/pipeline-lambda-ids.untyped.spec.js index 0dbca89..64dd39a 100644 --- a/src/test/unit/pipeline-lambda-ids.spec.ts +++ b/src/test/unit/pipeline-lambda-ids.untyped.spec.js @@ -19,44 +19,38 @@ const FILTER_ARGUMENT_TAIL = const MAP_CONSTANT = 'SELECT ($1::double precision) AS "value" FROM "directory"."people" AS "t0"'; -function Compile(...stages: QueryStage[]): string { - return Render(ApplyRaw(stages).relation); -} - describe("lambda parameter ids that are neither numbers nor texts", () => { for (const { label, id } of ODD_IDS) { it(`compiles a filter whose only id is ${label} and whose body is a constant`, () => { - const sql = Compile( - QueryStage( - "filter", - undefined, - // @ts-expect-error a parameter id that is not a number, which the filter compiles with its constant body - QueryStage("func", undefined, [id], true), - ), + const filter = QueryStage( + "filter", + undefined, + QueryStage("func", undefined, [id], true), ); + const sql = Render(ApplyRaw([filter]).relation); expect(sql.endsWith(FILTER_CONSTANT_TAIL)).to.equal(true); }); it(`compiles a filter whose body reads the ${label} id back`, () => { - const sql = Compile( - QueryStage( - "filter", - undefined, - // @ts-expect-error a parameter id that is not a number, on the func and its arg, which the filter compiles by reading the id back - QueryStage("func", undefined, [id], QueryStage("arg", undefined, id)), - ), + const filter = QueryStage( + "filter", + undefined, + QueryStage("func", undefined, [id], QueryStage("arg", undefined, id)), ); + const sql = Render(ApplyRaw([filter]).relation); expect(sql.endsWith(FILTER_ARGUMENT_TAIL)).to.equal(true); }); } it("compiles a map whose id is an empty object", () => { - const sql = Compile( - // @ts-expect-error an empty object as the parameter id, which the map compiles with its constant body - QueryStage("map", undefined, QueryStage("func", undefined, [{}], 5)), + const map = QueryStage( + "map", + undefined, + QueryStage("func", undefined, [{}], 5), ); + const sql = Render(ApplyRaw([map]).relation); expect(sql).to.equal(MAP_CONSTANT); }); diff --git a/src/test/unit/pipeline-projection.spec.ts b/src/test/unit/pipeline-projection.spec.ts index 12fd1bb..b202a94 100644 --- a/src/test/unit/pipeline-projection.spec.ts +++ b/src/test/unit/pipeline-projection.spec.ts @@ -1,11 +1,9 @@ import { expect } from "chai"; import { ValueProxy } from "@antelopejs/interface-database"; -import { QueryStage } from "@antelopejs/interface-database/common"; import { Render } from "../../implementations/database/render"; import { Apply, - ApplyRaw, CallerRoot, DOCUMENT, FROM_TABLE, @@ -225,13 +223,6 @@ describe("the pluck stage", () => { Apply(Root().pluck("name", "age")).relation.projection?.type, ).to.deep.equal({ kind: "json", keys: { name: TEXT, age: FLOAT } }); }); - - it("rejects a field list that is not a list of names", () => { - // @ts-expect-error a field list of numbers, which the pluck stage refuses by naming itself - expect(() => ApplyRaw([QueryStage("pluck", undefined, [1])])).to.throw( - "Stage 'pluck' requires a list of field names", - ); - }); }); describe("the without stage", () => { @@ -286,11 +277,4 @@ describe("the without stage", () => { .projection?.type; expect(type).to.deep.equal({ kind: "json", keys: { name: TEXT } }); }); - - it("rejects a field list that is not a list of names", () => { - // @ts-expect-error a field list of numbers, which the without stage refuses by naming itself - expect(() => ApplyRaw([QueryStage("without", undefined, [2])])).to.throw( - "Stage 'without' requires a list of field names", - ); - }); }); diff --git a/src/test/unit/pipeline-projection.untyped.spec.js b/src/test/unit/pipeline-projection.untyped.spec.js new file mode 100644 index 0000000..dc16df1 --- /dev/null +++ b/src/test/unit/pipeline-projection.untyped.spec.js @@ -0,0 +1,20 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { ApplyRaw } from "./pipeline-fixture"; + +describe("the pluck stage", () => { + it("rejects a field list that is not a list of names", () => { + expect(() => ApplyRaw([QueryStage("pluck", undefined, [1])])).to.throw( + "Stage 'pluck' requires a list of field names", + ); + }); +}); + +describe("the without stage", () => { + it("rejects a field list that is not a list of names", () => { + expect(() => ApplyRaw([QueryStage("without", undefined, [2])])).to.throw( + "Stage 'without' requires a list of field names", + ); + }); +}); diff --git a/src/test/unit/pipeline-selection.spec.ts b/src/test/unit/pipeline-selection.spec.ts index 89d05a9..ef14bdd 100644 --- a/src/test/unit/pipeline-selection.spec.ts +++ b/src/test/unit/pipeline-selection.spec.ts @@ -66,13 +66,6 @@ describe("the get stage", () => { expect(sql).to.not.contain("jsonb_build_object"); }); - it("requires the key, naming the stage", () => { - // @ts-expect-error no key, which the get stage refuses by naming itself and the position - expect(() => ApplyRaw([QueryStage("get", undefined)])).to.throw( - "Stage 'get' requires an operand at position 0", - ); - }); - it("marks the relation as yielding exactly one row", () => { const { relation } = Apply(Root().get("k")); expect(relation.single).to.equal(true); @@ -121,26 +114,6 @@ describe("the getAll stage", () => { ).to.deep.equal([ACTIVE_KEY]); }); - it("reads a null key against a boolean column as no answer, not as false", () => { - const { relation, context } = ApplyRaw([ - // @ts-expect-error a null key, which getAll reads against a boolean column as no answer - QueryStage("getAll", { index: "isActive" }, null), - ]); - expect(relation.where).to.deep.equal([ - `("t0"."isActive" IN ((CASE WHEN jsonb_typeof('null'::jsonb) = 'boolean' THEN (('null'::jsonb #>> '{}')::boolean) END)))`, - ]); - expect(context.params.all()).to.deep.equal([]); - }); - - it("reads a document key against a boolean column as no answer, not as true", () => { - const { relation } = ApplyRaw([ - // @ts-expect-error a document key, which getAll reads against a boolean column as no answer - QueryStage("getAll", { index: "isActive" }, { a: 1 }), - ]); - expect(relation.where[0]).to.contain("jsonb_typeof"); - expect(relation.where[0]).to.not.contain("<> ALL"); - }); - it("reads a key as the column's type rather than casting it", () => { expect(Apply(Root().getAll("3000", "age")).relation.where).to.deep.equal([ NUMERIC_TEXT_KEY, @@ -177,21 +150,6 @@ describe("the getAll stage", () => { "The 'byNameAge' index takes a key of 2 values, received 1 values", ); }); - - it("names the index and the position of a hole inside a compound key", () => { - expect(() => - ApplyRaw([ - QueryStage( - "getAll", - { index: COMPOUND_INDEX }, - // @ts-expect-error a hole in a compound key, which the index refuses by naming the position - [["Alice", undefined]], - ), - ]), - ).to.throw( - "The 'byNameAge' index takes a value for every field, and has none at position 1", - ); - }); }); describe("the getAll stage", () => { @@ -354,24 +312,6 @@ describe("the between stage", () => { ); }); - it("requires both bounds, naming the stage and the missing one", () => { - expect(() => - // @ts-expect-error one bound, which the between stage refuses by naming itself and the position - ApplyRaw([QueryStage("between", { index: "age" }, 0)]), - ).to.throw("Stage 'between' requires an operand at position 1"); - // @ts-expect-error no bound, which the between stage refuses by naming itself and the position - expect(() => ApplyRaw([QueryStage("between", { index: "age" })])).to.throw( - "Stage 'between' requires an operand at position 0", - ); - }); - - it("requires the field to range over", () => { - expect(() => - // @ts-expect-error no field, which the between stage refuses by naming itself - ApplyRaw([QueryStage("between", { index: undefined }, 0, 10)]), - ).to.throw("The 'between' stage is missing its field name"); - }); - it("reads a text bound as the column's type rather than casting it", () => { expect( ApplyRaw([QueryStage("between", { index: "age" }, "0", "10")]).relation diff --git a/src/test/unit/pipeline-selection.untyped.spec.js b/src/test/unit/pipeline-selection.untyped.spec.js new file mode 100644 index 0000000..0d895f2 --- /dev/null +++ b/src/test/unit/pipeline-selection.untyped.spec.js @@ -0,0 +1,61 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { ApplyRaw } from "./pipeline-fixture"; + +const COMPOUND_INDEX = "byNameAge"; + +describe("the get stage", () => { + it("requires the key, naming the stage", () => { + expect(() => ApplyRaw([QueryStage("get", undefined)])).to.throw( + "Stage 'get' requires an operand at position 0", + ); + }); +}); + +describe("the getAll stage", () => { + it("reads a null key against a boolean column as no answer, not as false", () => { + const { relation, context } = ApplyRaw([ + QueryStage("getAll", { index: "isActive" }, null), + ]); + expect(relation.where).to.deep.equal([ + `("t0"."isActive" IN ((CASE WHEN jsonb_typeof('null'::jsonb) = 'boolean' THEN (('null'::jsonb #>> '{}')::boolean) END)))`, + ]); + expect(context.params.all()).to.deep.equal([]); + }); + + it("reads a document key against a boolean column as no answer, not as true", () => { + const { relation } = ApplyRaw([ + QueryStage("getAll", { index: "isActive" }, { a: 1 }), + ]); + expect(relation.where[0]).to.contain("jsonb_typeof"); + expect(relation.where[0]).to.not.contain("<> ALL"); + }); + + it("names the index and the position of a hole inside a compound key", () => { + expect(() => + ApplyRaw([ + QueryStage("getAll", { index: COMPOUND_INDEX }, [["Alice", undefined]]), + ]), + ).to.throw( + "The 'byNameAge' index takes a value for every field, and has none at position 1", + ); + }); +}); + +describe("the between stage", () => { + it("requires both bounds, naming the stage and the missing one", () => { + expect(() => + ApplyRaw([QueryStage("between", { index: "age" }, 0)]), + ).to.throw("Stage 'between' requires an operand at position 1"); + expect(() => ApplyRaw([QueryStage("between", { index: "age" })])).to.throw( + "Stage 'between' requires an operand at position 0", + ); + }); + + it("requires the field to range over", () => { + expect(() => + ApplyRaw([QueryStage("between", { index: undefined }, 0, 10)]), + ).to.throw("The 'between' stage is missing its field name"); + }); +}); diff --git a/src/test/unit/pipeline.spec.ts b/src/test/unit/pipeline.spec.ts index 84a1483..3ed024d 100644 --- a/src/test/unit/pipeline.spec.ts +++ b/src/test/unit/pipeline.spec.ts @@ -1,66 +1,18 @@ import { expect } from "chai"; import { QueryStage } from "@antelopejs/interface-database/common"; -import { RefusingCompilers } from "./spec-fixture"; -import { TEXT } from "../../implementations/database/types"; -import type { TableModel } from "../../implementations/database/fields"; -import { DecodingContext } from "../../implementations/database/context"; -import { - type Relation, - TableRelation, -} from "../../implementations/database/relation"; import { ApplyStages, DEFERRED_STAGES, REJECTED_STAGES, } from "../../implementations/database/pipeline"; - -const VEHICLES: TableModel = { - fields: { - car: { column: "car", type: TEXT }, - }, -}; - -const TABLE = '"shop"."vehicles"'; -const ROOT_ALIAS = "t0"; -const INHERITED_STAGE = "constructor"; -const REJECTED_STAGE = "changes"; - -/** - * A deferral installed by the spec rather than read off the map, which no longer carries one. - * - * Every stage the contract records is now dispatched or permanently declined, so the deferred - * branch is reachable only from a map this spec writes to — the same door the precedence case - * beside it already uses. - */ -const DEFERRED_STAGE = "someStageThisBackendHasNotBuilt"; -const DEFERRAL = "The PostgreSQL backend does not implement something yet"; - -function WithDeferral(name: string, read: () => T): T { - DEFERRED_STAGES[name] = DEFERRAL; - try { - return read(); - } finally { - delete DEFERRED_STAGES[name]; - } -} - -function NewContext(): DecodingContext { - return new DecodingContext(RefusingCompilers()); -} - -function NewTable(): Relation { - return TableRelation(TABLE, ROOT_ALIAS, { - schemaId: "shop", - tableId: "vehicles", - model: VEHICLES, - index: (name) => [name], - }); -} - -function Apply(...stages: QueryStage[]): Relation { - return ApplyStages(NewTable(), stages, NewContext()); -} +import { + Apply, + NewContext, + NewTable, + REJECTED_STAGE, + WithDeferral, +} from "./pipeline-fold-fixture"; describe("ApplyStages", () => { it("folds nothing over an empty stage list", () => { @@ -68,22 +20,6 @@ describe("ApplyStages", () => { expect(ApplyStages(relation, [], NewContext())).to.equal(relation); }); - it("declines a stage named after an inherited member", () => { - // @ts-expect-error a stage named after an inherited member, which the fold declines as unsupported - expect(() => Apply(QueryStage(INHERITED_STAGE))).to.throw( - `Unsupported query stage '${INHERITED_STAGE}'`, - ); - }); - - it("names the stage a deferred message belongs to", () => { - WithDeferral(DEFERRED_STAGE, () => { - // @ts-expect-error a stage outside the union, which the fold refuses with its deferral - expect(() => Apply(QueryStage(DEFERRED_STAGE))).to.throw( - `${DEFERRAL} (stage '${DEFERRED_STAGE}')`, - ); - }); - }); - it("defers nothing, now that every stage is dispatched or declined", () => { expect(Object.keys(DEFERRED_STAGES)).to.deep.equal([]); }); @@ -101,11 +37,4 @@ describe("ApplyStages", () => { ); }); }); - - it("fails on the first stage it cannot apply", () => { - expect(() => - // @ts-expect-error a stage outside the union after a change feed, which the fold never reaches because it refuses the feed first - Apply(QueryStage(REJECTED_STAGE), QueryStage(DEFERRED_STAGE)), - ).to.throw(REJECTED_STAGES[REJECTED_STAGE]); - }); }); diff --git a/src/test/unit/pipeline.untyped.spec.js b/src/test/unit/pipeline.untyped.spec.js new file mode 100644 index 0000000..afd7de2 --- /dev/null +++ b/src/test/unit/pipeline.untyped.spec.js @@ -0,0 +1,35 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { REJECTED_STAGES } from "../../implementations/database/pipeline"; +import { + Apply, + DEFERRAL, + DEFERRED_STAGE, + REJECTED_STAGE, + WithDeferral, +} from "./pipeline-fold-fixture"; + +const INHERITED_STAGE = "constructor"; + +describe("ApplyStages", () => { + it("declines a stage named after an inherited member", () => { + expect(() => Apply(QueryStage(INHERITED_STAGE))).to.throw( + `Unsupported query stage '${INHERITED_STAGE}'`, + ); + }); + + it("names the stage a deferred message belongs to", () => { + WithDeferral(DEFERRED_STAGE, () => { + expect(() => Apply(QueryStage(DEFERRED_STAGE))).to.throw( + `${DEFERRAL} (stage '${DEFERRED_STAGE}')`, + ); + }); + }); + + it("fails on the first stage it cannot apply", () => { + expect(() => + Apply(QueryStage(REJECTED_STAGE), QueryStage(DEFERRED_STAGE)), + ).to.throw(REJECTED_STAGES[REJECTED_STAGE]); + }); +}); diff --git a/src/test/unit/selection-fixture.ts b/src/test/unit/selection-fixture.ts new file mode 100644 index 0000000..f454948 --- /dev/null +++ b/src/test/unit/selection-fixture.ts @@ -0,0 +1,70 @@ +import type { CROSS_INSTANCE } from "@antelopejs/interface-database/schema"; +import { SchemaInstance } from "@antelopejs/interface-database"; +import { + QueryStage, + type StagedObject, +} from "@antelopejs/interface-database/common"; + +import { RefusingCompilers, WithOptions } from "./spec-fixture"; +import { FLOAT, TEXT } from "../../implementations/database/types"; +import type { TableModel } from "../../implementations/database/fields"; +import { DecodingContext } from "../../implementations/database/context"; +import type { TableOrigin } from "../../implementations/database/relation"; +import { + BuildRoot, + type RootSelection, +} from "../../implementations/database/selection"; + +interface Vehicle { + car: string; + price: number; +} + +interface Shop { + vehicles: Vehicle; +} + +export const SCHEMA_ID = "shop"; +export const TABLE_ID = "vehicles"; + +const VEHICLES: TableModel = { + fields: { + car: { column: "car", type: TEXT }, + price: { column: "price", type: FLOAT }, + }, +}; + +const INDEXES = new Map([["byCar", ["car", "price"]]]); + +type InstanceId = string | typeof CROSS_INSTANCE | undefined; + +function StubOrigin(schemaId: string, tableId: string): TableOrigin { + return { + schemaId, + tableId, + model: VEHICLES, + index: (name) => INDEXES.get(name) ?? [name], + }; +} + +export function NewContext(): DecodingContext { + return new DecodingContext(RefusingCompilers(), StubOrigin); +} + +export function Root(schemaId = SCHEMA_ID, instanceId?: InstanceId) { + const schema = new SchemaInstance( + QueryStage("schema", { id: schemaId }), + ); + const instance = new SchemaInstance( + QueryStage("instance", { id: instanceId }), + schema, + ); + return instance.table(TABLE_ID); +} + +export function Build( + query: StagedObject, + context: DecodingContext, +): RootSelection { + return WithOptions({}, () => BuildRoot(query.build(), context)); +} diff --git a/src/test/unit/selection.spec.ts b/src/test/unit/selection.spec.ts index 1beb52e..122e730 100644 --- a/src/test/unit/selection.spec.ts +++ b/src/test/unit/selection.spec.ts @@ -1,77 +1,29 @@ import { expect } from "chai"; import { CROSS_INSTANCE } from "@antelopejs/interface-database/schema"; -import { SchemaInstance, ValueProxy } from "@antelopejs/interface-database"; +import { ValueProxy } from "@antelopejs/interface-database"; import { QueryStage, StagedObject, } from "@antelopejs/interface-database/common"; -import { RefusingCompilers, WithOptions } from "./spec-fixture"; -import { FLOAT, TEXT } from "../../implementations/database/types"; -import type { TableModel } from "../../implementations/database/fields"; -import { DecodingContext } from "../../implementations/database/context"; -import type { TableOrigin } from "../../implementations/database/relation"; +import { WithOptions } from "./spec-fixture"; import { BuildRoot, CollectSchemaIds, RegisteredOrigin, - type RootSelection, } from "../../implementations/database/selection"; +import { + Build, + NewContext, + Root, + SCHEMA_ID, + TABLE_ID, +} from "./selection-fixture"; -interface Vehicle { - car: string; - price: number; -} - -interface Shop { - vehicles: Vehicle; -} - -const SCHEMA_ID = "shop"; const OTHER_SCHEMA_ID = "warehouse"; -const TABLE_ID = "vehicles"; const LAMBDA_ID_FLOOR = 0; const ROW_ID = LAMBDA_ID_FLOOR - 1; -const VEHICLES: TableModel = { - fields: { - car: { column: "car", type: TEXT }, - price: { column: "price", type: FLOAT }, - }, -}; - -const INDEXES = new Map([["byCar", ["car", "price"]]]); - -type InstanceId = string | typeof CROSS_INSTANCE | undefined; - -function StubOrigin(schemaId: string, tableId: string): TableOrigin { - return { - schemaId, - tableId, - model: VEHICLES, - index: (name) => INDEXES.get(name) ?? [name], - }; -} - -function NewContext(): DecodingContext { - return new DecodingContext(RefusingCompilers(), StubOrigin); -} - -function Root(schemaId = SCHEMA_ID, instanceId?: InstanceId) { - const schema = new SchemaInstance( - QueryStage("schema", { id: schemaId }), - ); - const instance = new SchemaInstance( - QueryStage("instance", { id: instanceId }), - schema, - ); - return instance.table(TABLE_ID); -} - -function Build(query: StagedObject, context: DecodingContext): RootSelection { - return WithOptions({}, () => BuildRoot(query.build(), context)); -} - type TableQuery = ReturnType; type CyclicPayload = { @@ -128,14 +80,6 @@ describe("BuildRoot", () => { expect(context.params.all()).to.deep.equal([]); }); - it("rejects an instance id that is neither a string nor the sentinel", () => { - // @ts-expect-error the number 7 as an instance id; building the query refuses it, naming the type received - const query = Root(SCHEMA_ID, 7); - expect(() => Build(query, NewContext())).to.throw( - "An instance id must be a string or CROSS_INSTANCE, received number", - ); - }); - it("starts in row mode addressing the origin's own columns", () => { const { relation } = Build(Root(), NewContext()); expect(relation.projection).to.equal(undefined); @@ -163,15 +107,6 @@ describe("BuildRoot", () => { WithOptions({}, () => BuildRoot(stages, NewContext())), ).to.throw("stage 0 is 'instance'"); }); - - it("rejects a prefix stage carrying no id", () => { - const stages = Root().build(); - // @ts-expect-error no id, which BuildRoot refuses on the schema stage - stages[0] = QueryStage("schema"); - expect(() => - WithOptions({}, () => BuildRoot(stages, NewContext())), - ).to.throw("The 'schema' stage of a table query is missing its id"); - }); }); describe("RegisteredOrigin", () => { diff --git a/src/test/unit/selection.untyped.spec.js b/src/test/unit/selection.untyped.spec.js new file mode 100644 index 0000000..5ad7949 --- /dev/null +++ b/src/test/unit/selection.untyped.spec.js @@ -0,0 +1,23 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { WithOptions } from "./spec-fixture"; +import { BuildRoot } from "../../implementations/database/selection"; +import { Build, NewContext, Root, SCHEMA_ID } from "./selection-fixture"; + +describe("BuildRoot", () => { + it("rejects an instance id that is neither a string nor the sentinel", () => { + const query = Root(SCHEMA_ID, 7); + expect(() => Build(query, NewContext())).to.throw( + "An instance id must be a string or CROSS_INSTANCE, received number", + ); + }); + + it("rejects a prefix stage carrying no id", () => { + const stages = Root().build(); + stages[0] = QueryStage("schema"); + expect(() => + WithOptions({}, () => BuildRoot(stages, NewContext())), + ).to.throw("The 'schema' stage of a table query is missing its id"); + }); +}); diff --git a/src/test/unit/utils.spec.ts b/src/test/unit/utils.spec.ts index 8f96996..83a0034 100644 --- a/src/test/unit/utils.spec.ts +++ b/src/test/unit/utils.spec.ts @@ -1,26 +1,9 @@ import { expect } from "chai"; import { QueryStage } from "@antelopejs/interface-database/common"; -import { CROSS_INSTANCE } from "@antelopejs/interface-database/schema"; import { NormalizeInstanceId } from "../../implementations/database/utils"; describe("NormalizeInstanceId", () => { - it("maps an absent id to the default instance", () => { - expect( - NormalizeInstanceId( - "createInstance", - QueryStage("createInstance", { id: undefined }), - ), - ).to.equal(""); - expect( - NormalizeInstanceId( - "createInstance", - // @ts-expect-error a null id, which NormalizeInstanceId maps to the default instance - QueryStage("createInstance", { id: null }), - ), - ).to.equal(""); - }); - it("passes a named id through", () => { expect( NormalizeInstanceId( @@ -29,25 +12,4 @@ describe("NormalizeInstanceId", () => { ), ).to.equal("alpha"); }); - - it("rejects CROSS_INSTANCE, naming the operation", () => { - // @ts-expect-error CROSS_INSTANCE as the id, which NormalizeInstanceId refuses by naming the operation - const stage = QueryStage("destroyInstance", { id: CROSS_INSTANCE }); - expect(() => NormalizeInstanceId("destroyInstance", stage)).to.throw( - /destroyInstance/, - ); - expect(() => NormalizeInstanceId("destroyInstance", stage)).to.throw( - /CROSS_INSTANCE/, - ); - }); - - it("rejects a non-string id", () => { - expect(() => - NormalizeInstanceId( - "createInstance", - // @ts-expect-error a number id, which NormalizeInstanceId refuses by naming its type - QueryStage("createInstance", { id: 7 }), - ), - ).to.throw(/number/); - }); }); diff --git a/src/test/unit/utils.untyped.spec.js b/src/test/unit/utils.untyped.spec.js new file mode 100644 index 0000000..607bd7d --- /dev/null +++ b/src/test/unit/utils.untyped.spec.js @@ -0,0 +1,41 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; +import { CROSS_INSTANCE } from "@antelopejs/interface-database/schema"; + +import { NormalizeInstanceId } from "../../implementations/database/utils"; + +describe("NormalizeInstanceId", () => { + it("maps an absent id to the default instance", () => { + expect( + NormalizeInstanceId( + "createInstance", + QueryStage("createInstance", { id: undefined }), + ), + ).to.equal(""); + expect( + NormalizeInstanceId( + "createInstance", + QueryStage("createInstance", { id: null }), + ), + ).to.equal(""); + }); + + it("rejects CROSS_INSTANCE, naming the operation", () => { + const stage = QueryStage("destroyInstance", { id: CROSS_INSTANCE }); + expect(() => NormalizeInstanceId("destroyInstance", stage)).to.throw( + /destroyInstance/, + ); + expect(() => NormalizeInstanceId("destroyInstance", stage)).to.throw( + /CROSS_INSTANCE/, + ); + }); + + it("rejects a non-string id", () => { + expect(() => + NormalizeInstanceId( + "createInstance", + QueryStage("createInstance", { id: 7 }), + ), + ).to.throw(/number/); + }); +}); diff --git a/src/test/unit/value.spec.ts b/src/test/unit/value.spec.ts index 3238ef4..59ff534 100644 --- a/src/test/unit/value.spec.ts +++ b/src/test/unit/value.spec.ts @@ -21,7 +21,6 @@ import { DecodeFunction, DecodeValue, IsRecordedFunction, - RecordedLambda, type RecordedFunction, WithBoundArguments, } from "../../implementations/database/value"; @@ -284,16 +283,6 @@ describe("DecodeFunction", () => { }); describe("RecordedLambda", () => { - it("accepts the text parameter ids of a func rebuilt from JSON", () => { - const stage = QueryStage( - "filter", - undefined, - // @ts-expect-error a text parameter id, which RecordedLambda accepts and hands back unchanged - QueryStage("func", undefined, ["a"], true), - ); - expect(RecordedLambda(stage, 0).args[0]).to.deep.equal(["a"]); - }); - it("does not take text parameter ids for a lambda where a document is allowed", () => { expect(IsRecordedFunction({ stage: "func", args: [["a"], true] })).to.equal( false, diff --git a/src/test/unit/value.untyped.spec.js b/src/test/unit/value.untyped.spec.js new file mode 100644 index 0000000..2bf677b --- /dev/null +++ b/src/test/unit/value.untyped.spec.js @@ -0,0 +1,15 @@ +import { expect } from "chai"; +import { QueryStage } from "@antelopejs/interface-database/common"; + +import { RecordedLambda } from "../../implementations/database/value"; + +describe("RecordedLambda", () => { + it("accepts the text parameter ids of a func rebuilt from JSON", () => { + const stage = QueryStage( + "filter", + undefined, + QueryStage("func", undefined, ["a"], true), + ); + expect(RecordedLambda(stage, 0).args[0]).to.deep.equal(["a"]); + }); +}); diff --git a/src/test/unit/writes-insert.spec.ts b/src/test/unit/writes-insert.spec.ts index 986ec6a..ab743e4 100644 --- a/src/test/unit/writes-insert.spec.ts +++ b/src/test/unit/writes-insert.spec.ts @@ -166,18 +166,6 @@ describe("the insert statement's conflict modes", () => { ); expect(Sql(written)).to.not.contain("COALESCE"); }); - - it("refuses a conflict mode it does not know, naming the ones it does", () => { - expect(() => - Insert( - { name: "a" }, - // @ts-expect-error the unknown conflict mode "ignore"; insert refuses it, naming update, replace and the mode received - { conflict: "ignore" }, - ), - ).to.throw( - "The 'insert' stage takes a conflict mode of update or replace, received \"ignore\"", - ); - }); }); describe("the insert statement's heterogeneous batch", () => { @@ -324,24 +312,6 @@ describe("the ids an insert answers", () => { expect(written.statement.ids).to.deep.equal([]); expect(written.statement.sql).to.equal(""); }); - - it("refuses an argument that is not a document", () => { - expect(() => - // @ts-expect-error a string document; insert refuses it, naming the stage, the position and the kind received - Insert("a"), - ).to.throw( - "The 'insert' stage takes documents, received text at position 0", - ); - }); - - it("refuses a nested array rather than storing its indices as keys", () => { - expect(() => - // @ts-expect-error an array as a batch entry; insert refuses it, naming the stage, the position and the kind received - Insert([[]]), - ).to.throw( - "The 'insert' stage takes documents, received list at position 0", - ); - }); }); describe("insert under CROSS_INSTANCE", () => { diff --git a/src/test/unit/writes-insert.untyped.spec.js b/src/test/unit/writes-insert.untyped.spec.js new file mode 100644 index 0000000..d03f01d --- /dev/null +++ b/src/test/unit/writes-insert.untyped.spec.js @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { CallerRoot, Write } from "./pipeline-fixture"; + +describe("the insert statement's conflict modes", () => { + it("refuses a conflict mode it does not know, naming the ones it does", () => { + expect(() => + Write(CallerRoot().insert({ name: "a" }, { conflict: "ignore" })), + ).to.throw( + "The 'insert' stage takes a conflict mode of update or replace, received \"ignore\"", + ); + }); +}); + +describe("the ids an insert answers", () => { + it("refuses an argument that is not a document", () => { + expect(() => Write(CallerRoot().insert("a"))).to.throw( + "The 'insert' stage takes documents, received text at position 0", + ); + }); + + it("refuses a nested array rather than storing its indices as keys", () => { + expect(() => Write(CallerRoot().insert([[]]))).to.throw( + "The 'insert' stage takes documents, received list at position 0", + ); + }); +}); diff --git a/src/test/unit/writes-replace.spec.ts b/src/test/unit/writes-replace.spec.ts index ccec1bf..dba5628 100644 --- a/src/test/unit/writes-replace.spec.ts +++ b/src/test/unit/writes-replace.spec.ts @@ -175,13 +175,6 @@ describe("the replace statement's refusals", () => { "Payload key '_extra' is a column this adapter owns and no payload may write it", ); }); - - it("refuses a payload that is not a document, naming the stage", () => { - expect(() => - // @ts-expect-error a string payload; replace refuses it, naming the stage and the kind received - Replace(NAME), - ).to.throw("The 'replace' stage takes a document, received text"); - }); }); describe("the replace statement's parameter ledger", () => { diff --git a/src/test/unit/writes-replace.untyped.spec.js b/src/test/unit/writes-replace.untyped.spec.js new file mode 100644 index 0000000..cc9dcdc --- /dev/null +++ b/src/test/unit/writes-replace.untyped.spec.js @@ -0,0 +1,14 @@ +import { expect } from "chai"; + +import { CallerRoot, Write } from "./pipeline-fixture"; + +const KEY = "k"; +const NAME = "a"; + +describe("the replace statement's refusals", () => { + it("refuses a payload that is not a document, naming the stage", () => { + expect(() => Write(CallerRoot().get(KEY).replace(NAME))).to.throw( + "The 'replace' stage takes a document, received text", + ); + }); +}); diff --git a/src/test/unit/writes-update.spec.ts b/src/test/unit/writes-update.spec.ts index 80d8403..0a6a8b2 100644 --- a/src/test/unit/writes-update.spec.ts +++ b/src/test/unit/writes-update.spec.ts @@ -102,20 +102,6 @@ describe("the update statement", () => { const written = Write(Root().update({ age: AGE })); expect(Sql(written)).to.equal(Changes('"age" = ($2::double precision)')); }); - - it("refuses a payload that is not a document, naming the stage", () => { - expect(() => - // @ts-expect-error a string payload; update refuses it, naming the stage and the kind received - Update("a"), - ).to.throw("The 'update' stage takes a document, received text"); - }); - - it("refuses an array rather than writing its indices as keys", () => { - expect(() => - // @ts-expect-error an array payload; update refuses it, naming the stage and the kind received - Update([]), - ).to.throw("The 'update' stage takes a document, received list"); - }); }); describe("the update statement's overflow column", () => { diff --git a/src/test/unit/writes-update.untyped.spec.js b/src/test/unit/writes-update.untyped.spec.js new file mode 100644 index 0000000..845cd7d --- /dev/null +++ b/src/test/unit/writes-update.untyped.spec.js @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Update } from "./writes-update-fixture"; + +describe("the update statement", () => { + it("refuses a payload that is not a document, naming the stage", () => { + expect(() => Update("a")).to.throw( + "The 'update' stage takes a document, received text", + ); + }); + + it("refuses an array rather than writing its indices as keys", () => { + expect(() => Update([])).to.throw( + "The 'update' stage takes a document, received list", + ); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index a983cc5..1497f02 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "target": "esnext", "module": "commonjs", "lib": ["ES2022"], - "allowJs": false, + "allowJs": true, "outDir": "dist", "rootDir": "src", "strict": true, @@ -20,5 +20,5 @@ "useDefineForClassFields": true, "types": ["chai", "mocha", "node", "pg"] }, - "include": ["src/**/*.ts"] + "include": ["src/**/*.ts", "src/**/*.js"] }