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,425 @@
1
+ import { Option, Schema } from "effect";
2
+ import { Collation, Entity, Expr, Order, Query, Relation } from "../index.js";
3
+ // src/conformance/relational.ts
4
+ /**
5
+ * The conformance suite for paths and exists: bodies that read other rows,
6
+ * over a domain whose reader may not see every row.
7
+ *
8
+ * Two laws are checked against these cases. An interpreter that runs over
9
+ * every row the reader may see (SQL, under each table's visibility rule)
10
+ * answers `expected`. An interpreter that runs over what a holder has
11
+ * (`Judge`, over each of `heldWorlds`) answers unknown or what `expected`
12
+ * says, never the other answer, and over everything the reader may see it
13
+ * answers every row.
14
+ *
15
+ * The fixture is chosen so a path meets each way of reaching no row (a null
16
+ * link, a row the reader may not see), a field that is null on the row
17
+ * reached, and an exists whose only witness is hidden.
18
+ */
19
+ const Team = Entity.define("Team", Schema.Struct({
20
+ id: Schema.String,
21
+ name: Schema.String,
22
+ /** Null on purpose: a path reaching a row whose field is null. */
23
+ region: Schema.NullOr(Schema.String)
24
+ }));
25
+ const Member = Entity.define("Member", Schema.Struct({
26
+ id: Schema.String,
27
+ handle: Schema.String,
28
+ rank: Schema.Number
29
+ }));
30
+ const Badge = Entity.define("Badge", Schema.Struct({
31
+ id: Schema.String,
32
+ kind: Schema.String
33
+ }));
34
+ const Pin = Entity.define("Pin", Schema.Struct({
35
+ id: Schema.String,
36
+ label: Schema.String
37
+ }));
38
+ /**
39
+ * A member is on a team or none; a badge is a member's; a pin is a team's.
40
+ * Stored as foreign keys named after each relation plus `_id`.
41
+ */
42
+ const Relational = Entity.relate({
43
+ Team,
44
+ Member,
45
+ Badge,
46
+ Pin
47
+ }, {
48
+ Member: { team: Relation.one(Team, { optional: true }) },
49
+ Badge: { member: Relation.one(Member) },
50
+ Pin: { team: Relation.one(Team) }
51
+ });
52
+ const relationalTables = [
53
+ {
54
+ entity: Relational.Team,
55
+ visible: [{
56
+ id: "t1",
57
+ name: "Red",
58
+ region: "eu"
59
+ }, {
60
+ id: "t2",
61
+ name: "Blue",
62
+ region: null
63
+ }],
64
+ hidden: [{
65
+ id: "t3",
66
+ name: "Hidden",
67
+ region: "eu"
68
+ }]
69
+ },
70
+ {
71
+ entity: Relational.Member,
72
+ visible: [
73
+ {
74
+ id: "m1",
75
+ handle: "ann",
76
+ rank: 1,
77
+ team: "t1"
78
+ },
79
+ {
80
+ id: "m2",
81
+ handle: "bob",
82
+ rank: 2,
83
+ team: "t2"
84
+ },
85
+ {
86
+ id: "m3",
87
+ handle: "cy",
88
+ rank: 3,
89
+ team: null
90
+ },
91
+ {
92
+ id: "m4",
93
+ handle: "dee",
94
+ rank: 4,
95
+ team: "t3"
96
+ },
97
+ {
98
+ id: "m5",
99
+ handle: "Eve",
100
+ rank: 5,
101
+ team: "t1"
102
+ }
103
+ ],
104
+ hidden: []
105
+ },
106
+ {
107
+ entity: Relational.Badge,
108
+ visible: [
109
+ {
110
+ id: "b1",
111
+ kind: "gold",
112
+ member: "m1"
113
+ },
114
+ {
115
+ id: "b2",
116
+ kind: "silver",
117
+ member: "m1"
118
+ },
119
+ {
120
+ id: "b3",
121
+ kind: "gold",
122
+ member: "m2"
123
+ },
124
+ {
125
+ id: "b5",
126
+ kind: "silver",
127
+ member: "m4"
128
+ }
129
+ ],
130
+ hidden: [{
131
+ id: "b4",
132
+ kind: "secret",
133
+ member: "m3"
134
+ }]
135
+ },
136
+ {
137
+ entity: Relational.Pin,
138
+ visible: [
139
+ {
140
+ id: "p1",
141
+ label: "top",
142
+ team: "t1"
143
+ },
144
+ {
145
+ id: "p2",
146
+ label: "low",
147
+ team: "t2"
148
+ },
149
+ {
150
+ id: "p3",
151
+ label: "top",
152
+ team: "t3"
153
+ }
154
+ ],
155
+ hidden: []
156
+ }
157
+ ];
158
+ /** What a case's `Expr.viewer` reads: who asks, or a visitor where nobody does. */
159
+ const relationalContext = (c) => ({
160
+ viewer: Option.fromNullishOr(c.viewer),
161
+ now: Option.none()
162
+ });
163
+ const member = (id) => ({
164
+ entity: "Member",
165
+ id
166
+ });
167
+ const { Team: T, Member: M, Badge: B, Pin: P } = Relational;
168
+ const members = Query.from(M).pipe(Query.orderBy(Order.asc(M.fields.id)));
169
+ const badges = Query.from(B).pipe(Query.orderBy(Order.asc(B.fields.id)));
170
+ const teams = Query.from(T).pipe(Query.orderBy(Order.asc(T.fields.id)));
171
+ const teamName = Expr.path(M.relations.team, T.fields.name);
172
+ const topPin = Expr.path(M.relations.team, Expr.exists(P.relations.team, Expr.eq(P.fields.label, "top")));
173
+ const viewerTeam = Expr.path(Expr.viewer(M), Expr.path(M.relations.team, T.fields.name));
174
+ const viewerTeamId = Expr.path(Expr.viewer(M), Expr.path(M.relations.team, T.fields.id));
175
+ const gold = Expr.exists(B.relations.member, Expr.eq(B.fields.kind, "gold"));
176
+ const relationalCases = [
177
+ {
178
+ what: "a path reads a field of the row its relation points at",
179
+ body: members.pipe(Query.where(Expr.eq(teamName, "Red"))),
180
+ input: {},
181
+ expected: ["m1", "m5"]
182
+ },
183
+ {
184
+ what: "a path reads null through a null link, and through a row the reader may not see",
185
+ body: members.pipe(Query.where(Expr.isNull(teamName))),
186
+ input: {},
187
+ expected: ["m3", "m4"]
188
+ },
189
+ {
190
+ what: "a path's null is unknown under not, so neither side keeps the row",
191
+ body: members.pipe(Query.where(Expr.not(Expr.eq(teamName, "Red")))),
192
+ input: {},
193
+ expected: ["m2"]
194
+ },
195
+ {
196
+ what: "a path reads a null field of the row reached as null",
197
+ body: members.pipe(Query.where(Expr.isNull(Expr.path(M.relations.team, T.fields.region)))),
198
+ input: {},
199
+ expected: [
200
+ "m2",
201
+ "m3",
202
+ "m4"
203
+ ]
204
+ },
205
+ {
206
+ what: "a path compares with an input",
207
+ body: members.pipe(Query.where(Expr.eq(Expr.path(M.relations.team, T.fields.region), Expr.input("region", Schema.String)))),
208
+ input: { region: "eu" },
209
+ expected: ["m1", "m5"]
210
+ },
211
+ {
212
+ what: "contains folds a path's text as it folds a field's",
213
+ body: members.pipe(Query.where(Expr.contains(teamName, "E"))),
214
+ input: {},
215
+ expected: [
216
+ "m1",
217
+ "m2",
218
+ "m5"
219
+ ]
220
+ },
221
+ {
222
+ what: "a comparison orders a path's text under the collation it names",
223
+ body: members.pipe(Query.where(Expr.lt(teamName, "C", { collation: Collation.binary }))),
224
+ input: {},
225
+ expected: ["m2"]
226
+ },
227
+ {
228
+ what: "a path follows two relations",
229
+ body: badges.pipe(Query.where(Expr.eq(Expr.path(B.relations.member, Expr.path(M.relations.team, T.fields.name)), "Red"))),
230
+ input: {},
231
+ expected: ["b1", "b2"]
232
+ },
233
+ {
234
+ what: "a path of two relations reads null where either reaches no row or the field is null",
235
+ body: badges.pipe(Query.where(Expr.isNull(Expr.path(B.relations.member, Expr.path(M.relations.team, T.fields.region))))),
236
+ input: {},
237
+ expected: ["b3", "b5"]
238
+ },
239
+ {
240
+ what: "in tests a path's value against a list",
241
+ body: badges.pipe(Query.where(Expr.in(Expr.path(B.relations.member, M.fields.rank), [1, 4]))),
242
+ input: {},
243
+ expected: [
244
+ "b1",
245
+ "b2",
246
+ "b5"
247
+ ]
248
+ },
249
+ {
250
+ what: "exists finds a row pointing here, and never one the reader may not see",
251
+ body: members.pipe(Query.where(Expr.exists(B.relations.member))),
252
+ input: {},
253
+ expected: [
254
+ "m1",
255
+ "m2",
256
+ "m4"
257
+ ]
258
+ },
259
+ {
260
+ what: "exists holds when a pointing row holds its filter",
261
+ body: members.pipe(Query.where(gold)),
262
+ input: {},
263
+ expected: ["m1", "m2"]
264
+ },
265
+ {
266
+ what: "exists is never unknown, so its not keeps every other row",
267
+ body: members.pipe(Query.where(Expr.not(gold))),
268
+ input: {},
269
+ expected: [
270
+ "m3",
271
+ "m4",
272
+ "m5"
273
+ ]
274
+ },
275
+ {
276
+ what: "an exists' filter reads the input",
277
+ body: members.pipe(Query.where(Expr.exists(B.relations.member, Expr.eq(B.fields.kind, Expr.input("kind", Schema.String))))),
278
+ input: { kind: "silver" },
279
+ expected: ["m1", "m4"]
280
+ },
281
+ {
282
+ what: "or holds by either side, an exists or the row's own field",
283
+ body: members.pipe(Query.where(Expr.or(Expr.eq(M.fields.rank, 5), gold))),
284
+ input: {},
285
+ expected: [
286
+ "m1",
287
+ "m2",
288
+ "m5"
289
+ ]
290
+ },
291
+ {
292
+ what: "and joins a path and the negation of an exists",
293
+ body: members.pipe(Query.where(Expr.and(Expr.isNotNull(teamName), Expr.not(Expr.exists(B.relations.member))))),
294
+ input: {},
295
+ expected: ["m5"]
296
+ },
297
+ {
298
+ what: "an exists' filter folds text as contains does",
299
+ body: teams.pipe(Query.where(Expr.exists(M.relations.team, Expr.contains(M.fields.handle, "E")))),
300
+ input: {},
301
+ expected: ["t1"]
302
+ },
303
+ {
304
+ what: "not of an exists holds where no pointing row holds the filter",
305
+ body: teams.pipe(Query.where(Expr.not(Expr.exists(M.relations.team, Expr.gte(M.fields.rank, 5))))),
306
+ input: {},
307
+ expected: ["t2"]
308
+ },
309
+ {
310
+ what: "an exists asked of the row a path reaches",
311
+ body: members.pipe(Query.where(topPin)),
312
+ input: {},
313
+ expected: ["m1", "m5"]
314
+ },
315
+ {
316
+ what: "an exists through a path that reaches no row is unknown, so its not keeps neither",
317
+ body: members.pipe(Query.where(Expr.not(topPin))),
318
+ input: {},
319
+ expected: ["m2"]
320
+ },
321
+ {
322
+ what: "a path from the viewer reads their team's name, on the table it judges",
323
+ body: members.pipe(Query.where(Expr.eq(teamName, viewerTeam))),
324
+ input: {},
325
+ viewer: member("m1"),
326
+ expected: ["m1", "m5"]
327
+ },
328
+ {
329
+ what: "a path from the viewer reaches another table's row",
330
+ body: teams.pipe(Query.where(Expr.eq(T.fields.id, viewerTeamId))),
331
+ input: {},
332
+ viewer: member("m2"),
333
+ expected: ["t2"]
334
+ },
335
+ {
336
+ what: "a path from the viewer reads null through a team the reader may not see",
337
+ body: members.pipe(Query.where(Expr.isNull(viewerTeam))),
338
+ input: {},
339
+ viewer: member("m4"),
340
+ expected: [
341
+ "m1",
342
+ "m2",
343
+ "m3",
344
+ "m4",
345
+ "m5"
346
+ ]
347
+ },
348
+ {
349
+ what: "a path from the viewer reads null through a null link",
350
+ body: teams.pipe(Query.where(Expr.isNull(viewerTeamId))),
351
+ input: {},
352
+ viewer: member("m3"),
353
+ expected: ["t1", "t2"]
354
+ },
355
+ {
356
+ what: "a path from a viewer the reader may not see reads null, as a path to that row does",
357
+ body: teams.pipe(Query.where(Expr.isNull(Expr.path(Expr.viewer(T), T.fields.name)))),
358
+ input: {},
359
+ viewer: {
360
+ entity: "Team",
361
+ id: "t3"
362
+ },
363
+ expected: ["t1", "t2"]
364
+ },
365
+ {
366
+ what: "a path from a visitor reaches no row, so a comparison with it keeps none",
367
+ body: teams.pipe(Query.where(Expr.not(Expr.eq(T.fields.id, viewerTeamId)))),
368
+ input: {},
369
+ viewer: null,
370
+ expected: []
371
+ }
372
+ ];
373
+ const held = (change) => relationalTables.map((table) => ({
374
+ entity: table.entity,
375
+ rows: table.visible,
376
+ ...change(table)
377
+ }));
378
+ const named = (table, entity) => table.entity.identity.token === entity.identity.token;
379
+ /** A record without the keys named. */
380
+ const without = (row, keys) => Object.fromEntries(Object.entries(row).filter(([key]) => !keys.includes(key)));
381
+ /**
382
+ * What a holder might have, first everything the reader may see. Each later
383
+ * one lacks something a case reads, so some judgement in it is unknown.
384
+ */
385
+ const heldWorlds = [
386
+ {
387
+ what: "everything the reader may see",
388
+ tables: held(() => ({}))
389
+ },
390
+ {
391
+ what: "no team",
392
+ tables: held((table) => named(table, T) ? {
393
+ rows: [],
394
+ complete: false
395
+ } : {})
396
+ },
397
+ {
398
+ what: "every other row of each table",
399
+ tables: held((table) => ({
400
+ rows: table.visible.filter((_, index) => index % 2 === 0),
401
+ complete: false
402
+ }))
403
+ },
404
+ {
405
+ what: "a team's name and region hidden",
406
+ tables: held((table) => named(table, T) ? { hidden: ["name", "region"] } : {})
407
+ },
408
+ {
409
+ what: "no badge, and not every pin",
410
+ tables: held((table) => named(table, B) ? {
411
+ rows: [],
412
+ complete: false
413
+ } : named(table, P) ? {
414
+ rows: table.visible.slice(1),
415
+ complete: false
416
+ } : {})
417
+ },
418
+ {
419
+ what: "no link held",
420
+ tables: held((table) => ({ rows: table.visible.map((row) => without(row, ["team", "member"])) }))
421
+ }
422
+ ];
423
+ export { Relational, heldWorlds, relationalCases, relationalContext, relationalTables };
424
+
425
+ //# sourceMappingURL=relational.js.map
@@ -0,0 +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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AU;EAAM,IAAI,CAAC,CAAE;CAC9E;CACA;EACE,MAAM;EACN,QAAQ,MAAK,WAAU;GACrB,MAAM,MAAM,QAAQ,QAAQ,GAAG,UAAU,QAAQ,MAAM,CAAC;GACxD,UAAU;EACZ,EAAE;CACJ;CACA;EACE,MAAM;EACN,QAAQ,MAAK,UAAU,MAAM,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,QAAQ,EAAE,IAAI,CAAC,CAAE;CAC/E;CACA;EACE,MAAM;EACN,QAAQ,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"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * At most `limit` tuples of one value from each list, chosen by `seed` when
3
+ * there are more. Their number is the lists' lengths multiplied, exponential
4
+ * in how many there are, so none is built but those chosen: a partial
5
+ * Fisher-Yates shuffle over their indices, holding only the indices it moved.
6
+ */
7
+ export declare const tuplesOf: <A>(lists: ReadonlyArray<ReadonlyArray<A>>, limit: number, seed: number) => ReadonlyArray<ReadonlyArray<A>>;
8
+ //# sourceMappingURL=tuples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuples.d.ts","names":[],"sources":["../../src/conformance/tuples.ts"],"mappings":";;;;;;qBAkBa,WAAY,GAAC,OACjB,cAAc,cAAc,KAAG,eACzB,iBAEZ,cAAc,cAAc"}
@@ -0,0 +1,43 @@
1
+ // src/conformance/tuples.ts
2
+ /** A small seeded generator (mulberry32), so a chosen subset is the same on every run. */
3
+ const random = (seed) => {
4
+ let state = seed >>> 0;
5
+ return () => {
6
+ state = state + 1831565813 >>> 0;
7
+ let t = state;
8
+ t = Math.imul(t ^ t >>> 15, t | 1);
9
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
10
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
11
+ };
12
+ };
13
+ /**
14
+ * At most `limit` tuples of one value from each list, chosen by `seed` when
15
+ * there are more. Their number is the lists' lengths multiplied, exponential
16
+ * in how many there are, so none is built but those chosen: a partial
17
+ * Fisher-Yates shuffle over their indices, holding only the indices it moved.
18
+ */
19
+ const tuplesOf = (lists, limit, seed) => {
20
+ const size = lists.reduce((count, list) => count * list.length, 1);
21
+ const at = (index) => {
22
+ const tuple = new Array(lists.length);
23
+ let rest = index;
24
+ for (let i = lists.length - 1; i >= 0; i--) {
25
+ const list = lists[i];
26
+ tuple[i] = list[rest % list.length];
27
+ rest = Math.floor(rest / list.length);
28
+ }
29
+ return tuple;
30
+ };
31
+ if (size <= limit) return Array.from({ length: size }, (_, index) => at(index));
32
+ const next = random(seed);
33
+ const moved = /* @__PURE__ */ new Map();
34
+ return Array.from({ length: limit }, (_, i) => {
35
+ const j = i + Math.floor(next() * (size - i));
36
+ const picked = moved.get(j) ?? j;
37
+ moved.set(j, moved.get(i) ?? i);
38
+ return at(picked);
39
+ });
40
+ };
41
+ export { tuplesOf };
42
+
43
+ //# sourceMappingURL=tuples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuples.js","names":[],"sources":["../../src/conformance/tuples.ts"],"sourcesContent":["/** A small seeded generator (mulberry32), so a chosen subset is the same on every run. */\nconst random = (seed: number) => {\n let state = seed >>> 0\n return () => {\n state = (state + 0x6d2b79f5) >>> 0\n let t = state\n t = Math.imul(t ^ (t >>> 15), t | 1)\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61)\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n }\n}\n\n/**\n * At most `limit` tuples of one value from each list, chosen by `seed` when\n * there are more. Their number is the lists' lengths multiplied, exponential\n * in how many there are, so none is built but those chosen: a partial\n * Fisher-Yates shuffle over their indices, holding only the indices it moved.\n */\nexport const tuplesOf = <A>(\n lists: ReadonlyArray<ReadonlyArray<A>>,\n limit: number,\n seed: number,\n): ReadonlyArray<ReadonlyArray<A>> => {\n const size = lists.reduce((count, list) => count * list.length, 1)\n // The index-th tuple, the last list varying fastest.\n const at = (index: number): ReadonlyArray<A> => {\n const tuple = new Array<A>(lists.length)\n let rest = index\n for (let i = lists.length - 1; i >= 0; i--) {\n const list = lists[i]!\n tuple[i] = list[rest % list.length]!\n rest = Math.floor(rest / list.length)\n }\n return tuple\n }\n if (size <= limit) return Array.from({ length: size }, (_, index) => at(index))\n const next = random(seed)\n const moved = new Map<number, number>()\n return Array.from({ length: limit }, (_, i) => {\n const j = i + Math.floor(next() * (size - i))\n const picked = moved.get(j) ?? j\n moved.set(j, moved.get(i) ?? i)\n return at(picked)\n })\n}\n"],"mappings":";;AACA,MAAM,UAAU,SAAiB;CAC/B,IAAI,QAAQ,SAAS;CACrB,aAAa;EACX,QAAS,QAAQ,eAAgB;EACjC,IAAI,IAAI;EACR,IAAI,KAAK,KAAK,IAAK,MAAM,IAAK,IAAI,CAAC;EACnC,KAAK,IAAI,KAAK,KAAK,IAAK,MAAM,GAAI,IAAI,EAAE;EACxC,SAAS,IAAK,MAAM,QAAS,KAAK;CACpC;AACF;;;;;;;AAQA,MAAa,YACX,OACA,OACA,SACoC;CACpC,MAAM,OAAO,MAAM,QAAQ,OAAO,SAAS,QAAQ,KAAK,QAAQ,CAAC;CAEjE,MAAM,MAAM,UAAoC;EAC9C,MAAM,QAAQ,IAAI,MAAS,MAAM,MAAM;EACvC,IAAI,OAAO;EACX,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;GAC1C,MAAM,OAAO,MAAM;GACnB,MAAM,KAAK,KAAK,OAAO,KAAK;GAC5B,OAAO,KAAK,MAAM,OAAO,KAAK,MAAM;EACtC;EACA,OAAO;CACT;CACA,IAAI,QAAQ,OAAO,OAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,UAAU,GAAG,KAAK,CAAC;CAC9E,MAAM,OAAO,OAAO,IAAI;CACxB,MAAM,wBAAQ,IAAI,IAAoB;CACtC,OAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GAAG,MAAM;EAC7C,MAAM,IAAI,IAAI,KAAK,MAAM,KAAK,KAAK,OAAO,EAAE;EAC5C,MAAM,SAAS,MAAM,IAAI,CAAC,KAAK;EAC/B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC;EAC9B,OAAO,GAAG,MAAM;CAClB,CAAC;AACH"}
@@ -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"}