foldkit-entity 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +147 -5
  2. package/dist/collation.d.ts +33 -2
  3. package/dist/collation.d.ts.map +1 -0
  4. package/dist/conformance/index.d.ts +4 -4
  5. package/dist/conformance/index.d.ts.map +1 -1
  6. package/dist/conformance/index.js +5 -7
  7. package/dist/conformance/index.js.map +1 -1
  8. package/dist/conformance/operator.d.ts +1 -2
  9. package/dist/conformance/operator.d.ts.map +1 -1
  10. package/dist/conformance/operator.js +2 -6
  11. package/dist/conformance/operator.js.map +1 -1
  12. package/dist/conformance/relational.d.ts +17 -17
  13. package/dist/conformance/relational.d.ts.map +1 -1
  14. package/dist/conformance/relational.js +1 -3
  15. package/dist/conformance/relational.js.map +1 -1
  16. package/dist/conformance/variants.d.ts +47 -0
  17. package/dist/conformance/variants.d.ts.map +1 -0
  18. package/dist/conformance/variants.js +126 -0
  19. package/dist/conformance/variants.js.map +1 -0
  20. package/dist/context.d.ts +60 -2
  21. package/dist/context.d.ts.map +1 -0
  22. package/dist/descriptor.d.ts +33 -0
  23. package/dist/descriptor.d.ts.map +1 -0
  24. package/dist/descriptor.js +137 -0
  25. package/dist/descriptor.js.map +1 -0
  26. package/dist/entity.d.ts +231 -0
  27. package/dist/entity.d.ts.map +1 -0
  28. package/dist/entity.js +436 -0
  29. package/dist/entity.js.map +1 -0
  30. package/dist/evaluate.d.ts +204 -2
  31. package/dist/evaluate.d.ts.map +1 -0
  32. package/dist/evaluate.js +51 -7
  33. package/dist/evaluate.js.map +1 -1
  34. package/dist/expr.d.ts +915 -2
  35. package/dist/expr.d.ts.map +1 -0
  36. package/dist/expr.js +50 -10
  37. package/dist/expr.js.map +1 -1
  38. package/dist/held.d.ts +112 -2
  39. package/dist/held.d.ts.map +1 -0
  40. package/dist/held.js +13 -2
  41. package/dist/held.js.map +1 -1
  42. package/dist/ids.d.ts +8 -0
  43. package/dist/ids.d.ts.map +1 -0
  44. package/dist/ids.js +8 -0
  45. package/dist/ids.js.map +1 -0
  46. package/dist/index.d.ts +400 -6
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +113 -12
  49. package/dist/index.js.map +1 -0
  50. package/dist/invariant.d.ts +123 -2
  51. package/dist/invariant.d.ts.map +1 -0
  52. package/dist/invariant.js +236 -1
  53. package/dist/invariant.js.map +1 -0
  54. package/dist/law.d.ts +264 -2
  55. package/dist/law.d.ts.map +1 -0
  56. package/dist/law.js +1 -1
  57. package/dist/operators.d.ts +170 -2
  58. package/dist/operators.d.ts.map +1 -0
  59. package/dist/operators.js +3 -3
  60. package/dist/readFilter.d.ts +8 -2
  61. package/dist/readFilter.d.ts.map +1 -0
  62. package/dist/sets.d.ts +18 -2
  63. package/dist/sets.d.ts.map +1 -0
  64. package/dist/sets.js +1 -1
  65. package/dist/shape.d.ts +23 -2
  66. package/dist/shape.d.ts.map +1 -0
  67. package/dist/tested.d.ts +8 -2
  68. package/dist/tested.d.ts.map +1 -0
  69. package/dist/text.d.ts +27 -2
  70. package/dist/text.d.ts.map +1 -0
  71. package/dist/text.js +1 -1
  72. package/dist/variants.d.ts +72 -0
  73. package/dist/variants.d.ts.map +1 -0
  74. package/dist/variants.js +76 -0
  75. package/dist/variants.js.map +1 -0
  76. package/dist/words.d.ts +17 -2
  77. package/dist/words.d.ts.map +1 -0
  78. package/dist/write.d.ts +312 -2
  79. package/dist/write.d.ts.map +1 -0
  80. package/dist/write.js +3 -3
  81. package/package.json +3 -3
  82. package/dist/collation-BB4YTIbY.d.ts +0 -34
  83. package/dist/collation-BB4YTIbY.d.ts.map +0 -1
  84. package/dist/index-48JeXG0A.d.ts +0 -2585
  85. package/dist/index-48JeXG0A.d.ts.map +0 -1
  86. package/dist/readFilter-CWMnFRVw.d.ts +0 -9
  87. package/dist/readFilter-CWMnFRVw.d.ts.map +0 -1
  88. package/dist/shape-LAowRf9f.d.ts +0 -23
  89. package/dist/shape-LAowRf9f.d.ts.map +0 -1
  90. package/dist/src-DKhUqLoC.js +0 -731
  91. package/dist/src-DKhUqLoC.js.map +0 -1
  92. package/dist/words-a4e9o-TK.d.ts +0 -18
  93. package/dist/words-a4e9o-TK.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"operator.js","names":[],"sources":["../../src/conformance/operator.ts"],"sourcesContent":["/**\n * An operator held to what it declares (expr-operations-DESIGN §10.4): its\n * laws tested against an implementation, and one set of calls run through\n * every implementation given, their answers and refusals compared.\n *\n * Cases are drawn from a fixed sample of each kind of value (text with the\n * empty string, mixed case, non-ASCII, an astral character and `like`'s\n * wildcards; numbers with zero, negatives and a fraction; both booleans), kept\n * where the operator's input schema and the law's domain decode them, and\n * chosen by a seeded shuffle when there are more than asked for, so a run is\n * repeatable.\n */\nimport { Data, Option, Schema, SchemaAST } from 'effect'\nimport {\n Collation,\n Evidence,\n Expr,\n Law,\n Operators,\n QueryEvaluateError,\n valueOfOperand,\n type LawDescription,\n type MemoryOperators,\n type Operandish,\n type Operator,\n type TestedEvidence,\n} from '../index.js'\nimport { stampRun, stampTested } from '../tested.js'\nimport { tuplesOf } from './tuples.js'\n\ntype AnyOperator = Operator<ReadonlyArray<Schema.Top>, Schema.Top>\n\n/** What an implementation said of one call: a value, or that it refused it. */\nexport type Outcome = Data.TaggedEnum<{\n Value: { readonly value: unknown }\n Refused: { readonly reason: string }\n}>\nexport const Outcome = Data.taggedEnum<Outcome>()\n\n/**\n * What `Conformance.laws` found: every law held, with the evidence; the first\n * case one did not; or a law no case of which both sides answered, which\n * shows nothing of it.\n */\nexport type LawsVerdict = Data.TaggedEnum<{\n Holds: { readonly evidence: ReadonlyArray<TestedEvidence> }\n Unanswered: {\n readonly law: LawDescription\n /** Why the first refused call was refused. */\n readonly reason: string\n }\n Counterexample: {\n readonly law: LawDescription\n readonly args: ReadonlyArray<unknown>\n /** The collation the calls were made under, for an operator that compares text. */\n readonly collation: Option.Option<Collation>\n readonly left: Outcome\n readonly right: Outcome\n }\n}>\nexport const LawsVerdict = Data.taggedEnum<LawsVerdict>()\n\n/**\n * One way to run a call: its value, or a throw for a call it refuses. A call\n * of a predicate answers its truth, unknown as `null`.\n */\nexport type Runner = (call: Operandish) => unknown\n\n/** A call the implementations did not agree on, with what each said. */\nexport interface Disagreement {\n readonly args: ReadonlyArray<unknown>\n readonly collation: Option.Option<Collation>\n readonly outcomes: Readonly<Record<string, Outcome>>\n}\n\nexport interface OperatorReport {\n /** How many calls ran, each through every implementation. */\n readonly cases: number\n readonly disagreements: ReadonlyArray<Disagreement>\n}\n\nconst NUL = String.fromCharCode(0)\n// 'B' sorts before 'a' by code point and after it folded: what tells the collations apart.\n// `%`, `_` and `\\` are what `like` reads as wildcards and its escape.\nconst texts = [\n '',\n 'a',\n 'A',\n 'ab',\n 'aB',\n 'b',\n 'B',\n 'é',\n 'É',\n String.fromCodePoint(0x1f600),\n '%',\n '_',\n '\\\\',\n]\nconst numbers = [-2, -1, 0, 1, 2, 7, 0.5, -0.5, 1e6]\nconst booleans = [true, false]\n\n/** The sample values of a stored kind, before any schema narrows them. */\nconst candidates = (ast: SchemaAST.AST): ReadonlyArray<unknown> => {\n if (SchemaAST.isString(ast) || SchemaAST.isTemplateLiteral(ast)) return texts\n if (SchemaAST.isNumber(ast)) return numbers\n if (SchemaAST.isBoolean(ast)) return booleans\n if (SchemaAST.isLiteral(ast)) return [ast.literal]\n if (SchemaAST.isUnion(ast)) return ast.types.flatMap(candidates)\n return []\n}\n\n/** Whether a stored value is one `schema` stores. */\nconst decodes = (schema: Schema.Top) => (value: unknown) =>\n Schema.is(Schema.toEncoded(schema))(value)\n\n/** The non-null samples every schema of `schemas` decodes, and the domain too when one is given. */\nconst samplesOf = (\n schemas: ReadonlyArray<Schema.Top>,\n domain: Option.Option<Schema.Top>,\n): ReadonlyArray<unknown> =>\n [...new Set(candidates(Schema.toEncoded(schemas[0]!).ast))].filter(\n value =>\n value !== null &&\n schemas.every(schema => decodes(schema)(value)) &&\n Option.match(domain, { onNone: () => true, onSome: within => decodes(within)(value) }),\n )\n\n/** A plain object: what JSON makes, and nothing whose data sits in a prototype. */\nconst isRecord = (value: unknown): value is Readonly<Record<string, unknown>> => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false\n const prototype = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\n/** A plain object's keys holding a value: one holding `undefined` is as absent, as JSON writes it. */\nconst keysOf = (record: Readonly<Record<string, unknown>>): ReadonlyArray<string> =>\n Object.keys(record).filter(key => record[key] !== undefined)\n\n/**\n * Two stored values alike, structurally. Not by their JSON, which writes\n * `Infinity` and `NaN` as `null`: a division by zero answering `Infinity` in\n * memory and null in SQL would read as agreeing. An object that is not plain\n * (its data in a prototype: a Date) is compared by its JSON, a Date's its time.\n */\nconst sameValue = (left: unknown, right: unknown): boolean => {\n if (typeof left === 'number' && typeof right === 'number') {\n return left === right || (Number.isNaN(left) && Number.isNaN(right))\n }\n if (Array.isArray(left) && Array.isArray(right)) {\n return left.length === right.length && left.every((each, i) => sameValue(each, right[i]))\n }\n if (isRecord(left) && isRecord(right)) {\n const keys = keysOf(left)\n return (\n keys.length === keysOf(right).length &&\n keys.every(key => Object.hasOwn(right, key) && sameValue(left[key], right[key]))\n )\n }\n if (typeof left === 'object' && left !== null && typeof right === 'object' && right !== null) {\n return JSON.stringify(left) === JSON.stringify(right)\n }\n return left === right\n}\n\n/** Two outcomes alike: equal values as stored, or both refusals. */\nconst same = (left: Outcome, right: Outcome): boolean =>\n left._tag === 'Refused' || right._tag === 'Refused'\n ? left._tag === right._tag\n : sameValue(left.value, right.value)\n\n/** Text by code point, as every interpreter's `binary` orders it; `<` compares UTF-16 units. */\nconst byCodePoint = (left: string, right: string): number => {\n const [a, b] = [[...left], [...right]]\n for (let i = 0; i < Math.min(a.length, b.length); i++) {\n const sign = a[i]!.codePointAt(0)! - b[i]!.codePointAt(0)!\n if (sign !== 0) return sign\n }\n return a.length - b.length\n}\n\n/** Two values of one kind in order: numbers, booleans, text by code point. */\nconst orderOf = (left: unknown, right: unknown): number =>\n typeof left === 'string' && typeof right === 'string'\n ? byCodePoint(left, right)\n : Number(left) - Number(right)\n\n/** A call of `op`, given `collation` when its rule takes one. */\nconst callOf = (\n op: AnyOperator,\n args: ReadonlyArray<unknown>,\n collation: Option.Option<Collation>,\n): Operandish =>\n Option.match(collation, {\n onNone: () => op(...args),\n onSome: each => op(...args, { collation: each }),\n })\n\n/** One side of an equation: a call to run (its text folded first, for a collation law), or a value. */\ntype Side = { readonly node: Operandish; readonly fold: boolean } | { readonly value: unknown }\n\n/** One equation for one tuple: its two sides, and what makes their outcomes keep the law. */\ninterface Plan {\n readonly args: ReadonlyArray<unknown>\n readonly collation: Option.Option<Collation>\n readonly left: Side\n readonly right: Side\n readonly holds: (left: Outcome, right: Outcome) => boolean\n}\n\n/** Each law `op` declares, with its equations: what `laws` and `lawsBy` evaluate. */\ninterface LawPlans {\n readonly law: LawDescription\n readonly plans: ReadonlyArray<Plan>\n}\n\nconst foldText = (value: unknown): unknown =>\n typeof value === 'string' ? Collation.foldAscii(value) : value\n\nconst nameOf = (op: AnyOperator): string =>\n op.descriptor.version === 1 ? op.descriptor.id : `${op.descriptor.id}@${op.descriptor.version}`\n\n/**\n * The equations of every law `op` declares, over up to `limit` tuples a law\n * chosen by `seed`. Nothing is run: a memory table and an SQL runner\n * evaluate the same plans.\n */\nconst lawPlans = (op: AnyOperator, limit: number, seed: number): ReadonlyArray<LawPlans> => {\n const { descriptor } = op\n const comparesText = (each: AnyOperator) => each.descriptor.collation !== 'none'\n // Each operator is called under a collation only where it compares text.\n const under = (each: AnyOperator, collation: Option.Option<Collation>) =>\n comparesText(each) ? collation : Option.none<Collation>()\n const run = (node: Operandish): Side => ({ node, fold: false })\n const value = (held: unknown): Side => ({ value: held })\n return descriptor.laws.map(law => {\n const shared = samplesOf(descriptor.input, law.domain)\n const tuples = (arity: number) =>\n tuplesOf(\n Array.from({ length: arity }, () => shared),\n limit,\n seed,\n )\n // The kernel compares text only under a collation, and literals bring none. An\n // implementation is told the collation, and may answer differently under each:\n // a pass under each where `op`, or a witness the law calls, compares text.\n const witnesses = Law.$match(law, {\n Inverse: ({ other }) => [other],\n Distributes: ({ over }) => [over],\n Associative: () => [],\n Commutative: () => [],\n Idempotent: () => [],\n Identity: () => [],\n Absorbing: () => [],\n Monotonic: () => [],\n PreservesCollation: () => [],\n })\n const collations = [op, ...witnesses].some(comparesText)\n ? [Option.some(Collation.binary), Option.some(Collation.asciiFold)]\n : [Option.none<Collation>()]\n const plans = collations.flatMap((collation): ReadonlyArray<Plan> => {\n const call = (...args: ReadonlyArray<unknown>) => callOf(op, args, under(op, collation))\n // A witness operator is called as `op` is: under the collation when it compares text.\n const witness = (other: AnyOperator, ...args: ReadonlyArray<unknown>) =>\n callOf(other, args, under(other, collation))\n const equal = (args: ReadonlyArray<unknown>, left: Side, right: Side): Plan => ({\n args,\n collation,\n left,\n right,\n holds: same,\n })\n const sided = (\n witness: unknown,\n side: 'left' | 'right' | 'both',\n answer: (a: unknown) => unknown,\n ) =>\n tuples(1).flatMap(([a]) => [\n ...(side === 'right'\n ? []\n : [equal([witness, a], run(call(witness, a)), value(answer(a)))]),\n ...(side === 'left'\n ? []\n : [equal([a, witness], run(call(a, witness)), value(answer(a)))]),\n ])\n return Law.$match(law, {\n Associative: () =>\n tuples(3).map(([a, b, c]) =>\n equal([a, b, c], run(call(call(a, b), c)), run(call(a, call(b, c)))),\n ),\n Commutative: () =>\n tuples(2).map(([a, b]) => equal([a, b], run(call(a, b)), run(call(b, a)))),\n Idempotent: () => tuples(1).map(([a]) => equal([a], run(call(a, a)), value(a))),\n Identity: ({ value: witness, side }) => sided(witness, side, a => a),\n Absorbing: ({ value: witness, side }) => sided(witness, side, () => witness),\n Inverse: ({ other, identity }) =>\n tuples(1).map(([a]) => equal([a], run(call(a, witness(other, a))), value(identity))),\n Distributes: ({ over }) =>\n tuples(3).map(([a, b, c]) =>\n equal(\n [a, b, c],\n run(call(a, witness(over, b, c))),\n run(witness(over, call(a, b), call(a, c))),\n ),\n ),\n Monotonic: ({ direction, position }) => {\n // Text in order as the collation orders it, folded under asciiFold.\n const under = (held: unknown) =>\n Option.exists(collation, each => each._tag === 'AsciiFold') ? foldText(held) : held\n const order = (left: unknown, right: unknown) => orderOf(under(left), under(right))\n const each = descriptor.input.map(schema => samplesOf([schema], law.domain))\n const pairs = each[position]!.flatMap(low =>\n each[position]!.filter(high => order(low, high) < 0).map(high => [low, high] as const),\n )\n const rest = each.filter((_, index) => index !== position)\n const sign = direction === 'increasing' ? 1 : -1\n return tuplesOf<unknown>([pairs, ...rest], limit, seed).map(([pair, ...others]) => {\n const [low, high] = pair as readonly [unknown, unknown]\n const at = (held: unknown) => {\n const args = [...others]\n args.splice(position, 0, held)\n return args\n }\n return {\n args: at(low),\n collation,\n left: run(call(...at(low))),\n right: run(call(...at(high))),\n // Equal outcomes agree, as under every other law: two refusals (no case),\n // and two equal infinities, whose difference `order` reads is NaN.\n holds: (left: Outcome, right: Outcome) =>\n same(left, right) ||\n (left._tag === 'Value' &&\n right._tag === 'Value' &&\n sign * order(left.value, right.value) <= 0),\n }\n })\n },\n // A law about the fold itself: its equations are made once, in the asciiFold pass.\n PreservesCollation: () =>\n Option.exists(collation, each => each._tag === 'AsciiFold')\n ? tuples(2).map(([a, b]) =>\n equal(\n [a, b],\n { node: call(a, b), fold: true },\n { node: call(foldText(a), foldText(b)), fold: true },\n ),\n )\n : [],\n })\n })\n if (plans.length === 0) {\n throw new Error(\n `[foldkit-entity] Conformance.laws: no sample of ${nameOf(op)}'s arguments is in ${Law.describe(law).kind}'s domain`,\n )\n }\n return { law: Law.describe(law), plans }\n })\n}\n\n/**\n * The verdict over laws whose calls' outcomes `answered` gives: the first\n * failure, or evidence of each. Two sides that both refuse agree, as a law\n * over values says nothing of a call neither answers, but they are no case of\n * it: a law is shown only by the cases whose sides both answer a value, and\n * one with none is `Unanswered`.\n */\nconst verdictOf = (\n op: AnyOperator,\n laws: ReadonlyArray<LawPlans>,\n answered: (node: Operandish) => Outcome,\n options: { readonly implementation: string; readonly seed: number },\n): LawsVerdict => {\n const outcomes = (side: Side): Outcome => {\n if ('value' in side) return Outcome.Value({ value: side.value })\n const outcome = answered(side.node)\n return side.fold\n ? Outcome.$match(outcome, {\n Value: ({ value }) => Outcome.Value({ value: foldText(value) }),\n Refused: refused => refused,\n })\n : outcome\n }\n const evidence: Array<TestedEvidence> = []\n for (const { law, plans } of laws) {\n let cases = 0\n let refusal = Option.none<string>()\n for (const plan of plans) {\n const left = outcomes(plan.left)\n const right = outcomes(plan.right)\n if (!plan.holds(left, right)) {\n return LawsVerdict.Counterexample({\n law,\n args: plan.args,\n collation: plan.collation,\n left,\n right,\n })\n }\n if (left._tag === 'Value' && right._tag === 'Value') cases += 1\n else if (Option.isNone(refusal) && left._tag === 'Refused') refusal = Option.some(left.reason)\n }\n if (cases === 0) {\n return LawsVerdict.Unanswered({\n law,\n reason: Option.getOrElse(refusal, () => 'no call was answered'),\n })\n }\n evidence.push(\n Evidence.Tested({\n operator: nameOf(op),\n law,\n implementation: options.implementation,\n cases,\n seed: options.seed,\n }),\n )\n }\n return LawsVerdict.Holds({ evidence })\n}\n\nexport const Conformance = {\n /** A runner of calls through a memory table: `Conformance.operator`'s for the in-memory interpreter. */\n memory:\n (operators: MemoryOperators): Runner =>\n call =>\n valueOfOperand(call, { operators }),\n\n /**\n * Tests every law `op` declares against `operators`' implementation of it,\n * up to `cases` tuples a law (200 by default), chosen by `seed` (0); a law\n * of both sides checks each tuple from each. Holds with a `Tested` record a\n * law, which `Operators.withEvidence` keeps; or the first case a law fails,\n * with both sides.\n */\n laws: <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(\n op: Operator<In, Out>,\n operators: MemoryOperators,\n options: {\n readonly implementation?: string | undefined\n readonly cases?: number | undefined\n readonly seed?: number | undefined\n } = {},\n ): LawsVerdict => {\n const operator: AnyOperator = op\n const seed = options.seed ?? 0\n const outcome = (node: Operandish): Outcome => {\n try {\n return Outcome.Value({ value: valueOfOperand(node, { operators }) })\n } catch (error) {\n if (error instanceof QueryEvaluateError) return Outcome.Refused({ reason: error.message })\n throw error\n }\n }\n const verdict = verdictOf(operator, lawPlans(operator, options.cases ?? 200, seed), outcome, {\n implementation: options.implementation ?? 'memory',\n seed,\n })\n // Each record is of this table's implementations, its witnesses' too, which `withEvidence` checks.\n if (verdict._tag === 'Holds') verdict.evidence.forEach(record => stampTested(record, operators))\n return verdict\n },\n\n /**\n * As `laws`, each call run by `run` instead of a memory table: an SQL\n * implementation selected from a database, say, whose evidence a binding's\n * SQL table records. A throw is a refusal.\n */\n lawsBy: async <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(\n op: Operator<In, Out>,\n run: Runner,\n options: {\n readonly implementation: string\n readonly cases?: number | undefined\n readonly seed?: number | undefined\n },\n ): Promise<LawsVerdict> => {\n const operator: AnyOperator = op\n const seed = options.seed ?? 0\n const laws = lawPlans(operator, options.cases ?? 200, seed)\n const answers = new Map<Operandish, Outcome>()\n for (const { plans } of laws) {\n for (const side of plans.flatMap(plan => [plan.left, plan.right])) {\n if (!('node' in side) || answers.has(side.node)) continue\n try {\n answers.set(side.node, Outcome.Value({ value: await run(side.node) }))\n } catch (error) {\n answers.set(side.node, Outcome.Refused({ reason: String(error) }))\n }\n }\n }\n // Every call was run above, so each has its answer.\n const verdict = verdictOf(operator, laws, node => answers.get(node)!, {\n implementation: options.implementation,\n seed,\n })\n // Each record is a runner's, which an SQL table's `withEvidence` checks.\n if (verdict._tag === 'Holds') verdict.evidence.forEach(stampRun)\n return verdict\n },\n\n /**\n * Runs one set of calls of `op` through every implementation and compares\n * what each answered or refused. The calls are `cases` (argument tuples, as\n * stored), or generated: each argument a sample of its kind, null where its\n * schema admits one, and text holding NUL, under `binary` and `asciiFold` where the operator compares\n * text, up to `limit` (300) chosen by `seed` (0). A defined operator's\n * expansion is run beside the others, as `expansion`, by `expansionTable`\n * (the kernel's when not given).\n */\n operator: async <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(\n op: Operator<In, Out>,\n options: {\n readonly implementations: Readonly<Record<string, Runner>>\n readonly cases?: ReadonlyArray<ReadonlyArray<unknown>> | undefined\n readonly limit?: number | undefined\n readonly seed?: number | undefined\n readonly expansionTable?: MemoryOperators | undefined\n },\n ): Promise<OperatorReport> => {\n const operator: AnyOperator = op\n const { descriptor } = operator\n const runners: Record<string, Runner> = { ...options.implementations }\n if (Option.isSome(descriptor.definedAs)) {\n if (Object.hasOwn(runners, 'expansion')) {\n throw new Error(\n `[foldkit-entity] Conformance.operator: \"expansion\" names the expansion of ${nameOf(operator)}, which runs beside the implementations; name yours otherwise`,\n )\n }\n const table = options.expansionTable ?? Operators.kernel\n runners.expansion = call => valueOfOperand(Expr.expanded(call), { operators: table })\n }\n const generated = () =>\n tuplesOf(\n descriptor.input.map(schema => {\n const text = candidates(Schema.toEncoded(schema).ast).some(\n value => typeof value === 'string',\n )\n // Null only where the schema admits it: a call refuses a null literal otherwise.\n const nulls = decodes(schema)(null) ? [null] : []\n return [...nulls, ...samplesOf([schema], Option.none()), ...(text ? [`a${NUL}`] : [])]\n }),\n options.limit ?? 300,\n options.seed ?? 0,\n )\n const collations =\n descriptor.collation === 'none'\n ? [Option.none<Collation>()]\n : [Option.some(Collation.binary), Option.some(Collation.asciiFold)]\n const disagreements: Array<Disagreement> = []\n let cases = 0\n for (const args of options.cases ?? generated()) {\n for (const collation of collations) {\n cases += 1\n const call = callOf(operator, args, collation)\n // No prototype: an implementation named `__proto__` would set it, not a key.\n const outcomes: Record<string, Outcome> = Object.create(null)\n for (const [name, run] of Object.entries(runners)) {\n try {\n outcomes[name] = Outcome.Value({ value: await run(call) })\n } catch (error) {\n outcomes[name] = Outcome.Refused({ reason: String(error) })\n }\n }\n const [first, ...others] = Object.values(outcomes)\n if (first !== undefined && others.some(each => !same(first, each))) {\n disagreements.push({ args, collation, outcomes })\n }\n }\n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K,EAAE,CAAC;GAC5D;GAEF,MAAM,CAAC,OAAO,GAAG,UAAU,OAAO,OAAO,QAAQ;GACjD,IAAI,UAAU,KAAA,KAAa,OAAO,MAAK,SAAQ,CAAC,KAAK,OAAO,IAAI,CAAC,GAC/D,cAAc,KAAK;IAAE;IAAM;IAAW;GAAS,CAAC;EAEpD;EAEF,OAAO;GAAE;GAAO;EAAc;CAChC;AACF"}
