@vllnt/convex-experiments 0.1.0-canary.f2cd1ba → 0.1.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 (50) hide show
  1. package/README.md +35 -6
  2. package/dist/client/index.d.ts +54 -3
  3. package/dist/client/index.d.ts.map +1 -1
  4. package/dist/client/index.js +53 -4
  5. package/dist/client/index.js.map +1 -1
  6. package/dist/client/types.d.ts +8 -3
  7. package/dist/client/types.d.ts.map +1 -1
  8. package/dist/component/_generated/component.d.ts +35 -0
  9. package/dist/component/_generated/component.d.ts.map +1 -1
  10. package/dist/component/_generated/server.d.ts +12 -0
  11. package/dist/component/_generated/server.d.ts.map +1 -1
  12. package/dist/component/_generated/server.js +2 -0
  13. package/dist/component/_generated/server.js.map +1 -1
  14. package/dist/component/convex.config.d.ts.map +1 -1
  15. package/dist/component/mutations.d.ts +46 -20
  16. package/dist/component/mutations.d.ts.map +1 -1
  17. package/dist/component/mutations.js +192 -23
  18. package/dist/component/mutations.js.map +1 -1
  19. package/dist/component/queries.d.ts +41 -8
  20. package/dist/component/queries.d.ts.map +1 -1
  21. package/dist/component/queries.js +81 -19
  22. package/dist/component/queries.js.map +1 -1
  23. package/dist/component/schema.d.ts +39 -17
  24. package/dist/component/schema.d.ts.map +1 -1
  25. package/dist/component/schema.js +19 -4
  26. package/dist/component/schema.js.map +1 -1
  27. package/dist/component/validators.d.ts +31 -18
  28. package/dist/component/validators.d.ts.map +1 -1
  29. package/dist/component/validators.js +14 -3
  30. package/dist/component/validators.js.map +1 -1
  31. package/dist/react/index.d.ts +57 -0
  32. package/dist/react/index.d.ts.map +1 -0
  33. package/dist/react/index.js +39 -0
  34. package/dist/react/index.js.map +1 -0
  35. package/dist/shared.d.ts +5 -3
  36. package/dist/shared.d.ts.map +1 -1
  37. package/dist/shared.js +5 -3
  38. package/dist/shared.js.map +1 -1
  39. package/package.json +34 -15
  40. package/src/client/index.ts +98 -4
  41. package/src/client/types.ts +8 -3
  42. package/src/component/_generated/component.ts +42 -1
  43. package/src/component/_generated/server.ts +13 -0
  44. package/src/component/mutations.ts +219 -23
  45. package/src/component/queries.ts +95 -18
  46. package/src/component/schema.ts +20 -4
  47. package/src/component/validators.ts +14 -3
  48. package/src/react/index.test.tsx +85 -0
  49. package/src/react/index.tsx +68 -0
  50. package/src/shared.ts +6 -3
@@ -3,25 +3,28 @@
3
3
  * touched. An experiment is unique within a `scope`; `subjectRef`, variant keys,
4
4
  * and the scope are all opaque host-owned strings.
5
5
  *
6
- * - `experiments` — the experiment definition (variants, weights, lifecycle, salt).
7
- * - `assignments` — a subject's sticky variant choice, persisted on first `assign`.
8
- * - `exposures` — a deduped per-subject exposure tally (the measurable surface).
6
+ * - `experiments` — the experiment definition (variants, weights, lifecycle, salt).
7
+ * - `assignments` — a subject's sticky variant choice, persisted on first `assign`.
8
+ * - `exposures` — a deduped per-subject exposure tally (the measurable surface).
9
+ * - `variantTallies` — one row per `(scope, experiment, variant)` holding running
10
+ * `assigned` / `subjects` (distinct exposed) / `exposures` counts, maintained on
11
+ * write so `results` reads O(variants) rows instead of scanning every exposure.
9
12
  */
