foldkit-entity 0.13.0 → 0.15.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 (119) hide show
  1. package/README.md +962 -512
  2. package/dist/collation.d.ts +33 -0
  3. package/dist/collation.d.ts.map +1 -0
  4. package/dist/collation.js +46 -0
  5. package/dist/collation.js.map +1 -0
  6. package/dist/conformance/index.d.ts +66 -0
  7. package/dist/conformance/index.d.ts.map +1 -0
  8. package/dist/conformance/{index.mjs → index.js} +22 -360
  9. package/dist/conformance/index.js.map +1 -0
  10. package/dist/conformance/operator.d.ts +115 -0
  11. package/dist/conformance/operator.d.ts.map +1 -0
  12. package/dist/conformance/operator.js +354 -0
  13. package/dist/conformance/operator.js.map +1 -0
  14. package/dist/conformance/relational.d.ts +240 -0
  15. package/dist/conformance/relational.d.ts.map +1 -0
  16. package/dist/conformance/relational.js +425 -0
  17. package/dist/conformance/relational.js.map +1 -0
  18. package/dist/conformance/tuples.d.ts +8 -0
  19. package/dist/conformance/tuples.d.ts.map +1 -0
  20. package/dist/conformance/tuples.js +43 -0
  21. package/dist/conformance/tuples.js.map +1 -0
  22. package/dist/conformance/variants.d.ts +47 -0
  23. package/dist/conformance/variants.d.ts.map +1 -0
  24. package/dist/conformance/variants.js +126 -0
  25. package/dist/conformance/variants.js.map +1 -0
  26. package/dist/context.d.ts +60 -0
  27. package/dist/context.d.ts.map +1 -0
  28. package/dist/context.js +36 -0
  29. package/dist/context.js.map +1 -0
  30. package/dist/descriptor.d.ts +33 -0
  31. package/dist/descriptor.d.ts.map +1 -0
  32. package/dist/descriptor.js +137 -0
  33. package/dist/descriptor.js.map +1 -0
  34. package/dist/entity.d.ts +231 -0
  35. package/dist/entity.d.ts.map +1 -0
  36. package/dist/entity.js +435 -0
  37. package/dist/entity.js.map +1 -0
  38. package/dist/evaluate.d.ts +204 -0
  39. package/dist/evaluate.d.ts.map +1 -0
  40. package/dist/evaluate.js +765 -0
  41. package/dist/evaluate.js.map +1 -0
  42. package/dist/expr.d.ts +915 -0
  43. package/dist/expr.d.ts.map +1 -0
  44. package/dist/expr.js +1630 -0
  45. package/dist/expr.js.map +1 -0
  46. package/dist/held.d.ts +112 -0
  47. package/dist/held.d.ts.map +1 -0
  48. package/dist/held.js +155 -0
  49. package/dist/held.js.map +1 -0
  50. package/dist/ids.d.ts +8 -0
  51. package/dist/ids.d.ts.map +1 -0
  52. package/dist/ids.js +8 -0
  53. package/dist/ids.js.map +1 -0
  54. package/dist/index.d.ts +380 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +110 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/invariant.d.ts +123 -0
  59. package/dist/invariant.d.ts.map +1 -0
  60. package/dist/invariant.js +236 -0
  61. package/dist/invariant.js.map +1 -0
  62. package/dist/jsonSchema.d.ts +3 -0
  63. package/dist/jsonSchema.d.ts.map +1 -0
  64. package/dist/jsonSchema.js +17 -0
  65. package/dist/jsonSchema.js.map +1 -0
  66. package/dist/law.d.ts +264 -0
  67. package/dist/law.d.ts.map +1 -0
  68. package/dist/law.js +111 -0
  69. package/dist/law.js.map +1 -0
  70. package/dist/operators.d.ts +170 -0
  71. package/dist/operators.d.ts.map +1 -0
  72. package/dist/operators.js +207 -0
  73. package/dist/operators.js.map +1 -0
  74. package/dist/readFilter.d.ts +8 -0
  75. package/dist/readFilter.d.ts.map +1 -0
  76. package/dist/readFilter.js +23 -0
  77. package/dist/readFilter.js.map +1 -0
  78. package/dist/record.d.ts +11 -0
  79. package/dist/record.d.ts.map +1 -0
  80. package/dist/record.js +21 -0
  81. package/dist/record.js.map +1 -0
  82. package/dist/sets.d.ts +18 -0
  83. package/dist/sets.d.ts.map +1 -0
  84. package/dist/sets.js +57 -0
  85. package/dist/sets.js.map +1 -0
  86. package/dist/shape.d.ts +23 -0
  87. package/dist/shape.d.ts.map +1 -0
  88. package/dist/shape.js +30 -0
  89. package/dist/shape.js.map +1 -0
  90. package/dist/tested.d.ts +8 -0
  91. package/dist/tested.d.ts.map +1 -0
  92. package/dist/tested.js +25 -0
  93. package/dist/tested.js.map +1 -0
  94. package/dist/text.d.ts +27 -0
  95. package/dist/text.d.ts.map +1 -0
  96. package/dist/text.js +39 -0
  97. package/dist/text.js.map +1 -0
  98. package/dist/variants.d.ts +72 -0
  99. package/dist/variants.d.ts.map +1 -0
  100. package/dist/variants.js +76 -0
  101. package/dist/variants.js.map +1 -0
  102. package/dist/words.d.ts +17 -0
  103. package/dist/words.d.ts.map +1 -0
  104. package/dist/words.js +22 -0
  105. package/dist/words.js.map +1 -0
  106. package/dist/write.d.ts +312 -0
  107. package/dist/write.d.ts.map +1 -0
  108. package/dist/write.js +520 -0
  109. package/dist/write.js.map +1 -0
  110. package/package.json +8 -8
  111. package/dist/conformance/index.d.mts +0 -274
  112. package/dist/conformance/index.d.mts.map +0 -1
  113. package/dist/conformance/index.mjs.map +0 -1
  114. package/dist/index-hu8IYlNc.d.mts +0 -2228
  115. package/dist/index-hu8IYlNc.d.mts.map +0 -1
  116. package/dist/index.d.mts +0 -2
  117. package/dist/index.mjs +0 -1
  118. package/dist/src-DBAilaDV.mjs +0 -3061
  119. package/dist/src-DBAilaDV.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/conformance/index.ts"],"sourcesContent":["/**\n * The conformance suite for a query body: what\n * [data-query-DESIGN §6.0.1](../../../../docs/design/data-query-DESIGN.md) says\n * each operator means, as cases an interpreter can be run against.\n *\n * Exported rather than kept in this repository's tests, because the interpreter\n * most worth checking against it is one written elsewhere: run every case\n * through yours and compare the ids, in order, against `expected`.\n *\n * §18 names portable-kernel conformance as what the reference interpreter is\n * for. This is that, extracted: one set of cases, run against every interpreter\n * rather than each interpreter having its own tests that happen to agree.\n * `foldkit-remote-server` runs them over rows in memory;\n * `foldkit-remote-drizzle` compiles them to SQL and runs them against a real\n * SQLite. A body that means two things fails in whichever is wrong.\n *\n * The cases are chosen to make interpreters *disagree*, which is the only kind\n * that tests anything. A fixture whose values are all lowercase cannot tell a\n * case-sensitive `contains` from a case-insensitive one — that is not a\n * hypothetical, it is how `contains` reached a released package meaning three\n * different things.\n */\nimport { Schema, SchemaGetter } from 'effect'\nimport { Collation, Entity, Expr, Order, Query, Text, type AnyQuery } from '../index.js'\n\n/**\n * A `Date` on the way in, an ISO string on the wire — the one fixture whose\n * **encoded form differs from its decoded form**.\n *\n * Every other column here encodes to itself, which is why the suite could not\n * previously see an interpreter comparing a decoded value against an encoded\n * row. That is not a hypothetical bug: a store holds wire values and decodes at\n * read, while a `QueryRef`'s input and a body's literals are written in domain\n * terms, so anything that runs a body over stored rows has to reconcile the two\n * and nothing was checking that it did.\n */\nconst Timestamp = Schema.Date.pipe(\n Schema.encodeTo(Schema.String, {\n decode: SchemaGetter.transform((iso: string) => new Date(iso)),\n encode: SchemaGetter.transform((at: Date) => at.toISOString()),\n }),\n)\n\n/** The one Entity every case reads, with a column of each kind that matters. */\nexport const Subject = Entity.define(\n 'Subject',\n Schema.Struct({\n id: Schema.String,\n /** Mixed case on purpose: a case-blind `contains` must be caught. */\n label: Schema.String,\n rank: Schema.Number,\n /** Nullable on purpose: three-valued logic has to be exercised. */\n tag: Schema.String,\n /** Encoded and decoded forms differ on purpose: see `Timestamp`. */\n at: Timestamp,\n }),\n)\n\n/**\n * How a row looks to an interpreter reading values, and to SQL as a table. The\n * index signature is what lets one be read by key without a cast, which is how\n * an interpreter over plain rows reads one.\n */\nexport interface ConformanceRow {\n readonly id: string\n readonly label: string\n readonly rank: number\n readonly tag: string | null\n /** The **encoded** form: what a store holds and an interpreter compares. */\n readonly at: string\n readonly [key: string]: unknown\n}\n\nexport const rows: ReadonlyArray<ConformanceRow> = [\n { id: 'a', label: 'Intro', rank: 2, tag: null, at: '2026-01-01T00:00:00.000Z' },\n { id: 'b', label: 'intro to sql', rank: 1, tag: 'x', at: '2026-01-02T00:00:00.000Z' },\n { id: 'c', label: 'Other', rank: 3, tag: null, at: '2026-01-02T00:00:00.000Z' },\n { id: 'd', label: '100% cotton', rank: 3, tag: 'x', at: '2026-01-03T00:00:00.000Z' },\n { id: 'e', label: 'snake_case', rank: 4, tag: 'y', at: '2026-01-04T00:00:00.000Z' },\n]\n\nexport interface ConformanceCase {\n /** What the case pins, as a sentence an interpreter fails by name. */\n readonly what: string\n readonly body: AnyQuery\n /**\n * The inputs, **encoded** — the space a store's rows are in, not the domain\n * space the body's types describe. For every column but `at` the two are the\n * same value, which is exactly why this has to be said rather than inferred\n * from the fixtures.\n */\n readonly input: Readonly<Record<string, unknown>>\n /** The ids the body matches, in the order it asks for. */\n readonly expected: ReadonlyArray<string>\n}\n\nconst from = Query.from(Subject)\nconst byId = Query.orderBy(Order.asc(Subject.fields.id))\nconst label = Expr.input('label', Schema.String)\nconst text = Expr.input('text', Schema.String)\nconst tag = Expr.input('tag', Schema.String)\nconst present = Expr.input('present', Schema.Boolean)\nconst labels = Expr.input('labels', Schema.Array(Schema.String))\nconst at = Expr.input('at', Timestamp)\n/** An optional filter's input: none chosen is null. */\nconst maybeTag = Expr.input('maybeTag', Schema.NullOr(Schema.String))\nconst below = Expr.input('below', Schema.Number)\nconst from_ = Expr.input('from', Timestamp)\nconst until = Expr.input('until', Timestamp)\nconst binary = { collation: Collation.binary }\n/** A list sorted by what its reader picked: `Order.chosen`'s input. */\nconst sort = Expr.input(\n 'sort',\n Schema.NullOr(\n Schema.Struct({ by: Schema.Literals(['rank']), direction: Schema.Literals(['asc', 'desc']) }),\n ),\n)\n/** Defined operators: an interpreter runs what each means, and needs nothing of its own. */\nconst tagged = Expr.operator('conformance.tagged', {\n input: [Schema.Unknown],\n output: Schema.Boolean,\n definedAs: value => Expr.isNotNull(value),\n})\nconst rankOf = Expr.operator('conformance.rankOf', {\n input: [Schema.Number],\n output: Schema.Number,\n definedAs: rank => rank,\n})\nconst chosen = Query.orderBy(\n Order.chosen(sort, { rank: Subject.fields.rank }),\n Order.asc(Subject.fields.id),\n)\n\nexport const cases: ReadonlyArray<ConformanceCase> = [\n // ---- eq ------------------------------------------------------------------\n {\n what: 'eq matches a field against a literal',\n body: from.pipe(Query.where(Expr.eq(Subject.fields.rank, 3)), byId),\n input: {},\n expected: ['c', 'd'],\n },\n {\n what: 'eq matches a field against the value the request supplies',\n body: from.pipe(Query.where(Expr.eq(Subject.fields.label, label)), byId),\n input: { label: 'Other' },\n expected: ['c'],\n },\n {\n what: 'eq is exact: a value that differs only by case does not match',\n body: from.pipe(Query.where(Expr.eq(Subject.fields.label, label)), byId),\n input: { label: 'other' },\n expected: [],\n },\n {\n what: 'eq against null matches nothing, not even the rows that are null',\n body: from.pipe(Query.where(Expr.eq(Subject.fields.tag, tag)), byId),\n input: { tag: null },\n expected: [],\n },\n {\n what: 'eq against a value skips the rows whose column is null',\n body: from.pipe(Query.where(Expr.eq(Subject.fields.tag, 'x')), byId),\n input: {},\n expected: ['b', 'd'],\n },\n\n // ---- isNull / isNotNull --------------------------------------------------\n {\n what: 'isNull finds exactly the rows with no value',\n body: from.pipe(Query.where(Expr.isNull(Subject.fields.tag)), byId),\n input: {},\n expected: ['a', 'c'],\n },\n {\n what: 'isNotNull finds exactly the rest',\n body: from.pipe(Query.where(Expr.isNotNull(Subject.fields.tag)), byId),\n input: {},\n expected: ['b', 'd', 'e'],\n },\n {\n what: 'a predicate compared to a true input is that predicate',\n body: from.pipe(Query.where(Expr.eq(Expr.isNotNull(Subject.fields.tag), present)), byId),\n input: { present: true },\n expected: ['b', 'd', 'e'],\n },\n {\n what: 'a predicate compared to a false input is its negation',\n body: from.pipe(Query.where(Expr.eq(Expr.isNotNull(Subject.fields.tag), present)), byId),\n input: { present: false },\n expected: ['a', 'c'],\n },\n ...[true, false].map(value => ({\n what: `a ${value} input compared to a predicate works in reverse order`,\n body: from.pipe(Query.where(Expr.eq(present, Expr.isNotNull(Subject.fields.tag))), byId),\n input: { present: value },\n expected: value ? ['b', 'd', 'e'] : ['a', 'c'],\n })),\n ...[true, false].map(value => ({\n what: `an unknown equality compared to ${value} stays unknown`,\n body: from.pipe(Query.where(Expr.eq(Expr.eq(Subject.fields.tag, tag), present)), byId),\n input: { tag: null, present: value },\n expected: [],\n })),\n\n // ---- contains ------------------------------------------------------------\n {\n what: 'contains ignores case, which is stated rather than left to the backend',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.label, label)), byId),\n input: { label: 'INTRO' },\n expected: ['a', 'b'],\n },\n {\n what: 'contains matches anywhere in the value, not only at the start',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.label, label)), byId),\n input: { label: 'to sql' },\n expected: ['b'],\n },\n {\n what: 'containing the empty string is everything',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.label, label)), byId),\n input: { label: '' },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n {\n what: 'a percent is searched for literally, not as a wildcard',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.label, label)), byId),\n input: { label: '%' },\n expected: ['d'],\n },\n {\n what: 'an underscore is searched for literally, not as a single-character wildcard',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.label, label)), byId),\n input: { label: '_' },\n expected: ['e'],\n },\n {\n what: 'contains over a null column drops those rows, so it is not the same as no filter',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.tag, label)), byId),\n input: { label: '' },\n expected: ['b', 'd', 'e'],\n },\n // The text searched is an input here so the fixture rows stay ASCII: each\n // case asks the same of every row, so it matches all of them or none.\n {\n what: 'contains folds ASCII letters only: an accented capital does not match its lowercase',\n body: from.pipe(Query.where(Expr.contains(text, label)), byId),\n input: { text: 'Élan', label: 'é' },\n expected: [],\n },\n {\n what: 'contains still matches a non-ASCII letter written the same way',\n body: from.pipe(Query.where(Expr.contains(text, label)), byId),\n input: { text: 'Élan', label: 'Él' },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n {\n what: 'contains with a null search is unknown for every row',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.label, label)), byId),\n input: { label: null },\n expected: [],\n },\n {\n what: 'an unknown containment compared to false stays unknown',\n body: from.pipe(Query.where(Expr.eq(Expr.contains(Subject.fields.label, label), false)), byId),\n input: { label: null },\n expected: [],\n },\n\n // ---- in ------------------------------------------------------------------\n {\n what: 'in matches a field against a list written out',\n body: from.pipe(Query.where(Expr.in(Subject.fields.rank, [1, 4])), byId),\n input: {},\n expected: ['b', 'e'],\n },\n {\n what: 'in matches a field against the list the request supplies, exactly',\n body: from.pipe(Query.where(Expr.in(Subject.fields.label, labels)), byId),\n input: { labels: ['Other', 'intro'] },\n expected: ['c'],\n },\n {\n what: 'in against an empty list matches nothing',\n body: from.pipe(Query.where(Expr.in(Subject.fields.label, labels)), byId),\n input: { labels: [] },\n expected: [],\n },\n {\n what: 'in skips the rows whose column is null',\n body: from.pipe(Query.where(Expr.in(Subject.fields.tag, ['x', 'y'])), byId),\n input: {},\n expected: ['b', 'd', 'e'],\n },\n {\n what: 'in compared to false is its negation, and a null column stays unknown',\n body: from.pipe(Query.where(Expr.eq(Expr.in(Subject.fields.tag, ['x']), present)), byId),\n input: { present: false },\n expected: ['e'],\n },\n {\n what: 'in against an empty list compared to false matches every row, null or not',\n body: from.pipe(Query.where(Expr.eq(Expr.in(Subject.fields.tag, labels), present)), byId),\n input: { labels: [], present: false },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n\n {\n what: 'in asks of an input as of a field: every row, when the input is listed',\n body: from.pipe(Query.where(Expr.in(text, ['x', 'y'])), byId),\n input: { text: 'y' },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n {\n what: 'in asks of an input against an empty list: no row',\n body: from.pipe(Query.where(Expr.in(text, labels)), byId),\n input: { text: 'y', labels: [] },\n expected: [],\n },\n\n // ---- conjunction, which is the list rather than an operator ---------------\n {\n what: 'two predicates conjoin: every one must hold',\n body: from.pipe(\n Query.where(Expr.eq(Subject.fields.rank, 3), Expr.isNotNull(Subject.fields.tag)),\n byId,\n ),\n input: {},\n expected: ['d'],\n },\n {\n what: 'no predicate at all is every row',\n body: from.pipe(byId),\n input: {},\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n\n // ---- and, or, not: SQL's three values -----------------------------------\n // `tag` is null on a and c, so a comparison of it is unknown there, and a\n // row is kept only on true.\n {\n what: 'or holds where one operand does, true beating unknown',\n body: from.pipe(\n Query.where(Expr.or(Expr.eq(Subject.fields.tag, 'x'), Expr.eq(Subject.fields.rank, 2))),\n byId,\n ),\n input: {},\n expected: ['a', 'b', 'd'],\n },\n {\n what: 'an and inside an or groups as written',\n body: from.pipe(\n Query.where(\n Expr.or(\n Expr.and(Expr.eq(Subject.fields.rank, 3), Expr.eq(Subject.fields.tag, 'x')),\n Expr.eq(Subject.fields.label, 'Intro'),\n ),\n ),\n byId,\n ),\n input: {},\n expected: ['a', 'd'],\n },\n {\n what: 'not of an unknown stays unknown, so a null matches neither side',\n body: from.pipe(Query.where(Expr.not(Expr.eq(Subject.fields.tag, 'x'))), byId),\n input: {},\n expected: ['e'],\n },\n {\n what: 'not of an and that is false, false beating unknown, holds',\n body: from.pipe(\n Query.where(\n Expr.not(Expr.and(Expr.eq(Subject.fields.tag, 'x'), Expr.eq(Subject.fields.rank, 1))),\n ),\n byId,\n ),\n input: {},\n expected: ['a', 'c', 'd', 'e'],\n },\n {\n what: 'everything but one value, nulls included, is said with isNull',\n body: from.pipe(\n Query.where(\n Expr.or(Expr.isNull(Subject.fields.tag), Expr.not(Expr.eq(Subject.fields.tag, 'x'))),\n ),\n byId,\n ),\n input: {},\n expected: ['a', 'c', 'e'],\n },\n {\n what: 'an optional filter with nothing chosen matches every row',\n body: from.pipe(\n Query.where(Expr.whenGiven(maybeTag, given => Expr.eq(Subject.fields.tag, given))),\n byId,\n ),\n input: { maybeTag: null },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n {\n what: 'an optional filter with a value chosen is that filter',\n body: from.pipe(\n Query.where(Expr.whenGiven(maybeTag, given => Expr.eq(Subject.fields.tag, given))),\n byId,\n ),\n input: { maybeTag: 'x' },\n expected: ['b', 'd'],\n },\n {\n what: 'an operand decided by the input alone settles an or either way',\n body: from.pipe(\n Query.where(Expr.or(Expr.eq(present, true), Expr.eq(Subject.fields.rank, 1))),\n byId,\n ),\n input: { present: false },\n expected: ['b'],\n },\n // ---- comparisons -----------------------------------------------------------\n // Ranks are a 2, b 1, c 3, d 3, e 4; text only under a collation every\n // interpreter agrees on, and a date by its encoded ISO string.\n {\n what: 'lt holds where a number orders before the other',\n body: from.pipe(Query.where(Expr.lt(Subject.fields.rank, 3)), byId),\n input: {},\n expected: ['a', 'b'],\n },\n {\n what: 'gte holds where a number orders after the other, or with it',\n body: from.pipe(Query.where(Expr.gte(Subject.fields.rank, 3)), byId),\n input: {},\n expected: ['c', 'd', 'e'],\n },\n {\n what: 'a field written second compares the same: the input is above the rank',\n body: from.pipe(Query.where(Expr.gt(below, Expr.field(Subject.fields.rank))), byId),\n input: { below: 3 },\n expected: ['a', 'b'],\n },\n {\n what: 'a comparison that reads no field orders numbers as numbers: 9 is below 10',\n body: from.pipe(Query.where(Expr.lt(below, 10)), byId),\n input: { below: 9 },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n {\n what: 'a range of dates compares their encoded ISO strings under binary',\n body: from.pipe(\n Query.where(\n Expr.and(\n Expr.gte(Subject.fields.at, from_, binary),\n Expr.lt(Subject.fields.at, until, binary),\n ),\n ),\n byId,\n ),\n input: { from: '2026-01-02T00:00:00.000Z', until: '2026-01-04T00:00:00.000Z' },\n expected: ['b', 'c', 'd'],\n },\n {\n what: 'text under binary orders by code point: capitals and digits before lower case',\n body: from.pipe(Query.where(Expr.lt(Subject.fields.label, 'a', binary)), byId),\n input: {},\n expected: ['a', 'c', 'd'],\n },\n {\n what: 'text under asciiFold orders with ASCII case folded',\n body: from.pipe(\n Query.where(Expr.lt(Subject.fields.label, 'j', { collation: Collation.asciiFold })),\n byId,\n ),\n input: {},\n expected: ['a', 'b', 'd'],\n },\n {\n what: 'a null compared is unknown, so it matches neither the comparison nor its not',\n body: from.pipe(Query.where(Expr.gte(Subject.fields.tag, 'x', binary)), byId),\n input: {},\n expected: ['b', 'd', 'e'],\n },\n {\n what: 'not of a comparison leaves a null out too',\n body: from.pipe(Query.where(Expr.not(Expr.gte(Subject.fields.tag, 'x', binary))), byId),\n input: {},\n expected: [],\n },\n // ---- encoded values ------------------------------------------------------\n // The body's types say `Date`; a store's rows and a request's inputs are ISO\n // strings. An interpreter compares in the **encoded** space, and these are the\n // cases that say so — for every other column the two spaces hold the same\n // value, so nothing here could previously tell them apart.\n //\n // What happens when a caller passes a *decoded* value is deliberately not a\n // case, because the interpreters do not agree: the reference one matches\n // nothing, SQLite raises `datatype mismatch`, and a local engine does\n // whatever its own comparison does. `cases` are what interpreters must agree\n // about. The consequence is pinned in `packages/entity/test/encoding.test.ts`\n // instead, and it is the one that matters: **a runtime error cannot be relied\n // on to catch the mistake**, because one of the three answers is an empty\n // result that reads exactly like a correct one.\n {\n what: 'an input whose encoded form differs from its decoded one matches on the encoded one',\n body: from.pipe(Query.where(Expr.eq(Subject.fields.at, at)), byId),\n input: { at: '2026-01-02T00:00:00.000Z' },\n expected: ['b', 'c'],\n },\n {\n what: 'a literal is encoded too, or it has the same problem as an input',\n body: from.pipe(\n Query.where(Expr.eq(Subject.fields.at, '2026-01-03T00:00:00.000Z' as never)),\n byId,\n ),\n input: {},\n expected: ['d'],\n },\n\n // ---- ordering ------------------------------------------------------------\n {\n what: 'orders ascending by a number',\n body: from.pipe(Query.orderBy(Order.asc(Subject.fields.rank), Order.asc(Subject.fields.id))),\n input: {},\n expected: ['b', 'a', 'c', 'd', 'e'],\n },\n {\n what: 'orders descending, and a later term breaks the tie',\n body: from.pipe(Query.orderBy(Order.desc(Subject.fields.rank), Order.asc(Subject.fields.id))),\n input: {},\n expected: ['e', 'c', 'd', 'a', 'b'],\n },\n {\n what: 'puts rows without a value last ascending, unless told otherwise',\n body: from.pipe(Query.orderBy(Order.asc(Subject.fields.tag))),\n input: {},\n expected: ['b', 'd', 'e', 'a', 'c'],\n },\n {\n what: 'puts rows without a value first descending, unless told otherwise',\n body: from.pipe(Query.orderBy(Order.desc(Subject.fields.tag))),\n input: {},\n expected: ['a', 'c', 'e', 'b', 'd'],\n },\n {\n what: 'puts rows without a value first ascending when the term says so',\n body: from.pipe(Query.orderBy(Order.asc(Subject.fields.tag, { nulls: 'first' }))),\n input: {},\n expected: ['a', 'c', 'b', 'd', 'e'],\n },\n {\n what: 'puts rows without a value last descending when the term says so',\n body: from.pipe(Query.orderBy(Order.desc(Subject.fields.tag, { nulls: 'last' }))),\n input: {},\n expected: ['e', 'b', 'd', 'a', 'c'],\n },\n {\n what: 'breaks a tie by the id where the order does not say how',\n body: from.pipe(Query.orderBy(Order.desc(Subject.fields.rank))),\n input: {},\n expected: ['e', 'c', 'd', 'a', 'b'],\n },\n {\n what: 'orders by the field the input chose, ascending',\n body: from.pipe(chosen),\n input: { sort: { by: 'rank', direction: 'asc' } },\n expected: ['b', 'a', 'c', 'd', 'e'],\n },\n {\n what: 'orders by the field the input chose, descending, the next term breaking the tie',\n body: from.pipe(chosen),\n input: { sort: { by: 'rank', direction: 'desc' } },\n expected: ['e', 'c', 'd', 'a', 'b'],\n },\n {\n what: 'orders by the terms after a chosen order when the input chose none',\n body: from.pipe(chosen),\n input: { sort: null },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n // ---- text, ordered by a declared collation -------------------------------\n {\n what: 'orders text by code point under a binary collation',\n body: from.pipe(\n Query.orderBy(Order.asc(Subject.fields.label, { collation: Collation.binary })),\n ),\n input: {},\n expected: ['d', 'a', 'c', 'b', 'e'],\n },\n {\n what: 'orders text with ASCII case folded under an asciiFold collation',\n body: from.pipe(\n Query.orderBy(Order.asc(Subject.fields.label, { collation: Collation.asciiFold })),\n ),\n input: {},\n expected: ['d', 'a', 'b', 'c', 'e'],\n },\n // Ordering by text with no declared collation is deliberately not here. How text compares is the\n // backend's — SQLite by code point, TanStack by locale, Postgres by whatever\n // the database was created with — and §6.0.1 puts it outside the conformant\n // subset rather than pretending one of them is the rule. A case asserting an\n // order would only pin whichever engine was written first.\n\n // ---- defined operators -----------------------------------------------------\n {\n what: 'a defined operator matches the rows what it means does',\n body: from.pipe(Query.where(tagged(Subject.fields.tag)), byId),\n input: {},\n expected: ['b', 'd', 'e'],\n },\n {\n what: 'a defined operator under not is the negation of what it means',\n body: from.pipe(Query.where(Expr.not(tagged(Subject.fields.tag))), byId),\n input: {},\n expected: ['a', 'c'],\n },\n {\n what: 'a defined operator over an input only is decided by the request',\n body: from.pipe(Query.where(Expr.or(tagged(maybeTag), Expr.eq(Subject.fields.rank, 3))), byId),\n input: { maybeTag: null },\n expected: ['c', 'd'],\n },\n {\n what: 'a defined scalar operator compares as what it means',\n body: from.pipe(Query.where(Expr.eq(rankOf(Subject.fields.rank), 3)), byId),\n input: {},\n expected: ['c', 'd'],\n },\n]\n\nconst prefix = Expr.input('prefix', Schema.NullOr(Schema.String))\nconst asciiFold = { collation: Collation.asciiFold }\n\n/**\n * Bodies calling the kernel's primitive operators (`Text.startsWith`). An\n * interpreter runs these once it implements them: the in-memory one through\n * `Operators.kernel`, a compiler through its own table.\n */\nexport const primitiveCases: ReadonlyArray<ConformanceCase> = [\n {\n what: 'startsWith under binary is exact about case',\n body: from.pipe(Query.where(Text.startsWith(Subject.fields.label, 'In', binary)), byId),\n input: {},\n expected: ['a'],\n },\n {\n what: 'startsWith under asciiFold folds ASCII case on both sides',\n body: from.pipe(Query.where(Text.startsWith(Subject.fields.label, 'IN', asciiFold)), byId),\n input: {},\n expected: ['a', 'b'],\n },\n {\n what: 'startsWith the empty prefix holds for every row with text',\n body: from.pipe(Query.where(Text.startsWith(Subject.fields.label, prefix, binary)), byId),\n input: { prefix: '' },\n expected: ['a', 'b', 'c', 'd', 'e'],\n },\n {\n what: 'startsWith over null text is unknown, so its rows are not matched',\n body: from.pipe(Query.where(Text.startsWith(Subject.fields.tag, '', binary)), byId),\n input: {},\n expected: ['b', 'd', 'e'],\n },\n {\n what: 'startsWith a null prefix is unknown for every row',\n body: from.pipe(Query.where(Text.startsWith(Subject.fields.label, prefix, binary)), byId),\n input: { prefix: null },\n expected: [],\n },\n {\n what: 'startsWith reads % and _ as characters, never as like wildcards',\n body: from.pipe(\n Query.where(\n Expr.or(\n Text.startsWith(Subject.fields.label, '100%', binary),\n Text.startsWith(Subject.fields.label, 'sn_', binary),\n Text.startsWith(Subject.fields.label, 'O%', binary),\n ),\n ),\n byId,\n ),\n input: {},\n expected: ['d'],\n },\n {\n what: 'startsWith under not keeps a null unknown',\n body: from.pipe(Query.where(Expr.not(Text.startsWith(Subject.fields.tag, 'x', binary))), byId),\n input: {},\n expected: ['e'],\n },\n]\n\n/**\n * A body whose answer no two interpreters agree on, so every interpreter must\n * refuse it rather than answer. Run each through yours and expect a failure.\n */\nexport interface ConformanceRefusal {\n readonly what: string\n readonly body: AnyQuery\n /** The inputs, encoded, as in `ConformanceCase`. */\n readonly input: Readonly<Record<string, unknown>>\n}\n\nconst NUL = String.fromCharCode(0)\n\nexport const refusals: ReadonlyArray<ConformanceRefusal> = [\n // Postgres text cannot hold NUL and SQLite's `like` stops at it.\n {\n what: 'contains refuses a search holding NUL',\n body: from.pipe(Query.where(Expr.contains(Subject.fields.label, label)), byId),\n input: { label: `in${NUL}` },\n },\n {\n what: 'a comparison refuses text holding NUL',\n body: from.pipe(\n Query.where(Expr.lt(Subject.fields.label, label, { collation: Collation.binary })),\n byId,\n ),\n input: { label: `b${NUL}` },\n },\n {\n what: 'contains refuses searched text holding NUL',\n body: from.pipe(Query.where(Expr.contains(text, label)), byId),\n input: { text: `a${NUL}b`, label: 'b' },\n },\n // SQLite stores NaN as null; Postgres orders it after every number, equal to itself.\n {\n what: 'an equality refuses NaN',\n body: from.pipe(Query.where(Expr.eq(Subject.fields.rank, below)), byId),\n input: { below: Number.NaN },\n },\n {\n what: 'a comparison refuses NaN',\n body: from.pipe(Query.where(Expr.gt(Subject.fields.rank, below)), byId),\n input: { below: Number.NaN },\n },\n {\n what: 'a membership test refuses a list holding NaN',\n body: from.pipe(\n Query.where(Expr.in(Subject.fields.rank, Expr.input('ranks', Schema.Array(Schema.Number)))),\n byId,\n ),\n input: { ranks: [1, Number.NaN] },\n },\n]\n\n/** As `refusals`, for bodies calling the kernel's primitive operators. */\nexport const primitiveRefusals: ReadonlyArray<ConformanceRefusal> = [\n {\n what: 'startsWith refuses a prefix holding NUL',\n body: from.pipe(Query.where(Text.startsWith(Subject.fields.label, prefix, binary)), byId),\n input: { prefix: `In${NUL}` },\n },\n]\nexport * from './operator.js'\nexport * from './relational.js'\nexport * from './variants.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,YAAY,OAAO,KAAK,KAC5B,OAAO,SAAS,OAAO,QAAQ;CAC7B,QAAQ,aAAa,WAAW,QAAgB,IAAI,KAAK,GAAG,CAAC;CAC7D,QAAQ,aAAa,WAAW,OAAa,GAAG,YAAY,CAAC;AAC/D,CAAC,CACH;;AAGA,MAAa,UAAU,OAAO,OAC5B,WACA,OAAO,OAAO;CACZ,IAAI,OAAO;;CAEX,OAAO,OAAO;CACd,MAAM,OAAO;;CAEb,KAAK,OAAO;;CAEZ,IAAI;AACN,CAAC,CACH;AAiBA,MAAa,OAAsC;CACjD;EAAE,IAAI;EAAK,OAAO;EAAS,MAAM;EAAG,KAAK;EAAM,IAAI;CAA2B;CAC9E;EAAE,IAAI;EAAK,OAAO;EAAgB,MAAM;EAAG,KAAK;EAAK,IAAI;CAA2B;CACpF;EAAE,IAAI;EAAK,OAAO;EAAS,MAAM;EAAG,KAAK;EAAM,IAAI;CAA2B;CAC9E;EAAE,IAAI;EAAK,OAAO;EAAe,MAAM;EAAG,KAAK;EAAK,IAAI;CAA2B;CACnF;EAAE,IAAI;EAAK,OAAO;EAAc,MAAM;EAAG,KAAK;EAAK,IAAI;CAA2B;AACpF;AAiBA,MAAM,OAAO,MAAM,KAAK,OAAO;AAC/B,MAAM,OAAO,MAAM,QAAQ,MAAM,IAAI,QAA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AC,GAAG,IAAI;CACxF,OAAO,EAAE,QAAQ,KAAK,MAAM;AAC9B,CACF"}
@@ -0,0 +1,115 @@
1
+ import { Data, Option, Schema } from "effect";
2
+ import { Collation, LawDescription, MemoryOperators, Operandish, Operator, TestedEvidence } from "../index.js";
3
+ /** What an implementation said of one call: a value, or that it refused it. */
4
+ export type Outcome = Data.TaggedEnum<{
5
+ Value: {
6
+ readonly value: unknown;
7
+ };
8
+ Refused: {
9
+ readonly reason: string;
10
+ };
11
+ }>;
12
+ export declare const Outcome: Data.TaggedEnum.Constructor<{
13
+ readonly _tag: "Refused";
14
+ readonly reason: string;
15
+ } | {
16
+ readonly _tag: "Value";
17
+ readonly value: unknown;
18
+ }>;
19
+ /**
20
+ * What `Conformance.laws` found: every law held, with the evidence; the first
21
+ * case one did not; or a law no case of which both sides answered, which
22
+ * shows nothing of it.
23
+ */
24
+ export type LawsVerdict = Data.TaggedEnum<{
25
+ Holds: {
26
+ readonly evidence: ReadonlyArray<TestedEvidence>;
27
+ };
28
+ Unanswered: {
29
+ readonly law: LawDescription;
30
+ /** Why the first refused call was refused. */
31
+ readonly reason: string;
32
+ };
33
+ Counterexample: {
34
+ readonly law: LawDescription;
35
+ readonly args: ReadonlyArray<unknown>;
36
+ /** The collation the calls were made under, for an operator that compares text. */
37
+ readonly collation: Option.Option<Collation>;
38
+ readonly left: Outcome;
39
+ readonly right: Outcome;
40
+ };
41
+ }>;
42
+ export declare const LawsVerdict: Data.TaggedEnum.Constructor<{
43
+ readonly _tag: "Counterexample";
44
+ readonly law: LawDescription;
45
+ readonly args: ReadonlyArray<unknown>;
46
+ readonly collation: Option.Option<Collation>;
47
+ readonly left: Outcome;
48
+ readonly right: Outcome;
49
+ } | {
50
+ readonly _tag: "Holds";
51
+ readonly evidence: ReadonlyArray<TestedEvidence>;
52
+ } | {
53
+ readonly _tag: "Unanswered";
54
+ readonly law: LawDescription;
55
+ readonly reason: string;
56
+ }>;
57
+ /**
58
+ * One way to run a call: its value, or a throw for a call it refuses. A call
59
+ * of a predicate answers its truth, unknown as `null`.
60
+ */
61
+ export type Runner = (call: Operandish) => unknown;
62
+ /** A call the implementations did not agree on, with what each said. */
63
+ export interface Disagreement {
64
+ readonly args: ReadonlyArray<unknown>;
65
+ readonly collation: Option.Option<Collation>;
66
+ readonly outcomes: Readonly<Record<string, Outcome>>;
67
+ }
68
+ export interface OperatorReport {
69
+ /** How many calls ran, each through every implementation. */
70
+ readonly cases: number;
71
+ readonly disagreements: ReadonlyArray<Disagreement>;
72
+ }
73
+ export declare const Conformance: {
74
+ /** A runner of calls through a memory table: `Conformance.operator`'s for the in-memory interpreter. */
75
+ memory: (operators: MemoryOperators) => Runner;
76
+ /**
77
+ * Tests every law `op` declares against `operators`' implementation of it,
78
+ * up to `cases` tuples a law (200 by default), chosen by `seed` (0); a law
79
+ * of both sides checks each tuple from each. Holds with a `Tested` record a
80
+ * law, which `Operators.withEvidence` keeps; or the first case a law fails,
81
+ * with both sides.
82
+ */
83
+ laws: <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(op: Operator<In, Out>, operators: MemoryOperators, options?: {
84
+ readonly implementation?: string | undefined;
85
+ readonly cases?: number | undefined;
86
+ readonly seed?: number | undefined;
87
+ }) => LawsVerdict;
88
+ /**
89
+ * As `laws`, each call run by `run` instead of a memory table: an SQL
90
+ * implementation selected from a database, say, whose evidence a binding's
91
+ * SQL table records. A throw is a refusal.
92
+ */
93
+ lawsBy: <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(op: Operator<In, Out>, run: Runner, options: {
94
+ readonly implementation: string;
95
+ readonly cases?: number | undefined;
96
+ readonly seed?: number | undefined;
97
+ }) => Promise<LawsVerdict>;
98
+ /**
99
+ * Runs one set of calls of `op` through every implementation and compares
100
+ * what each answered or refused. The calls are `cases` (argument tuples, as
101
+ * stored), or generated: each argument a sample of its kind, null where its
102
+ * schema admits one, and text holding NUL, under `binary` and `asciiFold` where the operator compares
103
+ * text, up to `limit` (300) chosen by `seed` (0). A defined operator's
104
+ * expansion is run beside the others, as `expansion`, by `expansionTable`
105
+ * (the kernel's when not given).
106
+ */
107
+ operator: <In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(op: Operator<In, Out>, options: {
108
+ readonly implementations: Readonly<Record<string, Runner>>;
109
+ readonly cases?: ReadonlyArray<ReadonlyArray<unknown>> | undefined;
110
+ readonly limit?: number | undefined;
111
+ readonly seed?: number | undefined;
112
+ readonly expansionTable?: MemoryOperators | undefined;
113
+ }) => Promise<OperatorReport>;
114
+ };
115
+ //# sourceMappingURL=operator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operator.d.ts","names":[],"sources":["../../src/conformance/operator.ts"],"mappings":";;;YAiCY,UAAU,KAAK;EACzB;aAAkB;;EAClB;aAAoB;;;qBAET,SAAO,KAAA,WAAA;;WAFU;;;WADH;;;;;;;YAUf,cAAc,KAAK;EAC7B;aAAkB,UAAU,cAAc;;EAC1C;aACW,KAAK;;aAEL;;EAEX;aACW,KAAK;aACL,MAAM;;aAEN,WAAW,OAAO,OAAO;aACzB,MAAM;aACN,OAAO;;;qBAGP,aAAW,KAAA,WAAA;;WARN,KAAA;WACC,MAAA;WAEK,WAAA,OAAO,OAAO;WACnB,MAAA;WACC,OAAA;;;WAZU,UAAA,cAAc;;;WAE1B,KAAA;WAEG;;;;;;YAiBT,UAAU,MAAM;;iBAGX;WACN,MAAM;WACN,WAAW,OAAO,OAAO;WACzB,UAAU,SAAS,eAAe;;iBAG5B;;WAEN;WACA,eAAe,cAAc;;qBAuV3B;;EAEX,SAAM,WACQ,oBAAkB;;;;;;;;EAWhC,OAAO,WAAW,cAAc,OAAO,MAAM,YAAY,OAAO,KAAG,IAC7D,SAAS,IAAI,MAAI,WACV,iBAAe;aAEf;aACA;aACA;QAEV;;;;;;EAyBH,SAAe,WAAW,cAAc,OAAO,MAAM,YAAY,OAAO,KAAG,IACrE,SAAS,IAAI,MAAI,KAChB,QAAM;aAEA;aACA;aACA;QAEV,QAAQ;;;;;;;;;;EAkCX,WAAiB,WAAW,cAAc,OAAO,MAAM,YAAY,OAAO,KAAG,IACvE,SAAS,IAAI,MAAI;aAEV,iBAAiB,SAAS,eAAe;aACzC,QAAQ,cAAc;aACtB;aACA;aACA,iBAAiB;QAE3B,QAAQ"}
@@ -0,0 +1,354 @@
1
+ import { Data, Option, Schema, SchemaAST } from "effect";
2
+ import { Collation, Evidence, Expr, Law, Operators, QueryEvaluateError, valueOfOperand } from "../index.js";
3
+ import { stampRun, stampTested } from "../tested.js";
4
+ import { tuplesOf } from "./tuples.js";
5
+ // src/conformance/operator.ts
6
+ /**
7
+ * An operator held to what it declares (expr-operations-DESIGN §10.4): its
8
+ * laws tested against an implementation, and one set of calls run through
9
+ * every implementation given, their answers and refusals compared.
10
+ *
11
+ * Cases are drawn from a fixed sample of each kind of value (text with the
12
+ * empty string, mixed case, non-ASCII, an astral character and `like`'s
13
+ * wildcards; numbers with zero, negatives and a fraction; both booleans), kept
14
+ * where the operator's input schema and the law's domain decode them, and
15
+ * chosen by a seeded shuffle when there are more than asked for, so a run is
16
+ * repeatable.
17
+ */
18
+ const Outcome = Data.taggedEnum();
19
+ const LawsVerdict = Data.taggedEnum();
20
+ const NUL = String.fromCharCode(0);
21
+ const texts = [
22
+ "",
23
+ "a",
24
+ "A",
25
+ "ab",
26
+ "aB",
27
+ "b",
28
+ "B",
29
+ "é",
30
+ "É",
31
+ String.fromCodePoint(128512),
32
+ "%",
33
+ "_",
34
+ "\\"
35
+ ];
36
+ const numbers = [
37
+ -2,
38
+ -1,
39
+ 0,
40
+ 1,
41
+ 2,
42
+ 7,
43
+ .5,
44
+ -.5,
45
+ 1e6
46
+ ];
47
+ const booleans = [true, false];
48
+ /** The sample values of a stored kind, before any schema narrows them. */
49
+ const candidates = (ast) => {
50
+ if (SchemaAST.isString(ast) || SchemaAST.isTemplateLiteral(ast)) return texts;
51
+ if (SchemaAST.isNumber(ast)) return numbers;
52
+ if (SchemaAST.isBoolean(ast)) return booleans;
53
+ if (SchemaAST.isLiteral(ast)) return [ast.literal];
54
+ if (SchemaAST.isUnion(ast)) return ast.types.flatMap(candidates);
55
+ return [];
56
+ };
57
+ /** Whether a stored value is one `schema` stores. */
58
+ const decodes = (schema) => (value) => Schema.is(Schema.toEncoded(schema))(value);
59
+ /** The non-null samples every schema of `schemas` decodes, and the domain too when one is given. */
60
+ const samplesOf = (schemas, domain) => [...new Set(candidates(Schema.toEncoded(schemas[0]).ast))].filter((value) => value !== null && schemas.every((schema) => decodes(schema)(value)) && Option.match(domain, {
61
+ onNone: () => true,
62
+ onSome: (within) => decodes(within)(value)
63
+ }));
64
+ /** A plain object: what JSON makes, and nothing whose data sits in a prototype. */
65
+ const isRecord = (value) => {
66
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
67
+ const prototype = Object.getPrototypeOf(value);
68
+ return prototype === Object.prototype || prototype === null;
69
+ };
70
+ /** A plain object's keys holding a value: one holding `undefined` is as absent, as JSON writes it. */
71
+ const keysOf = (record) => Object.keys(record).filter((key) => record[key] !== void 0);
72
+ /**
73
+ * Two stored values alike, structurally. Not by their JSON, which writes
74
+ * `Infinity` and `NaN` as `null`: a division by zero answering `Infinity` in
75
+ * memory and null in SQL would read as agreeing. An object that is not plain
76
+ * (its data in a prototype: a Date) is compared by its JSON, a Date's its time.
77
+ */
78
+ const sameValue = (left, right) => {
79
+ if (typeof left === "number" && typeof right === "number") return left === right || Number.isNaN(left) && Number.isNaN(right);
80
+ if (Array.isArray(left) && Array.isArray(right)) return left.length === right.length && left.every((each, i) => sameValue(each, right[i]));
81
+ if (isRecord(left) && isRecord(right)) {
82
+ const keys = keysOf(left);
83
+ return keys.length === keysOf(right).length && keys.every((key) => Object.hasOwn(right, key) && sameValue(left[key], right[key]));
84
+ }
85
+ if (typeof left === "object" && left !== null && typeof right === "object" && right !== null) return JSON.stringify(left) === JSON.stringify(right);
86
+ return left === right;
87
+ };
88
+ /** Two outcomes alike: equal values as stored, or both refusals. */
89
+ const same = (left, right) => left._tag === "Refused" || right._tag === "Refused" ? left._tag === right._tag : sameValue(left.value, right.value);
90
+ /** Text by code point, as every interpreter's `binary` orders it; `<` compares UTF-16 units. */
91
+ const byCodePoint = (left, right) => {
92
+ const [a, b] = [[...left], [...right]];
93
+ for (let i = 0; i < Math.min(a.length, b.length); i++) {
94
+ const sign = a[i].codePointAt(0) - b[i].codePointAt(0);
95
+ if (sign !== 0) return sign;
96
+ }
97
+ return a.length - b.length;
98
+ };
99
+ /** Two values of one kind in order: numbers, booleans, text by code point. */
100
+ const orderOf = (left, right) => typeof left === "string" && typeof right === "string" ? byCodePoint(left, right) : Number(left) - Number(right);
101
+ /** A call of `op`, given `collation` when its rule takes one. */
102
+ const callOf = (op, args, collation) => Option.match(collation, {
103
+ onNone: () => op(...args),
104
+ onSome: (each) => op(...args, { collation: each })
105
+ });
106
+ const foldText = (value) => typeof value === "string" ? Collation.foldAscii(value) : value;
107
+ const nameOf = (op) => op.descriptor.version === 1 ? op.descriptor.id : `${op.descriptor.id}@${op.descriptor.version}`;
108
+ /**
109
+ * The equations of every law `op` declares, over up to `limit` tuples a law
110
+ * chosen by `seed`. Nothing is run: a memory table and an SQL runner
111
+ * evaluate the same plans.
112
+ */
113
+ const lawPlans = (op, limit, seed) => {
114
+ const { descriptor } = op;
115
+ const comparesText = (each) => each.descriptor.collation !== "none";
116
+ const under = (each, collation) => comparesText(each) ? collation : Option.none();
117
+ const run = (node) => ({
118
+ node,
119
+ fold: false
120
+ });
121
+ const value = (held) => ({ value: held });
122
+ return descriptor.laws.map((law) => {
123
+ const shared = samplesOf(descriptor.input, law.domain);
124
+ const tuples = (arity) => tuplesOf(Array.from({ length: arity }, () => shared), limit, seed);
125
+ const plans = ([op, ...Law.$match(law, {
126
+ Inverse: ({ other }) => [other],
127
+ Distributes: ({ over }) => [over],
128
+ Associative: () => [],
129
+ Commutative: () => [],
130
+ Idempotent: () => [],
131
+ Identity: () => [],
132
+ Absorbing: () => [],
133
+ Monotonic: () => [],
134
+ PreservesCollation: () => []
135
+ })].some(comparesText) ? [Option.some(Collation.binary), Option.some(Collation.asciiFold)] : [Option.none()]).flatMap((collation) => {
136
+ const call = (...args) => callOf(op, args, under(op, collation));
137
+ const witness = (other, ...args) => callOf(other, args, under(other, collation));
138
+ const equal = (args, left, right) => ({
139
+ args,
140
+ collation,
141
+ left,
142
+ right,
143
+ holds: same
144
+ });
145
+ const sided = (witness, side, answer) => tuples(1).flatMap(([a]) => [...side === "right" ? [] : [equal([witness, a], run(call(witness, a)), value(answer(a)))], ...side === "left" ? [] : [equal([a, witness], run(call(a, witness)), value(answer(a)))]]);
146
+ return Law.$match(law, {
147
+ Associative: () => tuples(3).map(([a, b, c]) => equal([
148
+ a,
149
+ b,
150
+ c
151
+ ], run(call(call(a, b), c)), run(call(a, call(b, c))))),
152
+ Commutative: () => tuples(2).map(([a, b]) => equal([a, b], run(call(a, b)), run(call(b, a)))),
153
+ Idempotent: () => tuples(1).map(([a]) => equal([a], run(call(a, a)), value(a))),
154
+ Identity: ({ value: witness, side }) => sided(witness, side, (a) => a),
155
+ Absorbing: ({ value: witness, side }) => sided(witness, side, () => witness),
156
+ Inverse: ({ other, identity }) => tuples(1).map(([a]) => equal([a], run(call(a, witness(other, a))), value(identity))),
157
+ Distributes: ({ over }) => tuples(3).map(([a, b, c]) => equal([
158
+ a,
159
+ b,
160
+ c
161
+ ], run(call(a, witness(over, b, c))), run(witness(over, call(a, b), call(a, c))))),
162
+ Monotonic: ({ direction, position }) => {
163
+ const under = (held) => Option.exists(collation, (each) => each._tag === "AsciiFold") ? foldText(held) : held;
164
+ const order = (left, right) => orderOf(under(left), under(right));
165
+ const each = descriptor.input.map((schema) => samplesOf([schema], law.domain));
166
+ const pairs = each[position].flatMap((low) => each[position].filter((high) => order(low, high) < 0).map((high) => [low, high]));
167
+ const rest = each.filter((_, index) => index !== position);
168
+ const sign = direction === "increasing" ? 1 : -1;
169
+ return tuplesOf([pairs, ...rest], limit, seed).map(([pair, ...others]) => {
170
+ const [low, high] = pair;
171
+ const at = (held) => {
172
+ const args = [...others];
173
+ args.splice(position, 0, held);
174
+ return args;
175
+ };
176
+ return {
177
+ args: at(low),
178
+ collation,
179
+ left: run(call(...at(low))),
180
+ right: run(call(...at(high))),
181
+ holds: (left, right) => same(left, right) || left._tag === "Value" && right._tag === "Value" && sign * order(left.value, right.value) <= 0
182
+ };
183
+ });
184
+ },
185
+ PreservesCollation: () => Option.exists(collation, (each) => each._tag === "AsciiFold") ? tuples(2).map(([a, b]) => equal([a, b], {
186
+ node: call(a, b),
187
+ fold: true
188
+ }, {
189
+ node: call(foldText(a), foldText(b)),
190
+ fold: true
191
+ })) : []
192
+ });
193
+ });
194
+ if (plans.length === 0) throw new Error(`[foldkit-entity] Conformance.laws: no sample of ${nameOf(op)}'s arguments is in ${Law.describe(law).kind}'s domain`);
195
+ return {
196
+ law: Law.describe(law),
197
+ plans
198
+ };
199
+ });
200
+ };
201
+ /**
202
+ * The verdict over laws whose calls' outcomes `answered` gives: the first
203
+ * failure, or evidence of each. Two sides that both refuse agree, as a law
204
+ * over values says nothing of a call neither answers, but they are no case of
205
+ * it: a law is shown only by the cases whose sides both answer a value, and
206
+ * one with none is `Unanswered`.
207
+ */
208
+ const verdictOf = (op, laws, answered, options) => {
209
+ const outcomes = (side) => {
210
+ if ("value" in side) return Outcome.Value({ value: side.value });
211
+ const outcome = answered(side.node);
212
+ return side.fold ? Outcome.$match(outcome, {
213
+ Value: ({ value }) => Outcome.Value({ value: foldText(value) }),
214
+ Refused: (refused) => refused
215
+ }) : outcome;
216
+ };
217
+ const evidence = [];
218
+ for (const { law, plans } of laws) {
219
+ let cases = 0;
220
+ let refusal = Option.none();
221
+ for (const plan of plans) {
222
+ const left = outcomes(plan.left);
223
+ const right = outcomes(plan.right);
224
+ if (!plan.holds(left, right)) return LawsVerdict.Counterexample({
225
+ law,
226
+ args: plan.args,
227
+ collation: plan.collation,
228
+ left,
229
+ right
230
+ });
231
+ if (left._tag === "Value" && right._tag === "Value") cases += 1;
232
+ else if (Option.isNone(refusal) && left._tag === "Refused") refusal = Option.some(left.reason);
233
+ }
234
+ if (cases === 0) return LawsVerdict.Unanswered({
235
+ law,
236
+ reason: Option.getOrElse(refusal, () => "no call was answered")
237
+ });
238
+ evidence.push(Evidence.Tested({
239
+ operator: nameOf(op),
240
+ law,
241
+ implementation: options.implementation,
242
+ cases,
243
+ seed: options.seed
244
+ }));
245
+ }
246
+ return LawsVerdict.Holds({ evidence });
247
+ };
248
+ const Conformance = {
249
+ /** A runner of calls through a memory table: `Conformance.operator`'s for the in-memory interpreter. */
250
+ memory: (operators) => (call) => valueOfOperand(call, { operators }),
251
+ /**
252
+ * Tests every law `op` declares against `operators`' implementation of it,
253
+ * up to `cases` tuples a law (200 by default), chosen by `seed` (0); a law
254
+ * of both sides checks each tuple from each. Holds with a `Tested` record a
255
+ * law, which `Operators.withEvidence` keeps; or the first case a law fails,
256
+ * with both sides.
257
+ */
258
+ laws: (op, operators, options = {}) => {
259
+ const operator = op;
260
+ const seed = options.seed ?? 0;
261
+ const outcome = (node) => {
262
+ try {
263
+ return Outcome.Value({ value: valueOfOperand(node, { operators }) });
264
+ } catch (error) {
265
+ if (error instanceof QueryEvaluateError) return Outcome.Refused({ reason: error.message });
266
+ throw error;
267
+ }
268
+ };
269
+ const verdict = verdictOf(operator, lawPlans(operator, options.cases ?? 200, seed), outcome, {
270
+ implementation: options.implementation ?? "memory",
271
+ seed
272
+ });
273
+ if (verdict._tag === "Holds") verdict.evidence.forEach((record) => stampTested(record, operators));
274
+ return verdict;
275
+ },
276
+ /**
277
+ * As `laws`, each call run by `run` instead of a memory table: an SQL
278
+ * implementation selected from a database, say, whose evidence a binding's
279
+ * SQL table records. A throw is a refusal.
280
+ */
281
+ lawsBy: async (op, run, options) => {
282
+ const operator = op;
283
+ const seed = options.seed ?? 0;
284
+ const laws = lawPlans(operator, options.cases ?? 200, seed);
285
+ const answers = /* @__PURE__ */ new Map();
286
+ for (const { plans } of laws) for (const side of plans.flatMap((plan) => [plan.left, plan.right])) {
287
+ if (!("node" in side) || answers.has(side.node)) continue;
288
+ try {
289
+ answers.set(side.node, Outcome.Value({ value: await run(side.node) }));
290
+ } catch (error) {
291
+ answers.set(side.node, Outcome.Refused({ reason: String(error) }));
292
+ }
293
+ }
294
+ const verdict = verdictOf(operator, laws, (node) => answers.get(node), {
295
+ implementation: options.implementation,
296
+ seed
297
+ });
298
+ if (verdict._tag === "Holds") verdict.evidence.forEach(stampRun);
299
+ return verdict;
300
+ },
301
+ /**
302
+ * Runs one set of calls of `op` through every implementation and compares
303
+ * what each answered or refused. The calls are `cases` (argument tuples, as
304
+ * stored), or generated: each argument a sample of its kind, null where its
305
+ * schema admits one, and text holding NUL, under `binary` and `asciiFold` where the operator compares
306
+ * text, up to `limit` (300) chosen by `seed` (0). A defined operator's
307
+ * expansion is run beside the others, as `expansion`, by `expansionTable`
308
+ * (the kernel's when not given).
309
+ */
310
+ operator: async (op, options) => {
311
+ const operator = op;
312
+ const { descriptor } = operator;
313
+ const runners = { ...options.implementations };
314
+ if (Option.isSome(descriptor.definedAs)) {
315
+ if (Object.hasOwn(runners, "expansion")) throw new Error(`[foldkit-entity] Conformance.operator: "expansion" names the expansion of ${nameOf(operator)}, which runs beside the implementations; name yours otherwise`);
316
+ const table = options.expansionTable ?? Operators.kernel;
317
+ runners.expansion = (call) => valueOfOperand(Expr.expanded(call), { operators: table });
318
+ }
319
+ const generated = () => tuplesOf(descriptor.input.map((schema) => {
320
+ const text = candidates(Schema.toEncoded(schema).ast).some((value) => typeof value === "string");
321
+ return [
322
+ ...decodes(schema)(null) ? [null] : [],
323
+ ...samplesOf([schema], Option.none()),
324
+ ...text ? [`a${NUL}`] : []
325
+ ];
326
+ }), options.limit ?? 300, options.seed ?? 0);
327
+ const collations = descriptor.collation === "none" ? [Option.none()] : [Option.some(Collation.binary), Option.some(Collation.asciiFold)];
328
+ const disagreements = [];
329
+ let cases = 0;
330
+ for (const args of options.cases ?? generated()) for (const collation of collations) {
331
+ cases += 1;
332
+ const call = callOf(operator, args, collation);
333
+ const outcomes = Object.create(null);
334
+ for (const [name, run] of Object.entries(runners)) try {
335
+ outcomes[name] = Outcome.Value({ value: await run(call) });
336
+ } catch (error) {
337
+ outcomes[name] = Outcome.Refused({ reason: String(error) });
338
+ }
339
+ const [first, ...others] = Object.values(outcomes);
340
+ if (first !== void 0 && others.some((each) => !same(first, each))) disagreements.push({
341
+ args,
342
+ collation,
343
+ outcomes
344
+ });
345
+ }
346
+ return {
347
+ cases,
348
+ disagreements
349
+ };
350
+ }
351
+ };
352
+ export { Conformance, LawsVerdict, Outcome };
353
+
354
+ //# sourceMappingURL=operator.js.map