@vllnt/convex-experiments 0.1.0-canary.207ab91
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/LICENSE +21 -0
- package/README.md +132 -0
- package/dist/client/index.d.ts +117 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +105 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +70 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +3 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +38 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +93 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +7 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/mutations.d.ts +67 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +196 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +39 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +72 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +77 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +49 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +96 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +38 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/shared.d.ts +30 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +50 -0
- package/dist/shared.js.map +1 -0
- package/package.json +98 -0
- package/src/client/index.ts +249 -0
- package/src/client/types.ts +73 -0
- package/src/component/_generated/api.ts +54 -0
- package/src/component/_generated/component.ts +92 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +9 -0
- package/src/component/mutations.ts +224 -0
- package/src/component/queries.ts +84 -0
- package/src/component/schema.ts +55 -0
- package/src/component/validators.ts +54 -0
- package/src/shared.ts +66 -0
- package/src/test.ts +12 -0
- package/src/unit.test.ts +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bntvllnt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<!-- Badges -->
|
|
2
|
+
[](https://www.convex.dev/components)
|
|
3
|
+
[](https://www.npmjs.com/package/@vllnt/convex-experiments)
|
|
4
|
+
[](https://github.com/vllnt/convex-experiments/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
# @vllnt/convex-experiments
|
|
8
|
+
|
|
9
|
+
Deterministic A/B experimentation — sticky variant assignment and deduped exposure tracking, as a
|
|
10
|
+
Convex component.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const experiments = new Experiments(components.experiments);
|
|
14
|
+
await experiments.define(ctx, "checkout_button", {
|
|
15
|
+
variants: [
|
|
16
|
+
{ key: "control", weight: 1 },
|
|
17
|
+
{ key: "treatment", weight: 1 },
|
|
18
|
+
],
|
|
19
|
+
});
|
|
20
|
+
const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
|
|
21
|
+
if (variant === "treatment") showNewButton();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Define an experiment with weighted variants; enroll subjects into a **sticky** variant chosen
|
|
25
|
+
deterministically from `(salt, subjectRef)`; record exposures and read per-variant tallies. Pair it
|
|
26
|
+
with a feature-flag system for kill-switches and measure conversions in your own tables — this
|
|
27
|
+
component handles assignment and exposure. Domain-neutral: any subject, any surface.
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- **Deterministic + sticky** — the same subject always lands in the same weighted variant, even before anything is stored.
|
|
32
|
+
- **Weighted variants** — split traffic by relative weights (`1:1`, `90:10`, N-way); equal weights split evenly.
|
|
33
|
+
- **Enrollment lifecycle** — `draft → running → stopped`; only `running` enrolls, and stopping preserves recorded data.
|
|
34
|
+
- **Deduped exposures** — one tallied row per subject; `results` reports distinct subjects and total exposures per variant.
|
|
35
|
+
- **Salted re-runs** — change `salt` to reshuffle buckets without changing subject ids.
|
|
36
|
+
- **Scopes** — global by default, or namespace per tenant / surface.
|
|
37
|
+
- **Fully typed** — variant keys, weights, and outcomes are concrete types end to end; no `any`.
|
|
38
|
+
- **Server-sourced time** — assignment timestamps come from the server, never the caller.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm add @vllnt/convex-experiments
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Peer dependency: `convex@^1.41.0`.
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// convex/convex.config.ts
|
|
52
|
+
import { defineApp } from "convex/server";
|
|
53
|
+
import experiments from "@vllnt/convex-experiments/convex.config";
|
|
54
|
+
|
|
55
|
+
const app = defineApp();
|
|
56
|
+
app.use(experiments);
|
|
57
|
+
export default app;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// convex/checkout.ts — host owns auth; pass an opaque subjectRef in.
|
|
62
|
+
import { components } from "./_generated/api";
|
|
63
|
+
import { mutation } from "./_generated/server";
|
|
64
|
+
import { v } from "convex/values";
|
|
65
|
+
import { Experiments } from "@vllnt/convex-experiments";
|
|
66
|
+
|
|
67
|
+
const experiments = new Experiments(components.experiments);
|
|
68
|
+
|
|
69
|
+
export const view = mutation({
|
|
70
|
+
args: { userId: v.string() },
|
|
71
|
+
handler: async (ctx, { userId }) => {
|
|
72
|
+
const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
|
|
73
|
+
return { variant }; // "control" | "treatment" | null (not enrolled)
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Measure the outcome in your own table, joined on the assigned variant — then read tallies with
|
|
79
|
+
`results(ctx, "checkout_button")`. See [`example/convex/example.ts`](example/convex/example.ts) for a
|
|
80
|
+
host-side conversion recorder.
|
|
81
|
+
|
|
82
|
+
## API Reference
|
|
83
|
+
|
|
84
|
+
| Method | Kind | Result |
|
|
85
|
+
|--------|------|--------|
|
|
86
|
+
| `define(ctx, key, { variants, scope?, salt?, status? })` | mutation | `{ created: boolean }` |
|
|
87
|
+
| `setStatus(ctx, key, status, scope?)` | mutation | `boolean` |
|
|
88
|
+
| `assign(ctx, key, subjectRef, scope?)` | mutation | `{ variant: null } \| { variant: string; isNew: boolean }` |
|
|
89
|
+
| `logExposure(ctx, key, subjectRef, scope?)` | mutation | `{ variant: string \| null }` |
|
|
90
|
+
| `getExperiment(ctx, key, scope?)` | query | `ExperimentDefinition \| null` |
|
|
91
|
+
| `getAssignment(ctx, key, subjectRef, scope?)` | query | `{ variant, assignedAt } \| null` |
|
|
92
|
+
| `results(ctx, key, scope?)` | query | `{ variant, subjects, exposures }[]` |
|
|
93
|
+
|
|
94
|
+
Full reference: [docs/API.md](docs/API.md).
|
|
95
|
+
|
|
96
|
+
## React
|
|
97
|
+
|
|
98
|
+
Backend-only at this version — no `./react` entry. Assignment and exposure are recorded server-side;
|
|
99
|
+
a reactive read hook may ship in a later version.
|
|
100
|
+
|
|
101
|
+
## Security
|
|
102
|
+
|
|
103
|
+
- Auth-agnostic — the host resolves identity and decides who may define, start, stop, or enroll.
|
|
104
|
+
- Tables sandboxed — reached only through the exported functions; `subjectRef`, variant keys, and `scope` stay opaque.
|
|
105
|
+
- Server-sourced timestamps — a caller cannot supply assignment time.
|
|
106
|
+
|
|
107
|
+
See [docs/API.md](docs/API.md).
|
|
108
|
+
|
|
109
|
+
## Testing
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pnpm test # single run
|
|
113
|
+
pnpm test:coverage # enforced 100% on covered files
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Tests run against the real component runtime via `convex-test` (`@edge-runtime/vm`), not mocks.
|
|
117
|
+
|
|
118
|
+
## Contributing
|
|
119
|
+
|
|
120
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
121
|
+
|
|
122
|
+
## Author
|
|
123
|
+
|
|
124
|
+
Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
125
|
+
|
|
126
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
127
|
+
|
|
128
|
+
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server";
|
|
2
|
+
import type { Assignment, AssignOutcome, DefineOptions, ExperimentDefinition, ExperimentsOptions, ExperimentStatus, ExposureOutcome, Variant, VariantResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The experiments component's function references, as exposed on the host via
|
|
5
|
+
* `components.experiments`. All values are concrete (no opaque host data), so the
|
|
6
|
+
* client is fully typed end to end — there is no generic to narrow.
|
|
7
|
+
*/
|
|
8
|
+
export interface ExperimentsComponent {
|
|
9
|
+
mutations: {
|
|
10
|
+
define: FunctionReference<"mutation", "internal", {
|
|
11
|
+
scope: string;
|
|
12
|
+
key: string;
|
|
13
|
+
variants: Variant[];
|
|
14
|
+
salt: string;
|
|
15
|
+
status: ExperimentStatus;
|
|
16
|
+
}, {
|
|
17
|
+
created: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
setStatus: FunctionReference<"mutation", "internal", {
|
|
20
|
+
scope: string;
|
|
21
|
+
key: string;
|
|
22
|
+
status: ExperimentStatus;
|
|
23
|
+
}, boolean>;
|
|
24
|
+
assign: FunctionReference<"mutation", "internal", {
|
|
25
|
+
scope: string;
|
|
26
|
+
key: string;
|
|
27
|
+
subjectRef: string;
|
|
28
|
+
}, AssignOutcome>;
|
|
29
|
+
logExposure: FunctionReference<"mutation", "internal", {
|
|
30
|
+
scope: string;
|
|
31
|
+
key: string;
|
|
32
|
+
subjectRef: string;
|
|
33
|
+
}, ExposureOutcome>;
|
|
34
|
+
};
|
|
35
|
+
queries: {
|
|
36
|
+
getExperiment: FunctionReference<"query", "internal", {
|
|
37
|
+
scope: string;
|
|
38
|
+
key: string;
|
|
39
|
+
}, ExperimentDefinition | null>;
|
|
40
|
+
getAssignment: FunctionReference<"query", "internal", {
|
|
41
|
+
scope: string;
|
|
42
|
+
key: string;
|
|
43
|
+
subjectRef: string;
|
|
44
|
+
}, Assignment | null>;
|
|
45
|
+
results: FunctionReference<"query", "internal", {
|
|
46
|
+
scope: string;
|
|
47
|
+
key: string;
|
|
48
|
+
}, VariantResult[]>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface RunQueryCtx {
|
|
52
|
+
runQuery<Q extends FunctionReference<"query", "internal">>(reference: Q, args: FunctionArgs<Q>): Promise<FunctionReturnType<Q>>;
|
|
53
|
+
}
|
|
54
|
+
interface RunMutationCtx {
|
|
55
|
+
runMutation<M extends FunctionReference<"mutation", "internal">>(reference: M, args: FunctionArgs<M>): Promise<FunctionReturnType<M>>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Consumer-facing client for deterministic A/B experimentation. The host owns
|
|
59
|
+
* meaning and auth; it passes an opaque `subjectRef` and variant keys, and the
|
|
60
|
+
* component answers a sticky, weight-respecting variant plus a deduped exposure
|
|
61
|
+
* tally. Assignment is release-control-free — pair it with a feature-flag
|
|
62
|
+
* component for kill-switches; this layer only assigns and measures.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const experiments = new Experiments(components.experiments);
|
|
67
|
+
* await experiments.define(ctx, "checkout_button", {
|
|
68
|
+
* variants: [
|
|
69
|
+
* { key: "control", weight: 1 },
|
|
70
|
+
* { key: "treatment", weight: 1 },
|
|
71
|
+
* ],
|
|
72
|
+
* });
|
|
73
|
+
* const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
|
|
74
|
+
* if (variant === "treatment") renderNewButton();
|
|
75
|
+
* // later: const tally = await experiments.results(ctx, "checkout_button");
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare class Experiments {
|
|
79
|
+
private readonly component;
|
|
80
|
+
private readonly defaultScope;
|
|
81
|
+
private readonly defaultStatus;
|
|
82
|
+
constructor(component: ExperimentsComponent, options?: ExperimentsOptions);
|
|
83
|
+
private scopeOf;
|
|
84
|
+
/**
|
|
85
|
+
* Create or update an experiment. `variants` are weighted (equal weights split
|
|
86
|
+
* evenly). `salt` defaults to `key`; `status` to the client default (`running`).
|
|
87
|
+
* Returns `{ created }` — `false` when an existing definition was updated.
|
|
88
|
+
* Updating never disturbs existing sticky assignments.
|
|
89
|
+
*/
|
|
90
|
+
define(ctx: RunMutationCtx, key: string, opts: DefineOptions & {
|
|
91
|
+
variants: Variant[];
|
|
92
|
+
}): Promise<{
|
|
93
|
+
created: boolean;
|
|
94
|
+
}>;
|
|
95
|
+
/** Move an experiment to a new lifecycle status. Returns `false` if it is absent. */
|
|
96
|
+
setStatus(ctx: RunMutationCtx, key: string, status: ExperimentStatus, scope?: string): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Enroll a subject and return the sticky variant. `{ variant: null }` when the
|
|
99
|
+
* experiment is absent or not running; otherwise `{ variant, isNew }`, `isNew`
|
|
100
|
+
* true only on the first persisting call.
|
|
101
|
+
*/
|
|
102
|
+
assign(ctx: RunMutationCtx, key: string, subjectRef: string, scope?: string): Promise<AssignOutcome>;
|
|
103
|
+
/**
|
|
104
|
+
* Record an exposure (enrolling the subject if needed) and return their variant,
|
|
105
|
+
* or `null` if not enrolled. Repeated exposures for one subject are deduped into
|
|
106
|
+
* a single tallied row.
|
|
107
|
+
*/
|
|
108
|
+
logExposure(ctx: RunMutationCtx, key: string, subjectRef: string, scope?: string): Promise<ExposureOutcome>;
|
|
109
|
+
/** The experiment definition, or `null` if none exists. */
|
|
110
|
+
getExperiment(ctx: RunQueryCtx, key: string, scope?: string): Promise<ExperimentDefinition | null>;
|
|
111
|
+
/** A subject's sticky assignment, or `null` if not enrolled. */
|
|
112
|
+
getAssignment(ctx: RunQueryCtx, key: string, subjectRef: string, scope?: string): Promise<Assignment | null>;
|
|
113
|
+
/** Per-variant exposure tallies (distinct subjects + total exposures). */
|
|
114
|
+
results(ctx: RunQueryCtx, key: string, scope?: string): Promise<VariantResult[]>;
|
|
115
|
+
}
|
|
116
|
+
export type { Assignment, AssignOutcome, DefineOptions, ExperimentDefinition, ExperimentsOptions, ExperimentStatus, ExposureOutcome, Variant, VariantResult, };
|
|
117
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE;QACT,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YACE,KAAK,EAAE,MAAM,CAAC;YACd,GAAG,EAAE,MAAM,CAAC;YACZ,QAAQ,EAAE,OAAO,EAAE,CAAC;YACpB,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,gBAAgB,CAAC;SAC1B,EACD;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,CACrB,CAAC;QACF,SAAS,EAAE,iBAAiB,CAC1B,UA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AAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAOvC,gEAAgE;IAChE,aAAa,CACX,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAQ7B,0EAA0E;IAC1E,OAAO,CACL,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,EAAE,CAAC;CAM5B;AAED,YAAY,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,aAAa,GACd,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DEFAULT_SCOPE, DEFAULT_STATUS } from "../shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Consumer-facing client for deterministic A/B experimentation. The host owns
|
|
4
|
+
* meaning and auth; it passes an opaque `subjectRef` and variant keys, and the
|
|
5
|
+
* component answers a sticky, weight-respecting variant plus a deduped exposure
|
|
6
|
+
* tally. Assignment is release-control-free — pair it with a feature-flag
|
|
7
|
+
* component for kill-switches; this layer only assigns and measures.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const experiments = new Experiments(components.experiments);
|
|
12
|
+
* await experiments.define(ctx, "checkout_button", {
|
|
13
|
+
* variants: [
|
|
14
|
+
* { key: "control", weight: 1 },
|
|
15
|
+
* { key: "treatment", weight: 1 },
|
|
16
|
+
* ],
|
|
17
|
+
* });
|
|
18
|
+
* const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
|
|
19
|
+
* if (variant === "treatment") renderNewButton();
|
|
20
|
+
* // later: const tally = await experiments.results(ctx, "checkout_button");
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class Experiments {
|
|
24
|
+
component;
|
|
25
|
+
defaultScope;
|
|
26
|
+
defaultStatus;
|
|
27
|
+
constructor(component, options = {}) {
|
|
28
|
+
this.component = component;
|
|
29
|
+
this.defaultScope = options.defaultScope ?? DEFAULT_SCOPE;
|
|
30
|
+
this.defaultStatus = options.defaultStatus ?? DEFAULT_STATUS;
|
|
31
|
+
}
|
|
32
|
+
scopeOf(scope) {
|
|
33
|
+
return scope ?? this.defaultScope;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create or update an experiment. `variants` are weighted (equal weights split
|
|
37
|
+
* evenly). `salt` defaults to `key`; `status` to the client default (`running`).
|
|
38
|
+
* Returns `{ created }` — `false` when an existing definition was updated.
|
|
39
|
+
* Updating never disturbs existing sticky assignments.
|
|
40
|
+
*/
|
|
41
|
+
define(ctx, key, opts) {
|
|
42
|
+
return ctx.runMutation(this.component.mutations.define, {
|
|
43
|
+
scope: this.scopeOf(opts.scope),
|
|
44
|
+
key,
|
|
45
|
+
variants: opts.variants,
|
|
46
|
+
salt: opts.salt ?? key,
|
|
47
|
+
status: opts.status ?? this.defaultStatus,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Move an experiment to a new lifecycle status. Returns `false` if it is absent. */
|
|
51
|
+
setStatus(ctx, key, status, scope) {
|
|
52
|
+
return ctx.runMutation(this.component.mutations.setStatus, {
|
|
53
|
+
scope: this.scopeOf(scope),
|
|
54
|
+
key,
|
|
55
|
+
status,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Enroll a subject and return the sticky variant. `{ variant: null }` when the
|
|
60
|
+
* experiment is absent or not running; otherwise `{ variant, isNew }`, `isNew`
|
|
61
|
+
* true only on the first persisting call.
|
|
62
|
+
*/
|
|
63
|
+
assign(ctx, key, subjectRef, scope) {
|
|
64
|
+
return ctx.runMutation(this.component.mutations.assign, {
|
|
65
|
+
scope: this.scopeOf(scope),
|
|
66
|
+
key,
|
|
67
|
+
subjectRef,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Record an exposure (enrolling the subject if needed) and return their variant,
|
|
72
|
+
* or `null` if not enrolled. Repeated exposures for one subject are deduped into
|
|
73
|
+
* a single tallied row.
|
|
74
|
+
*/
|
|
75
|
+
logExposure(ctx, key, subjectRef, scope) {
|
|
76
|
+
return ctx.runMutation(this.component.mutations.logExposure, {
|
|
77
|
+
scope: this.scopeOf(scope),
|
|
78
|
+
key,
|
|
79
|
+
subjectRef,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** The experiment definition, or `null` if none exists. */
|
|
83
|
+
getExperiment(ctx, key, scope) {
|
|
84
|
+
return ctx.runQuery(this.component.queries.getExperiment, {
|
|
85
|
+
scope: this.scopeOf(scope),
|
|
86
|
+
key,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** A subject's sticky assignment, or `null` if not enrolled. */
|
|
90
|
+
getAssignment(ctx, key, subjectRef, scope) {
|
|
91
|
+
return ctx.runQuery(this.component.queries.getAssignment, {
|
|
92
|
+
scope: this.scopeOf(scope),
|
|
93
|
+
key,
|
|
94
|
+
subjectRef,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Per-variant exposure tallies (distinct subjects + total exposures). */
|
|
98
|
+
results(ctx, key, scope) {
|
|
99
|
+
return ctx.runQuery(this.component.queries.results, {
|
|
100
|
+
scope: this.scopeOf(scope),
|
|
101
|
+
key,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA4E7D;;;;;;;;;;;;;;;;;;;;GAoBG;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,CAAC,KAAK,CAAC;YAC1B,GAAG;YACH,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,WAAW,CACT,GAAmB,EACnB,GAAW,EACX,UAAkB,EAClB,KAAc;QAEd,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE;YAC3D,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,GAAG;YACH,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IAC3D,aAAa,CACX,GAAgB,EAChB,GAAW,EACX,KAAc;QAEd,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE;YACxD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,gEAAgE;IAChE,aAAa,CACX,GAAgB,EAChB,GAAW,EACX,UAAkB,EAClB,KAAc;QAEd,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE;YACxD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,GAAG;YACH,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,0EAA0E;IAC1E,OAAO,CACL,GAAgB,EAChB,GAAW,EACX,KAAc;QAEd,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE;YAClD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Public TypeScript surface for the experiments client. */
|
|
2
|
+
/** A weighted variant — an opaque variant key and its relative selection weight. */
|
|
3
|
+
export interface Variant {
|
|
4
|
+
/** The host's opaque variant key (e.g. `"control"`, `"treatment"`). */
|
|
5
|
+
key: string;
|
|
6
|
+
/** Relative selection weight; the bucket width is `weight / sum(weights)`. */
|
|
7
|
+
weight: number;
|
|
8
|
+
}
|
|
9
|
+
/** Experiment lifecycle status. `running` is the only status that enrolls subjects. */
|
|
10
|
+
export type ExperimentStatus = "draft" | "running" | "stopped";
|
|
11
|
+
/** Construction options for the {@link Experiments} client. */
|
|
12
|
+
export interface ExperimentsOptions {
|
|
13
|
+
/** Namespace applied when a call omits `scope`. Default `"global"`. */
|
|
14
|
+
defaultScope?: string;
|
|
15
|
+
/** Status applied by `define` when a call omits `status`. Default `"running"`. */
|
|
16
|
+
defaultStatus?: ExperimentStatus;
|
|
17
|
+
}
|
|
18
|
+
/** Per-call overrides for {@link Experiments.define}. */
|
|
19
|
+
export interface DefineOptions {
|
|
20
|
+
/** Namespace for this experiment. Defaults to the client `defaultScope`. */
|
|
21
|
+
scope?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Hash salt for deterministic assignment. Defaults to the experiment `key`;
|
|
24
|
+
* change it to re-randomize buckets without changing subject ids.
|
|
25
|
+
*/
|
|
26
|
+
salt?: string;
|
|
27
|
+
/** Initial lifecycle status. Defaults to the client `defaultStatus`. */
|
|
28
|
+
status?: ExperimentStatus;
|
|
29
|
+
}
|
|
30
|
+
/** An experiment definition, as returned by {@link Experiments.getExperiment}. */
|
|
31
|
+
export interface ExperimentDefinition {
|
|
32
|
+
key: string;
|
|
33
|
+
scope: string;
|
|
34
|
+
status: ExperimentStatus;
|
|
35
|
+
variants: Variant[];
|
|
36
|
+
salt: string;
|
|
37
|
+
/** Absolute ms timestamp the experiment was first defined. */
|
|
38
|
+
createdAt: number;
|
|
39
|
+
}
|
|
40
|
+
/** A subject's sticky assignment, as returned by {@link Experiments.getAssignment}. */
|
|
41
|
+
export interface Assignment {
|
|
42
|
+
variant: string;
|
|
43
|
+
/** Absolute ms timestamp the assignment was first persisted. */
|
|
44
|
+
assignedAt: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Outcome of {@link Experiments.assign}. `{ variant: null }` — not enrolled
|
|
48
|
+
* (experiment absent or not running). `{ variant, isNew }` — the enrolled variant,
|
|
49
|
+
* with `isNew` true only on the call that first persisted the assignment.
|
|
50
|
+
*/
|
|
51
|
+
export type AssignOutcome = {
|
|
52
|
+
variant: null;
|
|
53
|
+
} | {
|
|
54
|
+
variant: string;
|
|
55
|
+
isNew: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** Outcome of {@link Experiments.logExposure}: the variant, or `null` if not enrolled. */
|
|
58
|
+
export type ExposureOutcome = {
|
|
59
|
+
variant: string | null;
|
|
60
|
+
};
|
|
61
|
+
/** A per-variant exposure tally, as returned by {@link Experiments.results}. */
|
|
62
|
+
export interface VariantResult {
|
|
63
|
+
/** The variant key. */
|
|
64
|
+
variant: string;
|
|
65
|
+
/** Distinct subjects exposed to this variant (the funnel denominator). */
|
|
66
|
+
subjects: number;
|
|
67
|
+
/** Total exposure events recorded for this variant. */
|
|
68
|
+
exposures: number;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,oFAAoF;AACpF,MAAM,WAAW,OAAO;IACtB,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,uFAAuF;AACvF,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kFAAkF;IAClF,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC;AAED,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED,kFAAkF;AAClF,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GACjB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAExC,0FAA0F;AAC1F,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEzD,gFAAgF;AAChF,MAAM,WAAW,aAAa;IAC5B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `api` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type * as mutations from "../mutations.js";
|
|
10
|
+
import type * as queries from "../queries.js";
|
|
11
|
+
import type * as validators from "../validators.js";
|
|
12
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
13
|
+
declare const fullApi: ApiFromModules<{
|
|
14
|
+
mutations: typeof mutations;
|
|
15
|
+
queries: typeof queries;
|
|
16
|
+
validators: typeof validators;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* ```js
|
|
23
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
27
|
+
/**
|
|
28
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
29
|
+
*
|
|
30
|
+
* Usage:
|
|
31
|
+
* ```js
|
|
32
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
36
|
+
export declare const components: {};
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,UAAU,EAAE,OAAO,UAAU,CAAC;CAC/B,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
11
|
+
const fullApi = anyApi;
|
|
12
|
+
/**
|
|
13
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```js
|
|
17
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const api = anyApi;
|
|
21
|
+
/**
|
|
22
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* ```js
|
|
26
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const internal = anyApi;
|
|
30
|
+
export const components = componentsGeneric();
|
|
31
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAWH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAIR,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAmB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `ComponentApi` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FunctionReference } from "convex/server";
|
|
10
|
+
/**
|
|
11
|
+
* A utility for referencing a Convex component's exposed API.
|
|
12
|
+
*
|
|
13
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
17
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
22
|
+
mutations: {
|
|
23
|
+
assign: FunctionReference<"mutation", "internal", {
|
|
24
|
+
key: string;
|
|
25
|
+
scope: string;
|
|
26
|
+
subjectRef: string;
|
|
27
|
+
}, {
|
|
28
|
+
variant: null;
|
|
29
|
+
} | {
|
|
30
|
+
isNew: boolean;
|
|
31
|
+
variant: string;
|
|
32
|
+
}, Name>;
|
|
33
|
+
define: FunctionReference<"mutation", "internal", {
|
|
34
|
+
key: string;
|
|
35
|
+
salt: string;
|
|
36
|
+
scope: string;
|
|
37
|
+
status: "draft" | "running" | "stopped";
|
|
38
|
+
variants: Array<{
|
|
39
|
+
key: string;
|
|
40
|
+
weight: number;
|
|
41
|
+
}>;
|
|
42
|
+
}, {
|
|
43
|
+
created: boolean;
|
|
44
|
+
}, Name>;
|
|
45
|
+
logExposure: FunctionReference<"mutation", "internal", {
|
|
46
|
+
key: string;
|
|
47
|
+
scope: string;
|
|
48
|
+
subjectRef: string;
|
|
49
|
+
}, {
|
|
50
|
+
variant: null;
|
|
51
|
+
} | {
|
|
52
|
+
variant: string;
|
|
53
|
+
}, Name>;
|
|
54
|
+
setStatus: FunctionReference<"mutation", "internal", {
|
|
55
|
+
key: string;
|
|
56
|
+
scope: string;
|
|
57
|
+
status: "draft" | "running" | "stopped";
|
|
58
|
+
}, boolean, Name>;
|
|
59
|
+
};
|
|
60
|
+
queries: {
|
|
61
|
+
getAssignment: FunctionReference<"query", "internal", {
|
|
62
|
+
key: string;
|
|
63
|
+
scope: string;
|
|
64
|
+
subjectRef: string;
|
|
65
|
+
}, null | {
|
|
66
|
+
assignedAt: number;
|
|
67
|
+
variant: string;
|
|
68
|
+
}, Name>;
|
|
69
|
+
getExperiment: FunctionReference<"query", "internal", {
|
|
70
|
+
key: string;
|
|
71
|
+
scope: string;
|
|
72
|
+
}, null | {
|
|
73
|
+
createdAt: number;
|
|
74
|
+
key: string;
|
|
75
|
+
salt: string;
|
|
76
|
+
scope: string;
|
|
77
|
+
status: "draft" | "running" | "stopped";
|
|
78
|
+
variants: Array<{
|
|
79
|
+
key: string;
|
|
80
|
+
weight: number;
|
|
81
|
+
}>;
|
|
82
|
+
}, Name>;
|
|
83
|
+
results: FunctionReference<"query", "internal", {
|
|
84
|
+
key: string;
|
|
85
|
+
scope: string;
|
|
86
|
+
}, Array<{
|
|
87
|
+
exposures: number;
|
|
88
|
+
subjects: number;
|
|
89
|
+
variant: string;
|
|
90
|
+
}>, Name>;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,CAAC,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,IAC3E;IACE,SAAS,EAAE;QACT,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE,EAClD;YAAE,OAAO,EAAE,IAAI,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,OAAO,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,EACvD,IAAI,CACL,CAAC;QACF,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YACE,GAAG,EAAE,MAAM,CAAC;YACZ,IAAI,EAAE,MAAM,CAAC;YACb,KAAK,EAAE,MAAM,CAAC;YACd,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;YACxC,QAAQ,EAAE,KAAK,CAAC;gBAAE,GAAG,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAA;aAAE,CAAC,CAAC;SAClD,EACD;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,EACpB,IAAI,CACL,CAAC;QACF,WAAW,EAAE,iBAAiB,CAC5B,UAAU,EACV,UAAU,EACV;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM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