@vllnt/convex-events 0.1.0-canary.b92f383

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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +140 -0
  3. package/dist/client/index.d.ts +134 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +144 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +58 -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 +40 -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 +8 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +9 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/crons.d.ts +8 -0
  32. package/dist/component/crons.d.ts.map +1 -0
  33. package/dist/component/crons.js +11 -0
  34. package/dist/component/crons.js.map +1 -0
  35. package/dist/component/mutations.d.ts +30 -0
  36. package/dist/component/mutations.d.ts.map +1 -0
  37. package/dist/component/mutations.js +105 -0
  38. package/dist/component/mutations.js.map +1 -0
  39. package/dist/component/queries.d.ts +54 -0
  40. package/dist/component/queries.d.ts.map +1 -0
  41. package/dist/component/queries.js +103 -0
  42. package/dist/component/queries.js.map +1 -0
  43. package/dist/component/schema.d.ts +35 -0
  44. package/dist/component/schema.d.ts.map +1 -0
  45. package/dist/component/schema.js +28 -0
  46. package/dist/component/schema.js.map +1 -0
  47. package/dist/component/validators.d.ts +82 -0
  48. package/dist/component/validators.d.ts.map +1 -0
  49. package/dist/component/validators.js +29 -0
  50. package/dist/component/validators.js.map +1 -0
  51. package/dist/react/index.d.ts +63 -0
  52. package/dist/react/index.d.ts.map +1 -0
  53. package/dist/react/index.js +40 -0
  54. package/dist/react/index.js.map +1 -0
  55. package/dist/shared.d.ts +23 -0
  56. package/dist/shared.d.ts.map +1 -0
  57. package/dist/shared.js +23 -0
  58. package/dist/shared.js.map +1 -0
  59. package/package.json +112 -0
  60. package/src/client/index.ts +297 -0
  61. package/src/client/types.ts +62 -0
  62. package/src/component/_generated/api.ts +56 -0
  63. package/src/component/_generated/component.ts +113 -0
  64. package/src/component/_generated/dataModel.ts +60 -0
  65. package/src/component/_generated/server.ts +156 -0
  66. package/src/component/convex.config.ts +10 -0
  67. package/src/component/crons.ts +18 -0
  68. package/src/component/mutations.ts +108 -0
  69. package/src/component/queries.ts +109 -0
  70. package/src/component/schema.ts +28 -0
  71. package/src/component/validators.ts +32 -0
  72. package/src/react/index.test.tsx +133 -0
  73. package/src/react/index.tsx +83 -0
  74. package/src/shared.ts +35 -0
  75. package/src/test.ts +12 -0