10
13
  declare const _default: import("convex/server").SchemaDefinition<{
11
14
  experiments: import("convex/server").TableDefinition<import("convex/values").VObject<{
12
- scope: string;
15
+ createdAt: number;
13
16
  key: string;
17
+ salt: string;
18
+ scope: string;
19
+ status: "draft" | "running" | "stopped";
14
20
  variants: {
15
21
  key: string;
16
22
  weight: number;
17
23
  }[];
18
- salt: string;
19
- status: "running" | "draft" | "stopped";
20
- createdAt: number;
21
24
  }, {
22
25
  key: import("convex/values").VString<string, "required">;
23
26
  scope: import("convex/values").VString<string, "required">;
24
- status: import("convex/values").VUnion<"running" | "draft" | "stopped", [import("convex/values").VLiteral<"draft", "required">, import("convex/values").VLiteral<"running", "required">, import("convex/values").VLiteral<"stopped", "required">], "required", never>;
27
+ status: import("convex/values").VUnion<"draft" | "running" | "stopped", [import("convex/values").VLiteral<"draft", "required">, import("convex/values").VLiteral<"running", "required">, import("convex/values").VLiteral<"stopped", "required">], "required", never>;
25
28
  variants: import("convex/values").VArray<{
26
29
  key: string;
27
30
  weight: number;
@@ -34,32 +37,33 @@ declare const _default: import("convex/server").SchemaDefinition<{
34
37
  }, "required", "key" | "weight">, "required">;
35
38
  salt: import("convex/values").VString<string, "required">;
36
39
  createdAt: import("convex/values").VFloat64<number, "required">;
37
- }, "required", "scope" | "key" | "variants" | "salt" | "status" | "createdAt">, {
40
+ }, "required", "createdAt" | "key" | "salt" | "scope" | "status" | "variants">, {
41
+ by_scope: ["scope", "_creationTime"];
38
42
  by_scope_key: ["scope", "key", "_creationTime"];
39
43
  }, {}, {}>;
40
44
  assignments: import("convex/server").TableDefinition<import("convex/values").VObject<{
45
+ assignedAt: number;
46
+ experimentKey: string;
41
47
  scope: string;
42
48
  subjectRef: string;
43
49
  variant: string;
44
- assignedAt: number;
45
- experimentKey: string;
46
50
  }, {
47
51
  scope: import("convex/values").VString<string, "required">;
48
52
  experimentKey: import("convex/values").VString<string, "required">;
49
53
  subjectRef: import("convex/values").VString<string, "required">;
50
54
  variant: import("convex/values").VString<string, "required">;
51
55
  assignedAt: import("convex/values").VFloat64<number, "required">;
52
- }, "required", "scope" | "subjectRef" | "variant" | "assignedAt" | "experimentKey">, {
56
+ }, "required", "assignedAt" | "experimentKey" | "scope" | "subjectRef" | "variant">, {
53
57
  by_scope_experiment_subject: ["scope", "experimentKey", "subjectRef", "_creationTime"];
54
58
  }, {}, {}>;
55
59
  exposures: import("convex/server").TableDefinition<import("convex/values").VObject<{
56
- scope: string;
57
- subjectRef: string;
58
- variant: string;
60
+ count: number;
59
61
  experimentKey: string;
60
62
  firstExposedAt: number;
61
63
  lastExposedAt: number;
62
- count: number;
64
+ scope: string;
65
+ subjectRef: string;
66
+ variant: string;
63
67
  }, {
64
68
  scope: import("convex/values").VString<string, "required">;
65
69
  experimentKey: import("convex/values").VString<string, "required">;
@@ -68,9 +72,27 @@ declare const _default: import("convex/server").SchemaDefinition<{
68
72
  firstExposedAt: import("convex/values").VFloat64<number, "required">;
69
73
  lastExposedAt: import("convex/values").VFloat64<number, "required">;
70
74
  count: import("convex/values").VFloat64<number, "required">;
71
- }, "required", "scope" | "subjectRef" | "variant" | "experimentKey" | "firstExposedAt" | "lastExposedAt" | "count">, {
75
+ }, "required", "count" | "experimentKey" | "firstExposedAt" | "lastExposedAt" | "scope" | "subjectRef" | "variant">, {
76
+ by_scope_experiment: ["scope", "experimentKey", "_creationTime"];
72
77
  by_scope_experiment_subject: ["scope", "experimentKey", "subjectRef", "_creationTime"];
78
+ }, {}, {}>;
79
+ variantTallies: import("convex/server").TableDefinition<import("convex/values").VObject<{
80
+ assigned: number;
81
+ experimentKey: string;
82
+ exposures: number;
83
+ scope: string;
84
+ subjects: number;
85
+ variant: string;
86
+ }, {
87
+ scope: import("convex/values").VString<string, "required">;
88
+ experimentKey: import("convex/values").VString<string, "required">;
89
+ variant: import("convex/values").VString<string, "required">;
90
+ assigned: import("convex/values").VFloat64<number, "required">;
91
+ subjects: import("convex/values").VFloat64<number, "required">;
92
+ exposures: import("convex/values").VFloat64<number, "required">;
93
+ }, "required", "assigned" | "experimentKey" | "exposures" | "scope" | "subjects" | "variant">, {
73
94
  by_scope_experiment: ["scope", "experimentKey", "_creationTime"];
95
+ by_scope_experiment_variant: ["scope", "experimentKey", "variant", "_creationTime"];
74
96
  }, {}, {}>;
75
97
  }, true>;
76
98
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACH,wBAyCG"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG"}
@@ -6,9 +6,12 @@ import { variant } from "./validators";
6
6
  * touched. An experiment is unique within a `scope`; `subjectRef`, variant keys,
7
7
  * and the scope are all opaque host-owned strings.
8
8
  *
9
- * - `experiments` — the experiment definition (variants, weights, lifecycle, salt).
10
- * - `assignments` — a subject's sticky variant choice, persisted on first `assign`.
11
- * - `exposures` — a deduped per-subject exposure tally (the measurable surface).
9
+ * - `experiments` — the experiment definition (variants, weights, lifecycle, salt).
10
+ * - `assignments` — a subject's sticky variant choice, persisted on first `assign`.
11
+ * - `exposures` — a deduped per-subject exposure tally (the measurable surface).
12
+ * - `variantTallies` — one row per `(scope, experiment, variant)` holding running
13
+ * `assigned` / `subjects` (distinct exposed) / `exposures` counts, maintained on
14
+ * write so `results` reads O(variants) rows instead of scanning every exposure.
12
15
  */
13
16
  export default defineSchema({
14
17
  experiments: defineTable({
@@ -18,7 +21,9 @@ export default defineSchema({
18
21
  variants: v.array(variant),
19
22
  salt: v.string(),
20
23
  createdAt: v.number(),
21
- }).index("by_scope_key", ["scope", "key"]),
24
+ })
25
+ .index("by_scope_key", ["scope", "key"])
26
+ .index("by_scope", ["scope"]),
22
27
  assignments: defineTable({
23
28
  scope: v.string(),
24
29
  experimentKey: v.string(),
@@ -45,5 +50,15 @@ export default defineSchema({
45
50
  "subjectRef",
46
51
  ])
47
52
  .index("by_scope_experiment", ["scope", "experimentKey"]),
53
+ variantTallies: defineTable({
54
+ scope: v.string(),
55
+ experimentKey: v.string(),
56
+ variant: v.string(),
57
+ assigned: v.number(),
58
+ subjects: v.number(),
59
+ exposures: v.number(),
60
+ })
61
+ .index("by_scope_experiment_variant", ["scope", "experimentKey", "variant"])
62
+ .index("by_scope_experiment", ["scope", "experimentKey"]),
48
63
  });
49
64
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,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AAM,EAAE;QACnB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;KACvB,CAAC,CAAC,KAAK,CAAC,6BAA6B,EAAE;QACtC,OAAO;QACP,eAAe;QACf,YAAY;KACb,CAAC;IAEF,SAAS,EAAE,WAAW,CAAC;QACrB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;QACzB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;QAC1B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;QACzB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB,CAAC;SACC,KAAK,CAAC,6BAA6B,EAAE;QACpC,OAAO;QACP,eAAe;QACf,YAAY;KACb,CAAC;SACD,KAAK,CAAC,qBAAqB,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAE3D,cAAc,EAAE,WAAW,CAAC;QAC1B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;QACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;QACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;QACpB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC;SACC,KAAK,CAAC,6BAA6B,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;SAC3E,KAAK,CAAC,qBAAqB,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;CAC5D,CAAC,CAAC"}
@@ -7,7 +7,7 @@ export declare const variant: import("convex/values").VObject<{
7
7
  weight: import("convex/values").VFloat64<number, "required">;
8
8
  }, "required", "key" | "weight">;
9
9
  /** Experiment lifecycle status. `running` is the only status that enrolls subjects. */
10
- export declare const experimentStatus: import("convex/values").VUnion<"running" | "draft" | "stopped", [import("convex/values").VLiteral<"draft", "required">, import("convex/values").VLiteral<"running", "required">, import("convex/values").VLiteral<"stopped", "required">], "required", never>;
10
+ export declare const experimentStatus: import("convex/values").VUnion<"draft" | "running" | "stopped", [import("convex/values").VLiteral<"draft", "required">, import("convex/values").VLiteral<"running", "required">, import("convex/values").VLiteral<"stopped", "required">], "required", never>;
11
11
  /**
12
12
  * Result of `assign`. `{ variant: null }` — the experiment is absent or not
13
13
  * `running`, so the subject is not enrolled (the host treats this as control).
@@ -17,20 +17,23 @@ export declare const experimentStatus: import("convex/values").VUnion<"running"
17
17
  export declare const assignResult: import("convex/values").VUnion<{
18
18
  variant: null;
19
19
  } | {
20
- variant: string;
21
20
  isNew: boolean;
21
+ variant: string;
22
22
  }, [import("convex/values").VObject<{
23
23
  variant: null;
24
24
  }, {
25
25
  variant: import("convex/values").VNull<null, "required">;
26
26
  }, "required", "variant">, import("convex/values").VObject<{
27
- variant: string;
28
27
  isNew: boolean;
28
+ variant: string;
29
29
  }, {
30
30
  variant: import("convex/values").VString<string, "required">;
31
31
  isNew: import("convex/values").VBoolean<boolean, "required">;
32
- }, "required", "variant" | "isNew">], "required", "variant" | "isNew">;
33
- /** Result of `logExposure`: the enrolled variant, or `null` when not enrolled. */
32
+ }, "required", "isNew" | "variant">], "required", "isNew" | "variant">;
33
+ /**
34
+ * Result of `logExposure` / `peek`: the enrolled variant, or `null` when the
35
+ * subject is not enrolled (experiment absent or not `running`).
36
+ */
34
37
  export declare const exposureResult: import("convex/values").VUnion<{
35
38
  variant: null;
36
39
  } | {
@@ -44,21 +47,21 @@ export declare const exposureResult: import("convex/values").VUnion<{
44
47
  }, {
45
48
  variant: import("convex/values").VString<string, "required">;
46
49
  }, "required", "variant">], "required", "variant">;
47
- /** Projection of an experiment definition returned by `getExperiment`. */
50
+ /** Projection of an experiment definition returned by `getExperiment` / `listExperiments`. */
48
51
  export declare const experimentDef: import("convex/values").VObject<{
49
- scope: string;
52
+ createdAt: number;
50
53
  key: string;
54
+ salt: string;
55
+ scope: string;
56
+ status: "draft" | "running" | "stopped";
51
57
  variants: {
52
58
  key: string;
53
59
  weight: number;
54
60
  }[];
55
- salt: string;
56
- status: "running" | "draft" | "stopped";
57
- createdAt: number;
58
61
  }, {
59
62
  key: import("convex/values").VString<string, "required">;
60
63
  scope: import("convex/values").VString<string, "required">;
61
- status: import("convex/values").VUnion<"running" | "draft" | "stopped", [import("convex/values").VLiteral<"draft", "required">, import("convex/values").VLiteral<"running", "required">, import("convex/values").VLiteral<"stopped", "required">], "required", never>;
64
+ status: import("convex/values").VUnion<"draft" | "running" | "stopped", [import("convex/values").VLiteral<"draft", "required">, import("convex/values").VLiteral<"running", "required">, import("convex/values").VLiteral<"stopped", "required">], "required", never>;
62
65
  variants: import("convex/values").VArray<{
63
66
  key: string;
64
67
  weight: number;
@@ -71,26 +74,36 @@ export declare const experimentDef: import("convex/values").VObject<{
71
74
  }, "required", "key" | "weight">, "required">;
72
75
  salt: import("convex/values").VString<string, "required">;
73
76
  createdAt: import("convex/values").VFloat64<number, "required">;
74
- }, "required", "scope" | "key" | "variants" | "salt" | "status" | "createdAt">;
77
+ }, "required", "createdAt" | "key" | "salt" | "scope" | "status" | "variants">;
75
78
  /** Projection of a subject's sticky assignment returned by `getAssignment`. */
76
79
  export declare const assignmentProjection: import("convex/values").VObject<{
77
- variant: string;
78
80
  assignedAt: number;
81
+ variant: string;
79
82
  }, {
80
83
  variant: import("convex/values").VString<string, "required">;
81
84
  assignedAt: import("convex/values").VFloat64<number, "required">;
82
- }, "required", "variant" | "assignedAt">;
83
- /** Per-variant exposure tally returned by `results`. */
85
+ }, "required", "assignedAt" | "variant">;
86
+ /**
87
+ * Per-variant tally returned by `results`. `assigned` and `subjects` together with
88
+ * the configured `weight` let an analyst compute sample-ratio-mismatch (observed
89
+ * vs expected split) and the funnel denominator host-side.
90
+ */
84
91
  export declare const variantResult: import("convex/values").VObject<{
85
- variant: string;
86
- subjects: number;
92
+ assigned: number;
87
93
  exposures: number;
94
+ subjects: number;
95
+ variant: string;
96
+ weight: number;
88
97
  }, {
89
98
  /** The variant key. */
90
99
  variant: import("convex/values").VString<string, "required">;
100
+ /** Subjects assigned to this variant (the realized split for SRM). */
101
+ assigned: import("convex/values").VFloat64<number, "required">;
91
102
  /** Distinct subjects exposed to this variant (the funnel denominator). */
92
103
  subjects: import("convex/values").VFloat64<number, "required">;
93
104
  /** Total exposure events recorded for this variant. */
94
105
  exposures: import("convex/values").VFloat64<number, "required">;
95
- }, "required", "variant" | "subjects" | "exposures">;
106
+ /** The configured weight from the current definition (0 if the variant is gone). */
107
+ weight: import("convex/values").VFloat64<number, "required">;
108
+ }, "required", "assigned" | "exposures" | "subjects" | "variant" | "weight">;
96
109
  //# sourceMappingURL=validators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA,oFAAoF;AACpF,eAAO,MAAM,OAAO;;;;;;gCAAoD,CAAC;AAEzE,uFAAuF;AACvF,eAAO,MAAM,gBAAgB,+PAI5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;sEAGxB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,cAAc;;;;;;;;;;;;kDAG1B,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;8EAOxB,CAAC;AAEH,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB;;;;;;wCAG/B,CAAC;AAEH,wDAAwD;AACxD,eAAO,MAAM,aAAa;;;;;IACxB,uBAAuB;;IAEvB,0EAA0E;;IAE1E,uDAAuD;;oDAEvD,CAAC"}
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA,oFAAoF;AACpF,eAAO,MAAM,OAAO;;;;;;gCAAoD,CAAC;AAEzE,uFAAuF;AACvF,eAAO,MAAM,gBAAgB,+PAI5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;sEAGxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;kDAG1B,CAAC;AAEF,8FAA8F;AAC9F,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;8EAOxB,CAAC;AAEH,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB;;;;;;wCAG/B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;IACxB,uBAAuB;;IAEvB,sEAAsE;;IAEtE,0EAA0E;;IAE1E,uDAAuD;;IAEvD,oFAAoF;;4EAEpF,CAAC"}
@@ -10,9 +10,12 @@ export const experimentStatus = v.union(v.literal("draft"), v.literal("running")
10
10
  * call that first persisted the assignment.
11
11
  */
12
12
  export const assignResult = v.union(v.object({ variant: v.null() }), v.object({ variant: v.string(), isNew: v.boolean() }));
13
- /** Result of `logExposure`: the enrolled variant, or `null` when not enrolled. */
13
+ /**
14
+ * Result of `logExposure` / `peek`: the enrolled variant, or `null` when the
15
+ * subject is not enrolled (experiment absent or not `running`).
16
+ */
14
17
  export const exposureResult = v.union(v.object({ variant: v.null() }), v.object({ variant: v.string() }));
15
- /** Projection of an experiment definition returned by `getExperiment`. */
18
+ /** Projection of an experiment definition returned by `getExperiment` / `listExperiments`. */
16
19
  export const experimentDef = v.object({
17
20
  key: v.string(),
18
21
  scope: v.string(),
@@ -26,13 +29,21 @@ export const assignmentProjection = v.object({
26
29
  variant: v.string(),
27
30
  assignedAt: v.number(),
28
31
  });
29
- /** Per-variant exposure tally returned by `results`. */
32
+ /**
33
+ * Per-variant tally returned by `results`. `assigned` and `subjects` together with
34
+ * the configured `weight` let an analyst compute sample-ratio-mismatch (observed
35
+ * vs expected split) and the funnel denominator host-side.
36
+ */
30
37
  export const variantResult = v.object({
31
38
  /** The variant key. */
32
39
  variant: v.string(),
40
+ /** Subjects assigned to this variant (the realized split for SRM). */
41
+ assigned: v.number(),
33
42
  /** Distinct subjects exposed to this variant (the funnel denominator). */
34
43
  subjects: v.number(),
35
44
  /** Total exposure events recorded for this variant. */
36
45
  exposures: v.number(),
46
+ /** The configured weight from the current definition (0 if the variant is gone). */
47
+ weight: v.number(),
37
48
  });
38
49
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,oFAAoF;AACpF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAEzE,uFAAuF;AACvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CACrC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAClB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CACrB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CACjC,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAC/B,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACtD,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CACnC,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,EA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,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,uBAAuB;IACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,sEAAsE;IACtE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,0EAA0E;IAC1E,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,uDAAuD;IACvD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,oFAAoF;IACpF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Optional, tree-shakeable React front-tooling for `@vllnt/convex-experiments`.
3
+ *
4
+ * Thin reactive hooks over `useQuery` from `convex/react`. Each takes the HOST's
5
+ * re-exported query reference plus its args — the component never imports the host
6
+ * `api`. `react` and `convex/react` are optional peer deps: a backend-only consumer
7
+ * pulls none of this code.
8
+ *
9
+ * NO-LEAK CONTRACT: these hooks expose only non-secret experiment data — the
10
+ * subject's own variant key, their assignment, and aggregate per-variant tallies.
11
+ * There is no secret or cross-subject payload. `useVariant` reads the deterministic
12
+ * `peek` query, so it paints the correct variant on first render (no flash of
13
+ * control); call the `logExposure` mutation to enroll + tally.
14
+ */
15
+ import type { FunctionReference } from "convex/server";
16
+ import type { Assignment, VariantResult } from "../client/types.js";
17
+ /**
18
+ * Reactive, flicker-free variant for a subject — wraps the host's re-exported
19
+ * `peek` query (deterministic, read-only). Returns the variant key, `null` when not
20
+ * enrolled, or `undefined` while the query loads.
21
+ */
22
+ export declare function useVariant(peekRef: FunctionReference<"query", "public", {
23
+ scope?: string;
24
+ key: string;
25
+ subjectRef: string;
26
+ }, {
27
+ variant: string | null;
28
+ }>, args: {
29
+ scope?: string;
30
+ key: string;
31
+ subjectRef: string;
32
+ }): string | null | undefined;
33
+ /**
34
+ * Reactive sticky assignment — wraps the host's re-exported `getAssignment` query.
35
+ * `null` when not enrolled, `undefined` while loading.
36
+ */
37
+ export declare function useAssignment(getAssignmentRef: FunctionReference<"query", "public", {
38
+ scope?: string;
39
+ key: string;
40
+ subjectRef: string;
41
+ }, Assignment | null>, args: {
42
+ scope?: string;
43
+ key: string;
44
+ subjectRef: string;
45
+ }): Assignment | null | undefined;
46
+ /**
47
+ * Reactive per-variant tallies (`assigned`/`subjects`/`exposures`/`weight`) for a
48
+ * live results dashboard — wraps the host's re-exported `results` query.
49
+ */
50
+ export declare function useExperimentResults(resultsRef: FunctionReference<"query", "public", {
51
+ scope?: string;
52
+ key: string;
53
+ }, VariantResult[]>, args: {
54
+ scope?: string;
55
+ key: string;
56
+ }): VariantResult[] | undefined;
57
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEpE;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,iBAAiB,CACxB,OAAO,EACP,QAAQ,EACR;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EACnD;IAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAC3B,EACD,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACxD,MAAM,GAAG,IAAI,GAAG,SAAS,CAG3B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,gBAAgB,EAAE,iBAAiB,CACjC,OAAO,EACP,QAAQ,EACR;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EACnD,UAAU,GAAG,IAAI,CAClB,EACD,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACxD,UAAU,GAAG,IAAI,GAAG,SAAS,CAE/B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,iBAAiB,CAC3B,OAAO,EACP,QAAQ,EACR;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC/B,aAAa,EAAE,CAChB,EACD,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACpC,aAAa,EAAE,GAAG,SAAS,CAE7B"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Optional, tree-shakeable React front-tooling for `@vllnt/convex-experiments`.
3
+ *
4
+ * Thin reactive hooks over `useQuery` from `convex/react`. Each takes the HOST's
5
+ * re-exported query reference plus its args — the component never imports the host
6
+ * `api`. `react` and `convex/react` are optional peer deps: a backend-only consumer
7
+ * pulls none of this code.
8
+ *
9
+ * NO-LEAK CONTRACT: these hooks expose only non-secret experiment data — the
10
+ * subject's own variant key, their assignment, and aggregate per-variant tallies.
11
+ * There is no secret or cross-subject payload. `useVariant` reads the deterministic
12
+ * `peek` query, so it paints the correct variant on first render (no flash of
13
+ * control); call the `logExposure` mutation to enroll + tally.
14
+ */
15
+ import { useQuery } from "convex/react";
16
+ /**
17
+ * Reactive, flicker-free variant for a subject — wraps the host's re-exported
18
+ * `peek` query (deterministic, read-only). Returns the variant key, `null` when not
19
+ * enrolled, or `undefined` while the query loads.
20
+ */
21
+ export function useVariant(peekRef, args) {
22
+ const result = useQuery(peekRef, args);
23
+ return result === undefined ? undefined : result.variant;
24
+ }
25
+ /**
26
+ * Reactive sticky assignment — wraps the host's re-exported `getAssignment` query.
27
+ * `null` when not enrolled, `undefined` while loading.
28
+ */
29
+ export function useAssignment(getAssignmentRef, args) {
30
+ return useQuery(getAssignmentRef, args);
31
+ }
32
+ /**
33
+ * Reactive per-variant tallies (`assigned`/`subjects`/`exposures`/`weight`) for a
34
+ * live results dashboard — wraps the host's re-exported `results` query.
35
+ */
36
+ export function useExperimentResults(resultsRef, args) {
37
+ return useQuery(resultsRef, args);
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,OAKC,EACD,IAAyD;IAEzD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,gBAKC,EACD,IAAyD;IAEzD,OAAO,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAKC,EACD,IAAqC;IAErC,OAAO,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC"}
package/dist/shared.d.ts CHANGED
@@ -4,6 +4,8 @@ export declare const COMPONENT_NAME = "experiments";
4
4
  export declare const DEFAULT_SCOPE = "global";
5
5
  /** Lifecycle status the client applies to `define` when the caller omits one. */
6
6
  export declare const DEFAULT_STATUS = "running";
7
+ /** Default page size for a `deleteExperiment` cascade pass before it self-reschedules. */
8
+ export declare const DEFAULT_DELETE_BATCH = 200;
7
9
  /** A weighted variant: an opaque variant key and its relative selection weight. */
8
10
  export interface Variant {
9
11
  /** The host's opaque variant key (e.g. `"control"`, `"treatment"`). */
@@ -22,9 +24,9 @@ export declare function fnv1a(input: string): number;
22
24
  * Deterministically pick a variant for `subjectRef` from `variants`, weighted by
23
25
  * each variant's `weight`. The same `(salt, subjectRef)` always maps to the same
24
26
  * variant — sticky assignment with no storage — and the distribution matches the
25
- * weights. `salt` lets a host re-randomize an experiment (a fresh re-run) without
26
- * changing subject ids. Assumes a non-empty `variants` with positive weights; the
27
- * caller validates that upstream.
27
+ * weights. The component folds `scope` into the salt so the same subject buckets
28
+ * independently per scope. Assumes a non-empty `variants` with positive weights;
29
+ * the caller validates that upstream.
28
30
  */
29
31
  export declare function pickVariant(variants: readonly Variant[], salt: string, subjectRef: string): string;
30
32
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C,oEAAoE;AACpE,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,iFAAiF;AACjF,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,mFAAmF;AACnF,MAAM,WAAW,OAAO;IACtB,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO3C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,MAAM,CAoBR"}
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C,oEAAoE;AACpE,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,iFAAiF;AACjF,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,0FAA0F;AAC1F,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,mFAAmF;AACnF,MAAM,WAAW,OAAO;IACtB,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO3C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,MAAM,CAoBR"}
package/dist/shared.js CHANGED
@@ -4,6 +4,8 @@ export const COMPONENT_NAME = "experiments";
4
4
  export const DEFAULT_SCOPE = "global";
5
5
  /** Lifecycle status the client applies to `define` when the caller omits one. */
6
6
  export const DEFAULT_STATUS = "running";
7
+ /** Default page size for a `deleteExperiment` cascade pass before it self-reschedules. */
8
+ export const DEFAULT_DELETE_BATCH = 200;
7
9
  /**
8
10
  * FNV-1a 32-bit hash of `input`, returned as an unsigned integer. Deterministic,
9
11
  * synchronous, and dependency-free — the component runs in a V8 isolate, so a
@@ -22,9 +24,9 @@ export function fnv1a(input) {
22
24
  * Deterministically pick a variant for `subjectRef` from `variants`, weighted by
23
25
  * each variant's `weight`. The same `(salt, subjectRef)` always maps to the same
24
26
  * variant — sticky assignment with no storage — and the distribution matches the
25
- * weights. `salt` lets a host re-randomize an experiment (a fresh re-run) without
26
- * changing subject ids. Assumes a non-empty `variants` with positive weights; the
27
- * caller validates that upstream.
27
+ * weights. The component folds `scope` into the salt so the same subject buckets
28
+ * independently per scope. Assumes a non-empty `variants` with positive weights;
29
+ * the caller validates that upstream.
28
30
  */
29
31
  export function pickVariant(variants, salt, subjectRef) {
30
32
  const lastVariant = variants[variants.length - 1];
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAE5C,oEAAoE;AACpE,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;AAEtC,iFAAiF;AACjF,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAUxC;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACzB,QAA4B,EAC5B,IAAY,EACZ,UAAkB;IAElB,MAAM,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAC1B,CAAC;IACD,uEAAuE;IACvE,IAAI,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,UAAU,EAAE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AClD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAC1B,CAAC;IACD,uEAAuE;IACvE,IAAI,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,UAAU,EAAE,CAAC,GAAG,WAAW,CAAC,GAAG,KAAK,CAAC;IACpE,iEAAiE;IACjE,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;QACzB,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACf,OAAO,OAAO,CAAC,GAAG,CAAC;QACrB,CAAC;IACH,CAAC;IACD,+EAA+E;IAC/E,OAAO,WAAW,CAAC,GAAG,CAAC;AACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vllnt/convex-experiments",
3
- "version": "0.1.0-canary.f2cd1ba",
3
+ "version": "0.1.0",
4
4
  "description": "Deterministic A/B experimentation — sticky variant assignment and deduped exposure tracking, as a Convex component",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,6 +15,10 @@
15
15
  "types": "./dist/client/index.d.ts",
16
16
  "default": "./dist/client/index.js"
17
17
  },
18
+ "./react": {
19
+ "types": "./dist/react/index.d.ts",
20
+ "default": "./dist/react/index.js"
21
+ },
18
22
  "./test": "./src/test.ts",
19
23
  "./_generated/component.js": {
20
24
  "types": "./dist/component/_generated/component.d.ts"
@@ -35,11 +39,11 @@
35
39
  "module": "./dist/client/index.js",
36
40
  "scripts": {
37
41
  "build": "tsc --project ./tsconfig.build.json",
38
- "build:codegen": "pnpm convex codegen --component-dir ./src/component && pnpm build",
42
+ "build:codegen": "pnpm codegen && pnpm build",
39
43
  "build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
40
44
  "typecheck": "tsc --noEmit",
41
45
  "typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
42
- "lint": "eslint .",
46
+ "lint": "pnpm check:agents && eslint .",
43
47
  "test": "vitest run --passWithNoTests",
44
48
  "test:watch": "vitest --typecheck --clearScreen false",
45
49
  "test:coverage": "vitest run --coverage --coverage.reporter=text",
@@ -47,23 +51,38 @@
47
51
  "preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
48
52
  "prepublishOnly": "npm whoami || npm login",
49
53
  "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
50
- "release": "npm version patch && npm publish && git push --follow-tags"
54
+ "release": "npm version patch && npm publish && git push --follow-tags",
55
+ "check:agents": "node -e \"const f=require('node:fs');if(!f.existsSync('AGENTS.md')||f.existsSync('CLAUDE.md')||f.existsSync('.claude'))process.exit(1)\"",
56
+ "codegen": "pnpm convex codegen --component-dir ./src/component"
51
57
  },
52
- "dependencies": {},
53
58
  "peerDependencies": {
54
- "convex": "^1.41.0"
59
+ "convex": "^1.45.0",
60
+ "react": ">=18"
61
+ },
62
+ "peerDependenciesMeta": {
63
+ "react": {
64
+ "optional": true
65
+ }
55
66
  },
56
67
  "devDependencies": {
57
68
  "@edge-runtime/vm": "^5.0.0",
58
- "@vitest/coverage-v8": "^4.1.8",
59
- "@vllnt/eslint-config": "^1.0.0",
60
- "@vllnt/typescript": "^1.0.0",
61
- "convex": "^1.41.0",
62
- "convex-test": "^0.0.53",
63
- "eslint": "^9.0.0",
64
- "prettier": "^3.4.0",
65
- "typescript": "^5.7.0",
66
- "vitest": "^4.1.8"
69
+ "@testing-library/react": "^16.3.3",
70
+ "@types/react": "^19.2.18",
71
+ "@types/react-dom": "^19.2.5",
72
+ "@typescript/native": "npm:typescript@7.0.2",
73
+ "@vitest/coverage-v8": "^4.1.11",
74
+ "@vllnt/eslint-config": "2.0.0",
75
+ "@vllnt/typescript": "2.0.0",
76
+ "convex": "^1.45.0",
77
+ "convex-test": "^0.0.56",
78
+ "eslint": "^9.39.5",
79
+ "jsdom": "^29.1.1",
80
+ "prettier": "^3.9.6",
81
+ "react": "^19.2.8",
82
+ "react-dom": "^19.2.8",
83
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
84
+ "vite": "^8.2.2",
85
+ "vitest": "^4.1.11"
67
86
  },
68
87
  "homepage": "https://github.com/vllnt/convex-experiments#readme",
69
88
  "bugs": {