@vllnt/convex-analytics 0.1.0-canary.2b9f918

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 (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +198 -0
  3. package/dist/client/index.d.ts +94 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +132 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +109 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +2 -0
  10. package/dist/client/types.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +46 -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 +181 -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 +133 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +80 -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 +10 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/http.d.ts +13 -0
  32. package/dist/component/http.d.ts.map +1 -0
  33. package/dist/component/http.js +180 -0
  34. package/dist/component/http.js.map +1 -0
  35. package/dist/component/internal_mutations.d.ts +26 -0
  36. package/dist/component/internal_mutations.d.ts.map +1 -0
  37. package/dist/component/internal_mutations.js +126 -0
  38. package/dist/component/internal_mutations.js.map +1 -0
  39. package/dist/component/mutations.d.ts +24 -0
  40. package/dist/component/mutations.d.ts.map +1 -0
  41. package/dist/component/mutations.js +209 -0
  42. package/dist/component/mutations.js.map +1 -0
  43. package/dist/component/queries.d.ts +148 -0
  44. package/dist/component/queries.d.ts.map +1 -0
  45. package/dist/component/queries.js +376 -0
  46. package/dist/component/queries.js.map +1 -0
  47. package/dist/component/schema.d.ts +104 -0
  48. package/dist/component/schema.d.ts.map +1 -0
  49. package/dist/component/schema.js +72 -0
  50. package/dist/component/schema.js.map +1 -0
  51. package/dist/component/validators.d.ts +195 -0
  52. package/dist/component/validators.d.ts.map +1 -0
  53. package/dist/component/validators.js +71 -0
  54. package/dist/component/validators.js.map +1 -0
  55. package/dist/react/index.d.ts +89 -0
  56. package/dist/react/index.d.ts.map +1 -0
  57. package/dist/react/index.js +63 -0
  58. package/dist/react/index.js.map +1 -0
  59. package/dist/shared.d.ts +14 -0
  60. package/dist/shared.d.ts.map +1 -0
  61. package/dist/shared.js +18 -0
  62. package/dist/shared.js.map +1 -0
  63. package/dist/test.d.ts +117 -0
  64. package/dist/test.d.ts.map +1 -0
  65. package/dist/test.js +28 -0
  66. package/dist/test.js.map +1 -0
  67. package/dist/web/index.d.ts +121 -0
  68. package/dist/web/index.d.ts.map +1 -0
  69. package/dist/web/index.js +169 -0
  70. package/dist/web/index.js.map +1 -0
  71. package/package.json +121 -0
  72. package/src/client/index.ts +259 -0
  73. package/src/client/types.ts +121 -0
  74. package/src/component/_generated/api.ts +62 -0
  75. package/src/component/_generated/component.ts +196 -0
  76. package/src/component/_generated/dataModel.ts +60 -0
  77. package/src/component/_generated/server.ts +169 -0
  78. package/src/component/convex.config.ts +12 -0
  79. package/src/component/http.ts +204 -0
  80. package/src/component/internal_mutations.ts +167 -0
  81. package/src/component/mutations.ts +255 -0
  82. package/src/component/queries.ts +436 -0
  83. package/src/component/schema.ts +76 -0
  84. package/src/component/validators.ts +94 -0
  85. package/src/react/index.tsx +127 -0
  86. package/src/shared.ts +30 -0
  87. package/src/test.ts +44 -0
  88. package/src/web/index.ts +232 -0
@@ -0,0 +1,148 @@
1
+ /** Total event count over a range, optionally filtered by one dimension value. */
2
+ export declare const metric: import("convex/server").RegisteredQuery<"public", {
3
+ name: string;
4
+ range?: {
5
+ from?: number | undefined;
6
+ to?: number | undefined;
7
+ } | undefined;
8
+ scope: string;
9
+ where?: {
10
+ dim: string;
11
+ val: string | number | boolean | null;
12
+ } | undefined;
13
+ }, Promise<number>>;
14
+ /** Top values of a dimension (breakdown), ranked by count. */
15
+ export declare const top: import("convex/server").RegisteredQuery<"public", {
16
+ dimension: string;
17
+ limit?: number | undefined;
18
+ name: string;
19
+ range?: {
20
+ from?: number | undefined;
21
+ to?: number | undefined;
22
+ } | undefined;
23
+ scope: string;
24
+ }, Promise<{
25
+ value: string;
26
+ count: number;
27
+ }[]>>;
28
+ /** Bucketed counts over a range, optionally filtered by one dimension value. */
29
+ export declare const timeseries: import("convex/server").RegisteredQuery<"public", {
30
+ granularity: "day" | "hour" | "minute";
31
+ name: string;
32
+ range: {
33
+ from?: number | undefined;
34
+ to?: number | undefined;
35
+ };
36
+ scope: string;
37
+ where?: {
38
+ dim: string;
39
+ val: string | number | boolean | null;
40
+ } | undefined;
41
+ }, Promise<{
42
+ bucket: number;
43
+ count: number;
44
+ }[]>>;
45
+ /** DAU/WAU/MAU distinct-subject counts from the subjects table. */
46
+ export declare const uniques: import("convex/server").RegisteredQuery<"public", {
47
+ granularity: "day" | "hour" | "minute";
48
+ range: {
49
+ from?: number | undefined;
50
+ to?: number | undefined;
51
+ };
52
+ scope: string;
53
+ }, Promise<{
54
+ dau: number;
55
+ wau: number;
56
+ mau: number;
57
+ trend: {
58
+ bucket: number;
59
+ uniques: number;
60
+ }[];
61
+ }>>;
62
+ /** Ordered step conversion over raw events, keyed by subjectRef. */
63
+ export declare const funnel: import("convex/server").RegisteredQuery<"public", {
64
+ range: {
65
+ from?: number | undefined;
66
+ to?: number | undefined;
67
+ };
68
+ scope: string;
69
+ steps: string[];
70
+ }, Promise<{
71
+ name: string;
72
+ count: number;
73
+ rate: number;
74
+ }[]>>;
75
+ /** Cohort return rates by first-seen period. */
76
+ export declare const retention: import("convex/server").RegisteredQuery<"public", {
77
+ cohortRange: {
78
+ from?: number | undefined;
79
+ to?: number | undefined;
80
+ };
81
+ granularity?: "day" | "hour" | "minute" | undefined;
82
+ periods: number;
83
+ scope: string;
84
+ }, Promise<{
85
+ cohort: number;
86
+ size: number;
87
+ retained: number[];
88
+ }[]>>;
89
+ /**
90
+ * Histogram of a numeric measure over raw events: ascending upper-bound bins +
91
+ * an overflow bucket. A value `m` falls in the first bin whose `upper >= m`;
92
+ * values above the last bound land in `overflow`. Non-numeric measure values are
93
+ * ignored. `count`/`sum` give the population size and total (so mean = sum/count).
94
+ * Index-backed (`by_scope_name_ts`) and bounded — computed from raw events, like
95
+ * `funnel`/`retention`.
96
+ */
97
+ export declare const distribution: import("convex/server").RegisteredQuery<"public", {
98
+ buckets: number[];
99
+ measure: string;
100
+ name: string;
101
+ range?: {
102
+ from?: number | undefined;
103
+ to?: number | undefined;
104
+ } | undefined;
105
+ scope: string;
106
+ where?: {
107
+ dim: string;
108
+ val: string | number | boolean | null;
109
+ } | undefined;
110
+ }, Promise<{
111
+ bins: {
112
+ upper: number;
113
+ count: number;
114
+ }[];
115
+ overflow: number;
116
+ count: number;
117
+ sum: number;
118
+ }>>;
119
+ /** Paginated raw events for an event name, newest first. */
120
+ export declare const list: import("convex/server").RegisteredQuery<"public", {
121
+ name: string;
122
+ paginationOpts: {
123
+ cursor: string | null;
124
+ numItems: number;
125
+ };
126
+ scope: string;
127
+ }, Promise<{
128
+ page: {
129
+ _id: string;
130
+ _creationTime: number;
131
+ scope: string;
132
+ name: string;
133
+ subjectRef: string | undefined;
134
+ sessionRef: string | undefined;
135
+ props: Record<string, string | number | boolean | null>;
136
+ ts: number;
137
+ seq: number;
138
+ dedupeKey: string | undefined;
139
+ }[];
140
+ isDone: boolean;
141
+ continueCursor: string;
142
+ }>>;
143
+ /** Read a single config value for a scope. */
144
+ export declare const configGet: import("convex/server").RegisteredQuery<"public", {
145
+ key: string;
146
+ scope: string;
147
+ }, Promise<string | null>>;
148
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAyBA,kFAAkF;AAClF,eAAO,MAAM,MAAM;;;;;;;;;;;mBAuCjB,CAAC;AAEH,8DAA8D;AAC9D,eAAO,MAAM,GAAG;;;;;;;;;;;;KAsCd,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;KAsCrB,CAAC;AAEH,mEAAmE;AACnE,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;GA8ClB,CAAC;AAEH,oEAAoE;AACpE,eAAO,MAAM,MAAM;;;;;;;;UAmCc,MAAM;WAAS,MAAM;UAAQ,MAAM;KA0BlE,CAAC;AAEH,gDAAgD;AAChD,eAAO,MAAM,SAAS;;;;;;;;;;;;KAkDpB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;GAgDvB,CAAC;AAEH,4DAA4D;AAC5D,eAAO,MAAM,IAAI;;;;;;;;;aA+BK,MAAM;;;;;;;;;;;;;GAe1B,CAAC;AAEH,8CAA8C;AAC9C,eAAO,MAAM,SAAS;;;0BAYpB,CAAC"}
@@ -0,0 +1,376 @@
1
+ import { query } from "./_generated/server";
2
+ import { components } from "./_generated/api";
3
+ import { v } from "convex/values";
4
+ import { ShardedCounter } from "@convex-dev/sharded-counter";
5
+ import { rangeValidator, whereValidator, granularityValidator, topRow, timeseriesPoint, uniquesView, funnelStep, retentionCohort, eventPage, distributionView, } from "./validators.js";
6
+ import { bucketStart, bucketSize, valKey } from "../shared.js";
7
+ const counter = new ShardedCounter(components.shardedCounter, {
8
+ defaultShards: 16,
9
+ });
10
+ const TOTAL = "";
11
+ /** Total event count over a range, optionally filtered by one dimension value. */
12
+ export const metric = query({
13
+ args: {
14
+ scope: v.string(),
15
+ name: v.string(),
16
+ range: v.optional(rangeValidator),
17
+ where: v.optional(whereValidator),
18
+ },
19
+ returns: v.number(),
20
+ handler: async (ctx, args) => {
21
+ const dim = args.where ? args.where.dim : TOTAL;
22
+ const val = args.where ? valKey(args.where.val) : TOTAL;
23
+ if (!args.range && !args.where) {
24
+ return await counter.count(ctx, `${args.scope}:${args.name}`);
25
+ }
26
+ const rollups = await ctx.db
27
+ .query("rollups")
28
+ .withIndex("by_scope_name_gran_bucket_dim", (q) => q
29
+ .eq("scope", args.scope)
30
+ .eq("name", args.name)
31
+ .eq("granularity", "day"))
32
+ .collect();
33
+ let total = 0;
34
+ for (const r of rollups) {
35
+ if (r.dim !== dim || r.val !== val)
36
+ continue;
37
+ if (args.range?.from !== undefined && r.bucket < bucketStart(args.range.from, "day")) {
38
+ continue;
39
+ }
40
+ if (args.range?.to !== undefined && r.bucket > bucketStart(args.range.to, "day")) {
41
+ continue;
42
+ }
43
+ total += r.count;
44
+ }
45
+ return total;
46
+ },
47
+ });
48
+ /** Top values of a dimension (breakdown), ranked by count. */
49
+ export const top = query({
50
+ args: {
51
+ scope: v.string(),
52
+ name: v.string(),
53
+ dimension: v.string(),
54
+ range: v.optional(rangeValidator),
55
+ limit: v.optional(v.number()),
56
+ },
57
+ returns: v.array(topRow),
58
+ handler: async (ctx, args) => {
59
+ const limit = Math.min(args.limit ?? 20, 100);
60
+ const rollups = await ctx.db
61
+ .query("rollups")
62
+ .withIndex("by_scope_name_gran_bucket_dim", (q) => q
63
+ .eq("scope", args.scope)
64
+ .eq("name", args.name)
65
+ .eq("granularity", "day"))
66
+ .collect();
67
+ const counts = new Map();
68
+ for (const r of rollups) {
69
+ if (r.dim !== args.dimension)
70
+ continue;
71
+ if (args.range?.from !== undefined && r.bucket < bucketStart(args.range.from, "day")) {
72
+ continue;
73
+ }
74
+ if (args.range?.to !== undefined && r.bucket > bucketStart(args.range.to, "day")) {
75
+ continue;
76
+ }
77
+ counts.set(r.val, (counts.get(r.val) ?? 0) + r.count);
78
+ }
79
+ return [...counts.entries()]
80
+ .map(([value, count]) => ({ value, count }))
81
+ .sort((a, b) => b.count - a.count)
82
+ .slice(0, limit);
83
+ },
84
+ });
85
+ /** Bucketed counts over a range, optionally filtered by one dimension value. */
86
+ export const timeseries = query({
87
+ args: {
88
+ scope: v.string(),
89
+ name: v.string(),
90
+ granularity: granularityValidator,
91
+ range: rangeValidator,
92
+ where: v.optional(whereValidator),
93
+ },
94
+ returns: v.array(timeseriesPoint),
95
+ handler: async (ctx, args) => {
96
+ const gran = args.granularity;
97
+ const dim = args.where ? args.where.dim : TOTAL;
98
+ const val = args.where ? valKey(args.where.val) : TOTAL;
99
+ const rollups = await ctx.db
100
+ .query("rollups")
101
+ .withIndex("by_scope_name_gran_bucket_dim", (q) => q.eq("scope", args.scope).eq("name", args.name).eq("granularity", gran))
102
+ .collect();
103
+ const fromBucket = args.range.from !== undefined ? bucketStart(args.range.from, gran) : undefined;
104
+ const toBucket = args.range.to !== undefined ? bucketStart(args.range.to, gran) : undefined;
105
+ const counts = new Map();
106
+ for (const r of rollups) {
107
+ if (r.dim !== dim || r.val !== val)
108
+ continue;
109
+ if (fromBucket !== undefined && r.bucket < fromBucket)
110
+ continue;
111
+ if (toBucket !== undefined && r.bucket > toBucket)
112
+ continue;
113
+ counts.set(r.bucket, (counts.get(r.bucket) ?? 0) + r.count);
114
+ }
115
+ return [...counts.entries()]
116
+ .map(([bucket, count]) => ({ bucket, count }))
117
+ .sort((a, b) => a.bucket - b.bucket);
118
+ },
119
+ });
120
+ /** DAU/WAU/MAU distinct-subject counts from the subjects table. */
121
+ export const uniques = query({
122
+ args: {
123
+ scope: v.string(),
124
+ range: rangeValidator,
125
+ granularity: granularityValidator,
126
+ },
127
+ returns: uniquesView,
128
+ handler: async (ctx, args) => {
129
+ const now = Date.now();
130
+ const to = args.range.to ?? now;
131
+ const from = args.range.from ?? to - 30 * 24 * 60 * 60 * 1000;
132
+ const subjects = await ctx.db
133
+ .query("subjects")
134
+ .withIndex("by_scope_firstSeen", (q) => q.eq("scope", args.scope))
135
+ .collect();
136
+ const size = bucketSize(args.granularity);
137
+ const trendBuckets = new Map();
138
+ let mau = 0;
139
+ let wau = 0;
140
+ const dayMs = 24 * 60 * 60 * 1000;
141
+ const wauCutoff = to - 7 * dayMs;
142
+ const mauCutoff = to - 30 * dayMs;
143
+ for (const s of subjects) {
144
+ if (s.lastSeen < from || s.lastSeen > to)
145
+ continue;
146
+ mau += s.lastSeen >= mauCutoff ? 1 : 0;
147
+ wau += s.lastSeen >= wauCutoff ? 1 : 0;
148
+ const bucket = Math.floor(s.lastSeen / size) * size;
149
+ const set = trendBuckets.get(bucket) ?? new Set();
150
+ set.add(s.subjectRef);
151
+ trendBuckets.set(bucket, set);
152
+ }
153
+ const trend = [...trendBuckets.entries()]
154
+ .map(([bucket, set]) => ({ bucket, uniques: set.size }))
155
+ .sort((a, b) => a.bucket - b.bucket);
156
+ const dau = trend.length > 0
157
+ ? Math.round(trend.reduce((sum, p) => sum + p.uniques, 0) / trend.length)
158
+ : 0;
159
+ return { dau, wau, mau, trend };
160
+ },
161
+ });
162
+ /** Ordered step conversion over raw events, keyed by subjectRef. */
163
+ export const funnel = query({
164
+ args: {
165
+ scope: v.string(),
166
+ steps: v.array(v.string()),
167
+ range: rangeValidator,
168
+ },
169
+ returns: v.array(funnelStep),
170
+ handler: async (ctx, args) => {
171
+ if (args.steps.length < 2) {
172
+ throw new Error("Funnel requires at least 2 steps");
173
+ }
174
+ const now = Date.now();
175
+ const to = args.range.to ?? now;
176
+ const from = args.range.from ?? to - 30 * 24 * 60 * 60 * 1000;
177
+ const stepSubjects = await Promise.all(args.steps.map(async (step) => {
178
+ const events = await ctx.db
179
+ .query("events")
180
+ .withIndex("by_scope_name_ts", (q) => q.eq("scope", args.scope).eq("name", step).gte("ts", from).lte("ts", to))
181
+ .take(10000);
182
+ const firstTs = new Map();
183
+ for (const e of events) {
184
+ if (e.subjectRef === undefined)
185
+ continue;
186
+ const prev = firstTs.get(e.subjectRef);
187
+ if (prev === undefined || e.ts < prev) {
188
+ firstTs.set(e.subjectRef, e.ts);
189
+ }
190
+ }
191
+ return firstTs;
192
+ }));
193
+ const results = [];
194
+ let qualified = new Set(stepSubjects[0].keys());
195
+ let firstCount = qualified.size;
196
+ results.push({ name: args.steps[0], count: firstCount, rate: 1 });
197
+ for (let i = 1; i < args.steps.length; i++) {
198
+ const prevTimes = stepSubjects[i - 1];
199
+ const thisTimes = stepSubjects[i];
200
+ const next = new Set();
201
+ for (const subject of qualified) {
202
+ const prevTs = prevTimes.get(subject);
203
+ const thisTs = thisTimes.get(subject);
204
+ if (prevTs !== undefined && thisTs !== undefined && thisTs >= prevTs) {
205
+ next.add(subject);
206
+ }
207
+ }
208
+ results.push({
209
+ name: args.steps[i],
210
+ count: next.size,
211
+ rate: firstCount > 0 ? next.size / firstCount : 0,
212
+ });
213
+ qualified = next;
214
+ }
215
+ return results;
216
+ },
217
+ });
218
+ /** Cohort return rates by first-seen period. */
219
+ export const retention = query({
220
+ args: {
221
+ scope: v.string(),
222
+ cohortRange: rangeValidator,
223
+ periods: v.number(),
224
+ granularity: v.optional(granularityValidator),
225
+ },
226
+ returns: v.array(retentionCohort),
227
+ handler: async (ctx, args) => {
228
+ const gran = args.granularity ?? "day";
229
+ const size = bucketSize(gran);
230
+ const now = Date.now();
231
+ const to = args.cohortRange.to ?? now;
232
+ const from = args.cohortRange.from ?? to - args.periods * size;
233
+ const periods = Math.min(args.periods, 30);
234
+ const subjects = await ctx.db
235
+ .query("subjects")
236
+ .withIndex("by_scope_firstSeen", (q) => q.eq("scope", args.scope).gte("firstSeen", from).lte("firstSeen", to))
237
+ .take(10000);
238
+ const cohortMap = new Map();
239
+ for (const s of subjects) {
240
+ const cohort = Math.floor(s.firstSeen / size) * size;
241
+ const list = cohortMap.get(cohort) ?? [];
242
+ list.push({ firstSeen: s.firstSeen, lastSeen: s.lastSeen });
243
+ cohortMap.set(cohort, list);
244
+ }
245
+ return [...cohortMap.entries()]
246
+ .sort((a, b) => a[0] - b[0])
247
+ .map(([cohort, members]) => {
248
+ const retained = [];
249
+ for (let p = 1; p <= periods; p++) {
250
+ const periodStart = cohort + p * size;
251
+ const periodEnd = periodStart + size;
252
+ let count = 0;
253
+ for (const m of members) {
254
+ if (m.lastSeen >= periodStart && m.lastSeen < periodEnd)
255
+ count++;
256
+ }
257
+ retained.push(count / members.length);
258
+ }
259
+ return { cohort, size: members.length, retained };
260
+ });
261
+ },
262
+ });
263
+ /**
264
+ * Histogram of a numeric measure over raw events: ascending upper-bound bins +
265
+ * an overflow bucket. A value `m` falls in the first bin whose `upper >= m`;
266
+ * values above the last bound land in `overflow`. Non-numeric measure values are
267
+ * ignored. `count`/`sum` give the population size and total (so mean = sum/count).
268
+ * Index-backed (`by_scope_name_ts`) and bounded — computed from raw events, like
269
+ * `funnel`/`retention`.
270
+ */
271
+ export const distribution = query({
272
+ args: {
273
+ scope: v.string(),
274
+ name: v.string(),
275
+ measure: v.string(),
276
+ buckets: v.array(v.number()),
277
+ range: v.optional(rangeValidator),
278
+ where: v.optional(whereValidator),
279
+ },
280
+ returns: distributionView,
281
+ handler: async (ctx, args) => {
282
+ const bins = [...args.buckets]
283
+ .sort((a, b) => a - b)
284
+ .map((upper) => ({ upper, count: 0 }));
285
+ let overflow = 0;
286
+ let count = 0;
287
+ let sum = 0;
288
+ const now = Date.now();
289
+ const to = args.range?.to ?? now;
290
+ const from = args.range?.from ?? 0;
291
+ const events = await ctx.db
292
+ .query("events")
293
+ .withIndex("by_scope_name_ts", (q) => q.eq("scope", args.scope).eq("name", args.name).gte("ts", from).lte("ts", to))
294
+ .take(50000);
295
+ for (const e of events) {
296
+ if (args.where) {
297
+ const pv = e.props[args.where.dim];
298
+ if (pv === undefined || valKey(pv) !== valKey(args.where.val))
299
+ continue;
300
+ }
301
+ const m = e.props[args.measure];
302
+ if (typeof m !== "number")
303
+ continue;
304
+ count += 1;
305
+ sum += m;
306
+ const bin = bins.find((b) => m <= b.upper);
307
+ if (bin) {
308
+ bin.count += 1;
309
+ }
310
+ else {
311
+ overflow += 1;
312
+ }
313
+ }
314
+ return { bins, overflow, count, sum };
315
+ },
316
+ });
317
+ /** Paginated raw events for an event name, newest first. */
318
+ export const list = query({
319
+ args: {
320
+ scope: v.string(),
321
+ name: v.string(),
322
+ paginationOpts: v.object({
323
+ numItems: v.number(),
324
+ cursor: v.union(v.string(), v.null()),
325
+ }),
326
+ },
327
+ returns: eventPage,
328
+ handler: async (ctx, args) => {
329
+ // `.paginate()` is not supported inside a Convex component, so paginate
330
+ // manually with a `ts`-keyed cursor (newest-first). Bounded + index-backed.
331
+ // Note: events sharing the exact boundary `ts` may be skipped across a page
332
+ // edge — adequate for a raw-event peek; precise feeds belong in the host.
333
+ const { numItems, cursor } = args.paginationOpts;
334
+ const before = cursor ? Number(cursor) : null;
335
+ const rows = await ctx.db
336
+ .query("events")
337
+ .withIndex("by_scope_name_ts", (q) => {
338
+ const base = q.eq("scope", args.scope).eq("name", args.name);
339
+ return before !== null ? base.lt("ts", before) : base;
340
+ })
341
+ .order("desc")
342
+ .take(numItems + 1);
343
+ const hasMore = rows.length > numItems;
344
+ const page = hasMore ? rows.slice(0, numItems) : rows;
345
+ const last = page.length > 0 ? page[page.length - 1] : null;
346
+ return {
347
+ page: page.map((e) => ({
348
+ _id: e._id,
349
+ _creationTime: e._creationTime,
350
+ scope: e.scope,
351
+ name: e.name,
352
+ subjectRef: e.subjectRef,
353
+ sessionRef: e.sessionRef,
354
+ props: e.props,
355
+ ts: e.ts,
356
+ seq: e.seq,
357
+ dedupeKey: e.dedupeKey,
358
+ })),
359
+ isDone: !hasMore,
360
+ continueCursor: last ? String(last.ts) : "",
361
+ };
362
+ },
363
+ });
364
+ /** Read a single config value for a scope. */
365
+ export const configGet = query({
366
+ args: { scope: v.string(), key: v.string() },
367
+ returns: v.union(v.string(), v.null()),
368
+ handler: async (ctx, args) => {
369
+ const entry = await ctx.db
370
+ .query("config")
371
+ .withIndex("by_scope_key", (q) => q.eq("scope", args.scope).eq("key", args.key))
372
+ .unique();
373
+ return entry?.value ?? null;
374
+ },
375
+ });
376
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,MAAM,EACN,eAAe,EACf,WAAW,EACX,UAAU,EACV,eAAe,EACf,SAAS,EACT,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG/D,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,UAAU,CAAC,cAAuB,EAAE;IACrE,aAAa,EAAE,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,EAAE,CAAC;AAEjB,kFAAkF;AAClF,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC;IAC1B,IAAI,EAAE;QACJ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC;QACjC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC;KAClC;IACD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QA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,EAAE;QAC3B,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE;aACvB,KAAK,CAAC,QAAQ,CAAC;aACf,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAC/B,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAC9C;aACA,MAAM,EAAE,CAAC;QACZ,OAAO,KAAK,EAAE,KAAK,IAAI,IAAI,CAAC;IAC9B,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Generic, domain-neutral analytics schema. Zero hardcoded web fields, zero `v.any()`.
3
+ *
4
+ * - `events` — raw event log (TTL-pruned).
5
+ * - `rollups` — rollup-on-write counts per (scope, name, granularity, bucket, dim, val).
6
+ * - `subjects` — per-subject lifecycle for uniques/retention.
7
+ * - `sessions` — optional generic session aggregates for idle-close + session reads.
8
+ * - `config` — cron-relevant config (retention/sampling) keyed by scope.
9
+ */
10
+ declare const _default: import("convex/server").SchemaDefinition<{
11
+ events: import("convex/server").TableDefinition<import("convex/values").VObject<{
12
+ dedupeKey?: string | undefined;
13
+ name: string;
14
+ props: Record<string, string | number | boolean | null>;
15
+ scope: string;
16
+ seq: number;
17
+ sessionRef?: string | undefined;
18
+ subjectRef?: string | undefined;
19
+ ts: number;
20
+ }, {
21
+ scope: import("convex/values").VString<string, "required">;
22
+ name: import("convex/values").VString<string, "required">;
23
+ subjectRef: import("convex/values").VString<string | undefined, "optional">;
24
+ sessionRef: import("convex/values").VString<string | undefined, "optional">;
25
+ props: import("convex/values").VRecord<Record<string, string | number | boolean | null>, import("convex/values").VString<string, "required">, import("convex/values").VUnion<string | number | boolean | null, [import("convex/values").VString<string, "required">, import("convex/values").VFloat64<number, "required">, import("convex/values").VBoolean<boolean, "required">, import("convex/values").VNull<null, "required">], "required", never>, "required", string>;
26
+ ts: import("convex/values").VFloat64<number, "required">;
27
+ seq: import("convex/values").VFloat64<number, "required">;
28
+ dedupeKey: import("convex/values").VString<string | undefined, "optional">;
29
+ }, "required", "dedupeKey" | "name" | "props" | "scope" | "seq" | "sessionRef" | "subjectRef" | "ts" | `props.${string}`>, {
30
+ by_dedupe: ["scope", "dedupeKey", "_creationTime"];
31
+ by_scope_name_ts: ["scope", "name", "ts", "_creationTime"];
32
+ by_scope_session_ts: ["scope", "sessionRef", "ts", "_creationTime"];
33
+ by_scope_subject_ts: ["scope", "subjectRef", "ts", "_creationTime"];
34
+ }, {}, {}>;
35
+ rollups: import("convex/server").TableDefinition<import("convex/values").VObject<{
36
+ bucket: number;
37
+ count: number;
38
+ dim: string;
39
+ granularity: "day" | "hour" | "minute";
40
+ name: string;
41
+ scope: string;
42
+ val: string;
43
+ }, {
44
+ scope: import("convex/values").VString<string, "required">;
45
+ name: import("convex/values").VString<string, "required">;
46
+ granularity: import("convex/values").VUnion<"day" | "hour" | "minute", [import("convex/values").VLiteral<"minute", "required">, import("convex/values").VLiteral<"hour", "required">, import("convex/values").VLiteral<"day", "required">], "required", never>;
47
+ bucket: import("convex/values").VFloat64<number, "required">;
48
+ dim: import("convex/values").VString<string, "required">;
49
+ val: import("convex/values").VString<string, "required">;
50
+ count: import("convex/values").VFloat64<number, "required">;
51
+ }, "required", "bucket" | "count" | "dim" | "granularity" | "name" | "scope" | "val">, {
52
+ by_scope_name_dim_val: ["scope", "name", "dim", "val", "_creationTime"];
53
+ by_scope_name_gran_bucket_dim: ["scope", "name", "granularity", "bucket", "dim", "val", "_creationTime"];
54
+ }, {}, {}>;
55
+ subjects: import("convex/server").TableDefinition<import("convex/values").VObject<{
56
+ eventCount: number;
57
+ firstSeen: number;
58
+ lastSeen: number;
59
+ scope: string;
60
+ subjectRef: string;
61
+ }, {
62
+ scope: import("convex/values").VString<string, "required">;
63
+ subjectRef: import("convex/values").VString<string, "required">;
64
+ firstSeen: import("convex/values").VFloat64<number, "required">;
65
+ lastSeen: import("convex/values").VFloat64<number, "required">;
66
+ eventCount: import("convex/values").VFloat64<number, "required">;
67
+ }, "required", "eventCount" | "firstSeen" | "lastSeen" | "scope" | "subjectRef">, {
68
+ by_scope_firstSeen: ["scope", "firstSeen", "_creationTime"];
69
+ by_scope_subject: ["scope", "subjectRef", "_creationTime"];
70
+ }, {}, {}>;
71
+ sessions: import("convex/server").TableDefinition<import("convex/values").VObject<{
72
+ endTs?: number | undefined;
73
+ eventCount: number;
74
+ lastTs: number;
75
+ scope: string;
76
+ sessionRef: string;
77
+ startTs: number;
78
+ subjectRef?: string | undefined;
79
+ }, {
80
+ scope: import("convex/values").VString<string, "required">;
81
+ sessionRef: import("convex/values").VString<string, "required">;
82
+ subjectRef: import("convex/values").VString<string | undefined, "optional">;
83
+ startTs: import("convex/values").VFloat64<number, "required">;
84
+ endTs: import("convex/values").VFloat64<number | undefined, "optional">;
85
+ lastTs: import("convex/values").VFloat64<number, "required">;
86
+ eventCount: import("convex/values").VFloat64<number, "required">;
87
+ }, "required", "endTs" | "eventCount" | "lastTs" | "scope" | "sessionRef" | "startTs" | "subjectRef">, {
88
+ by_scope_lastTs: ["scope", "lastTs", "_creationTime"];
89
+ by_scope_session: ["scope", "sessionRef", "_creationTime"];
90
+ }, {}, {}>;
91
+ config: import("convex/server").TableDefinition<import("convex/values").VObject<{
92
+ key: string;
93
+ scope: string;
94
+ value: string;
95
+ }, {
96
+ scope: import("convex/values").VString<string, "required">;
97
+ key: import("convex/values").VString<string, "required">;
98
+ value: import("convex/values").VString<string, "required">;
99
+ }, "required", "key" | "scope" | "value">, {
100
+ by_scope_key: ["scope", "key", "_creationTime"];
101
+ }, {}, {}>;
102
+ }, true>;
103
+ export default _default;
104
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG"}