@@ -0,0 +1,297 @@
1
+ import type {
2
+ FunctionArgs,
3
+ FunctionReference,
4
+ FunctionReturnType,
5
+ PaginationOptions,
6
+ } from "convex/server";
7
+ import type {
8
+ CountResult,
9
+ EventDoc,
10
+ EventPage,
11
+ EventsOptions,
12
+ MetadataValidator,
13
+ } from "./types.js";
14
+ import {
15
+ DEFAULT_LIMIT,
16
+ DEFAULT_MAX_COUNT,
17
+ EVENT_ERROR_CODES,
18
+ EventValidationError,
19
+ } from "../shared.js";
20
+
21
+ /**
22
+ * The events component's function references, as exposed on the host via
23
+ * `components.events`. Generic over the host's metadata type `TMeta`.
24
+ */
25
+ export interface EventsComponent<TMeta = unknown> {
26
+ mutations: {
27
+ record: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ {
31
+ subjectRef: string;
32
+ type: string;
33
+ actorRef?: string;
34
+ metadata?: TMeta;
35
+ },
36
+ string
37
+ >;
38
+ purge: FunctionReference<
39
+ "mutation",
40
+ "internal",
41
+ { subjectRef: string; before?: number; batch?: number },
42
+ number
43
+ >;
44
+ configure: FunctionReference<
45
+ "mutation",
46
+ "internal",
47
+ { retentionMs?: number },
48
+ null
49
+ >;
50
+ pruneExpired: FunctionReference<
51
+ "mutation",
52
+ "internal",
53
+ { batch?: number },
54
+ number
55
+ >;
56
+ };
57
+ queries: {
58
+ list: FunctionReference<
59
+ "query",
60
+ "internal",
61
+ { subjectRef: string; type?: string; since?: number; limit: number },
62
+ EventDoc<TMeta>[]
63
+ >;
64
+ listPaginated: FunctionReference<
65
+ "query",
66
+ "internal",
67
+ {
68
+ subjectRef: string;
69
+ type?: string;
70
+ since?: number;
71
+ paginationOpts: PaginationOptions;
72
+ },
73
+ EventPage<TMeta>
74
+ >;
75
+ count: FunctionReference<
76
+ "query",
77
+ "internal",
78
+ { subjectRef: string; type?: string; maxCount?: number },
79
+ CountResult
80
+ >;
81
+ };
82
+ }
83
+
84
+ interface RunQueryCtx {
85
+ runQuery<Q extends FunctionReference<"query", "internal">>(
86
+ reference: Q,
87
+ args: FunctionArgs<Q>,
88
+ ): Promise<FunctionReturnType<Q>>;
89
+ }
90
+
91
+ interface RunMutationCtx {
92
+ runMutation<M extends FunctionReference<"mutation", "internal">>(
93
+ reference: M,
94
+ args: FunctionArgs<M>,
95
+ ): Promise<FunctionReturnType<M>>;
96
+ }
97
+
98
+ /**
99
+ * Serialized byte size of a defined value (UTF-8), for the `maxMetadataBytes`
100
+ * guard. Only ever called with non-`undefined` metadata.
101
+ */
102
+ function byteSize(value: unknown): number {
103
+ return new TextEncoder().encode(JSON.stringify(value)).length;
104
+ }
105
+
106
+ /**
107
+ * Consumer-facing client for the append-only per-subject activity feed. The
108
+ * host owns meaning and auth; it passes opaque `subjectRef` / `actorRef` refs
109
+ * and a host-typed `metadata` payload (typed here as `TMeta`).
110
+ */
111
+ export class Events<TMeta = unknown> {
112
+ private readonly defaultLimit: number;
113
+ private readonly defaultMaxCount: number;
114
+ private readonly allowedTypes?: ReadonlySet<string>;
115
+ private readonly maxTypeLength?: number;
116
+ private readonly maxMetadataBytes?: number;
117
+ private readonly metadataValidator?: MetadataValidator<TMeta>;
118
+
119
+ constructor(
120
+ private readonly component: EventsComponent<TMeta>,
121
+ options: EventsOptions<TMeta> = {},
122
+ ) {
123
+ this.defaultLimit = options.defaultLimit ?? DEFAULT_LIMIT;
124
+ this.defaultMaxCount = options.defaultMaxCount ?? DEFAULT_MAX_COUNT;
125
+ this.allowedTypes = options.allowedTypes
126
+ ? new Set(options.allowedTypes)
127
+ : undefined;
128
+ this.maxTypeLength = options.maxTypeLength;
129
+ this.maxMetadataBytes = options.maxMetadataBytes;
130
+ this.metadataValidator = options.metadataValidator;
131
+ }
132
+
133
+ /**
134
+ * Apply the configured client-boundary guards to one `record` call.
135
+ * Returns the (possibly transformed) metadata to store; throws an
136
+ * {@link EventValidationError} on rejection.
137
+ */
138
+ private guard(type: string, metadata?: TMeta): TMeta | undefined {
139
+ if (this.allowedTypes && !this.allowedTypes.has(type)) {
140
+ throw new EventValidationError(
141
+ EVENT_ERROR_CODES.TYPE_NOT_ALLOWED,
142
+ `event type "${type}" is not in the allowed set`,
143
+ );
144
+ }
145
+ if (this.maxTypeLength !== undefined && type.length > this.maxTypeLength) {
146
+ throw new EventValidationError(
147
+ EVENT_ERROR_CODES.TYPE_TOO_LONG,
148
+ `event type exceeds maxTypeLength (${this.maxTypeLength})`,
149
+ );
150
+ }
151
+ let next = metadata;
152
+ if (next !== undefined && this.metadataValidator) {
153
+ try {
154
+ next = this.metadataValidator(next);
155
+ } catch (err) {
156
+ throw new EventValidationError(
157
+ EVENT_ERROR_CODES.METADATA_INVALID,
158
+ err instanceof Error
159
+ ? err.message
160
+ : "metadata validation failed",
161
+ );
162
+ }
163
+ }
164
+ if (
165
+ this.maxMetadataBytes !== undefined &&
166
+ next !== undefined &&
167
+ byteSize(next) > this.maxMetadataBytes
168
+ ) {
169
+ throw new EventValidationError(
170
+ EVENT_ERROR_CODES.METADATA_TOO_LARGE,
171
+ `metadata exceeds maxMetadataBytes (${this.maxMetadataBytes})`,
172
+ );
173
+ }
174
+ return next;
175
+ }
176
+
177
+ /**
178
+ * Append an event of `type` for `subjectRef`. Returns the new event id.
179
+ * Applies the configured boundary guards (`allowedTypes`, `maxTypeLength`,
180
+ * `maxMetadataBytes`, `metadataValidator`) before writing — throws an
181
+ * {@link EventValidationError} on rejection.
182
+ */
183
+ record(
184
+ ctx: RunMutationCtx,
185
+ subjectRef: string,
186
+ type: string,
187
+ opts: { actorRef?: string; metadata?: TMeta } = {},
188
+ ): Promise<string> {
189
+ const metadata = this.guard(type, opts.metadata);
190
+ return ctx.runMutation(this.component.mutations.record, {
191
+ subjectRef,
192
+ type,
193
+ actorRef: opts.actorRef,
194
+ metadata,
195
+ });
196
+ }
197
+
198
+ /** List events for `subjectRef`, newest-first. Filter by `type` / `since`; `limit` defaults to the client's `defaultLimit`. */
199
+ list(
200
+ ctx: RunQueryCtx,
201
+ subjectRef: string,
202
+ opts: { type?: string; since?: number; limit?: number } = {},
203
+ ): Promise<EventDoc<TMeta>[]> {
204
+ return ctx.runQuery(this.component.queries.list, {
205
+ subjectRef,
206
+ type: opts.type,
207
+ since: opts.since,
208
+ limit: opts.limit ?? this.defaultLimit,
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Cursor-paginated feed for `subjectRef`, newest-first, honoring the same
214
+ * `type` / `since` filters as {@link Events.list}. Returns Convex's
215
+ * `{ page, isDone, continueCursor }` so a host can page past any `limit`.
216
+ */
217
+ paginate(
218
+ ctx: RunQueryCtx,
219
+ subjectRef: string,
220
+ paginationOpts: PaginationOptions,
221
+ opts: { type?: string; since?: number } = {},
222
+ ): Promise<EventPage<TMeta>> {
223
+ return ctx.runQuery(this.component.queries.listPaginated, {
224
+ subjectRef,
225
+ type: opts.type,
226
+ since: opts.since,
227
+ paginationOpts,
228
+ });
229
+ }
230
+
231
+ /**
232
+ * Bounded count for `subjectRef` (optionally one `type`). Scans at most
233
+ * `maxCount + 1` rows (default the client's `defaultMaxCount`); `isExact` is
234
+ * `false` when the feed is larger than the bound.
235
+ */
236
+ count(
237
+ ctx: RunQueryCtx,
238
+ subjectRef: string,
239
+ opts: { type?: string; maxCount?: number } = {},
240
+ ): Promise<CountResult> {
241
+ return ctx.runQuery(this.component.queries.count, {
242
+ subjectRef,
243
+ type: opts.type,
244
+ maxCount: opts.maxCount ?? this.defaultMaxCount,
245
+ });
246
+ }
247
+
248
+ /**
249
+ * Delete events for `subjectRef` (all, or only those before `before`). Batched
250
+ * and self-rescheduling for large feeds; returns the count deleted in the
251
+ * first batch (the remainder is pruned by scheduled follow-ups).
252
+ */
253
+ purge(
254
+ ctx: RunMutationCtx,
255
+ subjectRef: string,
256
+ opts: { before?: number; batch?: number } = {},
257
+ ): Promise<number> {
258
+ return ctx.runMutation(this.component.mutations.purge, {
259
+ subjectRef,
260
+ before: opts.before,
261
+ batch: opts.batch,
262
+ });
263
+ }
264
+
265
+ /**
266
+ * Set (or clear, with `undefined`) the retention window the component's daily
267
+ * cron prunes against. Without this, the retention sweep is a no-op.
268
+ */
269
+ configure(ctx: RunMutationCtx, retentionMs?: number): Promise<null> {
270
+ return ctx.runMutation(this.component.mutations.configure, { retentionMs });
271
+ }
272
+
273
+ /**
274
+ * Manually run the retention sweep (the same work the daily cron performs):
275
+ * prune one batch of events older than the configured window, rescheduling
276
+ * follow-up batches. A no-op until {@link Events.configure} sets a window.
277
+ * Returns the count deleted in the first batch.
278
+ */
279
+ pruneExpired(
280
+ ctx: RunMutationCtx,
281
+ opts: { batch?: number } = {},
282
+ ): Promise<number> {
283
+ return ctx.runMutation(this.component.mutations.pruneExpired, {
284
+ batch: opts.batch,
285
+ });
286
+ }
287
+ }
288
+
289
+ export type {
290
+ CountResult,
291
+ EventDoc,
292
+ EventPage,
293
+ EventsOptions,
294
+ MetadataValidator,
295
+ };
296
+ export { EventValidationError, EVENT_ERROR_CODES } from "../shared.js";
297
+ export type { EventErrorCode } from "../shared.js";
@@ -0,0 +1,62 @@
1
+ /** Public TypeScript surface for the events client. */
2
+
3
+ /**
4
+ * A stored event, as returned by {@link Events.list} / {@link Events.paginate}.
5
+ * `TMeta` is the host's metadata type. `metadata` is optional: a record made
6
+ * without it round-trips as `undefined`, so the shape never lies to a host whose
7
+ * `TMeta` is non-nullable.
8
+ */
9
+ export interface EventDoc<TMeta = unknown> {
10
+ _id: string;
11
+ _creationTime: number;
12
+ /** Opaque host-owned subject this event belongs to. */
13
+ subjectRef: string;
14
+ /** Host-defined event type / verb (e.g. `"created"`, `"login"`). */
15
+ type: string;
16
+ /** Opaque host-owned actor that caused the event, if any. */
17
+ actorRef?: string;
18
+ /** Host-owned payload. Opaque to the component; typed as `TMeta` for the host. Omitted when the event was recorded without metadata. */
19
+ metadata?: TMeta;
20
+ /** Host-stamped creation time (ms since epoch); the ledger's sort key. */
21
+ createdAt: number;
22
+ }
23
+
24
+ /** One page of events, as returned by {@link Events.paginate}. */
25
+ export interface EventPage<TMeta = unknown> {
26
+ page: EventDoc<TMeta>[];
27
+ isDone: boolean;
28
+ continueCursor: string;
29
+ splitCursor?: string | null;
30
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
31
+ }
32
+
33
+ /** A capped count, as returned by {@link Events.count}. */
34
+ export interface CountResult {
35
+ /** Number of matching events, capped at the scan bound. */
36
+ count: number;
37
+ /** `false` when more events exist than the scan bound (so `count` is the bound). */
38
+ isExact: boolean;
39
+ }
40
+
41
+ /**
42
+ * Validate (or parse) a host metadata payload at the `record` boundary. Return
43
+ * the value to store (optionally transformed); throw to reject. Lets a host with
44
+ * a non-`unknown` `TMeta` enforce its own shape without the component knowing it.
45
+ */
46
+ export type MetadataValidator<TMeta> = (metadata: TMeta) => TMeta;
47
+
48
+ /** Construction options for the {@link Events} client. */
49
+ export interface EventsOptions<TMeta = unknown> {
50
+ /** Page size applied when a `list` call omits `limit`. Default `50`. */
51
+ defaultLimit?: number;
52
+ /** Scan bound applied when a `count` call omits `maxCount`. Default `1000`. */
53
+ defaultMaxCount?: number;
54
+ /** If set, `record` rejects any `type` not in this allow-list. Default: freeform. */
55
+ allowedTypes?: readonly string[];
56
+ /** Max length of an event `type`. `record` rejects longer. Default: unbounded. */
57
+ maxTypeLength?: number;
58
+ /** Max serialized byte size of `metadata`. `record` rejects larger. Default: unbounded. */
59
+ maxMetadataBytes?: number;
60
+ /** Host-supplied validator/parser run on `metadata` at the `record` boundary. */
61
+ metadataValidator?: MetadataValidator<TMeta>;
62
+ }
@@ -0,0 +1,56 @@
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 crons from "../crons.js";
12
+ import type * as mutations from "../mutations.js";
13
+ import type * as queries from "../queries.js";
14
+ import type * as validators from "../validators.js";
15
+
16
+ import type {
17
+ ApiFromModules,
18
+ FilterApi,
19
+ FunctionReference,
20
+ } from "convex/server";
21
+ import { anyApi, componentsGeneric } from "convex/server";
22
+
23
+ const fullApi: ApiFromModules<{
24
+ crons: typeof crons;
25
+ mutations: typeof mutations;
26
+ queries: typeof queries;
27
+ validators: typeof validators;
28
+ }> = anyApi as any;
29
+
30
+ /**
31
+ * A utility for referencing Convex functions in your app's public API.
32
+ *
33
+ * Usage:
34
+ * ```js
35
+ * const myFunctionReference = api.myModule.myFunction;
36
+ * ```
37
+ */
38
+ export const api: FilterApi<
39
+ typeof fullApi,
40
+ FunctionReference<any, "public">
41
+ > = anyApi as any;
42
+
43
+ /**
44
+ * A utility for referencing Convex functions in your app's internal API.
45
+ *
46
+ * Usage:
47
+ * ```js
48
+ * const myFunctionReference = internal.myModule.myFunction;
49
+ * ```
50
+ */
51
+ export const internal: FilterApi<
52
+ typeof fullApi,
53
+ FunctionReference<any, "internal">
54
+ > = anyApi as any;
55
+
56
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,113 @@
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
+ configure: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ { retentionMs?: number },
31
+ null,
32
+ Name
33
+ >;
34
+ pruneExpired: FunctionReference<
35
+ "mutation",
36
+ "internal",
37
+ { batch?: number },
38
+ number,
39
+ Name
40
+ >;
41
+ purge: FunctionReference<
42
+ "mutation",
43
+ "internal",
44
+ { batch?: number; before?: number; subjectRef: string },
45
+ number,
46
+ Name
47
+ >;
48
+ record: FunctionReference<
49
+ "mutation",
50
+ "internal",
51
+ { actorRef?: string; metadata?: any; subjectRef: string; type: string },
52
+ string,
53
+ Name
54
+ >;
55
+ };
56
+ queries: {
57
+ count: FunctionReference<
58
+ "query",
59
+ "internal",
60
+ { maxCount?: number; subjectRef: string; type?: string },
61
+ { count: number; isExact: boolean },
62
+ Name
63
+ >;
64
+ list: FunctionReference<
65
+ "query",
66
+ "internal",
67
+ { limit: number; since?: number; subjectRef: string; type?: string },
68
+ Array<{
69
+ _creationTime: number;
70
+ _id: string;
71
+ actorRef?: string;
72
+ createdAt: number;
73
+ metadata?: any;
74
+ subjectRef: string;
75
+ type: string;
76
+ }>,
77
+ Name
78
+ >;
79
+ listPaginated: FunctionReference<
80
+ "query",
81
+ "internal",
82
+ {
83
+ paginationOpts: {
84
+ cursor: string | null;
85
+ endCursor?: string | null;
86
+ id?: number;
87
+ maximumBytesRead?: number;
88
+ maximumRowsRead?: number;
89
+ numItems: number;
90
+ };
91
+ since?: number;
92
+ subjectRef: string;
93
+ type?: string;
94
+ },
95
+ {
96
+ continueCursor: string;
97
+ isDone: boolean;
98
+ page: Array<{
99
+ _creationTime: number;
100
+ _id: string;
101
+ actorRef?: string;
102
+ createdAt: number;
103
+ metadata?: any;
104
+ subjectRef: string;
105
+ type: string;
106
+ }>;
107
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
108
+ splitCursor?: string | null;
109
+ },
110
+ Name
111
+ >;
112
+ };
113
+ };
@@ -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>;