@vllnt/convex-analytics 0.2.0-canary.d5fa959 → 0.2.0-canary.dee16f7
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/CHANGELOG.md +113 -49
- package/README.md +461 -157
- package/dist/client/index.d.ts +34 -12
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +34 -12
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +9 -5
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/convex.config.d.ts +1 -0
- package/dist/component/convex.config.d.ts.map +1 -1
- package/dist/component/convex.config.js +1 -0
- package/dist/component/convex.config.js.map +1 -1
- package/dist/component/internal_mutations.d.ts +1 -1
- package/dist/component/internal_mutations.d.ts.map +1 -1
- package/dist/component/internal_mutations.js +16 -6
- package/dist/component/internal_mutations.js.map +1 -1
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +22 -20
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +67 -17
- package/dist/component/queries.js.map +1 -1
- package/dist/component/validators.d.ts +15 -1
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +32 -0
- package/dist/component/validators.js.map +1 -1
- package/dist/react/index.d.ts +2 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -3
- package/dist/react/index.js.map +1 -1
- package/dist/test.d.ts +3 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +3 -1
- package/dist/test.js.map +1 -1
- package/dist/web/index.d.ts +3 -2
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/index.js +2 -1
- package/dist/web/index.js.map +1 -1
- package/docs/api-reference.md +29 -10
- package/docs/architecture.md +33 -20
- package/docs/client-sdk.md +358 -140
- package/docs/multi-product.md +51 -40
- package/docs/quick-start.md +67 -70
- package/docs/react.md +146 -0
- package/docs/schema.md +13 -9
- package/docs/web-preset.md +96 -61
- package/llms.txt +43 -25
- package/package.json +14 -10
- package/src/client/index.ts +34 -12
- package/src/client/types.ts +9 -5
- package/src/component/convex.config.ts +1 -0
- package/src/component/internal_mutations.ts +16 -6
- package/src/component/mutations.ts +26 -20
- package/src/component/queries.ts +68 -16
- package/src/component/validators.ts +39 -0
- package/src/react/index.tsx +2 -3
- package/src/test.ts +3 -1
- package/src/web/index.ts +3 -2
package/docs/multi-product.md
CHANGED
|
@@ -1,69 +1,80 @@
|
|
|
1
|
-
# Multi-
|
|
1
|
+
# Multi-product scoping
|
|
2
2
|
|
|
3
|
-
Every table, mutation
|
|
4
|
-
|
|
3
|
+
Every table, mutation and query is partitioned by one opaque `scope` string. Use it to keep
|
|
4
|
+
products, environments or tenants apart.
|
|
5
5
|
|
|
6
6
|
| Concept | Field | Default |
|
|
7
7
|
| --------- | ------- | ----------- |
|
|
8
8
|
| Partition | `scope` | `"default"` |
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Default scope and per-call override
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Set a default on the client; every method also takes `scope` in its options.
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
|
+
// convex/tenants.ts
|
|
16
|
+
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
17
|
+
import { v } from "convex/values";
|
|
18
|
+
|
|
19
|
+
import { components } from "./_generated/api";
|
|
20
|
+
import { mutation, query } from "./_generated/server";
|
|
21
|
+
|
|
15
22
|
const analytics = new AnalyticsClient(components.analytics, {
|
|
16
23
|
scope: "my-saas",
|
|
17
24
|
dimensions: ["plan"],
|
|
18
25
|
});
|
|
19
|
-
```
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
export const featureUsed = mutation({
|
|
28
|
+
args: { tenantId: v.string(), userId: v.string() },
|
|
29
|
+
returns: v.null(),
|
|
30
|
+
handler: async (ctx, { tenantId, userId }) => {
|
|
31
|
+
await analytics.track(ctx, "feature_used", { subjectRef: userId, scope: tenantId });
|
|
32
|
+
return null;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
22
35
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
export const featureUses = query({
|
|
37
|
+
args: { tenantId: v.string() },
|
|
38
|
+
returns: v.number(),
|
|
39
|
+
handler: async (ctx, { tenantId }) =>
|
|
40
|
+
await analytics.metric(ctx, "feature_used", { scope: tenantId }),
|
|
27
41
|
});
|
|
28
|
-
const total = await analytics.metric(ctx, "signup", { scope: "customer-a" });
|
|
29
42
|
```
|
|
30
43
|
|
|
31
|
-
Every read takes the same `scope` option; omit it to fall back to the client's default.
|
|
32
|
-
|
|
33
44
|
## What scope isolates
|
|
34
45
|
|
|
35
|
-
- `events`, `rollups`, `subjects`, `sessions`, `scopes
|
|
36
|
-
|
|
37
|
-
- The
|
|
38
|
-
- `configure`
|
|
46
|
+
- `events`, `rollups`, `subjects`, `sessions`, `scopes` and `config` rows carry `scope`, and
|
|
47
|
+
every index starts with it, so a read for one scope never returns another scope's rows.
|
|
48
|
+
- The lifetime counter is keyed by `(scope, name)`.
|
|
49
|
+
- `configure` stores `retentionDays` and `sessionIdleMs` per scope, and REST `apiKeys` are
|
|
50
|
+
stored per scope.
|
|
51
|
+
- The crons visit every scope that has tracked an event or has config (the `scopes` table).
|
|
39
52
|
|
|
40
|
-
|
|
53
|
+
The component does not check who may read a scope: your functions decide which `scope` a
|
|
54
|
+
caller may pass.
|
|
41
55
|
|
|
42
|
-
|
|
56
|
+
## Mounting twice instead of scoping
|
|
43
57
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
scope: "customer-a",
|
|
48
|
-
});
|
|
49
|
-
const used = await analytics.metric(ctx, "feature_used", {
|
|
50
|
-
scope: "customer-a",
|
|
51
|
-
});
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Environment split** — separate staging from production:
|
|
58
|
+
For a fixed set of partitions known at deploy time, you can mount the component more than once.
|
|
59
|
+
Each mount has its own tables and crons. Use `scope` when partitions are created at runtime
|
|
60
|
+
(a new tenant).
|
|
55
61
|
|
|
56
62
|
```ts
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
// convex/convex.config.ts
|
|
64
|
+
import analytics from "@vllnt/convex-analytics/convex.config";
|
|
65
|
+
import { defineApp } from "convex/server";
|
|
66
|
+
|
|
67
|
+
const app = defineApp();
|
|
68
|
+
app.use(analytics);
|
|
69
|
+
app.use(analytics, { name: "mobileAnalytics" });
|
|
70
|
+
export default app;
|
|
59
71
|
```
|
|
60
72
|
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
```ts
|
|
74
|
+
// convex/mobile.ts
|
|
75
|
+
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
import { components } from "./_generated/api";
|
|
65
78
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Reach for `scope` when partitions are **runtime-created** (a new tenant you can't declare at
|
|
69
|
-
deploy time).
|
|
79
|
+
export const mobileAnalytics = new AnalyticsClient(components.mobileAnalytics);
|
|
80
|
+
```
|
package/docs/quick-start.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Quick
|
|
1
|
+
# Quick start
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Install, mount, track and read events in a Convex app.
|
|
4
4
|
|
|
5
5
|
## 1. Install
|
|
6
6
|
|
|
@@ -9,107 +9,104 @@ npm install @vllnt/convex-analytics
|
|
|
9
9
|
# or: pnpm add @vllnt/convex-analytics
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
`convex` (`^1.45.0`) is a required peer dependency.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
## 2. Mount the component
|
|
15
15
|
|
|
16
16
|
```ts
|
|
17
|
-
|
|
17
|
+
// convex/convex.config.ts
|
|
18
18
|
import analytics from "@vllnt/convex-analytics/convex.config";
|
|
19
|
+
import { defineApp } from "convex/server";
|
|
19
20
|
|
|
20
21
|
const app = defineApp();
|
|
21
22
|
app.use(analytics);
|
|
22
23
|
export default app;
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
Run `npx convex dev` to generate `components.analytics`.
|
|
27
|
+
|
|
28
|
+
## 3. Track and read
|
|
26
29
|
|
|
27
30
|
```ts
|
|
31
|
+
// convex/signups.ts
|
|
28
32
|
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
33
|
+
import { v } from "convex/values";
|
|
34
|
+
|
|
29
35
|
import { components } from "./_generated/api";
|
|
36
|
+
import { mutation, query } from "./_generated/server";
|
|
30
37
|
|
|
31
|
-
type
|
|
38
|
+
type SignupProps = { plan?: string; country?: string };
|
|
32
39
|
|
|
33
|
-
const analytics = new AnalyticsClient<
|
|
34
|
-
dimensions: ["plan", "country"], //
|
|
35
|
-
granularities: ["day"],
|
|
40
|
+
const analytics = new AnalyticsClient<SignupProps>(components.analytics, {
|
|
41
|
+
dimensions: ["plan", "country"], // props keys to roll up on
|
|
36
42
|
});
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
`TProps` types the `props` you pass to `track`. See [Client SDK](./client-sdk.md) for the
|
|
40
|
-
full config and verb reference.
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
props: { plan: "pro", country: "FR" },
|
|
44
|
+
export const signup = mutation({
|
|
45
|
+
args: { userId: v.string(), plan: v.string(), country: v.string() },
|
|
46
|
+
returns: v.null(),
|
|
47
|
+
handler: async (ctx, { userId, plan, country }) => {
|
|
48
|
+
await analytics.track(ctx, "signup", { subjectRef: userId, props: { plan, country } });
|
|
49
|
+
return null;
|
|
50
|
+
},
|
|
50
51
|
});
|
|
51
|
-
```
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
export const summary = query({
|
|
54
|
+
args: { from: v.number(), to: v.number() },
|
|
55
|
+
returns: v.object({
|
|
56
|
+
total: v.number(),
|
|
57
|
+
byPlan: v.array(v.object({ value: v.string(), count: v.number() })),
|
|
58
|
+
daily: v.array(v.object({ bucket: v.number(), count: v.number() })),
|
|
59
|
+
}),
|
|
60
|
+
handler: async (ctx, { from, to }) => ({
|
|
61
|
+
total: await analytics.metric(ctx, "signup"),
|
|
62
|
+
byPlan: await analytics.top(ctx, "signup", "plan"),
|
|
63
|
+
daily: await analytics.timeseries(ctx, "signup", { granularity: "day", range: { from, to } }),
|
|
64
|
+
}),
|
|
63
65
|
});
|
|
64
66
|
```
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
Event names are free strings; `subjectRef` and `sessionRef` are opaque to the component. See
|
|
69
|
+
[Client SDK](./client-sdk.md) for every option and method.
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
## 4. (Optional) REST access
|
|
72
|
+
|
|
73
|
+
Mount with `app.use(analytics, { httpPrefix: "/analytics" })` and deploy; without
|
|
74
|
+
`httpPrefix` the component's HTTP routes are not exposed. Store API keys from an internal
|
|
75
|
+
mutation (the client has no `configSet` method, so call the component mutation):
|
|
71
76
|
|
|
72
77
|
```ts
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
// convex/admin.ts
|
|
79
|
+
import { v } from "convex/values";
|
|
80
|
+
|
|
81
|
+
import { components } from "./_generated/api";
|
|
82
|
+
import { internalMutation } from "./_generated/server";
|
|
83
|
+
|
|
84
|
+
export const setApiKey = internalMutation({
|
|
85
|
+
args: { key: v.string() },
|
|
86
|
+
returns: v.null(),
|
|
87
|
+
handler: async (ctx, { key }) => {
|
|
88
|
+
await ctx.runMutation(components.analytics.mutations.configSet, {
|
|
89
|
+
scope: "default",
|
|
90
|
+
key: "apiKeys",
|
|
91
|
+
value: JSON.stringify([key]),
|
|
92
|
+
});
|
|
93
|
+
return null;
|
|
94
|
+
},
|
|
78
95
|
});
|
|
79
96
|
```
|
|
80
97
|
|
|
81
98
|
```bash
|
|
99
|
+
npx convex run admin:setApiKey '{"key":"your-key"}'
|
|
82
100
|
curl -H "x-api-key: your-key" \
|
|
83
|
-
"https
|
|
101
|
+
"https://<deployment>.convex.site/analytics/metric?name=signup"
|
|
84
102
|
```
|
|
85
103
|
|
|
86
104
|
See the [REST API](./api-reference.md) for all five routes.
|
|
87
105
|
|
|
88
|
-
##
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import { webDimensions, trackPageview } from "@vllnt/convex-analytics/web";
|
|
92
|
-
|
|
93
|
-
const web = new AnalyticsClient(components.analytics, {
|
|
94
|
-
dimensions: [...webDimensions],
|
|
95
|
-
});
|
|
96
|
-
await trackPageview(web, ctx, { path: "/pricing", headers: request.headers });
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
See [Web Preset](./web-preset.md).
|
|
100
|
-
|
|
101
|
-
## 8. Testing
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
import analyticsTest from "@vllnt/convex-analytics/test";
|
|
105
|
-
import { convexTest } from "convex-test";
|
|
106
|
-
|
|
107
|
-
const t = convexTest(hostSchema, hostModules);
|
|
108
|
-
analyticsTest.register(t);
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Next steps
|
|
106
|
+
## 5. Next steps
|
|
112
107
|
|
|
113
|
-
- [Client SDK](./client-sdk.md)
|
|
114
|
-
- [
|
|
115
|
-
- [
|
|
108
|
+
- [Client SDK](./client-sdk.md): config, methods, types, test helper
|
|
109
|
+
- [Web preset](./web-preset.md): web dimensions, user-agent and geo helpers
|
|
110
|
+
- [React hooks](./react.md): reactive aggregate reads
|
|
111
|
+
- [Schema](./schema.md): the six component tables
|
|
112
|
+
- [Errors and fixes](../README.md#errors-and-fixes)
|
package/docs/react.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# React hooks reference
|
|
2
|
+
|
|
3
|
+
`@vllnt/convex-analytics/react` has four hooks that wrap `useQuery` from `convex/react` for the
|
|
4
|
+
aggregate reads. `react` is an optional peer dependency; backend-only code never imports this
|
|
5
|
+
entry. The hooks need a `ConvexProvider` above them.
|
|
6
|
+
|
|
7
|
+
The component never owns your `api`. Write a public query in your Convex functions that calls
|
|
8
|
+
the matching `AnalyticsClient` method, then pass that query's reference to the hook. The hook
|
|
9
|
+
forwards your args (or `"skip"`) and returns `undefined` while loading. The hooks only fix the
|
|
10
|
+
return type; your query decides who may read and which `scope` it reads.
|
|
11
|
+
|
|
12
|
+
Source: `src/react/index.tsx` in the package (`packages/convex-analytics/src/react/index.tsx` in
|
|
13
|
+
the repository).
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// convex/stats.ts
|
|
17
|
+
import { AnalyticsClient } from "@vllnt/convex-analytics";
|
|
18
|
+
import { v } from "convex/values";
|
|
19
|
+
|
|
20
|
+
import { components } from "./_generated/api";
|
|
21
|
+
import { query } from "./_generated/server";
|
|
22
|
+
|
|
23
|
+
const analytics = new AnalyticsClient(components.analytics, { dimensions: ["plan"] });
|
|
24
|
+
const range = v.object({ from: v.optional(v.number()), to: v.optional(v.number()) });
|
|
25
|
+
const granularity = v.union(v.literal("minute"), v.literal("hour"), v.literal("day"));
|
|
26
|
+
|
|
27
|
+
export const metric = query({
|
|
28
|
+
args: { name: v.string(), range: v.optional(range) },
|
|
29
|
+
returns: v.number(),
|
|
30
|
+
handler: async (ctx, args) => await analytics.metric(ctx, args.name, { range: args.range }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const top = query({
|
|
34
|
+
args: { name: v.string(), dimension: v.string(), limit: v.optional(v.number()) },
|
|
35
|
+
returns: v.array(v.object({ value: v.string(), count: v.number() })),
|
|
36
|
+
handler: async (ctx, args) =>
|
|
37
|
+
await analytics.top(ctx, args.name, args.dimension, { limit: args.limit }),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const timeseries = query({
|
|
41
|
+
args: { name: v.string(), granularity, range },
|
|
42
|
+
returns: v.array(v.object({ bucket: v.number(), count: v.number() })),
|
|
43
|
+
handler: async (ctx, args) =>
|
|
44
|
+
await analytics.timeseries(ctx, args.name, { granularity: args.granularity, range: args.range }),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const uniques = query({
|
|
48
|
+
args: { granularity, range },
|
|
49
|
+
returns: v.object({
|
|
50
|
+
dau: v.number(),
|
|
51
|
+
wau: v.number(),
|
|
52
|
+
mau: v.number(),
|
|
53
|
+
trend: v.array(v.object({ bucket: v.number(), uniques: v.number() })),
|
|
54
|
+
}),
|
|
55
|
+
handler: async (ctx, args) => await analytics.uniques(ctx, args),
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
// src/Stats.tsx
|
|
61
|
+
import { useMetric, useTimeseries, useTop, useUniques } from "@vllnt/convex-analytics/react";
|
|
62
|
+
|
|
63
|
+
import { api } from "../convex/_generated/api";
|
|
64
|
+
|
|
65
|
+
export function Stats({ from, to }: { from: number; to: number }) {
|
|
66
|
+
const signups = useMetric(api.stats.metric, { name: "signup" });
|
|
67
|
+
const plans = useTop(api.stats.top, { name: "signup", dimension: "plan" });
|
|
68
|
+
const daily = useTimeseries(api.stats.timeseries, {
|
|
69
|
+
name: "signup",
|
|
70
|
+
granularity: "day",
|
|
71
|
+
range: { from, to },
|
|
72
|
+
});
|
|
73
|
+
const active = useUniques(api.stats.uniques, { granularity: "day", range: { from, to } });
|
|
74
|
+
if (signups === undefined || plans === undefined || daily === undefined || active === undefined) {
|
|
75
|
+
return <p>Loading</p>;
|
|
76
|
+
}
|
|
77
|
+
return (
|
|
78
|
+
<p>
|
|
79
|
+
{signups} signups, top plan {plans[0]?.value ?? "none"}, {daily.length} active days,{" "}
|
|
80
|
+
{active.mau} monthly users
|
|
81
|
+
</p>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## useMetric
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// signature
|
|
90
|
+
useMetric(ref: FunctionReference<"query", "public", any, number>, args | "skip"): number | undefined
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## useTop
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// signature
|
|
97
|
+
useTop(ref: FunctionReference<"query", "public", any, TopRow[]>, args | "skip"): TopRow[] | undefined
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## useTimeseries
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
// signature
|
|
104
|
+
useTimeseries(ref: FunctionReference<"query", "public", any, TimeseriesPoint[]>, args | "skip"): TimeseriesPoint[] | undefined
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## useUniques
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
// signature
|
|
111
|
+
useUniques(ref: FunctionReference<"query", "public", any, UniquesView>, args | "skip"): UniquesView | undefined
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## MetricArgs
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
// signature
|
|
118
|
+
interface MetricArgs { scope?: string; name: string; range?: Range; where?: Where }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## TopArgs
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
// signature
|
|
125
|
+
interface TopArgs { scope?: string; name: string; dimension: string; range?: Range; limit?: number }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## TimeseriesArgs
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
// signature
|
|
132
|
+
interface TimeseriesArgs { scope?: string; name: string; granularity: Granularity; range: Range; where?: Where }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## UniquesArgs
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
// signature
|
|
139
|
+
interface UniquesArgs { scope?: string; range: Range; granularity: Granularity }
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
These four interfaces document the args a host query is expected to accept. The hooks do not
|
|
143
|
+
enforce them: the args type comes from the query reference you pass.
|
|
144
|
+
|
|
145
|
+
The entry also re-exports the types `Range`, `Where`, `Granularity`, `TopRow`,
|
|
146
|
+
`TimeseriesPoint` and `UniquesView` (see [Client SDK](./client-sdk.md#types)).
|
package/docs/schema.md
CHANGED
|
@@ -6,8 +6,9 @@ Six sandboxed tables. Generic and domain-neutral — zero hardcoded web fields,
|
|
|
6
6
|
|
|
7
7
|
## events
|
|
8
8
|
|
|
9
|
-
Raw event log. One row per tracked event. TTL-pruned past `retentionDays
|
|
10
|
-
|
|
9
|
+
Raw event log. One row per tracked event. TTL-pruned past `retentionDays`. Rollups are kept
|
|
10
|
+
forever unless you run `backfill`: it deletes every rollup row of that name and rebuilds them
|
|
11
|
+
only from raw events still retained, so buckets older than `retentionDays` drop to 0.
|
|
11
12
|
|
|
12
13
|
| Field | Type | Description |
|
|
13
14
|
| ------------ | ---------------------- | ---------------------------------------------------------------- |
|
|
@@ -75,7 +76,7 @@ Per-subject lifecycle, for uniques and retention. Upserted on every event that c
|
|
|
75
76
|
## sessions
|
|
76
77
|
|
|
77
78
|
Optional generic session aggregates. Created when an event carries a `sessionRef`; closed
|
|
78
|
-
by the `closeSessions` cron after `sessionIdleMs`.
|
|
79
|
+
by the `closeSessions` function (cron `analytics:close-sessions`) after `sessionIdleMs`.
|
|
79
80
|
|
|
80
81
|
| Field | Type | Description |
|
|
81
82
|
| ------------ | ------- | ----------------------------------------- |
|
|
@@ -96,8 +97,10 @@ by the `closeSessions` cron after `sessionIdleMs`.
|
|
|
96
97
|
|
|
97
98
|
## scopes
|
|
98
99
|
|
|
99
|
-
Registry of every scope
|
|
100
|
-
|
|
100
|
+
Registry of every scope the component has seen. Written the first time a scope is seen by
|
|
101
|
+
`track`, `configSet` or `configure`; the `prune` and `closeSessions` functions (crons
|
|
102
|
+
`analytics:prune-events` and `analytics:close-sessions`) page through it to
|
|
103
|
+
visit each scope.
|
|
101
104
|
|
|
102
105
|
| Field | Type | Description |
|
|
103
106
|
| ------- | ------ | ----------- |
|
|
@@ -111,8 +114,9 @@ is seen; the `prune` and `closeSessions` crons page through it to visit each sco
|
|
|
111
114
|
|
|
112
115
|
## config
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
`
|
|
117
|
+
Config keyed by `(scope, key)`; values are strings. `client.configure(ctx, { ... })` writes
|
|
118
|
+
`retentionDays`, `sessionIdleMs` (read by the crons) and `sampleRate` (stored, not read). The
|
|
119
|
+
component mutation `configSet` writes any key, including the REST `apiKeys` array (JSON string).
|
|
116
120
|
|
|
117
121
|
| Field | Type | Description |
|
|
118
122
|
| ------- | ------ | ----------------------------------------------------------------------- |
|
|
@@ -130,6 +134,6 @@ Cron-relevant config, keyed by `(scope, key)`. Values are stored as strings. Set
|
|
|
130
134
|
|
|
131
135
|
| Component | Package | Role |
|
|
132
136
|
| -------------- | ----------------------------- | ---------------------------------------- |
|
|
133
|
-
| aggregate | `@convex-dev/aggregate` | Mounted
|
|
137
|
+
| aggregate | `@convex-dev/aggregate` | Mounted; not written or read. |
|
|
134
138
|
| shardedCounter | `@convex-dev/sharded-counter` | O(1) total per `(scope, name)` (16 shards). |
|
|
135
|
-
| rateLimiter | `@convex-dev/rate-limiter` |
|
|
139
|
+
| rateLimiter | `@convex-dev/rate-limiter` | Token bucket per `(scope, sessionRef)` at ingest. |
|