@gaganref/confect-test 10.3.1-fork.87 → 10.3.1-fork.89

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 (51) hide show
  1. package/dist/internal/Attempt.d.ts +77 -0
  2. package/dist/internal/Attempt.d.ts.map +1 -0
  3. package/dist/internal/Attempt.js +154 -0
  4. package/dist/internal/Attempt.js.map +1 -0
  5. package/dist/internal/ConvexTest.d.ts +34 -0
  6. package/dist/internal/ConvexTest.d.ts.map +1 -0
  7. package/dist/internal/ConvexTest.js +59 -0
  8. package/dist/internal/ConvexTest.js.map +1 -0
  9. package/dist/internal/Execution.d.ts +167 -0
  10. package/dist/internal/Execution.d.ts.map +1 -0
  11. package/dist/internal/Execution.js +790 -0
  12. package/dist/internal/Execution.js.map +1 -0
  13. package/dist/internal/Globals.d.ts +11 -0
  14. package/dist/internal/Globals.d.ts.map +1 -0
  15. package/dist/internal/Globals.js +76 -0
  16. package/dist/internal/Globals.js.map +1 -0
  17. package/dist/internal/Invocation.d.ts +57 -0
  18. package/dist/internal/Invocation.d.ts.map +1 -0
  19. package/dist/internal/Invocation.js +145 -0
  20. package/dist/internal/Invocation.js.map +1 -0
  21. package/dist/internal/Kernel.d.ts +93 -0
  22. package/dist/internal/Kernel.d.ts.map +1 -0
  23. package/dist/internal/Kernel.js +91 -0
  24. package/dist/internal/Kernel.js.map +1 -0
  25. package/dist/internal/KernelQuery.d.ts +55 -0
  26. package/dist/internal/KernelQuery.d.ts.map +1 -0
  27. package/dist/internal/KernelQuery.js +205 -0
  28. package/dist/internal/KernelQuery.js.map +1 -0
  29. package/dist/internal/KernelRefusal.d.ts +77 -0
  30. package/dist/internal/KernelRefusal.d.ts.map +1 -0
  31. package/dist/internal/KernelRefusal.js +73 -0
  32. package/dist/internal/KernelRefusal.js.map +1 -0
  33. package/dist/internal/KernelValues.d.ts +136 -0
  34. package/dist/internal/KernelValues.d.ts.map +1 -0
  35. package/dist/internal/KernelValues.js +266 -0
  36. package/dist/internal/KernelValues.js.map +1 -0
  37. package/dist/internal/ReadSet.d.ts +55 -0
  38. package/dist/internal/ReadSet.d.ts.map +1 -0
  39. package/dist/internal/ReadSet.js +29 -0
  40. package/dist/internal/ReadSet.js.map +1 -0
  41. package/package.json +3 -3
  42. package/src/internal/Attempt.ts +185 -0
  43. package/src/internal/ConvexTest.ts +118 -0
  44. package/src/internal/Execution.ts +1430 -0
  45. package/src/internal/Globals.ts +93 -0
  46. package/src/internal/Invocation.ts +291 -0
  47. package/src/internal/Kernel.ts +190 -0
  48. package/src/internal/KernelQuery.ts +405 -0
  49. package/src/internal/KernelRefusal.ts +88 -0
  50. package/src/internal/KernelValues.ts +725 -0
  51. package/src/internal/ReadSet.ts +108 -0
@@ -0,0 +1,108 @@
1
+ import { compareValues, type Value } from "convex/values";
2
+ import type {
3
+ DocumentId,
4
+ SerializedRangeExpression,
5
+ StoredDocument,
6
+ } from "./KernelValues.js";
7
+ import {
8
+ evaluateFieldPath,
9
+ evaluateRangeFilter,
10
+ tableNameFromId,
11
+ } from "./KernelValues.js";
12
+
13
+ /**
14
+ * A row's position in an interval's order: its value at each of the interval's
15
+ * fields.
16
+ */
17
+ export type Key = ReadonlyArray<Value | undefined>;
18
+
19
+ /**
20
+ * A read of one document by ID. It records the document's absence as well as
21
+ * its presence, so a commit that creates the document invalidates it.
22
+ */
23
+ export interface DocumentRead {
24
+ readonly kind: "document";
25
+ readonly componentPath: string;
26
+ readonly id: DocumentId;
27
+ }
28
+
29
+ /**
30
+ * A read of an ordered interval of one table.
31
+ *
32
+ * `fields` is the sort key: an index's fields, then the tie-breakers
33
+ * `_creationTime` and `_id`. `range` is the index range expression, whose `Gt`
34
+ * and `Lt` bounds are exclusive and `Gte` and `Lte` inclusive. `after` is an
35
+ * exclusive start in `order`, a page's cursor. `through` is how far the query
36
+ * examined, inclusive: nothing yet, up to a key, or to the end of the range. An
37
+ * empty result reads to the end, so it still covers an insert into the range.
38
+ *
39
+ * Only the attempt that owns the read advances `through`.
40
+ */
41
+ export interface IntervalRead {
42
+ readonly kind: "interval";
43
+ readonly componentPath: string;
44
+ readonly table: string;
45
+ readonly fields: ReadonlyArray<string>;
46
+ readonly order: "asc" | "desc";
47
+ readonly range: ReadonlyArray<SerializedRangeExpression>;
48
+ readonly after: Key | null;
49
+ through: Key | "end" | null;
50
+ }
51
+
52
+ export type Read = DocumentRead | IntervalRead;
53
+
54
+ /**
55
+ * Where `doc` sorts against `key` in the interval's order.
56
+ */
57
+ export const compareToKey = (
58
+ fields: ReadonlyArray<string>,
59
+ order: "asc" | "desc",
60
+ doc: StoredDocument,
61
+ key: Key,
62
+ ): number => {
63
+ const direction = order === "asc" ? 1 : -1;
64
+ for (let i = 0; i < fields.length; i++) {
65
+ const cmp = compareValues(
66
+ evaluateFieldPath(fields[i]!, doc),
67
+ key[i] as Value,
68
+ );
69
+ if (cmp !== 0) return cmp * direction;
70
+ }
71
+ return 0;
72
+ };
73
+
74
+ export const keyOf = (
75
+ fields: ReadonlyArray<string>,
76
+ doc: StoredDocument,
77
+ ): Key => fields.map((field) => evaluateFieldPath(field, doc));
78
+
79
+ const inInterval = (read: IntervalRead, doc: StoredDocument): boolean =>
80
+ read.through !== null &&
81
+ read.range.every((filter) => evaluateRangeFilter(doc, filter)) &&
82
+ (read.after === null ||
83
+ compareToKey(read.fields, read.order, doc, read.after) > 0) &&
84
+ (read.through === "end" ||
85
+ compareToKey(read.fields, read.order, doc, read.through) <= 0);
86
+
87
+ /**
88
+ * Whether a commit's change to one document invalidates `read`: it wrote the
89
+ * document read by ID, or the document entered or left the interval.
90
+ */
91
+ export const covers = (
92
+ read: Read,
93
+ change: {
94
+ readonly componentPath: string;
95
+ readonly id: DocumentId;
96
+ readonly before: StoredDocument | null;
97
+ readonly after: StoredDocument | null;
98
+ },
99
+ ): boolean => {
100
+ if (read.componentPath !== change.componentPath) return false;
101
+ if (read.kind === "document") return read.id === change.id;
102
+ return (
103
+ tableNameFromId(change.id) === read.table &&
104
+ [change.before, change.after].some(
105
+ (doc) => doc !== null && inInterval(read, doc),
106
+ )
107
+ );
108
+ };