@vllnt/convex-experiments 0.1.0-canary.f2cd1ba → 0.1.1-canary.b4e25b0
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.
- package/README.md +150 -36
- package/dist/client/index.d.ts +54 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +53 -4
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +8 -3
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/component.d.ts +35 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/_generated/server.d.ts +12 -0
- package/dist/component/_generated/server.d.ts.map +1 -1
- package/dist/component/_generated/server.js +2 -0
- package/dist/component/_generated/server.js.map +1 -1
- package/dist/component/convex.config.d.ts.map +1 -1
- package/dist/component/mutations.d.ts +47 -20
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +220 -26
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts +41 -8
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +82 -20
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.d.ts +39 -17
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +20 -5
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +31 -18
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +14 -3
- package/dist/component/validators.js.map +1 -1
- package/dist/react/index.d.ts +57 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +39 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared.d.ts +5 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +5 -3
- package/dist/shared.js.map +1 -1
- package/package.json +50 -20
- package/src/client/index.ts +98 -4
- package/src/client/types.ts +8 -3
- package/src/component/_generated/component.ts +42 -1
- package/src/component/_generated/server.ts +13 -0
- package/src/component/mutations.ts +250 -28
- package/src/component/queries.ts +97 -20
- package/src/component/schema.ts +21 -5
- package/src/component/validators.ts +14 -3
- package/src/react/index.tsx +68 -0
- package/src/shared.ts +6 -3
- package/src/test.ts +2 -1
- package/src/unit.test.ts +0 -84
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
|
-
import { query } from "./_generated/server";
|
|
3
|
-
import {
|
|
2
|
+
import { query } from "./_generated/server.js";
|
|
3
|
+
import { pickVariant } from "../shared.js";
|
|
4
|
+
import { assignmentProjection, experimentDef, experimentStatus, exposureResult, variantResult, } from "./validators.js";
|
|
4
5
|
/** The experiment definition for `(scope, key)`, or `null` if none exists. */
|
|
5
6
|
export const getExperiment = query({
|
|
6
7
|
args: { scope: v.string(), key: v.string() },
|
|
@@ -23,6 +24,28 @@ export const getExperiment = query({
|
|
|
23
24
|
};
|
|
24
25
|
},
|
|
25
26
|
});
|
|
27
|
+
/** Every experiment in a scope, optionally filtered by `status`. */
|
|
28
|
+
export const listExperiments = query({
|
|
29
|
+
args: { scope: v.string(), status: v.optional(experimentStatus) },
|
|
30
|
+
returns: v.array(experimentDef),
|
|
31
|
+
handler: async (ctx, args) => {
|
|
32
|
+
const rows = await ctx.db
|
|
33
|
+
.query("experiments")
|
|
34
|
+
.withIndex("by_scope", (q) => q.eq("scope", args.scope))
|
|
35
|
+
.collect();
|
|
36
|
+
const filtered = args.status === undefined
|
|
37
|
+
? rows
|
|
38
|
+
: rows.filter((row) => row.status === args.status);
|
|
39
|
+
return filtered.map((row) => ({
|
|
40
|
+
key: row.key,
|
|
41
|
+
scope: row.scope,
|
|
42
|
+
status: row.status,
|
|
43
|
+
variants: row.variants,
|
|
44
|
+
salt: row.salt,
|
|
45
|
+
createdAt: row.createdAt,
|
|
46
|
+
}));
|
|
47
|
+
},
|
|
48
|
+
});
|
|
26
49
|
/** A subject's sticky assignment for an experiment, or `null` if not enrolled. */
|
|
27
50
|
export const getAssignment = query({
|
|
28
51
|
args: { scope: v.string(), key: v.string(), subjectRef: v.string() },
|
|
@@ -42,31 +65,70 @@ export const getAssignment = query({
|
|
|
42
65
|
},
|
|
43
66
|
});
|
|
44
67
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
68
|
+
* Read-only deterministic variant for a subject — the sticky variant **without
|
|
69
|
+
* persisting** anything. Returns the stored assignment if one exists, otherwise
|
|
70
|
+
* the deterministic `pickVariant` result; `{ variant: null }` when the experiment
|
|
71
|
+
* is absent or not `running`. Use this for SSR / server-component render and as a
|
|
72
|
+
* flicker-free first paint; call the `logExposure` mutation to enroll + tally.
|
|
73
|
+
*/
|
|
74
|
+
export const peek = query({
|
|
75
|
+
args: { scope: v.string(), key: v.string(), subjectRef: v.string() },
|
|
76
|
+
returns: exposureResult,
|
|
77
|
+
handler: async (ctx, args) => {
|
|
78
|
+
const experiment = await ctx.db
|
|
79
|
+
.query("experiments")
|
|
80
|
+
.withIndex("by_scope_key", (q) => q.eq("scope", args.scope).eq("key", args.key))
|
|
81
|
+
.unique();
|
|
82
|
+
if (experiment === null || experiment.status !== "running") {
|
|
83
|
+
return { variant: null };
|
|
84
|
+
}
|
|
85
|
+
const assignment = await ctx.db
|
|
86
|
+
.query("assignments")
|
|
87
|
+
.withIndex("by_scope_experiment_subject", (q) => q
|
|
88
|
+
.eq("scope", args.scope)
|
|
89
|
+
.eq("experimentKey", args.key)
|
|
90
|
+
.eq("subjectRef", args.subjectRef))
|
|
91
|
+
.unique();
|
|
92
|
+
if (assignment !== null) {
|
|
93
|
+
return { variant: assignment.variant };
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
variant: pickVariant(experiment.variants, `${experiment.scope}:${experiment.salt}`, args.subjectRef),
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Per-variant tallies for an experiment — `assigned`, distinct `subjects` exposed,
|
|
102
|
+
* total `exposures`, and the configured `weight` (for sample-ratio-mismatch).
|
|
103
|
+
* Reads the maintained `variantTallies` rows (O(variants)), never scanning the
|
|
104
|
+
* exposure table. An experiment with no enrollment returns an empty array.
|
|
49
105
|
*/
|
|
50
106
|
export const results = query({
|
|
51
107
|
args: { scope: v.string(), key: v.string() },
|
|
52
108
|
returns: v.array(variantResult),
|
|
53
109
|
handler: async (ctx, args) => {
|
|
54
|
-
const
|
|
55
|
-
.query("
|
|
110
|
+
const experiment = await ctx.db
|
|
111
|
+
.query("experiments")
|
|
112
|
+
.withIndex("by_scope_key", (q) => q.eq("scope", args.scope).eq("key", args.key))
|
|
113
|
+
.unique();
|
|
114
|
+
if (experiment === null) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
const tallies = await ctx.db
|
|
118
|
+
.query("variantTallies")
|
|
56
119
|
.withIndex("by_scope_experiment", (q) => q.eq("scope", args.scope).eq("experimentKey", args.key))
|
|
57
120
|
.collect();
|
|
58
|
-
const byVariant = new Map();
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}));
|
|
121
|
+
const byVariant = new Map(tallies.map((tally) => [tally.variant, tally]));
|
|
122
|
+
return experiment.variants.map((variant) => {
|
|
123
|
+
const tally = byVariant.get(variant.key);
|
|
124
|
+
return {
|
|
125
|
+
variant: variant.key,
|
|
126
|
+
assigned: tally?.assigned ?? 0,
|
|
127
|
+
subjects: tally?.subjects ?? 0,
|
|
128
|
+
exposures: tally?.exposures ?? 0,
|
|
129
|
+
weight: variant.weight,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
70
132
|
},
|
|
71
133
|
});
|
|
72
134
|
//# sourceMappingURL=queries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC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,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -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`
|
|
7
|
-
* - `assignments`
|
|
8
|
-
* - `exposures`
|
|
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
|
-
|
|
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<"
|
|
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", "
|
|
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", "
|
|
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
|
-
|
|
57
|
-
subjectRef: string;
|
|
58
|
-
variant: string;
|
|
60
|
+
count: number;
|
|
59
61
|
experimentKey: string;
|
|
60
62
|
firstExposedAt: number;
|
|
61
63
|
lastExposedAt: number;
|
|
62
|
-
|
|
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", "
|
|
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
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG"}
|
package/dist/component/schema.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { defineSchema, defineTable } from "convex/server";
|
|
2
2
|
import { v } from "convex/values";
|
|
3
|
-
import { variant } from "./validators";
|
|
3
|
+
import { variant } from "./validators.js";
|
|
4
4
|
/**
|
|
5
5
|
* Sandboxed tables — the experimentation ledger's own concern. No host tables are
|
|
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`
|
|
10
|
-
* - `assignments`
|
|
11
|
-
* - `exposures`
|
|
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
|
-
})
|
|
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,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
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,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,eAAe,YAAY,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;QACvB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;QACf,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,MAAM,EAAE,CAAC,CAAC,KAAK,CACb,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAClB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CACrB;QACD,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QAC1B,IAAI,EAAE,CAAC,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AAC,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<"
|
|
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", "
|
|
33
|
-
/**
|
|
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
|
-
|
|
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<"
|
|
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", "
|
|
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", "
|
|
83
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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,EA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,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. `
|
|
26
|
-
*
|
|
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
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -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"}
|