@vllnt/convex-analytics 0.1.0-canary.332b387
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 +209 -0
- package/dist/client/index.d.ts +94 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +132 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +109 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +22 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +12 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +13 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +8 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +20 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +15 -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 +10 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/http.d.ts +13 -0
- package/dist/component/http.d.ts.map +1 -0
- package/dist/component/http.js +180 -0
- package/dist/component/http.js.map +1 -0
- package/dist/component/internal_mutations.d.ts +26 -0
- package/dist/component/internal_mutations.d.ts.map +1 -0
- package/dist/component/internal_mutations.js +126 -0
- package/dist/component/internal_mutations.js.map +1 -0
- package/dist/component/mutations.d.ts +24 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +209 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +148 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +376 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +104 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +72 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +195 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +71 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/react/index.d.ts +89 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +63 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared.d.ts +14 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +18 -0
- package/dist/shared.js.map +1 -0
- package/dist/test.d.ts +117 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +28 -0
- package/dist/test.js.map +1 -0
- package/dist/web/index.d.ts +121 -0
- package/dist/web/index.d.ts.map +1 -0
- package/dist/web/index.js +169 -0
- package/dist/web/index.js.map +1 -0
- package/package.json +116 -0
- package/src/client/index.ts +259 -0
- package/src/client/types.ts +121 -0
- package/src/component/_generated/api.ts +35 -0
- package/src/component/_generated/dataModel.ts +24 -0
- package/src/component/_generated/server.ts +42 -0
- package/src/component/convex.config.ts +12 -0
- package/src/component/http.ts +204 -0
- package/src/component/internal_mutations.ts +165 -0
- package/src/component/mutations.ts +255 -0
- package/src/component/queries.ts +436 -0
- package/src/component/schema.ts +76 -0
- package/src/component/validators.ts +94 -0
- package/src/react/index.tsx +127 -0
- package/src/shared.ts +30 -0
- package/src/test.ts +44 -0
- package/src/web/index.ts +232 -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,209 @@
|
|
|
1
|
+
<!-- Badges -->
|
|
2
|
+
[](https://www.convex.dev/components)
|
|
3
|
+
[](https://www.npmjs.com/package/@vllnt/convex-analytics)
|
|
4
|
+
[](https://github.com/vllnt/convex-analytics/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
# @vllnt/convex-analytics
|
|
8
|
+
|
|
9
|
+
A generic, configurable, embedded analytics component for Convex — any event,
|
|
10
|
+
any dimension, any domain — with rollup-on-write so reads stay O(1).
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
14
|
+
import { components } from "./_generated/api";
|
|
15
|
+
|
|
16
|
+
const analytics = new AnalyticsClient(components.analytics, {
|
|
17
|
+
dimensions: ["plan", "country"], // prop keys to roll up on
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await analytics.track(ctx, "signup", { subjectRef: userId, props: { plan: "pro", country: "FR" } });
|
|
21
|
+
const byPlan = await analytics.top(ctx, "signup", "plan"); // [{ value: "pro", count: 1 }]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Generic events** — free-string event name, opaque `subjectRef` / `sessionRef`, host-typed `props`.
|
|
27
|
+
- **Host-declared dimensions** — you pass the prop keys to roll up on; nothing is hardcoded.
|
|
28
|
+
- **Rollup-on-write** — counts are incremented as events land, so `metric` / `top` / `timeseries` read in O(1) (backed by `@convex-dev/aggregate` + `@convex-dev/sharded-counter`).
|
|
29
|
+
- **Rich verb set** — `metric`, `top`, `timeseries`, `uniques`, `funnel`, `retention`, `distribution`, plus paginated raw `list`.
|
|
30
|
+
- **Configurable** — `scope`, `dimensions`, `granularities`, `retentionDays`, `sampleRate`, `propsValidator`; sensible defaults, zero config required.
|
|
31
|
+
- **Per-session rate limiting + dedupe + sampling** built into `track`.
|
|
32
|
+
- **Opt-in web preset** — `@vllnt/convex-analytics/web` adds web dimensions + UA/geo helpers when you want them.
|
|
33
|
+
- **Optional React hooks** — `@vllnt/convex-analytics/react` for reactive aggregate reads.
|
|
34
|
+
- **Zero hardcoded domain** — no `v.any()`, no baked-in web fields; the host owns meaning and auth.
|
|
35
|
+
|
|
36
|
+
## Generic core vs web preset
|
|
37
|
+
|
|
38
|
+
The core is domain-neutral: it knows nothing about web, mobile, or any vertical.
|
|
39
|
+
Web analytics — pageview dimensions (`path`, `referrer`, `device`, `browser`, `os`,
|
|
40
|
+
`country`, UTM) plus `parseUserAgent` / `geoFromHeaders` / `trackPageview` helpers —
|
|
41
|
+
lives in the opt-in `@vllnt/convex-analytics/web` preset. You turn it on by passing
|
|
42
|
+
`webDimensions` to the client's `dimensions` config; otherwise the core ships no web
|
|
43
|
+
fields. See [docs/web-preset.md](docs/web-preset.md).
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install @vllnt/convex-analytics
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// convex/convex.config.ts
|
|
55
|
+
import { defineApp } from "convex/server";
|
|
56
|
+
import analytics from "@vllnt/convex-analytics/convex.config";
|
|
57
|
+
|
|
58
|
+
const app = defineApp();
|
|
59
|
+
app.use(analytics);
|
|
60
|
+
export default app;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// convex/analytics.ts — track + read, server-side
|
|
65
|
+
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
66
|
+
import { components } from "./_generated/api";
|
|
67
|
+
|
|
68
|
+
type MyProps = { plan?: string; country?: string };
|
|
69
|
+
|
|
70
|
+
const analytics = new AnalyticsClient<MyProps>(components.analytics, {
|
|
71
|
+
dimensions: ["plan", "country"],
|
|
72
|
+
granularities: ["day"],
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await analytics.track(ctx, "signup", { subjectRef: userId, props: { plan: "pro" } });
|
|
76
|
+
const total = await analytics.metric(ctx, "signup");
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Config
|
|
80
|
+
|
|
81
|
+
Passed to the `AnalyticsClient` constructor. All optional — the defaults work with zero config.
|
|
82
|
+
|
|
83
|
+
| Option | Type | Default | Purpose |
|
|
84
|
+
|--------|------|---------|---------|
|
|
85
|
+
| `scope` | `string` | `"default"` | Multi-tenant partition; isolates one tenant's data. |
|
|
86
|
+
| `dimensions` | `string[]` | `[]` | Prop keys to roll up on (drives rollup-on-write). Empty = count by event name only. |
|
|
87
|
+
| `granularities` | `("minute" \| "hour" \| "day")[]` | `["day"]` | Rollup bucket sizes (`minute` for short live windows). |
|
|
88
|
+
| `retentionDays` | `number` | `90` | Raw-event TTL in days (rollups are kept forever). Applied via `configure`. |
|
|
89
|
+
| `sampleRate` | `number` | `1` | Fraction `0..1` of events to keep at ingest. |
|
|
90
|
+
| `sessionIdleMs` | `number` | `1800000` | Idle timeout before a session is closed. Applied via `configure`. |
|
|
91
|
+
| `propsValidator` | Convex validator | typed scalar record | Optional host validator narrowing `props` at the boundary. |
|
|
92
|
+
|
|
93
|
+
`scope`, `dimensions`, `granularities`, and `sampleRate` apply per call from the client.
|
|
94
|
+
`retentionDays`, `sampleRate`, and `sessionIdleMs` are persisted for the prune/close-sessions
|
|
95
|
+
crons by calling `analytics.configure(ctx, { ... })` once.
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
| Verb | Kind | Purpose |
|
|
100
|
+
|------|------|---------|
|
|
101
|
+
| `track(ctx, name, opts)` | mutation | Ingest an event; rollup-on-write + raw event + counter. Returns `"tracked" \| "dropped" \| "duplicate"`. |
|
|
102
|
+
| `metric(ctx, name, opts)` | query | Total count over a range, optionally filtered by a dimension value. |
|
|
103
|
+
| `top(ctx, name, dimension, opts)` | query | Top values of a dimension (breakdown). |
|
|
104
|
+
| `timeseries(ctx, name, opts)` | query | Bucketed counts over a range. |
|
|
105
|
+
| `uniques(ctx, opts)` | query | DAU / WAU / MAU from subjects. |
|
|
106
|
+
| `funnel(ctx, steps, opts)` | query | Ordered step conversion, keyed by `subjectRef`. |
|
|
107
|
+
| `retention(ctx, opts)` | query | Cohort return rates by first-seen period. |
|
|
108
|
+
| `distribution(ctx, name, measure, opts)` | query | Histogram of a numeric measure over declared buckets + overflow (with `count` / `sum`). |
|
|
109
|
+
| `list(ctx, name, paginationOpts, opts)` | query | Paginated raw events, newest first. |
|
|
110
|
+
| `configure(ctx, opts)` | mutation | Persist cron-relevant config (retention / sampling / idle). |
|
|
111
|
+
|
|
112
|
+
Full reference: [docs/client-sdk.md](docs/client-sdk.md). REST surface: [docs/api-reference.md](docs/api-reference.md).
|
|
113
|
+
|
|
114
|
+
## What it serves
|
|
115
|
+
|
|
116
|
+
The Convex-native, authoritative in-app aggregate layer — predefined-dimension rollups served
|
|
117
|
+
**reactively** in O(1). It complements a product-analytics warehouse; it doesn't replace one.
|
|
118
|
+
Declare the dimensions and measures you'll query and the rollups answer instantly; ad-hoc or
|
|
119
|
+
retroactive questions over **non-declared** dimensions, or beyond the raw-event retention window,
|
|
120
|
+
are an export concern. `metric` / `top` / `timeseries` read pre-aggregated rollups (kept forever);
|
|
121
|
+
`funnel` / `retention` / `distribution` read raw events in range (index-backed, bounded, TTL-pruned).
|
|
122
|
+
|
|
123
|
+
## Web preset
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
127
|
+
import { webDimensions, trackPageview } from "@vllnt/convex-analytics/web";
|
|
128
|
+
|
|
129
|
+
const analytics = new AnalyticsClient(components.analytics, { dimensions: webDimensions });
|
|
130
|
+
|
|
131
|
+
await trackPageview(analytics, ctx, {
|
|
132
|
+
path: "/pricing",
|
|
133
|
+
ua: request.headers.get("user-agent") ?? undefined,
|
|
134
|
+
headers: request.headers,
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`webDimensions` opts the rollups into `path` / `referrer` / `device` / `browser` / `os` /
|
|
139
|
+
`country` / UTM; `parseUserAgent` and `geoFromHeaders` build those props from a request.
|
|
140
|
+
See [docs/web-preset.md](docs/web-preset.md).
|
|
141
|
+
|
|
142
|
+
## React
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import { useMetric, useTop } from "@vllnt/convex-analytics/react";
|
|
146
|
+
import { api } from "../convex/_generated/api";
|
|
147
|
+
|
|
148
|
+
const signups = useMetric(api.analytics.metric, { name: "signup" });
|
|
149
|
+
const byPlan = useTop(api.analytics.top, { name: "signup", dimension: "plan" });
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Thin reactive wrappers over the host's re-exported query refs (`metric`, `top`, `timeseries`,
|
|
153
|
+
`uniques`). `react` + `convex` are optional peer deps; backend-only consumers pull no React.
|
|
154
|
+
|
|
155
|
+
## MCP (Claude Code)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
claude mcp add convex-analytics-mcp \
|
|
159
|
+
--env CONVEX_URL=https://your-deployment.convex.cloud \
|
|
160
|
+
--env ANALYTICS_API_KEY=your-key
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
7 tools: `track`, `get_metric`, `get_top`, `get_timeseries`, `get_uniques`, `detect_anomalies`,
|
|
164
|
+
`query_analytics` (NL router). See [docs/mcp-tools.md](docs/mcp-tools.md).
|
|
165
|
+
|
|
166
|
+
## Security
|
|
167
|
+
|
|
168
|
+
- Auth-agnostic mount — the host gates access and passes opaque `subjectRef` / `sessionRef` in.
|
|
169
|
+
- Tables are sandboxed; the host reaches them only through the exported functions.
|
|
170
|
+
- REST endpoints require an `x-api-key` header, compared timing-safe.
|
|
171
|
+
|
|
172
|
+
See [docs/architecture.md](docs/architecture.md).
|
|
173
|
+
|
|
174
|
+
## Testing
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pnpm test
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import analyticsTest from "@vllnt/convex-analytics/test";
|
|
182
|
+
import { convexTest } from "convex-test";
|
|
183
|
+
|
|
184
|
+
const t = convexTest(hostSchema, hostModules);
|
|
185
|
+
analyticsTest.register(t);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Documentation
|
|
189
|
+
|
|
190
|
+
[Schema](docs/schema.md) · [Client SDK](docs/client-sdk.md) · [REST API](docs/api-reference.md) ·
|
|
191
|
+
[Web Preset](docs/web-preset.md) · [Multi-Product](docs/multi-product.md) ·
|
|
192
|
+
[Architecture](docs/architecture.md) · [MCP Tools](docs/mcp-tools.md). For AI agents:
|
|
193
|
+
[`llms.txt`](llms.txt) · [`llms-full.txt`](llms-full.txt).
|
|
194
|
+
|
|
195
|
+
## Contributing
|
|
196
|
+
|
|
197
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
198
|
+
|
|
199
|
+
## Author
|
|
200
|
+
|
|
201
|
+
Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
202
|
+
|
|
203
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
204
|
+
|
|
205
|
+
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { GenericMutationCtx, GenericQueryCtx, GenericDataModel } from "convex/server";
|
|
2
|
+
import type { AnalyticsConfig, Props, Granularity, Range, Where, TrackOpts, TrackResult, TopRow, TimeseriesPoint, UniquesView, FunnelStep, RetentionCohort, DistributionView, PaginationOpts, EventPage } from "./types.js";
|
|
3
|
+
export type { AnalyticsConfig, Range, Where, TrackOpts, TrackResult, TopRow, TimeseriesPoint, UniquesView, FunnelStep, RetentionCohort, DistributionBin, DistributionView, PaginationOpts, EventPage, EventView, } from "./types.js";
|
|
4
|
+
export type { Scalar, Props, Granularity } from "../shared.js";
|
|
5
|
+
type MutationCtx = {
|
|
6
|
+
runMutation: GenericMutationCtx<GenericDataModel>["runMutation"];
|
|
7
|
+
};
|
|
8
|
+
type QueryCtx = {
|
|
9
|
+
runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* AnalyticsClient — typed, configurable wrapper over the analytics component.
|
|
13
|
+
*
|
|
14
|
+
* Generic over the host's props shape `TProps` for compile-time typing of
|
|
15
|
+
* `track`. Config (`scope`, `dimensions`, `granularities`, ...) is stored on
|
|
16
|
+
* the client and applied to every call — not ignored.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const analytics = new AnalyticsClient(components.analytics, {
|
|
21
|
+
* dimensions: ["plan", "source"],
|
|
22
|
+
* granularities: ["hour", "day"],
|
|
23
|
+
* });
|
|
24
|
+
* await analytics.track(ctx, "signup", { subjectRef: userId, props: { plan: "pro" } });
|
|
25
|
+
* const total = await analytics.metric(ctx, "signup");
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class AnalyticsClient<TProps extends Props = Props> {
|
|
29
|
+
private readonly component;
|
|
30
|
+
private readonly scope;
|
|
31
|
+
private readonly dimensions;
|
|
32
|
+
private readonly granularities;
|
|
33
|
+
private readonly sampleRate;
|
|
34
|
+
private readonly config;
|
|
35
|
+
constructor(component: unknown, config?: AnalyticsConfig);
|
|
36
|
+
/** Ingest an event: rollup-on-write + raw event + counter. Sampling + dedupe applied. */
|
|
37
|
+
track(ctx: MutationCtx, name: string, opts?: TrackOpts<TProps>): Promise<TrackResult>;
|
|
38
|
+
/** Total count over a range, optionally filtered by a dimension value. */
|
|
39
|
+
metric(ctx: QueryCtx, name: string, opts?: {
|
|
40
|
+
range?: Range;
|
|
41
|
+
where?: Where;
|
|
42
|
+
scope?: string;
|
|
43
|
+
}): Promise<number>;
|
|
44
|
+
/** Top values of a dimension (breakdown). */
|
|
45
|
+
top(ctx: QueryCtx, name: string, dimension: string, opts?: {
|
|
46
|
+
range?: Range;
|
|
47
|
+
limit?: number;
|
|
48
|
+
scope?: string;
|
|
49
|
+
}): Promise<TopRow[]>;
|
|
50
|
+
/** Bucketed counts over a range. */
|
|
51
|
+
timeseries(ctx: QueryCtx, name: string, opts: {
|
|
52
|
+
granularity: Granularity;
|
|
53
|
+
range: Range;
|
|
54
|
+
where?: Where;
|
|
55
|
+
scope?: string;
|
|
56
|
+
}): Promise<TimeseriesPoint[]>;
|
|
57
|
+
/** DAU/WAU/MAU from subjects. */
|
|
58
|
+
uniques(ctx: QueryCtx, opts: {
|
|
59
|
+
range: Range;
|
|
60
|
+
granularity: Granularity;
|
|
61
|
+
scope?: string;
|
|
62
|
+
}): Promise<UniquesView>;
|
|
63
|
+
/** Ordered step conversion (generic, keyed by subjectRef). */
|
|
64
|
+
funnel(ctx: QueryCtx, steps: string[], opts: {
|
|
65
|
+
range: Range;
|
|
66
|
+
scope?: string;
|
|
67
|
+
}): Promise<FunnelStep[]>;
|
|
68
|
+
/** Cohort return rates by first-seen period. */
|
|
69
|
+
retention(ctx: QueryCtx, opts: {
|
|
70
|
+
cohortRange: Range;
|
|
71
|
+
periods: number;
|
|
72
|
+
granularity?: Granularity;
|
|
73
|
+
scope?: string;
|
|
74
|
+
}): Promise<RetentionCohort[]>;
|
|
75
|
+
/** Histogram of a numeric measure: ascending upper-bound bins + overflow. */
|
|
76
|
+
distribution(ctx: QueryCtx, name: string, measure: string, opts: {
|
|
77
|
+
buckets: number[];
|
|
78
|
+
range?: Range;
|
|
79
|
+
where?: Where;
|
|
80
|
+
scope?: string;
|
|
81
|
+
}): Promise<DistributionView>;
|
|
82
|
+
/** Paginated raw events for an event name, newest first. */
|
|
83
|
+
list(ctx: QueryCtx, name: string, paginationOpts: PaginationOpts, opts?: {
|
|
84
|
+
scope?: string;
|
|
85
|
+
}): Promise<EventPage>;
|
|
86
|
+
/** Persist cron-relevant config (retention/sampling/idle) for the scope. */
|
|
87
|
+
configure(ctx: MutationCtx, opts?: {
|
|
88
|
+
retentionDays?: number;
|
|
89
|
+
sampleRate?: number;
|
|
90
|
+
sessionIdleMs?: number;
|
|
91
|
+
scope?: string;
|
|
92
|
+
}): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
//# 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,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,eAAe,EACf,KAAK,EACL,WAAW,EACX,KAAK,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,MAAM,EACN,eAAe,EACf,WAAW,EACX,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,cAAc,E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,GACA,OAAO,CAAC,eAAe,EAAE,CAAC;IAS7B,6EAA6E;IACvE,YAAY,CAChB,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACxE,OAAO,CAAC,gBAAgB,CAAC;IAW5B,4DAA4D;IACtD,IAAI,CACR,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,cAAc,EAC9B,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5B,OAAO,CAAC,SAAS,CAAC;IAQrB,4EAA4E;IACtE,SAAS,CACb,GAAG,EAAE,WAAW,EAChB,IAAI,GAAE;QACJ,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;KACX,GACL,OAAO,CAAC,IAAI,CAAC;CAQjB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const DEFAULT_SCOPE = "default";
|
|
2
|
+
/**
|
|
3
|
+
* AnalyticsClient — typed, configurable wrapper over the analytics component.
|
|
4
|
+
*
|
|
5
|
+
* Generic over the host's props shape `TProps` for compile-time typing of
|
|
6
|
+
* `track`. Config (`scope`, `dimensions`, `granularities`, ...) is stored on
|
|
7
|
+
* the client and applied to every call — not ignored.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const analytics = new AnalyticsClient(components.analytics, {
|
|
12
|
+
* dimensions: ["plan", "source"],
|
|
13
|
+
* granularities: ["hour", "day"],
|
|
14
|
+
* });
|
|
15
|
+
* await analytics.track(ctx, "signup", { subjectRef: userId, props: { plan: "pro" } });
|
|
16
|
+
* const total = await analytics.metric(ctx, "signup");
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class AnalyticsClient {
|
|
20
|
+
component;
|
|
21
|
+
scope;
|
|
22
|
+
dimensions;
|
|
23
|
+
granularities;
|
|
24
|
+
sampleRate;
|
|
25
|
+
config;
|
|
26
|
+
constructor(component, config = {}) {
|
|
27
|
+
this.component = component;
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.scope = config.scope ?? DEFAULT_SCOPE;
|
|
30
|
+
this.dimensions = config.dimensions ?? [];
|
|
31
|
+
this.granularities = config.granularities ?? ["day"];
|
|
32
|
+
this.sampleRate = config.sampleRate ?? 1;
|
|
33
|
+
}
|
|
34
|
+
/** Ingest an event: rollup-on-write + raw event + counter. Sampling + dedupe applied. */
|
|
35
|
+
async track(ctx, name, opts = {}) {
|
|
36
|
+
return (await ctx.runMutation(this.component.mutations.track, {
|
|
37
|
+
scope: opts.scope ?? this.scope,
|
|
38
|
+
name,
|
|
39
|
+
subjectRef: opts.subjectRef,
|
|
40
|
+
sessionRef: opts.sessionRef,
|
|
41
|
+
props: opts.props,
|
|
42
|
+
ts: opts.ts,
|
|
43
|
+
dedupeKey: opts.dedupeKey,
|
|
44
|
+
dimensions: this.dimensions,
|
|
45
|
+
granularities: this.granularities,
|
|
46
|
+
sampleRate: this.sampleRate,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
/** Total count over a range, optionally filtered by a dimension value. */
|
|
50
|
+
async metric(ctx, name, opts = {}) {
|
|
51
|
+
return (await ctx.runQuery(this.component.queries.metric, {
|
|
52
|
+
scope: opts.scope ?? this.scope,
|
|
53
|
+
name,
|
|
54
|
+
range: opts.range,
|
|
55
|
+
where: opts.where,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
/** Top values of a dimension (breakdown). */
|
|
59
|
+
async top(ctx, name, dimension, opts = {}) {
|
|
60
|
+
return (await ctx.runQuery(this.component.queries.top, {
|
|
61
|
+
scope: opts.scope ?? this.scope,
|
|
62
|
+
name,
|
|
63
|
+
dimension,
|
|
64
|
+
range: opts.range,
|
|
65
|
+
limit: opts.limit,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
/** Bucketed counts over a range. */
|
|
69
|
+
async timeseries(ctx, name, opts) {
|
|
70
|
+
return (await ctx.runQuery(this.component.queries.timeseries, {
|
|
71
|
+
scope: opts.scope ?? this.scope,
|
|
72
|
+
name,
|
|
73
|
+
granularity: opts.granularity,
|
|
74
|
+
range: opts.range,
|
|
75
|
+
where: opts.where,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
/** DAU/WAU/MAU from subjects. */
|
|
79
|
+
async uniques(ctx, opts) {
|
|
80
|
+
return (await ctx.runQuery(this.component.queries.uniques, {
|
|
81
|
+
scope: opts.scope ?? this.scope,
|
|
82
|
+
range: opts.range,
|
|
83
|
+
granularity: opts.granularity,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
/** Ordered step conversion (generic, keyed by subjectRef). */
|
|
87
|
+
async funnel(ctx, steps, opts) {
|
|
88
|
+
return (await ctx.runQuery(this.component.queries.funnel, {
|
|
89
|
+
scope: opts.scope ?? this.scope,
|
|
90
|
+
steps,
|
|
91
|
+
range: opts.range,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
/** Cohort return rates by first-seen period. */
|
|
95
|
+
async retention(ctx, opts) {
|
|
96
|
+
return (await ctx.runQuery(this.component.queries.retention, {
|
|
97
|
+
scope: opts.scope ?? this.scope,
|
|
98
|
+
cohortRange: opts.cohortRange,
|
|
99
|
+
periods: opts.periods,
|
|
100
|
+
granularity: opts.granularity,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
/** Histogram of a numeric measure: ascending upper-bound bins + overflow. */
|
|
104
|
+
async distribution(ctx, name, measure, opts) {
|
|
105
|
+
return (await ctx.runQuery(this.component.queries.distribution, {
|
|
106
|
+
scope: opts.scope ?? this.scope,
|
|
107
|
+
name,
|
|
108
|
+
measure,
|
|
109
|
+
buckets: opts.buckets,
|
|
110
|
+
range: opts.range,
|
|
111
|
+
where: opts.where,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
/** Paginated raw events for an event name, newest first. */
|
|
115
|
+
async list(ctx, name, paginationOpts, opts = {}) {
|
|
116
|
+
return (await ctx.runQuery(this.component.queries.list, {
|
|
117
|
+
scope: opts.scope ?? this.scope,
|
|
118
|
+
name,
|
|
119
|
+
paginationOpts,
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
/** Persist cron-relevant config (retention/sampling/idle) for the scope. */
|
|
123
|
+
async configure(ctx, opts = {}) {
|
|
124
|
+
await ctx.runMutation(this.component.mutations.configure, {
|
|
125
|
+
scope: opts.scope ?? this.scope,
|
|
126
|
+
retentionDays: opts.retentionDays ?? this.config.retentionDays,
|
|
127
|
+
sampleRate: opts.sampleRate ?? this.config.sampleRate,
|
|
128
|
+
sessionIdleMs: opts.sessionIdleMs ?? this.config.sessionIdleMs,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAkEA,MAAM,aAAa,GAAG,SAAS,CAAC;AAEhC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,eAAe;IACT,SAAS,CAAe;IACxB,KAAK,CAAS;IACd,UAAU,CAAW;IACrB,aAAa,CAAgB;IAC7B,UAAU,CAAS;IACnB,MAAM,CAAkB;IAEzC,YAAY,SAAkB,EAAE,SAA0B,EAAE;QAC1D,IAAI,CAAC,SAAS,GAAG,SAAyB,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK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,CAAC;IAED,4EAA4E;IAC5E,KAAK,CAAC,SAAS,CACb,GAAgB,EAChB,OAKI,EAAE;QAEN,MAAM,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,SAAkB,EAAE;YACjE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK;YAC/B,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa;YAC9D,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU;YACrD,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa;SACtD,CAAC,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Scalar, Props, Granularity } from "../shared.js";
|
|
2
|
+
export type { Scalar, Props, Granularity };
|
|
3
|
+
/** A time range in epoch millis. */
|
|
4
|
+
export interface Range {
|
|
5
|
+
from?: number;
|
|
6
|
+
to?: number;
|
|
7
|
+
}
|
|
8
|
+
/** Filter a query to events where one dimension equals one value. */
|
|
9
|
+
export interface Where {
|
|
10
|
+
dim: string;
|
|
11
|
+
val: Scalar;
|
|
12
|
+
}
|
|
13
|
+
/** Client-owned config. Stored on the client and applied to every call. */
|
|
14
|
+
export interface AnalyticsConfig {
|
|
15
|
+
/** Multi-tenant partition. Default `"default"`. */
|
|
16
|
+
scope?: string;
|
|
17
|
+
/** Prop keys to roll up on (drives rollup-on-write). Default `[]`. */
|
|
18
|
+
dimensions?: string[];
|
|
19
|
+
/** Rollup bucket granularities. Default `["day"]`. */
|
|
20
|
+
granularities?: Granularity[];
|
|
21
|
+
/** Raw-event TTL in days (rollups kept forever). Default `90`. */
|
|
22
|
+
retentionDays?: number;
|
|
23
|
+
/** Sampling rate `0..1`. Default `1`. */
|
|
24
|
+
sampleRate?: number;
|
|
25
|
+
/** Session idle-close timeout in millis. Default `1800000` (30m). */
|
|
26
|
+
sessionIdleMs?: number;
|
|
27
|
+
}
|
|
28
|
+
/** Options for a single `track` call. */
|
|
29
|
+
export interface TrackOpts<TProps extends Props = Props> {
|
|
30
|
+
subjectRef?: string;
|
|
31
|
+
sessionRef?: string;
|
|
32
|
+
props?: TProps;
|
|
33
|
+
ts?: number;
|
|
34
|
+
/** Override the client's default scope for this event. */
|
|
35
|
+
scope?: string;
|
|
36
|
+
/** Skip if an event with this dedupe key already exists in the scope. */
|
|
37
|
+
dedupeKey?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Outcome of a `track` call. */
|
|
40
|
+
export type TrackResult = "tracked" | "dropped" | "duplicate";
|
|
41
|
+
/** A `(value, count)` breakdown row. */
|
|
42
|
+
export interface TopRow {
|
|
43
|
+
value: string;
|
|
44
|
+
count: number;
|
|
45
|
+
}
|
|
46
|
+
/** A `(bucket, count)` timeseries point. */
|
|
47
|
+
export interface TimeseriesPoint {
|
|
48
|
+
bucket: number;
|
|
49
|
+
count: number;
|
|
50
|
+
}
|
|
51
|
+
/** DAU/WAU/MAU rollup. */
|
|
52
|
+
export interface UniquesView {
|
|
53
|
+
dau: number;
|
|
54
|
+
wau: number;
|
|
55
|
+
mau: number;
|
|
56
|
+
trend: Array<{
|
|
57
|
+
bucket: number;
|
|
58
|
+
uniques: number;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/** A funnel step result. */
|
|
62
|
+
export interface FunnelStep {
|
|
63
|
+
name: string;
|
|
64
|
+
count: number;
|
|
65
|
+
rate: number;
|
|
66
|
+
}
|
|
67
|
+
/** A retention cohort row. */
|
|
68
|
+
export interface RetentionCohort {
|
|
69
|
+
cohort: number;
|
|
70
|
+
size: number;
|
|
71
|
+
retained: number[];
|
|
72
|
+
}
|
|
73
|
+
/** A histogram bin: events whose measure is at or below `upper`. */
|
|
74
|
+
export interface DistributionBin {
|
|
75
|
+
upper: number;
|
|
76
|
+
count: number;
|
|
77
|
+
}
|
|
78
|
+
/** Histogram of a numeric measure: bins by ascending upper bound + overflow. */
|
|
79
|
+
export interface DistributionView {
|
|
80
|
+
bins: DistributionBin[];
|
|
81
|
+
overflow: number;
|
|
82
|
+
count: number;
|
|
83
|
+
sum: number;
|
|
84
|
+
}
|
|
85
|
+
/** A raw event as returned by `list`. */
|
|
86
|
+
export interface EventView {
|
|
87
|
+
_id: string;
|
|
88
|
+
_creationTime: number;
|
|
89
|
+
scope: string;
|
|
90
|
+
name: string;
|
|
91
|
+
subjectRef?: string;
|
|
92
|
+
sessionRef?: string;
|
|
93
|
+
props: Props;
|
|
94
|
+
ts: number;
|
|
95
|
+
seq: number;
|
|
96
|
+
dedupeKey?: string;
|
|
97
|
+
}
|
|
98
|
+
/** Convex pagination options. */
|
|
99
|
+
export interface PaginationOpts {
|
|
100
|
+
numItems: number;
|
|
101
|
+
cursor: string | null;
|
|
102
|
+
}
|
|
103
|
+
/** A page of raw events. */
|
|
104
|
+
export interface EventPage {
|
|
105
|
+
page: EventView[];
|
|
106
|
+
isDone: boolean;
|
|
107
|
+
continueCursor: string;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE/D,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AAE3C,oCAAoC;AACpC,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,qEAAqE;AACrE,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD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|
2
|
+
* Generated `api` utility.
|
|
3
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type * as mutations from "../mutations.js";
|
|
7
|
+
import type * as queries from "../queries.js";
|
|
8
|
+
import type * as internal_mutations from "../internal_mutations.js";
|
|
9
|
+
import type * as http from "../http.js";
|
|
10
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
11
|
+
import { componentsGeneric } from "convex/server";
|
|
12
|
+
declare const fullApi: ApiFromModules<{
|
|
13
|
+
mutations: typeof mutations;
|
|
14
|
+
queries: typeof queries;
|
|
15
|
+
internal_mutations: typeof internal_mutations;
|
|
16
|
+
http: typeof http;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
19
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
20
|
+
export declare const components: ReturnType<typeof componentsGeneric>;
|
|
21
|
+
export {};
|
|
22
|
+
//# 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;;;;GAIG;AAEH,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,KAAK,kBAAkB,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAU,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAC9C,IAAI,EAAE,OAAO,IAAI,CAAC;CACnB,CAAiB,CAAC;AAEnB,eAAO,MAAM,GAAG,EAAE,SAAS,CAAC,OAAO,OAAO,EAAE,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAC5D,CAAC;AACjB,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CAClB,CAAC;AAEnB,eAAO,MAAM,UAAU,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAChC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
8
|
+
const fullApi = anyApi;
|
|
9
|
+
export const api = fullApi;
|
|
10
|
+
export const internal = fullApi;
|
|
11
|
+
export const components = componentsGeneric();
|
|
12
|
+
//# 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;;;;GAIG;AAYH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAKR,MAAa,CAAC;AAEnB,MAAM,CAAC,MAAM,GAAG,GACd,OAAc,CAAC;AACjB,MAAM,CAAC,MAAM,QAAQ,GAGjB,OAAc,CAAC;AAEnB,MAAM,CAAC,MAAM,UAAU,GACrB,iBAAiB,EAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated data model types.
|
|
3
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { DataModelFromSchemaDefinition, DocumentByName, TableNamesInDataModel, SystemTableNames } from "convex/server";
|
|
7
|
+
import type { GenericId } from "convex/values";
|
|
8
|
+
import schema from "../schema.js";
|
|
9
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
10
|
+
export type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
11
|
+
export type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
12
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
|
|
13
|
+
//# sourceMappingURL=dataModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataModel.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,OAAO,KAAK,EACV,6BAA6B,EAC7B,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAC1D,MAAM,MAAM,GAAG,CAAC,SAAS,SAAS,UAAU,IAAI,cAAc,CAC5D,SAAS,EACT,SAAS,CACV,CAAC;AACF,MAAM,MAAM,EAAE,CAAC,SAAS,SAAS,UAAU,GAAG,gBAAgB,IAC5D,SAAS,CAAC,SAAS,CAAC,CAAC;AACvB,MAAM,MAAM,SAAS,GAAG,6BAA6B,CAAC,OAAO,MAAM,CAAC,CAAC"}
|