@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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -0
  3. package/dist/client/index.d.ts +117 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +105 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +70 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +3 -0
  10. package/dist/client/types.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +38 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +93 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +121 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +78 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +7 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/mutations.d.ts +67 -0
  32. package/dist/component/mutations.d.ts.map +1 -0
  33. package/dist/component/mutations.js +196 -0
  34. package/dist/component/mutations.js.map +1 -0
  35. package/dist/component/queries.d.ts +39 -0
  36. package/dist/component/queries.d.ts.map +1 -0
  37. package/dist/component/queries.js +72 -0
  38. package/dist/component/queries.js.map +1 -0
  39. package/dist/component/schema.d.ts +77 -0
  40. package/dist/component/schema.d.ts.map +1 -0
  41. package/dist/component/schema.js +49 -0
  42. package/dist/component/schema.js.map +1 -0
  43. package/dist/component/validators.d.ts +96 -0
  44. package/dist/component/validators.d.ts.map +1 -0
  45. package/dist/component/validators.js +38 -0
  46. package/dist/component/validators.js.map +1 -0
  47. package/dist/shared.d.ts +30 -0
  48. package/dist/shared.d.ts.map +1 -0
  49. package/dist/shared.js +50 -0
  50. package/dist/shared.js.map +1 -0
  51. package/package.json +98 -0
  52. package/src/client/index.ts +249 -0
  53. package/src/client/types.ts +73 -0
  54. package/src/component/_generated/api.ts +54 -0
  55. package/src/component/_generated/component.ts +92 -0
  56. package/src/component/_generated/dataModel.ts +60 -0
  57. package/src/component/_generated/server.ts +156 -0
  58. package/src/component/convex.config.ts +9 -0
  59. package/src/component/mutations.ts +224 -0
  60. package/src/component/queries.ts +84 -0
  61. package/src/component/schema.ts +55 -0
  62. package/src/component/validators.ts +54 -0
  63. package/src/shared.ts +66 -0
  64. package/src/test.ts +12 -0
  65. package/src/unit.test.ts +84 -0