1
+ {"version":3,"file":"operator.js","names":[],"sources":["../../src/conformance/operator.ts"],"sourcesContent":["/**\n * An operator held to what it declares (expr-operations-DESIGN §10.4): its\n * laws tested against an implementation, and one set of calls run through\n * every implementation given, their answers and refusals compared.\n *\n * Cases are drawn from a fixed sample of each kind of value (text with the\n * empty string, mixed case, non-ASCII, an astral character and `like`'s\n * wildcards; numbers with zero, negatives and a fraction; both booleans), kept\n * where the operator's input schema and the law's domain decode them, and\n * chosen by a seeded shuffle when there are more than asked for, so a run is\n * repeatable.\n */\nimport { Data, Option, Schema, SchemaAST } from 'effect'\nimport {\n Collation,\n Evidence,\n Expr,\n Law,\n Operators,\n QueryEvaluateError,\n valueOfOperand,\n type LawDescription,\n type MemoryOperators,\n type Operandish,\n type Operator,\n type TestedEvidence,\n} from '../index.js'\nimport { stampRun, stampTested } from '../tested.js'\nimport { tuplesOf } from './tuples.js'\n\ntype AnyOperator = Operator<ReadonlyArray<Schema.Top>, Schema.Top>\n\n/** What an implementation said of one call: a value, or that it refused it. */\nexport type Outcome = Data.TaggedEnum<{\n Value: { readonly value: unknown }\n Refused: { readonly reason: string }\n}>\nexport const Outcome = Data.taggedEnum<Outcome>()\n\n/**\n * What `Conformance.laws` found: every law held, with the evidence; the first\n * case one did not; or a law no case of which both sides answered, which\n * shows nothing of it.\n */\nexport type LawsVerdict = Data.TaggedEnum<{\n Holds: { readonly evidence: ReadonlyArray<TestedEvidence> }\n Unanswered: {\n readonly law: LawDescription\n /** Why the first refused call was refused. */\n readonly reason: string\n }\n Counterexample: {\n readonly law: LawDescription\n readonly args: ReadonlyArray<unknown>\n /** The collation the calls were made under, for an operator that compares text. */\n readonly collation: Option.Option<Collation>\n readonly left: Outcome\n readonly right: Outcome\n }\n}>\nexport const LawsVerdict = Data.taggedEnum<LawsVerdict>()\n\n/**\n * One way to run a call: its value, or a throw for a call it refuses. A call\n * of a predicate answers its truth, unknown as `null`.\n */\nexport type Runner = (call: Operandish) => unknown\n\n/** A call the implementations did not agree on, with what each said. */\nexport interface Disagreement {\n readonly args: ReadonlyArray<unknown>\n readonly collation: Option.Option<Collation>\n readonly outcomes: Readonly<Record<string, Outcome>>\n}\n\nexport interface OperatorReport {\n /** How many calls ran, each through every implementation. */\n readonly cases: number\n readonly disagreements: ReadonlyArray<Disagreement>\n}\n\nconst NUL = String.fromCharCode(0)\n// 'B' sorts before 'a' by code point and after it folded: what tells the collations apart.\n// `%`, `_` and `\\` are what `like` reads as wildcards and its escape.\nconst texts = [\n '',\n 'a',\n 'A',\n 'ab',\n 'aB',\n 'b',\n 'B',\n 'é',\n 'É',\n String.fromCodePoint(0x1f600),\n '%',\n '_',\n '\\\\',\n]\nconst numbers = [-2, -1, 0, 1, 2, 7, 0.5, -0.5, 1e6]\nconst booleans = [true, false]\n\n/** The sample values of a stored kind, before any schema narrows them. */\nconst candidates = (ast: SchemaAST.AST): ReadonlyArray<unknown> => {\n if (SchemaAST.isString(ast) || SchemaAST.isTemplateLiteral(ast)) return texts\n if (SchemaAST.isNumber(ast)) return numbers\n if (SchemaAST.isBoolean(ast)) return booleans\n if (SchemaAST.isLiteral(ast)) return [ast.literal]\n if (SchemaAST.isUnion(ast)) return ast.types.flatMap(candidates)\n return []\n}\n\n/** Whether a stored value is one `schema` stores. */\nconst decodes = (schema: Schema.Top) => (value: unknown) =>\n Schema.is(Schema.toEncoded(schema))(value)\n\n/** The non-null samples every schema of `schemas` decodes, and the domain too when one is given. */\nconst samplesOf = (\n schemas: ReadonlyArray<Schema.Top>,\n domain: Option.Option<Schema.Top>,\n): ReadonlyArray<unknown> =>\n [...new Set(candidates(Schema.toEncoded(schemas[0]!).ast))].filter(\n value =>\n value !== null &&\n schemas.every(schema => decodes(schema)(value)) &&\n Option.match(domain, { onNone: () => true, onSome: within => decodes(within)(value) }),\n )\n\n/** A plain object: what JSON makes, and nothing whose data sits in a prototype. */\nconst isRecord = (value: unknown): value is Readonly<Record<string, unknown>> => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false\n const prototype = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\n/** A plain object's keys holding a value: one holding `undefined` is as absent, as JSON writes it. */\nconst keysOf = (record: Readonly<Record<string, unknown>>): ReadonlyArray<string> =>\n Object.keys(record).filter(key => record[key] !== undefined)\n\n/**\n * Two stored values alike, structurally. Not by their JSON, which writes\n * `Infinity` and `NaN` as `null`: a division by zero answering `Infinity` in\n * memory and null in SQL would read as agreeing. An object that is not plain\n * (its data in a prototype: a Date) is compared by its JSON, a Date's its time.\n */\nconst sameValue = (left: unknown, right: unknown): boolean => {\n if (typeof left === 'number' && typeof right === 'number') {\n return left === right || (Number.isNaN(left) && Number.isNaN(right))\n }\n if (Array.isArray(left) && Array.isArray(right)) {\n return left.length === right.length && left.every((each, i) => sameValue(each, right[i]))\n }\n if (isRecord(left) && isRecord(right)) {\n const keys = keysOf(left)\n return (\n keys.length === keysOf(right).length &&\n keys.every(key => Object.hasOwn(right, key) && sameValue(left[key], right[key]))\n )\n }\n if (typeof left === 'object' && left !== null && typeof right === 'object' && right !== null) {\n return JSON.stringify(left) === JSON.stringify(right)\n }\n return left === right\n}\n\n/** Two outcomes alike: equal values as stored, or both refusals. */\nconst same = (left: Outcome, right: Outcome): boolean =>\n left._tag === 'Refused' || right._tag === 'Refused'\n ? left._tag === right._tag\n : sameValue(left.value, right.value)\n\n/** Text by code point, as every interpreter's `binary` orders it; `<` compares UTF-16 units. */\nconst byCodePoint = (left: string, right: string): number => {\n const [a, b] = [[...left], [...right]]\n for (let i = 0; i < Math.min(a.length, b.length); i++) {\n const sign = a[i]!.codePointAt(0)! - b[i]!.codePointAt(0)!\n if (sign !== 0) return sign\n }\n return a.length - b.length\n}\n\n/** Two values of one kind in order: numbers, booleans, text by code point. */\nconst orderOf = (left: unknown, right: unknown): number =>\n typeof left === 'string' && typeof right === 'string'\n ? byCodePoint(left, right)\n : Number(left) - Number(right)\n\n/** A call of `op`, given `collation` when its rule takes one. */\nconst callOf = (\n op: AnyOperator,\n args: ReadonlyArray<unknown>,\n collation: Option.Option<Collation>,\n): Operandish =>\n Option.match(collation, {\n onNone: () => op(...args),\n onSome: each => op(...args, { collation: each }),\n })\n\n/** One side of an equation: a call to run (its text folded first, for a collation law), or a value. */\ntype Side = { readonly node: Operandish; readonly fold: boolean } | { readonly value: unknown }\n\n/** One equation for one tuple: its two sides, and what makes their outcomes keep the law. */\ninterface Plan {\n readonly args: ReadonlyArray<unknown>\n readonly collation: Option.Option<Collation>\n readonly left: Side\n readonly right: Side\n readonly holds: (left: Outcome, right: Outcome) => boolean\n}\n\n/** Each law `op` declares, with its equations: what `laws` and `lawsBy` evaluate. */\ninterface LawPlans {\n readonly law: LawDescription\n readonly plans: ReadonlyArray<Plan>\n}\n\nconst foldText = (value: unknown): unknown =>\n typeof value === 'string' ? Collation.foldAscii(value) : value\n\nconst nameOf = (op: AnyOperator): string =>\n op.descriptor.version === 1 ? op.descriptor.id : `${op.descriptor.id}@${op.descriptor.version}`\n\n/**\n * The equations of every law `op` declares, over up to `limit` tuples a law\n * chosen by `seed`. Nothing is run: a memory table and an SQL runner\n * evaluate the same plans.\n */\nconst lawPlans = (op: AnyOperator, limit: number, seed: number): ReadonlyArray<LawPlans> => {\n const { descriptor } = op\n const comparesText = (each: AnyOperator) => each.descriptor.collation !== 'none'\n // Each operator is called under a collation only where it compares text.\n const under = (each: AnyOperator, collation: Option.Option<Collation>) =>\n comparesText(each) ? collation : Option.none<Collation>()\n const run = (node: Operandish): Side => ({ node, fold: false })\n const value = (held: unknown): Side => ({ value: held })\n return descriptor.laws.map(law => {\n const shared = samplesOf(descriptor.input, law.domain)\n const tuples = (arity: number) =>\n tuplesOf(\n Array.from({ length: arity }, () => shared),\n limit,\n seed,\n )\n // The kernel compares text only under a collation, and literals bring none. An\n // implementation is told the collation, and may answer differently under each:\n // a pass under each where `op`, or a witness the law calls, compares text.\n const witnesses = Law.$match(law, {\n Inverse: ({ other }) => [other],\n Distributes: ({ over }) => [over],\n Associative: () => [],\n Commutative: () => [],\n Idempotent: () => [],\n Identity: () => [],\n Absorbing: () => [],\n Monotonic: () => [],\n PreservesCollation: () => [],\n })\n const collations = [op, ...witnesses].some(comparesText)\n ? [Option.some(Collation.binary), Option.some(Collation.asciiFold)]\n : [Option.none<Collation>()]\n const plans = collations.flatMap((collation): ReadonlyArray<Plan> => {\n const call = (...args: ReadonlyArray<unknown>) => callOf(op, args, under(op, collation))\n // A witness operator is called as `op` is: under the collation when it compares text.\n const witness = (other: AnyOperator, ...args: ReadonlyArray<unknown>) =>\n callOf(other, args, under(other, collation))\n const equal = (args: ReadonlyArray<unknown>, left: Side, right: Side): Plan => ({\n args,\n collation,\n left,\n right,\n holds: same,\n })\n const sided = (\n witness: unknown,\n side: 'left' | 'right' | 'both',\n answer: (a: unknown) => unknown,\n ) =>\n tuples(1).flatMap(([a]) => [\n ...(side === 'right'\n ? []\n : [equal([witness, a], run(call(witness, a)), value(answer(a)))]),\n ...(side === 'left'\n ? []\n : [equal([a, witness], run(call(a, witness)), value(answer(a)))]),\n ])\n return Law.$match(law, {\n Associative: () =>\n tuples(3).map(([a, b, c]) =>\n equal([a, b, c], run(call(call(a, b), c)), run(call(a, call(b, c)))),\n ),\n Commutative: () =>\n tuples(2).map(([a, b]) => equal([a, b], run(call(a, b)), run(call(b, a)))),\n Idempotent: () => tuples(1).map(([a]) => equal([a], run(call(a, a)), value(a))),\n Identity: ({ value: witness, side }) => sided(witness, side, a => a),\n Absorbing: ({ value: witness, side }) => sided(witness, side, () => witness),\n Inverse: ({ other, identity }) =>\n tuples(1).map(([a]) => equal([a], run(call(a, witness(other, a))), value(identity))),\n Distributes: ({ over }) =>\n tuples(3).map(([a, b, c]) =>\n equal(\n [a, b, c],\n run(call(a, witness(over, b, c))),\n run(witness(over, call(a, b), call(a, c))),\n ),\n ),\n Monotonic: ({ direction, position }) => {\n // Text in order as the collation orders it, folded under asciiFold.\n const under = (held: unknown) =>\n Option.exists(collation, each => each._tag === 'AsciiFold') ? foldText(held) : held\n const order = (left: unknown, right: unknown) => orderOf(under(left), under(right))\n const each = descriptor.input.map(schema => samplesOf([schema], law.domain))\n const pairs = each[position]!.flatMap(low =>\n each[position]!.filter(high => order(low, high) < 0).map(high => [low, high] as const),\n )\n const rest = each.filter((_, index) => index !== position)\n const sign = direction === 'increasing' ? 1 : -1\n return tuplesOf<unknown>([pairs, ...rest], limit, seed).map(([pair, ...others]) => {\n const [low, high] = pair as readonly [unknown, unknown]\n const at = (held: unknown) => {\n const args = [...others]\n args.splice(position, 0, held)\n return args\n }\n return {\n args: at(low),\n collation,\n left: run(call(...at(low))),\n right: run(call(...at(high))),\n // Equal outcomes agree, as under every other law: two refusals (no case),\n // and two equal infinities, whose difference `order` reads is NaN.\n holds: (left: Outcome, right: Outcome) =>\n same(left, right) ||\n (left._tag === 'Value' &&\n right._tag === 'Value' &&\n sign * order(left.value, right.value) <= 0),\n }\n })\n },\n // A law about the fold itself: its equations are made once, in the asciiFold pass.\n PreservesCollation: () =>\n Option.exists(collation, each => each._tag === 'AsciiFold')\n ? tuples(2).map(([a, b]) =>\n equal(\n [a, b],\n { node: call(a, b), fold: true },\n { node: call(foldText(a), foldText(b)), fold: true },\n ),\n )\n : [],\n })\n })\n if (plans.length === 0) {\n throw new Error(\n `[foldkit-entity] Conformance.laws: no sample of ${nameOf(op)}'s arguments is in ${Law.describe(law).kind}'s domain`,\n )\n }\n return { law: Law.describe(law), plans }\n })\n}\n\n/**\n * The verdict over laws whose calls' outcomes `answered` gives: the first\n * failure, or evidence of each. Two sides that both refuse agree, as a law\n * over values says nothing of a call neither answers, but they are no case of\n * it: a law is shown only by the cases whose sides both answer a value, and\n * one with none is `Unanswered`.\n */\nconst verdictOf = (\n op: AnyOperator,\n laws: ReadonlyArray<LawPlans>,\n answered: (node: Operandish) => Outcome,\n options: { readonly implementation: string; readonly seed: number },\n): LawsVerdict => {\n const outcomes = (side: Side): Outcome => {\n if ('value' in side) return Outcome.Value({ value: side.value })\n const outcome = answered(side.node)\n return side.fold\n ? Outcome.$match(outcome, {\n Value: ({ value }) => Outcome.Value({ value: foldText(value) }),\n Refused: refused => refused,\n })\n : outcome\n }\n const evidence: Array<TestedEvidence> = []\n for (const { law, plans } of laws) {\n let cases = 0\n let refusal = Option.none<string>()\n for (const plan of plans) {\n const left = outcomes(plan.left)\n const right = outcomes(plan.right)\n if (!plan.holds(left, right)) {\n return LawsVerdict.Counterexample({\n law,\n args: plan.args,\n collation: plan.collation,\n left,\n right,\n })\n }\n if (left._tag === 'Value' && right._tag === 'Value') cases += 1\n else if (Option.isNone(refusal) && left._tag === 'Refused') refusal = Option.some(left.reason)\n }\n if (cases === 0) {\n return LawsVerdict.Unanswered({\n law,\n reason: Option.getOrElse(refusal, () => 'no call was answered'),\n })\n }\n evidence.push(\n Evidence.Tested({\n operator: nameOf(op),\n law,\n implementation: options.implementation,\n cases,\n seed: options.seed,\n }),\n )\n }\n return LawsVerdict.Holds({ evidence })\n}\n\nexport const Conformance = {\n /** A runner of calls through a memory table: `Conformance.operator`'s for the in-memory interpreter. */\n memory:\n (operators: MemoryOperators): Runner =>\n call =>\n valueOfOperand(call, { operators }),\n\n /**\n * Tests every law `op` declares against `operators`' implementation of it,\n * up to `cases` tuples a law (200 by default), chosen by `seed` (0); a law\n * of both sides checks each tuple from each. Holds with a `Tested` record a\n * law, which `Operators.withEvidence` keeps; or the first case a law fails,\n * with both sides.\n */\n laws: <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(\n op: Operator<In, Out>,\n operators: MemoryOperators,\n options: {\n readonly implementation?: string | undefined\n readonly cases?: number | undefined\n readonly seed?: number | undefined\n } = {},\n ): LawsVerdict => {\n const operator: AnyOperator = op\n const seed = options.seed ?? 0\n const outcome = (node: Operandish): Outcome => {\n try {\n return Outcome.Value({ value: valueOfOperand(node, { operators }) })\n } catch (error) {\n if (error instanceof QueryEvaluateError) return Outcome.Refused({ reason: error.message })\n throw error\n }\n }\n const verdict = verdictOf(operator, lawPlans(operator, options.cases ?? 200, seed), outcome, {\n implementation: options.implementation ?? 'memory',\n seed,\n })\n // Each record is of this table's implementations, its witnesses' too, which `withEvidence` checks.\n if (verdict._tag === 'Holds') verdict.evidence.forEach(record => stampTested(record, operators))\n return verdict\n },\n\n /**\n * As `laws`, each call run by `run` instead of a memory table: an SQL\n * implementation selected from a database, say, whose evidence a binding's\n * SQL table records. A throw is a refusal.\n */\n lawsBy: async <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(\n op: Operator<In, Out>,\n run: Runner,\n options: {\n readonly implementation: string\n readonly cases?: number | undefined\n readonly seed?: number | undefined\n },\n ): Promise<LawsVerdict> => {\n const operator: AnyOperator = op\n const seed = options.seed ?? 0\n const laws = lawPlans(operator, options.cases ?? 200, seed)\n const answers = new Map<Operandish, Outcome>()\n for (const { plans } of laws) {\n for (const side of plans.flatMap(plan => [plan.left, plan.right])) {\n if (!('node' in side) || answers.has(side.node)) continue\n try {\n answers.set(side.node, Outcome.Value({ value: await run(side.node) }))\n } catch (error) {\n answers.set(side.node, Outcome.Refused({ reason: String(error) }))\n }\n }\n }\n // Every call was run above, so each has its answer.\n const verdict = verdictOf(operator, laws, node => answers.get(node)!, {\n implementation: options.implementation,\n seed,\n })\n // Each record is a runner's, which an SQL table's `withEvidence` checks.\n if (verdict._tag === 'Holds') verdict.evidence.forEach(stampRun)\n return verdict\n },\n\n /**\n * Runs one set of calls of `op` through every implementation and compares\n * what each answered or refused. The calls are `cases` (argument tuples, as\n * stored), or generated: each argument a sample of its kind, null where its\n * schema admits one, and text holding NUL, under `binary` and `asciiFold` where the operator compares\n * text, up to `limit` (300) chosen by `seed` (0). A defined operator's\n * expansion is run beside the others, as `expansion`, by `expansionTable`\n * (the kernel's when not given).\n */\n operator: async <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(\n op: Operator<In, Out>,\n options: {\n readonly implementations: Readonly<Record<string, Runner>>\n readonly cases?: ReadonlyArray<ReadonlyArray<unknown>> | undefined\n readonly limit?: number | undefined\n readonly seed?: number | undefined\n readonly expansionTable?: MemoryOperators | undefined\n },\n ): Promise<OperatorReport> => {\n const operator: AnyOperator = op\n const { descriptor } = operator\n const runners: Record<string, Runner> = { ...options.implementations }\n if (Option.isSome(descriptor.definedAs)) {\n if (Object.hasOwn(runners, 'expansion')) {\n throw new Error(\n `[foldkit-entity] Conformance.operator: \"expansion\" names the expansion of ${nameOf(operator)}, which runs beside the implementations; name yours otherwise`,\n )\n }\n const table = options.expansionTable ?? Operators.kernel\n runners.expansion = call => valueOfOperand(Expr.expanded(call), { operators: table })\n }\n const generated = () =>\n tuplesOf(\n descriptor.input.map(schema => {\n const text = candidates(Schema.toEncoded(schema).ast).some(\n value => typeof value === 'string',\n )\n // Null only where the schema admits it: a call refuses a null literal otherwise.\n const nulls = decodes(schema)(null) ? [null] : []\n return [...nulls, ...samplesOf([schema], Option.none()), ...(text ? [`a${NUL}`] : [])]\n }),\n options.limit ?? 300,\n options.seed ?? 0,\n )\n const collations =\n descriptor.collation === 'none'\n ? [Option.none<Collation>()]\n : [Option.some(Collation.binary), Option.some(Collation.asciiFold)]\n const disagreements: Array<Disagreement> = []\n let cases = 0\n for (const args of options.cases ?? generated()) {\n for (const collation of collations) {\n cases += 1\n const call = callOf(operator, args, collation)\n // No prototype: an implementation named `__proto__` would set it, not a key.\n const outcomes: Record<string, Outcome> = Object.create(null)\n for (const [name, run] of Object.entries(runners)) {\n try {\n outcomes[name] = Outcome.Value({ value: await run(call) })\n } catch (error) {\n outcomes[name] = Outcome.Refused({ reason: String(error) })\n }\n }\n const [first, ...others] = Object.values(outcomes)\n if (first !== undefined && others.some(each => !same(first, each))) {\n disagreements.push({ args, collation, outcomes })\n }\n }\n }\n return { cases, disagreements }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,MAAa,UAAU,KAAK,WAAoB;AAuBhD,MAAa,cAAc,KAAK,WAAwB;AAqBxD,MAAM,MAAM,OAAO,aAAa,CAAC;AAGjC,MAAM,QAAQ;CACZ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,OAAO,cAAc,MAAO;CAC5B;CACA;CACA;AACF;AACA,MAAM,UAAU;CAAC;CAAI;CAAI;CAAG;CAAG;CAAG;CAAG;CAAK;CAAM;AAAG;AACnD,MAAM,WAAW,CAAC,MAAM,KAAK;;AAG7B,MAAM,cAAc,QAA+C;CACjE,IAAI,UAAU,SAAS,GAAG,KAAK,UAAU,kBAAkB,GAAG,GAAG,OAAO;CACxE,IAAI,UAAU,SAAS,GAAG,GAAG,OAAO;CACpC,IAAI,UAAU,UAAU,GAAG,GAAG,OAAO;CACrC,IAAI,UAAU,UAAU,GAAG,GAAG,OAAO,CAAC,IAAI,OAAO;CACjD,IAAI,UAAU,QAAQ,GAAG,GAAG,OAAO,IAAI,MAAM,QAAQ,UAAU;CAC/D,OAAO,CAAC;AACV;;AAGA,MAAM,WAAW,YAAwB,UACvC,OAAO,GAAG,OAAO,UAAU,MAAM,CAAC,CAAC,CAAC,KAAK;;AAG3C,MAAM,aACJ,SACA,WAEA,CAAC,GAAG,IAAI,IAAI,WAAW,OAAO,UAAU,QAAQ,EAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAC1D,UACE,UAAU,QACV,QAAQ,OAAM,WAAU,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,KAC9C,OAAO,MAAM,QAAQ;CAAE,cAAc;CAAM,SAAQ,WAAU,QAAQ,MAAM,CAAC,CAAC,KAAK;AAAE,CAAC,CACzF;;AAGF,MAAM,YAAY,UAA+D;CAC/E,IAAI,OAAO,UA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,OAAO;IACd,SAAS,QAAQ,QAAQ,QAAQ,EAAE,QAAQ,OAAO,KAAK,EAAE,CAAC;GAC5D;GAEF,MAAM,CAAC,OAAO,GAAG,UAAU,OAAO,OAAO,QAAQ;GACjD,IAAI,UAAU,KAAA,KAAa,OAAO,MAAK,SAAQ,CAAC,KAAK,OAAO,IAAI,CAAC,GAC/D,cAAc,KAAK;IAAE;IAAM;IAAW;GAAS,CAAC;EAEpD;EAEF,OAAO;GAAE;GAAO;EAAc;CAChC;AACF"}
@@ -1,5 +1,5 @@
1
- import { M as RelationSpec, O as RelatedSpecs, c as Entity, in as HeldTable, ln as AnyQuery, m as EntityRef, sr as ExprContext, t as AnyEntity } from "../index-48JeXG0A.js";
2
1
  import { Schema } from "effect";
2
+ import { AnyEntity, AnyQuery, Entity, EntityRef, ExprContext, HeldTable } from "../index.js";
3
3
  /**
4
4
  * A member is on a team or none; a badge is a member's; a pin is a team's.
5
5
  * Stored as foreign keys named after each relation plus `_id`.
@@ -10,7 +10,7 @@ export declare const Relational: {
10
10
  readonly name: Schema.String;
11
11
  /** Null on purpose: a path reaching a row whose field is null. */
12
12
  readonly region: Schema.NullOr<Schema.String>;
13
- }, RelatedSpecs<{
13
+ }, import("../index.js").RelatedSpecs<{
14
14
  readonly Team: Entity<"Team", {
15
15
  readonly id: Schema.String;
16
16
  readonly name: Schema.String;
@@ -32,7 +32,7 @@ export declare const Relational: {
32
32
  }, {}, {}>;
33
33
  }, {
34
34
  readonly Member: {
35
- team: RelationSpec<Entity<"Team", {
35
+ team: import("../index.js").RelationSpec<Entity<"Team", {
36
36
  readonly id: Schema.String;
37
37
  readonly name: Schema.String;
38
38
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -40,14 +40,14 @@ export declare const Relational: {
40
40
  }, {}, {}>, "one", true>;
41
41
  };
42
42
  readonly Badge: {
43
- member: RelationSpec<Entity<"Member", {
43
+ member: import("../index.js").RelationSpec<Entity<"Member", {
44
44
  readonly id: Schema.String;
45
45
  readonly handle: Schema.String;
46
46
  readonly rank: Schema.Number;
47
47
  }, {}, {}>, "one", false>;
48
48
  };
49
49
  readonly Pin: {
50
- team: RelationSpec<Entity<"Team", {
50
+ team: import("../index.js").RelationSpec<Entity<"Team", {
51
51
  readonly id: Schema.String;
52
52
  readonly name: Schema.String;
53
53
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -59,7 +59,7 @@ export declare const Relational: {
59
59
  readonly id: Schema.String;
60
60
  readonly handle: Schema.String;
61
61
  readonly rank: Schema.Number;
62
- }, RelatedSpecs<{
62
+ }, import("../index.js").RelatedSpecs<{
63
63
  readonly Team: Entity<"Team", {
64
64
  readonly id: Schema.String;
65
65
  readonly name: Schema.String;
@@ -81,7 +81,7 @@ export declare const Relational: {
81
81
  }, {}, {}>;
82
82
  }, {
83
83
  readonly Member: {
84
- team: RelationSpec<Entity<"Team", {
84
+ team: import("../index.js").RelationSpec<Entity<"Team", {
85
85
  readonly id: Schema.String;
86
86
  readonly name: Schema.String;
87
87
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -89,14 +89,14 @@ export declare const Relational: {
89
89
  }, {}, {}>, "one", true>;
90
90
  };
91
91
  readonly Badge: {
92
- member: RelationSpec<Entity<"Member", {
92
+ member: import("../index.js").RelationSpec<Entity<"Member", {
93
93
  readonly id: Schema.String;
94
94
  readonly handle: Schema.String;
95
95
  readonly rank: Schema.Number;
96
96
  }, {}, {}>, "one", false>;
97
97
  };
98
98
  readonly Pin: {
99
- team: RelationSpec<Entity<"Team", {
99
+ team: import("../index.js").RelationSpec<Entity<"Team", {
100
100
  readonly id: Schema.String;
101
101
  readonly name: Schema.String;
102
102
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -107,7 +107,7 @@ export declare const Relational: {
107
107
  readonly Badge: Entity<"Badge", {
108
108
  readonly id: Schema.String;
109
109
  readonly kind: Schema.String;
110
- }, RelatedSpecs<{
110
+ }, import("../index.js").RelatedSpecs<{
111
111
  readonly Team: Entity<"Team", {
112
112
  readonly id: Schema.String;
113
113
  readonly name: Schema.String;
@@ -129,7 +129,7 @@ export declare const Relational: {
129
129
  }, {}, {}>;
130
130
  }, {
131
131
  readonly Member: {
132
- team: RelationSpec<Entity<"Team", {
132
+ team: import("../index.js").RelationSpec<Entity<"Team", {
133
133
  readonly id: Schema.String;
134
134
  readonly name: Schema.String;
135
135
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -137,14 +137,14 @@ export declare const Relational: {
137
137
  }, {}, {}>, "one", true>;
138
138
  };
139
139
  readonly Badge: {
140
- member: RelationSpec<Entity<"Member", {
140
+ member: import("../index.js").RelationSpec<Entity<"Member", {
141
141
  readonly id: Schema.String;
142
142
  readonly handle: Schema.String;
143
143
  readonly rank: Schema.Number;
144
144
  }, {}, {}>, "one", false>;
145
145
  };
146
146
  readonly Pin: {
147
- team: RelationSpec<Entity<"Team", {
147
+ team: import("../index.js").RelationSpec<Entity<"Team", {
148
148
  readonly id: Schema.String;
149
149
  readonly name: Schema.String;
150
150
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -155,7 +155,7 @@ export declare const Relational: {
155
155
  readonly Pin: Entity<"Pin", {
156
156
  readonly id: Schema.String;
157
157
  readonly label: Schema.String;
158
- }, RelatedSpecs<{
158
+ }, import("../index.js").RelatedSpecs<{
159
159
  readonly Team: Entity<"Team", {
160
160
  readonly id: Schema.String;
161
161
  readonly name: Schema.String;
@@ -177,7 +177,7 @@ export declare const Relational: {
177
177
  }, {}, {}>;
178
178
  }, {
179
179
  readonly Member: {
180
- team: RelationSpec<Entity<"Team", {
180
+ team: import("../index.js").RelationSpec<Entity<"Team", {
181
181
  readonly id: Schema.String;
182
182
  readonly name: Schema.String;
183
183
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -185,14 +185,14 @@ export declare const Relational: {
185
185
  }, {}, {}>, "one", true>;
186
186
  };
187
187
  readonly Badge: {
188
- member: RelationSpec<Entity<"Member", {
188
+ member: import("../index.js").RelationSpec<Entity<"Member", {
189
189
  readonly id: Schema.String;
190
190
  readonly handle: Schema.String;
191
191
  readonly rank: Schema.Number;
192
192
  }, {}, {}>, "one", false>;
193
193
  };
194
194
  readonly Pin: {
195
- team: RelationSpec<Entity<"Team", {
195
+ team: import("../index.js").RelationSpec<Entity<"Team", {
196
196
  readonly id: Schema.String;
197
197
  readonly name: Schema.String;
198
198
  /** Null on purpose: a path reaching a row whose field is null. */
@@ -1 +1 @@
1
- {"version":3,"file":"relational.d.ts","names":["_$___index_js0.RelationSpec","_$___index_js0.RelatedSpecs"],"sources":["../../src/conformance/relational.ts"],"mappings":";;;;;;qBAuCa;;;;;;KAKEC;;;;;;;;;;;;;;;;;;;;;;MAFD,MAAID,aAAA;;;;;;;;MACL,QAAMA,aAAA;;;;;;;MACR,MAAIA,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAKH,gBAAgB,SAAS;;iBAGpB;WACN,QAAQ;WACR,SAAS,cAAc;;;;;WAKvB,QAAQ,cAAc;;qBAGpB,kBAAkB,cAAc;iBA2C5B;WACN;WACA,MAAM;;WAEN,OAAO,SAAS;;WAEhB,UAAU;;WAEV,SAAS;;;qBAIP,oBAAiB,GAAO,mBAAiB;qBAoBzC,iBAAiB,cAAc;;iBAmM3B;WACN;WACA,QAAQ,cAAc;;;;;;qBAmBpB,YAAY,cAAc"}
1
+ {"version":3,"file":"relational.d.ts","names":[],"sources":["../../src/conformance/relational.ts"],"mappings":";;;;;;qBAuCa;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAGC,4BAAI,aAAA;;;;;;;;MACL,8BAAM,aAAA;;;;;;;MACR,4BAAI,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAKH,gBAAgB,SAAS;;iBAGpB;WACN,QAAQ;WACR,SAAS,cAAc;;;;;WAKvB,QAAQ,cAAc;;qBAGpB,kBAAkB,cAAc;iBA2C5B;WACN;WACA,MAAM;;WAEN,OAAO,SAAS;;WAEhB,UAAU;;WAEV,SAAS;;;qBAIP,oBAAiB,GAAO,mBAAiB;qBAoBzC,iBAAiB,cAAc;;iBAmM3B;WACN;WACA,QAAQ,cAAc;;;;;;qBAmBpB,YAAY,cAAc"}
@@ -1,7 +1,5 @@
1
- import { Collation } from "../collation.js";
2
- import { Expr, Order, Query } from "../expr.js";
3
- import { a as Relation, r as Entity } from "../src-DKhUqLoC.js";
4
1
  import { Option, Schema } from "effect";
2
+ import { Collation, Entity, Expr, Order, Query, Relation } from "../index.js";
5
3
  // src/conformance/relational.ts
6
4
  /**
7
5
  * The conformance suite for paths and exists: bodies that read other rows,
@@ -1 +1 @@
1
- {"version":3,"file":"relational.js","names":[],"sources":["../../src/conformance/relational.ts"],"sourcesContent":["/**\n * The conformance suite for paths and exists: bodies that read other rows,\n * over a domain whose reader may not see every row.\n *\n * Two laws are checked against these cases. An interpreter that runs over\n * every row the reader may see (SQL, under each table's visibility rule)\n * answers `expected`. An interpreter that runs over what a holder has\n * (`Judge`, over each of `heldWorlds`) answers unknown or what `expected`\n * says, never the other answer, and over everything the reader may see it\n * answers every row.\n *\n * The fixture is chosen so a path meets each way of reaching no row (a null\n * link, a row the reader may not see), a field that is null on the row\n * reached, and an exists whose only witness is hidden.\n */\nimport { Option, Schema } from 'effect'\nimport { Collation, Entity, Expr, Order, Query, Relation } from '../index.js'\nimport type { AnyEntity, AnyQuery, EntityRef, ExprContext, HeldTable } from '../index.js'\n\nconst Team = Entity.define(\n 'Team',\n Schema.Struct({\n id: Schema.String,\n name: Schema.String,\n /** Null on purpose: a path reaching a row whose field is null. */\n region: Schema.NullOr(Schema.String),\n }),\n)\nconst Member = Entity.define(\n 'Member',\n Schema.Struct({ id: Schema.String, handle: Schema.String, rank: Schema.Number }),\n)\nconst Badge = Entity.define('Badge', Schema.Struct({ id: Schema.String, kind: Schema.String }))\nconst Pin = Entity.define('Pin', Schema.Struct({ id: Schema.String, label: Schema.String }))\n\n/**\n * A member is on a team or none; a badge is a member's; a pin is a team's.\n * Stored as foreign keys named after each relation plus `_id`.\n */\nexport const Relational = Entity.relate(\n { Team, Member, Badge, Pin },\n {\n Member: { team: Relation.one(Team, { optional: true }) },\n Badge: { member: Relation.one(Member) },\n Pin: { team: Relation.one(Team) },\n },\n)\n\n/** A row as the suite writes one: fields, and each `one` relation as the id it points at. */\nexport type RelationalRow = Readonly<Record<string, string | number | null>>\n\n/** One Entity's rows: those the reader may see, and those its visibility rule hides. */\nexport interface RelationalTable {\n readonly entity: AnyEntity\n readonly visible: ReadonlyArray<RelationalRow>\n /**\n * Rows the reader may not see. SQL's rule hides a Team named `Hidden` and a\n * Badge of kind `secret`; a holder never has them.\n */\n readonly hidden: ReadonlyArray<RelationalRow>\n}\n\nexport const relationalTables: ReadonlyArray<RelationalTable> = [\n {\n entity: Relational.Team,\n visible: [\n { id: 't1', name: 'Red', region: 'eu' },\n { id: 't2', name: 'Blue', region: null },\n ],\n hidden: [{ id: 't3', name: 'Hidden', region: 'eu' }],\n },\n {\n entity: Relational.Member,\n visible: [\n { id: 'm1', handle: 'ann', rank: 1, team: 't1' },\n { id: 'm2', handle: 'bob', rank: 2, team: 't2' },\n { id: 'm3', handle: 'cy', rank: 3, team: null },\n // On a team the reader may not see.\n { id: 'm4', handle: 'dee', rank: 4, team: 't3' },\n { id: 'm5', handle: 'Eve', rank: 5, team: 't1' },\n ],\n hidden: [],\n },\n {\n entity: Relational.Badge,\n visible: [\n { id: 'b1', kind: 'gold', member: 'm1' },\n { id: 'b2', kind: 'silver', member: 'm1' },\n { id: 'b3', kind: 'gold', member: 'm2' },\n { id: 'b5', kind: 'silver', member: 'm4' },\n ],\n // m3's only badge.\n hidden: [{ id: 'b4', kind: 'secret', member: 'm3' }],\n },\n {\n entity: Relational.Pin,\n visible: [\n { id: 'p1', label: 'top', team: 't1' },\n { id: 'p2', label: 'low', team: 't2' },\n { id: 'p3', label: 'top', team: 't3' },\n ],\n hidden: [],\n },\n]\n\nexport interface RelationalCase {\n readonly what: string\n readonly body: AnyQuery\n /** Encoded, as `ConformanceCase.input`. */\n readonly input: Readonly<Record<string, unknown>>\n /** The ids of the visible rows the body matches, by id. */\n readonly expected: ReadonlyArray<string>\n /** Who asks, or null for a visitor; a case that reads no viewer has none. */\n readonly viewer?: EntityRef | null\n}\n\n/** What a case's `Expr.viewer` reads: who asks, or a visitor where nobody does. */\nexport const relationalContext = (c: RelationalCase): ExprContext => ({\n viewer: Option.fromNullishOr(c.viewer),\n now: Option.none(),\n})\n\nconst member = (id: string): EntityRef => ({ entity: 'Member', id })\n\nconst { Team: T, Member: M, Badge: B, Pin: P } = Relational\nconst members = Query.from(M).pipe(Query.orderBy(Order.asc(M.fields.id)))\nconst badges = Query.from(B).pipe(Query.orderBy(Order.asc(B.fields.id)))\nconst teams = Query.from(T).pipe(Query.orderBy(Order.asc(T.fields.id)))\nconst teamName = Expr.path(M.relations.team, T.fields.name)\nconst topPin = Expr.path(\n M.relations.team,\n Expr.exists(P.relations.team, Expr.eq(P.fields.label, 'top')),\n)\nconst viewerTeam = Expr.path(Expr.viewer(M), Expr.path(M.relations.team, T.fields.name))\nconst viewerTeamId = Expr.path(Expr.viewer(M), Expr.path(M.relations.team, T.fields.id))\nconst gold = Expr.exists(B.relations.member, Expr.eq(B.fields.kind, 'gold'))\n\nexport const relationalCases: ReadonlyArray<RelationalCase> = [\n // ---- a path's field ---------------------------------------------------------\n {\n what: 'a path reads a field of the row its relation points at',\n body: members.pipe(Query.where(Expr.eq(teamName, 'Red'))),\n input: {},\n expected: ['m1', 'm5'],\n },\n {\n what: 'a path reads null through a null link, and through a row the reader may not see',\n body: members.pipe(Query.where(Expr.isNull(teamName))),\n input: {},\n expected: ['m3', 'm4'],\n },\n {\n what: \"a path's null is unknown under not, so neither side keeps the row\",\n body: members.pipe(Query.where(Expr.not(Expr.eq(teamName, 'Red')))),\n input: {},\n expected: ['m2'],\n },\n {\n what: 'a path reads a null field of the row reached as null',\n body: members.pipe(Query.where(Expr.isNull(Expr.path(M.relations.team, T.fields.region)))),\n input: {},\n expected: ['m2', 'm3', 'm4'],\n },\n {\n what: 'a path compares with an input',\n body: members.pipe(\n Query.where(\n Expr.eq(Expr.path(M.relations.team, T.fields.region), Expr.input('region', Schema.String)),\n ),\n ),\n input: { region: 'eu' },\n expected: ['m1', 'm5'],\n },\n {\n what: \"contains folds a path's text as it folds a field's\",\n body: members.pipe(Query.where(Expr.contains(teamName, 'E'))),\n input: {},\n expected: ['m1', 'm2', 'm5'],\n },\n {\n what: \"a comparison orders a path's text under the collation it names\",\n body: members.pipe(Query.where(Expr.lt(teamName, 'C', { collation: Collation.binary }))),\n input: {},\n expected: ['m2'],\n },\n {\n what: 'a path follows two relations',\n body: badges.pipe(\n Query.where(\n Expr.eq(Expr.path(B.relations.member, Expr.path(M.relations.team, T.fields.name)), 'Red'),\n ),\n ),\n input: {},\n expected: ['b1', 'b2'],\n },\n {\n what: 'a path of two relations reads null where either reaches no row or the field is null',\n body: badges.pipe(\n Query.where(\n Expr.isNull(Expr.path(B.relations.member, Expr.path(M.relations.team, T.fields.region))),\n ),\n ),\n input: {},\n expected: ['b3', 'b5'],\n },\n {\n what: \"in tests a path's value against a list\",\n body: badges.pipe(Query.where(Expr.in(Expr.path(B.relations.member, M.fields.rank), [1, 4]))),\n input: {},\n expected: ['b1', 'b2', 'b5'],\n },\n\n // ---- exists -----------------------------------------------------------------\n {\n what: 'exists finds a row pointing here, and never one the reader may not see',\n body: members.pipe(Query.where(Expr.exists(B.relations.member))),\n input: {},\n expected: ['m1', 'm2', 'm4'],\n },\n {\n what: 'exists holds when a pointing row holds its filter',\n body: members.pipe(Query.where(gold)),\n input: {},\n expected: ['m1', 'm2'],\n },\n {\n what: 'exists is never unknown, so its not keeps every other row',\n body: members.pipe(Query.where(Expr.not(gold))),\n input: {},\n expected: ['m3', 'm4', 'm5'],\n },\n {\n what: \"an exists' filter reads the input\",\n body: members.pipe(\n Query.where(\n Expr.exists(B.relations.member, Expr.eq(B.fields.kind, Expr.input('kind', Schema.String))),\n ),\n ),\n input: { kind: 'silver' },\n expected: ['m1', 'm4'],\n },\n {\n what: \"or holds by either side, an exists or the row's own field\",\n body: members.pipe(Query.where(Expr.or(Expr.eq(M.fields.rank, 5), gold))),\n input: {},\n expected: ['m1', 'm2', 'm5'],\n },\n {\n what: 'and joins a path and the negation of an exists',\n body: members.pipe(\n Query.where(Expr.and(Expr.isNotNull(teamName), Expr.not(Expr.exists(B.relations.member)))),\n ),\n input: {},\n expected: ['m5'],\n },\n {\n what: \"an exists' filter folds text as contains does\",\n body: teams.pipe(\n Query.where(Expr.exists(M.relations.team, Expr.contains(M.fields.handle, 'E'))),\n ),\n input: {},\n expected: ['t1'],\n },\n {\n what: 'not of an exists holds where no pointing row holds the filter',\n body: teams.pipe(\n Query.where(Expr.not(Expr.exists(M.relations.team, Expr.gte(M.fields.rank, 5)))),\n ),\n input: {},\n expected: ['t2'],\n },\n\n // ---- an exists at the end of a path ----------------------------------------\n {\n what: 'an exists asked of the row a path reaches',\n body: members.pipe(Query.where(topPin)),\n input: {},\n expected: ['m1', 'm5'],\n },\n {\n what: 'an exists through a path that reaches no row is unknown, so its not keeps neither',\n body: members.pipe(Query.where(Expr.not(topPin))),\n input: {},\n expected: ['m2'],\n },\n\n // ---- a path from the viewer -------------------------------------------------\n {\n what: \"a path from the viewer reads their team's name, on the table it judges\",\n body: members.pipe(Query.where(Expr.eq(teamName, viewerTeam))),\n input: {},\n viewer: member('m1'),\n expected: ['m1', 'm5'],\n },\n {\n what: \"a path from the viewer reaches another table's row\",\n body: teams.pipe(Query.where(Expr.eq(T.fields.id, viewerTeamId))),\n input: {},\n viewer: member('m2'),\n expected: ['t2'],\n },\n {\n what: 'a path from the viewer reads null through a team the reader may not see',\n body: members.pipe(Query.where(Expr.isNull(viewerTeam))),\n input: {},\n viewer: member('m4'),\n expected: ['m1', 'm2', 'm3', 'm4', 'm5'],\n },\n {\n what: 'a path from the viewer reads null through a null link',\n body: teams.pipe(Query.where(Expr.isNull(viewerTeamId))),\n input: {},\n viewer: member('m3'),\n expected: ['t1', 't2'],\n },\n {\n what: 'a path from a viewer the reader may not see reads null, as a path to that row does',\n body: teams.pipe(Query.where(Expr.isNull(Expr.path(Expr.viewer(T), T.fields.name)))),\n input: {},\n viewer: { entity: 'Team', id: 't3' },\n expected: ['t1', 't2'],\n },\n {\n what: 'a path from a visitor reaches no row, so a comparison with it keeps none',\n body: teams.pipe(Query.where(Expr.not(Expr.eq(T.fields.id, viewerTeamId)))),\n input: {},\n viewer: null,\n expected: [],\n },\n]\n\n/** The tables a holder has, from what the reader may see of each, and which rows it judges. */\nexport interface HeldWorld {\n readonly what: string\n readonly tables: ReadonlyArray<HeldTable>\n}\n\nconst held = (\n change: (table: RelationalTable) => Partial<Omit<HeldTable, 'entity'>>,\n): ReadonlyArray<HeldTable> =>\n relationalTables.map(table => ({ entity: table.entity, rows: table.visible, ...change(table) }))\n\nconst named = (table: RelationalTable, entity: AnyEntity): boolean =>\n table.entity.identity.token === entity.identity.token\n\n/** A record without the keys named. */\nconst without = (row: RelationalRow, keys: ReadonlyArray<string>): RelationalRow =>\n Object.fromEntries(Object.entries(row).filter(([key]) => !keys.includes(key)))\n\n/**\n * What a holder might have, first everything the reader may see. Each later\n * one lacks something a case reads, so some judgement in it is unknown.\n */\nexport const heldWorlds: ReadonlyArray<HeldWorld> = [\n { what: 'everything the reader may see', tables: held(() => ({})) },\n {\n what: 'no team',\n tables: held(table => (named(table, T) ? { rows: [], complete: false } : {})),\n },\n {\n what: 'every other row of each table',\n tables: held(table => ({\n rows: table.visible.filter((_, index) => index % 2 === 0),\n complete: false,\n })),\n },\n {\n what: \"a team's name and region hidden\",\n tables: held(table => (named(table, T) ? { hidden: ['name', 'region'] } : {})),\n },\n {\n what: 'no badge, and not every pin',\n tables: held(table =>\n named(table, B)\n ? { rows: [], complete: false }\n : named(table, P)\n ? { rows: table.visible.slice(1), complete: false }\n : {},\n ),\n },\n {\n what: 'no link held',\n tables: held(table => ({\n rows: table.visible.map(row => without(row, ['team', 'member'])),\n })),\n },\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,MAAM,OAAO,OAAO,OAClB,QACA,OAAO,OAAO;CACZ,IAAI,OAAO;CACX,MAAM,OAAO;;CAEb,QAAQ,OAAO,OAAO,OAAO,MAAM;AACrC,CAAC,CACH;AACA,MAAM,SAAS,OAAO,OACpB,UACA,OAAO,OAAO;CAAE,IAAI,OAAO;CAAQ,QAAQ,OAAO;CAAQ,MAAM,OAAO;AAAO,CAAC,CACjF;AACA,MAAM,QAAQ,OAAO,OAAO,SAAS,OAAO,OAAO;CAAE,IAAI,OAAO;CAAQ,MAAM,OAAO;AAAO,CAAC,CAAC;AAC9F,MAAM,MAAM,OAAO,OAAO,OAAO,OAAO,OAAO;CAAE,IAAI,OAAO;CAAQ,OAAO,OAAO;AAAO,CAAC,CAAC;;;;;AAM3F,MAAa,aAAa,OAAO,OAC/B;CAAE;CAAM;CAAQ;CAAO;AAAI,GAC3B;CACE,QAAQ,EAAE,MAAM,SAAS,IAAI,MAAM,EAAE,UAAU,KAAK,CAAC,EAAE;CACvD,OAAO,EAAE,QAAQ,SAAS,IAAI,MAAM,EAAE;CACtC,KAAK,EAAE,MAAM,SAAS,IAAI,IAAI,EAAE;AAClC,CACF;AAgBA,MAAa,mBAAmD;CAC9D;EACE,QAAQ,WAAW;EACnB,SAAS,CACP;GAAE,IAAI;GAAM,MAAM;GAAO,QAAQ;EAAK,GACtC;GAAE,IAAI;GAAM,MAAM;GAAQ,QAAQ;EAAK,CACzC;EACA,QAAQ,CAAC;GAAE,IAA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AAQ,MAAK,UACX,MAAM,OAAO,CAAC,IACV;GAAE,MAAM,CAAC;GAAG,UAAU;EAAM,IAC5B,MAAM,OAAO,CAAC,IACZ;GAAE,MAAM,MAAM,QAAQ,MAAM,CAAC;GAAG,UAAU;EAAM,IAChD,CAAC,CACT;CACF;CACA;EACE,MAAM;EACN,QAAQ,MAAK,WAAU,EACrB,MAAM,MAAM,QAAQ,KAAI,QAAO,QAAQ,KAAK,CAAC,QAAQ,QAAQ,CAAC,CAAC,EACjE,EAAE;CACJ;AACF"}
1
+ {"version":3,"file":"relational.js","names":[],"sources":["../../src/conformance/relational.ts"],"sourcesContent":["/**\n * The conformance suite for paths and exists: bodies that read other rows,\n * over a domain whose reader may not see every row.\n *\n * Two laws are checked against these cases. An interpreter that runs over\n * every row the reader may see (SQL, under each table's visibility rule)\n * answers `expected`. An interpreter that runs over what a holder has\n * (`Judge`, over each of `heldWorlds`) answers unknown or what `expected`\n * says, never the other answer, and over everything the reader may see it\n * answers every row.\n *\n * The fixture is chosen so a path meets each way of reaching no row (a null\n * link, a row the reader may not see), a field that is null on the row\n * reached, and an exists whose only witness is hidden.\n */\nimport { Option, Schema } from 'effect'\nimport { Collation, Entity, Expr, Order, Query, Relation } from '../index.js'\nimport type { AnyEntity, AnyQuery, EntityRef, ExprContext, HeldTable } from '../index.js'\n\nconst Team = Entity.define(\n 'Team',\n Schema.Struct({\n id: Schema.String,\n name: Schema.String,\n /** Null on purpose: a path reaching a row whose field is null. */\n region: Schema.NullOr(Schema.String),\n }),\n)\nconst Member = Entity.define(\n 'Member',\n Schema.Struct({ id: Schema.String, handle: Schema.String, rank: Schema.Number }),\n)\nconst Badge = Entity.define('Badge', Schema.Struct({ id: Schema.String, kind: Schema.String }))\nconst Pin = Entity.define('Pin', Schema.Struct({ id: Schema.String, label: Schema.String }))\n\n/**\n * A member is on a team or none; a badge is a member's; a pin is a team's.\n * Stored as foreign keys named after each relation plus `_id`.\n */\nexport const Relational = Entity.relate(\n { Team, Member, Badge, Pin },\n {\n Member: { team: Relation.one(Team, { optional: true }) },\n Badge: { member: Relation.one(Member) },\n Pin: { team: Relation.one(Team) },\n },\n)\n\n/** A row as the suite writes one: fields, and each `one` relation as the id it points at. */\nexport type RelationalRow = Readonly<Record<string, string | number | null>>\n\n/** One Entity's rows: those the reader may see, and those its visibility rule hides. */\nexport interface RelationalTable {\n readonly entity: AnyEntity\n readonly visible: ReadonlyArray<RelationalRow>\n /**\n * Rows the reader may not see. SQL's rule hides a Team named `Hidden` and a\n * Badge of kind `secret`; a holder never has them.\n */\n readonly hidden: ReadonlyArray<RelationalRow>\n}\n\nexport const relationalTables: ReadonlyArray<RelationalTable> = [\n {\n entity: Relational.Team,\n visible: [\n { id: 't1', name: 'Red', region: 'eu' },\n { id: 't2', name: 'Blue', region: null },\n ],\n hidden: [{ id: 't3', name: 'Hidden', region: 'eu' }],\n },\n {\n entity: Relational.Member,\n visible: [\n { id: 'm1', handle: 'ann', rank: 1, team: 't1' },\n { id: 'm2', handle: 'bob', rank: 2, team: 't2' },\n { id: 'm3', handle: 'cy', rank: 3, team: null },\n // On a team the reader may not see.\n { id: 'm4', handle: 'dee', rank: 4, team: 't3' },\n { id: 'm5', handle: 'Eve', rank: 5, team: 't1' },\n ],\n hidden: [],\n },\n {\n entity: Relational.Badge,\n visible: [\n { id: 'b1', kind: 'gold', member: 'm1' },\n { id: 'b2', kind: 'silver', member: 'm1' },\n { id: 'b3', kind: 'gold', member: 'm2' },\n { id: 'b5', kind: 'silver', member: 'm4' },\n ],\n // m3's only badge.\n hidden: [{ id: 'b4', kind: 'secret', member: 'm3' }],\n },\n {\n entity: Relational.Pin,\n visible: [\n { id: 'p1', label: 'top', team: 't1' },\n { id: 'p2', label: 'low', team: 't2' },\n { id: 'p3', label: 'top', team: 't3' },\n ],\n hidden: [],\n },\n]\n\nexport interface RelationalCase {\n readonly what: string\n readonly body: AnyQuery\n /** Encoded, as `ConformanceCase.input`. */\n readonly input: Readonly<Record<string, unknown>>\n /** The ids of the visible rows the body matches, by id. */\n readonly expected: ReadonlyArray<string>\n /** Who asks, or null for a visitor; a case that reads no viewer has none. */\n readonly viewer?: EntityRef | null\n}\n\n/** What a case's `Expr.viewer` reads: who asks, or a visitor where nobody does. */\nexport const relationalContext = (c: RelationalCase): ExprContext => ({\n viewer: Option.fromNullishOr(c.viewer),\n now: Option.none(),\n})\n\nconst member = (id: string): EntityRef => ({ entity: 'Member', id })\n\nconst { Team: T, Member: M, Badge: B, Pin: P } = Relational\nconst members = Query.from(M).pipe(Query.orderBy(Order.asc(M.fields.id)))\nconst badges = Query.from(B).pipe(Query.orderBy(Order.asc(B.fields.id)))\nconst teams = Query.from(T).pipe(Query.orderBy(Order.asc(T.fields.id)))\nconst teamName = Expr.path(M.relations.team, T.fields.name)\nconst topPin = Expr.path(\n M.relations.team,\n Expr.exists(P.relations.team, Expr.eq(P.fields.label, 'top')),\n)\nconst viewerTeam = Expr.path(Expr.viewer(M), Expr.path(M.relations.team, T.fields.name))\nconst viewerTeamId = Expr.path(Expr.viewer(M), Expr.path(M.relations.team, T.fields.id))\nconst gold = Expr.exists(B.relations.member, Expr.eq(B.fields.kind, 'gold'))\n\nexport const relationalCases: ReadonlyArray<RelationalCase> = [\n // ---- a path's field ---------------------------------------------------------\n {\n what: 'a path reads a field of the row its relation points at',\n body: members.pipe(Query.where(Expr.eq(teamName, 'Red'))),\n input: {},\n expected: ['m1', 'm5'],\n },\n {\n what: 'a path reads null through a null link, and through a row the reader may not see',\n body: members.pipe(Query.where(Expr.isNull(teamName))),\n input: {},\n expected: ['m3', 'm4'],\n },\n {\n what: \"a path's null is unknown under not, so neither side keeps the row\",\n body: members.pipe(Query.where(Expr.not(Expr.eq(teamName, 'Red')))),\n input: {},\n expected: ['m2'],\n },\n {\n what: 'a path reads a null field of the row reached as null',\n body: members.pipe(Query.where(Expr.isNull(Expr.path(M.relations.team, T.fields.region)))),\n input: {},\n expected: ['m2', 'm3', 'm4'],\n },\n {\n what: 'a path compares with an input',\n body: members.pipe(\n Query.where(\n Expr.eq(Expr.path(M.relations.team, T.fields.region), Expr.input('region', Schema.String)),\n ),\n ),\n input: { region: 'eu' },\n expected: ['m1', 'm5'],\n },\n {\n what: \"contains folds a path's text as it folds a field's\",\n body: members.pipe(Query.where(Expr.contains(teamName, 'E'))),\n input: {},\n expected: ['m1', 'm2', 'm5'],\n },\n {\n what: \"a comparison orders a path's text under the collation it names\",\n body: members.pipe(Query.where(Expr.lt(teamName, 'C', { collation: Collation.binary }))),\n input: {},\n expected: ['m2'],\n },\n {\n what: 'a path follows two relations',\n body: badges.pipe(\n Query.where(\n Expr.eq(Expr.path(B.relations.member, Expr.path(M.relations.team, T.fields.name)), 'Red'),\n ),\n ),\n input: {},\n expected: ['b1', 'b2'],\n },\n {\n what: 'a path of two relations reads null where either reaches no row or the field is null',\n body: badges.pipe(\n Query.where(\n Expr.isNull(Expr.path(B.relations.member, Expr.path(M.relations.team, T.fields.region))),\n ),\n ),\n input: {},\n expected: ['b3', 'b5'],\n },\n {\n what: \"in tests a path's value against a list\",\n body: badges.pipe(Query.where(Expr.in(Expr.path(B.relations.member, M.fields.rank), [1, 4]))),\n input: {},\n expected: ['b1', 'b2', 'b5'],\n },\n\n // ---- exists -----------------------------------------------------------------\n {\n what: 'exists finds a row pointing here, and never one the reader may not see',\n body: members.pipe(Query.where(Expr.exists(B.relations.member))),\n input: {},\n expected: ['m1', 'm2', 'm4'],\n },\n {\n what: 'exists holds when a pointing row holds its filter',\n body: members.pipe(Query.where(gold)),\n input: {},\n expected: ['m1', 'm2'],\n },\n {\n what: 'exists is never unknown, so its not keeps every other row',\n body: members.pipe(Query.where(Expr.not(gold))),\n input: {},\n expected: ['m3', 'm4', 'm5'],\n },\n {\n what: \"an exists' filter reads the input\",\n body: members.pipe(\n Query.where(\n Expr.exists(B.relations.member, Expr.eq(B.fields.kind, Expr.input('kind', Schema.String))),\n ),\n ),\n input: { kind: 'silver' },\n expected: ['m1', 'm4'],\n },\n {\n what: \"or holds by either side, an exists or the row's own field\",\n body: members.pipe(Query.where(Expr.or(Expr.eq(M.fields.rank, 5), gold))),\n input: {},\n expected: ['m1', 'm2', 'm5'],\n },\n {\n what: 'and joins a path and the negation of an exists',\n body: members.pipe(\n Query.where(Expr.and(Expr.isNotNull(teamName), Expr.not(Expr.exists(B.relations.member)))),\n ),\n input: {},\n expected: ['m5'],\n },\n {\n what: \"an exists' filter folds text as contains does\",\n body: teams.pipe(\n Query.where(Expr.exists(M.relations.team, Expr.contains(M.fields.handle, 'E'))),\n ),\n input: {},\n expected: ['t1'],\n },\n {\n what: 'not of an exists holds where no pointing row holds the filter',\n body: teams.pipe(\n Query.where(Expr.not(Expr.exists(M.relations.team, Expr.gte(M.fields.rank, 5)))),\n ),\n input: {},\n expected: ['t2'],\n },\n\n // ---- an exists at the end of a path ----------------------------------------\n {\n what: 'an exists asked of the row a path reaches',\n body: members.pipe(Query.where(topPin)),\n input: {},\n expected: ['m1', 'm5'],\n },\n {\n what: 'an exists through a path that reaches no row is unknown, so its not keeps neither',\n body: members.pipe(Query.where(Expr.not(topPin))),\n input: {},\n expected: ['m2'],\n },\n\n // ---- a path from the viewer -------------------------------------------------\n {\n what: \"a path from the viewer reads their team's name, on the table it judges\",\n body: members.pipe(Query.where(Expr.eq(teamName, viewerTeam))),\n input: {},\n viewer: member('m1'),\n expected: ['m1', 'm5'],\n },\n {\n what: \"a path from the viewer reaches another table's row\",\n body: teams.pipe(Query.where(Expr.eq(T.fields.id, viewerTeamId))),\n input: {},\n viewer: member('m2'),\n expected: ['t2'],\n },\n {\n what: 'a path from the viewer reads null through a team the reader may not see',\n body: members.pipe(Query.where(Expr.isNull(viewerTeam))),\n input: {},\n viewer: member('m4'),\n expected: ['m1', 'm2', 'm3', 'm4', 'm5'],\n },\n {\n what: 'a path from the viewer reads null through a null link',\n body: teams.pipe(Query.where(Expr.isNull(viewerTeamId))),\n input: {},\n viewer: member('m3'),\n expected: ['t1', 't2'],\n },\n {\n what: 'a path from a viewer the reader may not see reads null, as a path to that row does',\n body: teams.pipe(Query.where(Expr.isNull(Expr.path(Expr.viewer(T), T.fields.name)))),\n input: {},\n viewer: { entity: 'Team', id: 't3' },\n expected: ['t1', 't2'],\n },\n {\n what: 'a path from a visitor reaches no row, so a comparison with it keeps none',\n body: teams.pipe(Query.where(Expr.not(Expr.eq(T.fields.id, viewerTeamId)))),\n input: {},\n viewer: null,\n expected: [],\n },\n]\n\n/** The tables a holder has, from what the reader may see of each, and which rows it judges. */\nexport interface HeldWorld {\n readonly what: string\n readonly tables: ReadonlyArray<HeldTable>\n}\n\nconst held = (\n change: (table: RelationalTable) => Partial<Omit<HeldTable, 'entity'>>,\n): ReadonlyArray<HeldTable> =>\n relationalTables.map(table => ({ entity: table.entity, rows: table.visible, ...change(table) }))\n\nconst named = (table: RelationalTable, entity: AnyEntity): boolean =>\n table.entity.identity.token === entity.identity.token\n\n/** A record without the keys named. */\nconst without = (row: RelationalRow, keys: ReadonlyArray<string>): RelationalRow =>\n Object.fromEntries(Object.entries(row).filter(([key]) => !keys.includes(key)))\n\n/**\n * What a holder might have, first everything the reader may see. Each later\n * one lacks something a case reads, so some judgement in it is unknown.\n */\nexport const heldWorlds: ReadonlyArray<HeldWorld> = [\n { what: 'everything the reader may see', tables: held(() => ({})) },\n {\n what: 'no team',\n tables: held(table => (named(table, T) ? { rows: [], complete: false } : {})),\n },\n {\n what: 'every other row of each table',\n tables: held(table => ({\n rows: table.visible.filter((_, index) => index % 2 === 0),\n complete: false,\n })),\n },\n {\n what: \"a team's name and region hidden\",\n tables: held(table => (named(table, T) ? { hidden: ['name', 'region'] } : {})),\n },\n {\n what: 'no badge, and not every pin',\n tables: held(table =>\n named(table, B)\n ? { rows: [], complete: false }\n : named(table, P)\n ? { rows: table.visible.slice(1), complete: false }\n : {},\n ),\n },\n {\n what: 'no link held',\n tables: held(table => ({\n rows: table.visible.map(row => without(row, ['team', 'member'])),\n })),\n },\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA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;AACF"}
@@ -0,0 +1,47 @@
1
+ import { Schema } from "effect";
2
+ import { ConformanceCase } from "./index.js";
3
+ export declare const Variant: import("../index.js").VariantEntity<"Variant", import("../variants.js").StoredFields<{
4
+ readonly Priced: {
5
+ id: Schema.String;
6
+ label: Schema.String;
7
+ cents: Schema.Int;
8
+ };
9
+ readonly Free: {
10
+ id: Schema.String;
11
+ label: Schema.String;
12
+ };
13
+ readonly Held: {
14
+ id: Schema.String;
15
+ label: Schema.String;
16
+ cents: Schema.Int;
17
+ until: Schema.String;
18
+ };
19
+ }>, {}, {}, import("../variants.js").VariantUnion<{
20
+ readonly Priced: {
21
+ id: Schema.String;
22
+ label: Schema.String;
23
+ cents: Schema.Int;
24
+ };
25
+ readonly Free: {
26
+ id: Schema.String;
27
+ label: Schema.String;
28
+ };
29
+ readonly Held: {
30
+ id: Schema.String;
31
+ label: Schema.String;
32
+ cents: Schema.Int;
33
+ until: Schema.String;
34
+ };
35
+ }>>;
36
+ /** A stored row: every field of every case, null where the row is of another. */
37
+ export interface VariantRow {
38
+ readonly _tag: 'Priced' | 'Free' | 'Held';
39
+ readonly id: string;
40
+ readonly label: string;
41
+ readonly cents: number | null;
42
+ readonly until: string | null;
43
+ readonly [key: string]: unknown;
44
+ }
45
+ export declare const variantRows: ReadonlyArray<VariantRow>;
46
+ export declare const variantCases: ReadonlyArray<ConformanceCase>;
47
+ //# sourceMappingURL=variants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variants.d.ts","names":[],"sources":["../../src/conformance/variants.ts"],"mappings":";;qBAea,+BAAO,kDAAA;;IACR,IAAE,OAAA;IAAiB,OAAK,OAAA;IAAiB,OAAK,OAAA;;;IAChD,IAAE,OAAA;IAAiB,OAAK,OAAA;;;IACxB,IAAE,OAAA;IAAiB,OAAK,OAAA;IAAiB,OAAK,OAAA;IAAS,OAAK,OAAA;;;;;;;;;;;;;;;;;;;;iBAIrD;WACN;WACA;WACA;WACA;WACA;YACC;;qBAGC,aAAa,cAAc;qBAW3B,cAAc,cAAc"}
@@ -0,0 +1,126 @@
1
+ import { Schema } from "effect";
2
+ import { Entity, Expr, Order, Query } from "../index.js";
3
+ // src/conformance/variants.ts
4
+ /**
5
+ * Variants (#357): an Entity whose rows are one of several cases, stored as one
6
+ * row with `_tag` and a nullable column per case field. `Expr.is` compiles to
7
+ * `_tag = case` and what is asked of the case, so an interpreter runs it with
8
+ * the operations it has; these cases pin that a row of another case is false
9
+ * under `Expr.is`, while the stored column is null there and unknown under a
10
+ * comparison.
11
+ */
12
+ /** `cents` is shared by `Priced` and `Held`, so one nullable column serves two cases. */
13
+ const Cents = Schema.Int;
14
+ const Variant = Entity.defineVariants("Variant", {
15
+ Priced: {
16
+ id: Schema.String,
17
+ label: Schema.String,
18
+ cents: Cents
19
+ },
20
+ Free: {
21
+ id: Schema.String,
22
+ label: Schema.String
23
+ },
24
+ Held: {
25
+ id: Schema.String,
26
+ label: Schema.String,
27
+ cents: Cents,
28
+ until: Schema.String
29
+ }
30
+ });
31
+ const variantRows = [
32
+ {
33
+ _tag: "Priced",
34
+ id: "p1",
35
+ label: "Mug",
36
+ cents: 500,
37
+ until: null
38
+ },
39
+ {
40
+ _tag: "Priced",
41
+ id: "p2",
42
+ label: "Lamp",
43
+ cents: 1500,
44
+ until: null
45
+ },
46
+ {
47
+ _tag: "Free",
48
+ id: "f1",
49
+ label: "Sticker",
50
+ cents: null,
51
+ until: null
52
+ },
53
+ {
54
+ _tag: "Held",
55
+ id: "h1",
56
+ label: "Chair",
57
+ cents: 900,
58
+ until: "2026-02-01"
59
+ }
60
+ ];
61
+ const from = Query.from(Variant);
62
+ const byId = Query.orderBy(Order.asc(Variant.fields.id));
63
+ const cheapPriced = Expr.is(Variant, "Priced", ({ cents }) => Expr.lt(cents, 1e3));
64
+ const variantCases = [
65
+ {
66
+ what: "is matches the rows of a case",
67
+ body: from.pipe(Query.where(Expr.is(Variant, "Priced")), byId),
68
+ input: {},
69
+ expected: ["p1", "p2"]
70
+ },
71
+ {
72
+ what: "is asks of the case’s fields",
73
+ body: from.pipe(Query.where(cheapPriced), byId),
74
+ input: {},
75
+ expected: ["p1"]
76
+ },
77
+ {
78
+ what: "not of is holds on every other case, which is false and never unknown",
79
+ body: from.pipe(Query.where(Expr.not(cheapPriced)), byId),
80
+ input: {},
81
+ expected: [
82
+ "f1",
83
+ "h1",
84
+ "p2"
85
+ ]
86
+ },
87
+ {
88
+ what: "a stored case field is null on another case, so a comparison drops that row",
89
+ body: from.pipe(Query.where(Expr.lt(Variant.fields.cents, 1e3)), byId),
90
+ input: {},
91
+ expected: ["h1", "p1"]
92
+ },
93
+ {
94
+ what: "and so does its not",
95
+ body: from.pipe(Query.where(Expr.not(Expr.lt(Variant.fields.cents, 1e3))), byId),
96
+ input: {},
97
+ expected: ["p2"]
98
+ },
99
+ {
100
+ what: "a case field is never null within its case",
101
+ body: from.pipe(Query.where(Expr.is(Variant, "Priced", ({ cents }) => Expr.isNull(cents))), byId),
102
+ input: {},
103
+ expected: []
104
+ },
105
+ {
106
+ what: "a field of one case is read within it",
107
+ body: from.pipe(Query.where(Expr.is(Variant, "Held", ({ until }) => Expr.eq(until, "2026-02-01"))), byId),
108
+ input: {},
109
+ expected: ["h1"]
110
+ },
111
+ {
112
+ what: "several cases are an in over _tag",
113
+ body: from.pipe(Query.where(Expr.in(Variant.fields._tag, ["Free", "Held"])), byId),
114
+ input: {},
115
+ expected: ["f1", "h1"]
116
+ },
117
+ {
118
+ what: "cases combine under or",
119
+ body: from.pipe(Query.where(Expr.or(Expr.is(Variant, "Free"), Expr.is(Variant, "Priced", ({ cents }) => Expr.gt(cents, 1e3)))), byId),
120
+ input: {},
121
+ expected: ["f1", "p2"]
122
+ }
123
+ ];
124
+ export { Variant, variantCases, variantRows };
125
+
126
+ //# sourceMappingURL=variants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variants.js","names":[],"sources":["../../src/conformance/variants.ts"],"sourcesContent":["/**\n * Variants (#357): an Entity whose rows are one of several cases, stored as one\n * row with `_tag` and a nullable column per case field. `Expr.is` compiles to\n * `_tag = case` and what is asked of the case, so an interpreter runs it with\n * the operations it has; these cases pin that a row of another case is false\n * under `Expr.is`, while the stored column is null there and unknown under a\n * comparison.\n */\nimport { Schema } from 'effect'\nimport { Entity, Expr, Order, Query } from '../index.js'\nimport type { ConformanceCase } from './index.js'\n\n/** `cents` is shared by `Priced` and `Held`, so one nullable column serves two cases. */\nconst Cents = Schema.Int\n\nexport const Variant = Entity.defineVariants('Variant', {\n Priced: { id: Schema.String, label: Schema.String, cents: Cents },\n Free: { id: Schema.String, label: Schema.String },\n Held: { id: Schema.String, label: Schema.String, cents: Cents, until: Schema.String },\n})\n\n/** A stored row: every field of every case, null where the row is of another. */\nexport interface VariantRow {\n readonly _tag: 'Priced' | 'Free' | 'Held'\n readonly id: string\n readonly label: string\n readonly cents: number | null\n readonly until: string | null\n readonly [key: string]: unknown\n}\n\nexport const variantRows: ReadonlyArray<VariantRow> = [\n { _tag: 'Priced', id: 'p1', label: 'Mug', cents: 500, until: null },\n { _tag: 'Priced', id: 'p2', label: 'Lamp', cents: 1500, until: null },\n { _tag: 'Free', id: 'f1', label: 'Sticker', cents: null, until: null },\n { _tag: 'Held', id: 'h1', label: 'Chair', cents: 900, until: '2026-02-01' },\n]\n\nconst from = Query.from(Variant)\nconst byId = Query.orderBy(Order.asc(Variant.fields.id))\nconst cheapPriced = Expr.is(Variant, 'Priced', ({ cents }) => Expr.lt(cents, 1000))\n\nexport const variantCases: ReadonlyArray<ConformanceCase> = [\n {\n what: 'is matches the rows of a case',\n body: from.pipe(Query.where(Expr.is(Variant, 'Priced')), byId),\n input: {},\n expected: ['p1', 'p2'],\n },\n {\n what: 'is asks of the case’s fields',\n body: from.pipe(Query.where(cheapPriced), byId),\n input: {},\n expected: ['p1'],\n },\n {\n what: 'not of is holds on every other case, which is false and never unknown',\n body: from.pipe(Query.where(Expr.not(cheapPriced)), byId),\n input: {},\n expected: ['f1', 'h1', 'p2'],\n },\n {\n what: 'a stored case field is null on another case, so a comparison drops that row',\n body: from.pipe(Query.where(Expr.lt(Variant.fields.cents, 1000)), byId),\n input: {},\n expected: ['h1', 'p1'],\n },\n {\n what: 'and so does its not',\n body: from.pipe(Query.where(Expr.not(Expr.lt(Variant.fields.cents, 1000))), byId),\n input: {},\n expected: ['p2'],\n },\n {\n what: 'a case field is never null within its case',\n body: from.pipe(\n Query.where(Expr.is(Variant, 'Priced', ({ cents }) => Expr.isNull(cents))),\n byId,\n ),\n input: {},\n expected: [],\n },\n {\n what: 'a field of one case is read within it',\n body: from.pipe(\n Query.where(Expr.is(Variant, 'Held', ({ until }) => Expr.eq(until, '2026-02-01'))),\n byId,\n ),\n input: {},\n expected: ['h1'],\n },\n {\n what: 'several cases are an in over _tag',\n body: from.pipe(Query.where(Expr.in(Variant.fields._tag, ['Free', 'Held'])), byId),\n input: {},\n expected: ['f1', 'h1'],\n },\n {\n what: 'cases combine under or',\n body: from.pipe(\n Query.where(\n Expr.or(\n Expr.is(Variant, 'Free'),\n Expr.is(Variant, 'Priced', ({ cents }) => Expr.gt(cents, 1000)),\n ),\n ),\n byId,\n ),\n input: {},\n expected: ['f1', 'p2'],\n },\n]\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,QAAQ,OAAO;AAErB,MAAa,UAAU,OAAO,eAAe,WAAW;CACtD,QAAQ;EAAE,IAAI,OAAO;EAAQ,OAAO,OAAO;EAAQ,OAAO;CAAM;CAChE,MAAM;EAAE,IAAI,OAAO;EAAQ,OAAO,OAAO;CAAO;CAChD,MAAM;EAAE,IAAI,OAAO;EAAQ,OAAO,OAAO;EAAQ,OAAO;EAAO,OAAO,OAAO;CAAO;AACtF,CAAC;AAYD,MAAa,cAAyC;CACpD;EAAE,MAAM;EAAU,IAAI;EAAM,OAAO;EAAO,OAAO;EAAK,OAAO;CAAK;CAClE;EAAE,MAAM;EAAU,IAAI;EAAM,OAAO;EAAQ,OAAO;EAAM,OAAO;CAAK;CACpE;EAAE,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