@@ -0,0 +1,249 @@
1
+ import type {
2
+ FunctionArgs,
3
+ FunctionReference,
4
+ FunctionReturnType,
5
+ } from "convex/server";
6
+ import type {
7
+ Assignment,
8
+ AssignOutcome,
9
+ DefineOptions,
10
+ ExperimentDefinition,
11
+ ExperimentsOptions,
12
+ ExperimentStatus,
13
+ ExposureOutcome,
14
+ Variant,
15
+ VariantResult,
16
+ } from "./types.js";
17
+ import { DEFAULT_SCOPE, DEFAULT_STATUS } from "../shared.js";
18
+
19
+ /**
20
+ * The experiments component's function references, as exposed on the host via
21
+ * `components.experiments`. All values are concrete (no opaque host data), so the
22
+ * client is fully typed end to end — there is no generic to narrow.
23
+ */
24
+ export interface ExperimentsComponent {
25
+ mutations: {
26
+ define: FunctionReference<
27
+ "mutation",
28
+ "internal",
29
+ {
30
+ scope: string;
31
+ key: string;
32
+ variants: Variant[];
33
+ salt: string;
34
+ status: ExperimentStatus;
35
+ },
36
+ { created: boolean }
37
+ >;
38
+ setStatus: FunctionReference<
39
+ "mutation",
40
+ "internal",
41
+ { scope: string; key: string; status: ExperimentStatus },
42
+ boolean
43
+ >;
44
+ assign: FunctionReference<
45
+ "mutation",
46
+ "internal",
47
+ { scope: string; key: string; subjectRef: string },
48
+ AssignOutcome
49
+ >;
50
+ logExposure: FunctionReference<
51
+ "mutation",
52
+ "internal",
53
+ { scope: string; key: string; subjectRef: string },
54
+ ExposureOutcome
55
+ >;
56
+ };
57
+ queries: {
58
+ getExperiment: FunctionReference<
59
+ "query",
60
+ "internal",
61
+ { scope: string; key: string },
62
+ ExperimentDefinition | null
63
+ >;
64
+ getAssignment: FunctionReference<
65
+ "query",
66
+ "internal",
67
+ { scope: string; key: string; subjectRef: string },
68
+ Assignment | null
69
+ >;
70
+ results: FunctionReference<
71
+ "query",
72
+ "internal",
73
+ { scope: string; key: string },
74
+ VariantResult[]
75
+ >;
76
+ };
77
+ }
78
+
79
+ interface RunQueryCtx {
80
+ runQuery<Q extends FunctionReference<"query", "internal">>(
81
+ reference: Q,
82
+ args: FunctionArgs<Q>,
83
+ ): Promise<FunctionReturnType<Q>>;
84
+ }
85
+
86
+ interface RunMutationCtx {
87
+ runMutation<M extends FunctionReference<"mutation", "internal">>(
88
+ reference: M,
89
+ args: FunctionArgs<M>,
90
+ ): Promise<FunctionReturnType<M>>;
91
+ }
92
+
93
+ /**
94
+ * Consumer-facing client for deterministic A/B experimentation. The host owns
95
+ * meaning and auth; it passes an opaque `subjectRef` and variant keys, and the
96
+ * component answers a sticky, weight-respecting variant plus a deduped exposure
97
+ * tally. Assignment is release-control-free — pair it with a feature-flag
98
+ * component for kill-switches; this layer only assigns and measures.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const experiments = new Experiments(components.experiments);
103
+ * await experiments.define(ctx, "checkout_button", {
104
+ * variants: [
105
+ * { key: "control", weight: 1 },
106
+ * { key: "treatment", weight: 1 },
107
+ * ],
108
+ * });
109
+ * const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
110
+ * if (variant === "treatment") renderNewButton();
111
+ * // later: const tally = await experiments.results(ctx, "checkout_button");
112
+ * ```
113
+ */
114
+ export class Experiments {
115
+ private readonly defaultScope: string;
116
+ private readonly defaultStatus: ExperimentStatus;
117
+
118
+ constructor(
119
+ private readonly component: ExperimentsComponent,
120
+ options: ExperimentsOptions = {},
121
+ ) {
122
+ this.defaultScope = options.defaultScope ?? DEFAULT_SCOPE;
123
+ this.defaultStatus = options.defaultStatus ?? (DEFAULT_STATUS as "running");
124
+ }
125
+
126
+ private scopeOf(scope: string | undefined): string {
127
+ return scope ?? this.defaultScope;
128
+ }
129
+
130
+ /**
131
+ * Create or update an experiment. `variants` are weighted (equal weights split
132
+ * evenly). `salt` defaults to `key`; `status` to the client default (`running`).
133
+ * Returns `{ created }` — `false` when an existing definition was updated.
134
+ * Updating never disturbs existing sticky assignments.
135
+ */
136
+ define(
137
+ ctx: RunMutationCtx,
138
+ key: string,
139
+ opts: DefineOptions & { variants: Variant[] },
140
+ ): Promise<{ created: boolean }> {
141
+ return ctx.runMutation(this.component.mutations.define, {
142
+ scope: this.scopeOf(opts.scope),
143
+ key,
144
+ variants: opts.variants,
145
+ salt: opts.salt ?? key,
146
+ status: opts.status ?? this.defaultStatus,
147
+ });
148
+ }
149
+
150
+ /** Move an experiment to a new lifecycle status. Returns `false` if it is absent. */
151
+ setStatus(
152
+ ctx: RunMutationCtx,
153
+ key: string,
154
+ status: ExperimentStatus,
155
+ scope?: string,
156
+ ): Promise<boolean> {
157
+ return ctx.runMutation(this.component.mutations.setStatus, {
158
+ scope: this.scopeOf(scope),
159
+ key,
160
+ status,
161
+ });
162
+ }
163
+
164
+ /**
165
+ * Enroll a subject and return the sticky variant. `{ variant: null }` when the
166
+ * experiment is absent or not running; otherwise `{ variant, isNew }`, `isNew`
167
+ * true only on the first persisting call.
168
+ */
169
+ assign(
170
+ ctx: RunMutationCtx,
171
+ key: string,
172
+ subjectRef: string,
173
+ scope?: string,
174
+ ): Promise<AssignOutcome> {
175
+ return ctx.runMutation(this.component.mutations.assign, {
176
+ scope: this.scopeOf(scope),
177
+ key,
178
+ subjectRef,
179
+ });
180
+ }
181
+
182
+ /**
183
+ * Record an exposure (enrolling the subject if needed) and return their variant,
184
+ * or `null` if not enrolled. Repeated exposures for one subject are deduped into
185
+ * a single tallied row.
186
+ */
187
+ logExposure(
188
+ ctx: RunMutationCtx,
189
+ key: string,
190
+ subjectRef: string,
191
+ scope?: string,
192
+ ): Promise<ExposureOutcome> {
193
+ return ctx.runMutation(this.component.mutations.logExposure, {
194
+ scope: this.scopeOf(scope),
195
+ key,
196
+ subjectRef,
197
+ });
198
+ }
199
+
200
+ /** The experiment definition, or `null` if none exists. */
201
+ getExperiment(
202
+ ctx: RunQueryCtx,
203
+ key: string,
204
+ scope?: string,
205
+ ): Promise<ExperimentDefinition | null> {
206
+ return ctx.runQuery(this.component.queries.getExperiment, {
207
+ scope: this.scopeOf(scope),
208
+ key,
209
+ });
210
+ }
211
+
212
+ /** A subject's sticky assignment, or `null` if not enrolled. */
213
+ getAssignment(
214
+ ctx: RunQueryCtx,
215
+ key: string,
216
+ subjectRef: string,
217
+ scope?: string,
218
+ ): Promise<Assignment | null> {
219
+ return ctx.runQuery(this.component.queries.getAssignment, {
220
+ scope: this.scopeOf(scope),
221
+ key,
222
+ subjectRef,
223
+ });
224
+ }
225
+
226
+ /** Per-variant exposure tallies (distinct subjects + total exposures). */
227
+ results(
228
+ ctx: RunQueryCtx,
229
+ key: string,
230
+ scope?: string,
231
+ ): Promise<VariantResult[]> {
232
+ return ctx.runQuery(this.component.queries.results, {
233
+ scope: this.scopeOf(scope),
234
+ key,
235
+ });
236
+ }
237
+ }
238
+
239
+ export type {
240
+ Assignment,
241
+ AssignOutcome,
242
+ DefineOptions,
243
+ ExperimentDefinition,
244
+ ExperimentsOptions,
245
+ ExperimentStatus,
246
+ ExposureOutcome,
247
+ Variant,
248
+ VariantResult,
249
+ };
@@ -0,0 +1,73 @@
1
+ /** Public TypeScript surface for the experiments client. */
2
+
3
+ /** A weighted variant — an opaque variant key and its relative selection weight. */
4
+ export interface Variant {
5
+ /** The host's opaque variant key (e.g. `"control"`, `"treatment"`). */
6
+ key: string;
7
+ /** Relative selection weight; the bucket width is `weight / sum(weights)`. */
8
+ weight: number;
9
+ }
10
+
11
+ /** Experiment lifecycle status. `running` is the only status that enrolls subjects. */
12
+ export type ExperimentStatus = "draft" | "running" | "stopped";
13
+
14
+ /** Construction options for the {@link Experiments} client. */
15
+ export interface ExperimentsOptions {
16
+ /** Namespace applied when a call omits `scope`. Default `"global"`. */
17
+ defaultScope?: string;
18
+ /** Status applied by `define` when a call omits `status`. Default `"running"`. */
19
+ defaultStatus?: ExperimentStatus;
20
+ }
21
+
22
+ /** Per-call overrides for {@link Experiments.define}. */
23
+ export interface DefineOptions {
24
+ /** Namespace for this experiment. Defaults to the client `defaultScope`. */
25
+ scope?: string;
26
+ /**
27
+ * Hash salt for deterministic assignment. Defaults to the experiment `key`;
28
+ * change it to re-randomize buckets without changing subject ids.
29
+ */
30
+ salt?: string;
31
+ /** Initial lifecycle status. Defaults to the client `defaultStatus`. */
32
+ status?: ExperimentStatus;
33
+ }
34
+
35
+ /** An experiment definition, as returned by {@link Experiments.getExperiment}. */
36
+ export interface ExperimentDefinition {
37
+ key: string;
38
+ scope: string;
39
+ status: ExperimentStatus;
40
+ variants: Variant[];
41
+ salt: string;
42
+ /** Absolute ms timestamp the experiment was first defined. */
43
+ createdAt: number;
44
+ }
45
+
46
+ /** A subject's sticky assignment, as returned by {@link Experiments.getAssignment}. */
47
+ export interface Assignment {
48
+ variant: string;
49
+ /** Absolute ms timestamp the assignment was first persisted. */
50
+ assignedAt: number;
51
+ }
52
+
53
+ /**
54
+ * Outcome of {@link Experiments.assign}. `{ variant: null }` — not enrolled
55
+ * (experiment absent or not running). `{ variant, isNew }` — the enrolled variant,
56
+ * with `isNew` true only on the call that first persisted the assignment.
57
+ */
58
+ export type AssignOutcome =
59
+ | { variant: null }
60
+ | { variant: string; isNew: boolean };
61
+
62
+ /** Outcome of {@link Experiments.logExposure}: the variant, or `null` if not enrolled. */
63
+ export type ExposureOutcome = { variant: string | null };
64
+
65
+ /** A per-variant exposure tally, as returned by {@link Experiments.results}. */
66
+ export interface VariantResult {
67
+ /** The variant key. */
68
+ variant: string;
69
+ /** Distinct subjects exposed to this variant (the funnel denominator). */
70
+ subjects: number;
71
+ /** Total exposure events recorded for this variant. */
72
+ exposures: number;
73
+ }
@@ -0,0 +1,54 @@
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
+
11
+ import type * as mutations from "../mutations.js";
12
+ import type * as queries from "../queries.js";
13
+ import type * as validators from "../validators.js";
14
+
15
+ import type {
16
+ ApiFromModules,
17
+ FilterApi,
18
+ FunctionReference,
19
+ } from "convex/server";
20
+ import { anyApi, componentsGeneric } from "convex/server";
21
+
22
+ const fullApi: ApiFromModules<{
23
+ mutations: typeof mutations;
24
+ queries: typeof queries;
25
+ validators: typeof validators;
26
+ }> = anyApi as any;
27
+
28
+ /**
29
+ * A utility for referencing Convex functions in your app's public API.
30
+ *
31
+ * Usage:
32
+ * ```js
33
+ * const myFunctionReference = api.myModule.myFunction;
34
+ * ```
35
+ */
36
+ export const api: FilterApi<
37
+ typeof fullApi,
38
+ FunctionReference<any, "public">
39
+ > = anyApi as any;
40
+
41
+ /**
42
+ * A utility for referencing Convex functions in your app's internal API.
43
+ *
44
+ * Usage:
45
+ * ```js
46
+ * const myFunctionReference = internal.myModule.myFunction;
47
+ * ```
48
+ */
49
+ export const internal: FilterApi<
50
+ typeof fullApi,
51
+ FunctionReference<any, "internal">
52
+ > = anyApi as any;
53
+
54
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,92 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `ComponentApi` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type { FunctionReference } from "convex/server";
12
+
13
+ /**
14
+ * A utility for referencing a Convex component's exposed API.
15
+ *
16
+ * Useful when expecting a parameter like `components.myComponent`.
17
+ * Usage:
18
+ * ```ts
19
+ * async function myFunction(ctx: QueryCtx, component: ComponentApi) {
20
+ * return ctx.runQuery(component.someFile.someQuery, { ...args });
21
+ * }
22
+ * ```
23
+ */
24
+ export type ComponentApi<Name extends string | undefined = string | undefined> =
25
+ {
26
+ mutations: {
27
+ assign: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ { key: string; scope: string; subjectRef: string },
31
+ { variant: null } | { isNew: boolean; variant: string },
32
+ Name
33
+ >;
34
+ define: FunctionReference<
35
+ "mutation",
36
+ "internal",
37
+ {
38
+ key: string;
39
+ salt: string;
40
+ scope: string;
41
+ status: "draft" | "running" | "stopped";
42
+ variants: Array<{ key: string; weight: number }>;
43
+ },
44
+ { created: boolean },
45
+ Name
46
+ >;
47
+ logExposure: FunctionReference<
48
+ "mutation",
49
+ "internal",
50
+ { key: string; scope: string; subjectRef: string },
51
+ { variant: null } | { variant: string },
52
+ Name
53
+ >;
54
+ setStatus: FunctionReference<
55
+ "mutation",
56
+ "internal",
57
+ { key: string; scope: string; status: "draft" | "running" | "stopped" },
58
+ boolean,
59
+ Name
60
+ >;
61
+ };
62
+ queries: {
63
+ getAssignment: FunctionReference<
64
+ "query",
65
+ "internal",
66
+ { key: string; scope: string; subjectRef: string },
67
+ null | { assignedAt: number; variant: string },
68
+ Name
69
+ >;
70
+ getExperiment: FunctionReference<
71
+ "query",
72
+ "internal",
73
+ { key: string; scope: string },
74
+ null | {
75
+ createdAt: number;
76
+ key: string;
77
+ salt: string;
78
+ scope: string;
79
+ status: "draft" | "running" | "stopped";
80
+ variants: Array<{ key: string; weight: number }>;
81
+ },
82
+ Name
83
+ >;
84
+ results: FunctionReference<
85
+ "query",
86
+ "internal",
87
+ { key: string; scope: string },
88
+ Array<{ exposures: number; subjects: number; variant: string }>,
89
+ Name
90
+ >;
91
+ };
92
+ };
@@ -0,0 +1,60 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated data model types.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ DataModelFromSchemaDefinition,
13
+ DocumentByName,
14
+ TableNamesInDataModel,
15
+ SystemTableNames,
16
+ } from "convex/server";
17
+ import type { GenericId } from "convex/values";
18
+ import schema from "../schema.js";
19
+
20
+ /**
21
+ * The names of all of your Convex tables.
22
+ */
23
+ export type TableNames = TableNamesInDataModel<DataModel>;
24
+
25
+ /**
26
+ * The type of a document stored in Convex.
27
+ *
28
+ * @typeParam TableName - A string literal type of the table name (like "users").
29
+ */
30
+ export type Doc<TableName extends TableNames> = DocumentByName<
31
+ DataModel,
32
+ TableName
33
+ >;
34
+
35
+ /**
36
+ * An identifier for a document in Convex.
37
+ *
38
+ * Convex documents are uniquely identified by their `Id`, which is accessible
39
+ * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
40
+ *
41
+ * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
42
+ *
43
+ * IDs are just strings at runtime, but this type can be used to distinguish them from other
44
+ * strings when type checking.
45
+ *
46
+ * @typeParam TableName - A string literal type of the table name (like "users").
47
+ */
48
+ export type Id<TableName extends TableNames | SystemTableNames> =
49
+ GenericId<TableName>;
50
+
51
+ /**
52
+ * A type describing your Convex data model.
53
+ *
54
+ * This type includes information about what tables you have, the type of
55
+ * documents stored in those tables, and the indexes defined on them.
56
+ *
57
+ * This type is used to parameterize methods like `queryGeneric` and
58
+ * `mutationGeneric` to make them type-safe.
59
+ */
60
+ export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -0,0 +1,156 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for implementing server-side Convex query and mutation functions.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ ActionBuilder,
13
+ HttpActionBuilder,
14
+ MutationBuilder,
15
+ QueryBuilder,
16
+ GenericActionCtx,
17
+ GenericMutationCtx,
18
+ GenericQueryCtx,
19
+ GenericDatabaseReader,
20
+ GenericDatabaseWriter,
21
+ } from "convex/server";
22
+ import {
23
+ actionGeneric,
24
+ httpActionGeneric,
25
+ queryGeneric,
26
+ mutationGeneric,
27
+ internalActionGeneric,
28
+ internalMutationGeneric,
29
+ internalQueryGeneric,
30
+ } from "convex/server";
31
+ import type { DataModel } from "./dataModel.js";
32
+
33
+ /**
34
+ * Define a query in this Convex app's public API.
35
+ *
36
+ * This function will be allowed to read your Convex database and will be accessible from the client.
37
+ *
38
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
39
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
40
+ */
41
+ export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
42
+
43
+ /**
44
+ * Define a query that is only accessible from other Convex functions (but not from the client).
45
+ *
46
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
47
+ *
48
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
49
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
50
+ */
51
+ export const internalQuery: QueryBuilder<DataModel, "internal"> =
52
+ internalQueryGeneric;
53
+
54
+ /**
55
+ * Define a mutation in this Convex app's public API.
56
+ *
57
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
58
+ *
59
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
60
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
61
+ */
62
+ export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
63
+
64
+ /**
65
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
66
+ *
67
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
68
+ *
69
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
70
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
71
+ */
72
+ export const internalMutation: MutationBuilder<DataModel, "internal"> =
73
+ internalMutationGeneric;
74
+
75
+ /**
76
+ * Define an action in this Convex app's public API.
77
+ *
78
+ * An action is a function which can execute any JavaScript code, including non-deterministic
79
+ * code and code with side-effects, like calling third-party services.
80
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
81
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
82
+ *
83
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
84
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
85
+ */
86
+ export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
87
+
88
+ /**
89
+ * Define an action that is only accessible from other Convex functions (but not from the client).
90
+ *
91
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
92
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
93
+ */
94
+ export const internalAction: ActionBuilder<DataModel, "internal"> =
95
+ internalActionGeneric;
96
+
97
+ /**
98
+ * Define an HTTP action.
99
+ *
100
+ * The wrapped function will be used to respond to HTTP requests received
101
+ * by a Convex deployment if the requests matches the path and method where
102
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
103
+ *
104
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
105
+ * and a Fetch API `Request` object as its second.
106
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
107
+ */
108
+ export const httpAction: HttpActionBuilder = httpActionGeneric;
109
+
110
+ /**
111
+ * A set of services for use within Convex query functions.
112
+ *
113
+ * The query context is passed as the first argument to any Convex query
114
+ * function run on the server.
115
+ *
116
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
117
+ */
118
+ export type QueryCtx = GenericQueryCtx<DataModel>;
119
+
120
+ /**
121
+ * A set of services for use within Convex mutation functions.
122
+ *
123
+ * The mutation context is passed as the first argument to any Convex mutation
124
+ * function run on the server.
125
+ *
126
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
127
+ */
128
+ export type MutationCtx = GenericMutationCtx<DataModel>;
129
+
130
+ /**
131
+ * A set of services for use within Convex action functions.
132
+ *
133
+ * The action context is passed as the first argument to any Convex action
134
+ * function run on the server.
135
+ */
136
+ export type ActionCtx = GenericActionCtx<DataModel>;
137
+
138
+ /**
139
+ * An interface to read from the database within Convex query functions.
140
+ *
141
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
142
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
143
+ * building a query.
144
+ */
145
+ export type DatabaseReader = GenericDatabaseReader<DataModel>;
146
+
147
+ /**
148
+ * An interface to read from and write to the database within Convex mutation
149
+ * functions.
150
+ *
151
+ * Convex guarantees that all writes within a single mutation are
152
+ * executed atomically, so you never have to worry about partial writes leaving
153
+ * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
154
+ * for the guarantees Convex provides your functions.
155
+ */
156
+ export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -0,0 +1,9 @@
1
+ import { defineComponent } from "convex/server";
2
+
3
+ const component = defineComponent("experiments");
4
+
5
+ // Nest official child components here, e.g.:
6
+ // import aggregate from "@convex-dev/aggregate/convex.config";
7
+ // component.use(aggregate);
8
+
9
+ export default component;