@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataModel.js","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;GAIG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
3
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { ActionBuilder, HttpActionBuilder, MutationBuilder, QueryBuilder, GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDatabaseReader, GenericDatabaseWriter } from "convex/server";
|
|
7
|
+
import type { DataModel } from "./dataModel.js";
|
|
8
|
+
export declare const query: QueryBuilder<DataModel, "public">;
|
|
9
|
+
export declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
10
|
+
export declare const mutation: MutationBuilder<DataModel, "public">;
|
|
11
|
+
export declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
12
|
+
export declare const action: ActionBuilder<DataModel, "public">;
|
|
13
|
+
export declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
14
|
+
export declare const httpAction: HttpActionBuilder;
|
|
15
|
+
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
16
|
+
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
17
|
+
export type ActionCtx = GenericActionCtx<DataModel>;
|
|
18
|
+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
19
|
+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
20
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAUvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,KAAK,EAAE,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAgB,CAAC;AACrE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,SAAS,EAAE,UAAU,CAAwB,CAAC;AACvF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAmB,CAAC;AAC9E,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,SAAS,EAAE,UAAU,CAA2B,CAAC;AAChG,eAAO,MAAM,MAAM,EAAE,aAAa,CAAC,SAAS,EAAE,QAAQ,CAAiB,CAAC;AACxE,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC,SAAS,EAAE,UAAU,CAAyB,CAAC;AAC1F,eAAO,MAAM,UAAU,EAAE,iBAAqC,CAAC;AAE/D,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;AAClD,MAAM,MAAM,WAAW,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACpD,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAC9D,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { actionGeneric, httpActionGeneric, queryGeneric, mutationGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, } from "convex/server";
|
|
8
|
+
export const query = queryGeneric;
|
|
9
|
+
export const internalQuery = internalQueryGeneric;
|
|
10
|
+
export const mutation = mutationGeneric;
|
|
11
|
+
export const internalMutation = internalMutationGeneric;
|
|
12
|
+
export const action = actionGeneric;
|
|
13
|
+
export const internalAction = internalActionGeneric;
|
|
14
|
+
export const httpAction = httpActionGeneric;
|
|
15
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;GAIG;AAaH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAGvB,MAAM,CAAC,MAAM,KAAK,GAAsC,YAAY,CAAC;AACrE,MAAM,CAAC,MAAM,aAAa,GAAwC,oBAAoB,CAAC;AACvF,MAAM,CAAC,MAAM,QAAQ,GAAyC,eAAe,CAAC;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAA2C,uBAAuB,CAAC;AAChG,MAAM,CAAC,MAAM,MAAM,GAAuC,aAAa,CAAC;AACxE,MAAM,CAAC,MAAM,cAAc,GAAyC,qBAAqB,CAAC;AAC1F,MAAM,CAAC,MAAM,UAAU,GAAsB,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex.config.d.ts","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,SAAS,kDAA+B,CAAC;AAM/C,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineComponent } from "convex/server";
|
|
2
|
+
import aggregate from "@convex-dev/aggregate/convex.config";
|
|
3
|
+
import shardedCounter from "@convex-dev/sharded-counter/convex.config";
|
|
4
|
+
import rateLimiter from "@convex-dev/rate-limiter/convex.config";
|
|
5
|
+
const component = defineComponent("analytics");
|
|
6
|
+
component.use(aggregate);
|
|
7
|
+
component.use(shardedCounter);
|
|
8
|
+
component.use(rateLimiter);
|
|
9
|
+
export default component;
|
|
10
|
+
//# sourceMappingURL=convex.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex.config.js","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,SAAS,MAAM,qCAAqC,CAAC;AAC5D,OAAO,cAAc,MAAM,2CAA2C,CAAC;AACvE,OAAO,WAAW,MAAM,wCAAwC,CAAC;AAEjE,MAAM,SAAS,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;AAE/C,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACzB,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAC9B,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAE3B,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const trackEndpoint: import("convex/server").PublicHttpAction;
|
|
2
|
+
export declare const metricEndpoint: import("convex/server").PublicHttpAction;
|
|
3
|
+
export declare const topEndpoint: import("convex/server").PublicHttpAction;
|
|
4
|
+
export declare const timeseriesEndpoint: import("convex/server").PublicHttpAction;
|
|
5
|
+
export declare const uniquesEndpoint: import("convex/server").PublicHttpAction;
|
|
6
|
+
/**
|
|
7
|
+
* Lean generic HTTP surface. Routes are namespaced under the host's chosen
|
|
8
|
+
* `httpPrefix` when the component is mounted with one. All routes require an
|
|
9
|
+
* `x-api-key` matching the JSON-array config at `(scope, "apiKeys")`.
|
|
10
|
+
*/
|
|
11
|
+
declare const http: import("convex/server").HttpRouter;
|
|
12
|
+
export default http;
|
|
13
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAyEA,eAAO,MAAM,aAAa,0CA8BxB,CAAC;AAEH,eAAO,MAAM,cAAc,0CAmBzB,CAAC;AAEH,eAAO,MAAM,WAAW,0CAoBtB,CAAC;AAEH,eAAO,MAAM,kBAAkB,0CAqB7B,CAAC;AAEH,eAAO,MAAM,eAAe,0CAkB1B,CAAC;AAEH;;;;GAIG;AACH,QAAA,MAAM,IAAI,oCAAe,CAAC;AAO1B,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { httpRouter } from "convex/server";
|
|
2
|
+
import { httpAction } from "./_generated/server";
|
|
3
|
+
import { api } from "./_generated/api";
|
|
4
|
+
function json(data, status = 200) {
|
|
5
|
+
return new Response(JSON.stringify(data), {
|
|
6
|
+
status,
|
|
7
|
+
headers: { "Content-Type": "application/json" },
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function error(message, status = 400) {
|
|
11
|
+
return json({ error: message }, status);
|
|
12
|
+
}
|
|
13
|
+
function timingSafeEqual(a, b) {
|
|
14
|
+
if (a.length !== b.length)
|
|
15
|
+
return false;
|
|
16
|
+
let result = 0;
|
|
17
|
+
for (let i = 0; i < a.length; i++) {
|
|
18
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
19
|
+
}
|
|
20
|
+
return result === 0;
|
|
21
|
+
}
|
|
22
|
+
function scopeOf(value) {
|
|
23
|
+
return typeof value === "string" && value.length > 0 ? value : "default";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gate a request by API key. Keys are a JSON string array stored at config
|
|
27
|
+
* `(scope, "apiKeys")`. Returns an error Response on failure, else null.
|
|
28
|
+
*/
|
|
29
|
+
async function requireApiKey(ctx, request, scope) {
|
|
30
|
+
const key = request.headers.get("x-api-key");
|
|
31
|
+
if (!key)
|
|
32
|
+
return error("Missing x-api-key header", 401);
|
|
33
|
+
const config = await ctx.runQuery(api.queries.configGet, {
|
|
34
|
+
scope,
|
|
35
|
+
key: "apiKeys",
|
|
36
|
+
});
|
|
37
|
+
if (!config)
|
|
38
|
+
return error("API keys not configured", 401);
|
|
39
|
+
const keys = JSON.parse(config);
|
|
40
|
+
const matched = keys.some((stored) => timingSafeEqual(stored, key));
|
|
41
|
+
if (!matched)
|
|
42
|
+
return error("Invalid API key", 401);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function parseJsonSafe(request) {
|
|
46
|
+
return request.json().then((data) => ({ ok: true, data }), () => ({ ok: false }));
|
|
47
|
+
}
|
|
48
|
+
function getParams(request) {
|
|
49
|
+
return new URL(request.url).searchParams;
|
|
50
|
+
}
|
|
51
|
+
function range(params) {
|
|
52
|
+
const from = params.get("from");
|
|
53
|
+
const to = params.get("to");
|
|
54
|
+
if (from === null && to === null)
|
|
55
|
+
return undefined;
|
|
56
|
+
return {
|
|
57
|
+
from: from !== null ? Number(from) : undefined,
|
|
58
|
+
to: to !== null ? Number(to) : undefined,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export const trackEndpoint = httpAction(async (ctx, request) => {
|
|
62
|
+
const parsed = await parseJsonSafe(request);
|
|
63
|
+
if (!parsed.ok)
|
|
64
|
+
return error("Invalid JSON body");
|
|
65
|
+
const body = parsed.data;
|
|
66
|
+
const scope = scopeOf(body["scope"]);
|
|
67
|
+
const authError = await requireApiKey(ctx, request, scope);
|
|
68
|
+
if (authError)
|
|
69
|
+
return authError;
|
|
70
|
+
if (typeof body["name"] !== "string" || body["name"].length === 0) {
|
|
71
|
+
return error("name is required");
|
|
72
|
+
}
|
|
73
|
+
if (!Array.isArray(body["dimensions"])) {
|
|
74
|
+
return error("dimensions (string[]) is required");
|
|
75
|
+
}
|
|
76
|
+
const result = await ctx.runMutation(api.mutations.track, {
|
|
77
|
+
scope,
|
|
78
|
+
name: body["name"],
|
|
79
|
+
subjectRef: typeof body["subjectRef"] === "string" ? body["subjectRef"] : undefined,
|
|
80
|
+
sessionRef: typeof body["sessionRef"] === "string" ? body["sessionRef"] : undefined,
|
|
81
|
+
props: body["props"] ?? undefined,
|
|
82
|
+
ts: typeof body["ts"] === "number" ? body["ts"] : undefined,
|
|
83
|
+
dedupeKey: typeof body["dedupeKey"] === "string" ? body["dedupeKey"] : undefined,
|
|
84
|
+
dimensions: body["dimensions"],
|
|
85
|
+
granularities: Array.isArray(body["granularities"]) ? body["granularities"] : ["day"],
|
|
86
|
+
sampleRate: typeof body["sampleRate"] === "number" ? body["sampleRate"] : undefined,
|
|
87
|
+
});
|
|
88
|
+
return json({ result }, 201);
|
|
89
|
+
});
|
|
90
|
+
export const metricEndpoint = httpAction(async (ctx, request) => {
|
|
91
|
+
const params = getParams(request);
|
|
92
|
+
const scope = scopeOf(params.get("scope"));
|
|
93
|
+
const authError = await requireApiKey(ctx, request, scope);
|
|
94
|
+
if (authError)
|
|
95
|
+
return authError;
|
|
96
|
+
const name = params.get("name");
|
|
97
|
+
if (!name)
|
|
98
|
+
return error("name parameter required");
|
|
99
|
+
const dim = params.get("dim");
|
|
100
|
+
const val = params.get("val");
|
|
101
|
+
const count = await ctx.runQuery(api.queries.metric, {
|
|
102
|
+
scope,
|
|
103
|
+
name,
|
|
104
|
+
range: range(params),
|
|
105
|
+
where: dim !== null && val !== null ? { dim, val } : undefined,
|
|
106
|
+
});
|
|
107
|
+
return json({ name, count });
|
|
108
|
+
});
|
|
109
|
+
export const topEndpoint = httpAction(async (ctx, request) => {
|
|
110
|
+
const params = getParams(request);
|
|
111
|
+
const scope = scopeOf(params.get("scope"));
|
|
112
|
+
const authError = await requireApiKey(ctx, request, scope);
|
|
113
|
+
if (authError)
|
|
114
|
+
return authError;
|
|
115
|
+
const name = params.get("name");
|
|
116
|
+
const dimension = params.get("dimension");
|
|
117
|
+
if (!name)
|
|
118
|
+
return error("name parameter required");
|
|
119
|
+
if (!dimension)
|
|
120
|
+
return error("dimension parameter required");
|
|
121
|
+
const result = await ctx.runQuery(api.queries.top, {
|
|
122
|
+
scope,
|
|
123
|
+
name,
|
|
124
|
+
dimension,
|
|
125
|
+
range: range(params),
|
|
126
|
+
limit: params.get("limit") ? Number(params.get("limit")) : undefined,
|
|
127
|
+
});
|
|
128
|
+
return json(result);
|
|
129
|
+
});
|
|
130
|
+
export const timeseriesEndpoint = httpAction(async (ctx, request) => {
|
|
131
|
+
const params = getParams(request);
|
|
132
|
+
const scope = scopeOf(params.get("scope"));
|
|
133
|
+
const authError = await requireApiKey(ctx, request, scope);
|
|
134
|
+
if (authError)
|
|
135
|
+
return authError;
|
|
136
|
+
const name = params.get("name");
|
|
137
|
+
if (!name)
|
|
138
|
+
return error("name parameter required");
|
|
139
|
+
const granularity = params.get("granularity") ?? "day";
|
|
140
|
+
if (granularity !== "minute" && granularity !== "hour" && granularity !== "day") {
|
|
141
|
+
return error("granularity must be minute, hour, or day");
|
|
142
|
+
}
|
|
143
|
+
const result = await ctx.runQuery(api.queries.timeseries, {
|
|
144
|
+
scope,
|
|
145
|
+
name,
|
|
146
|
+
granularity,
|
|
147
|
+
range: range(params) ?? {},
|
|
148
|
+
});
|
|
149
|
+
return json(result);
|
|
150
|
+
});
|
|
151
|
+
export const uniquesEndpoint = httpAction(async (ctx, request) => {
|
|
152
|
+
const params = getParams(request);
|
|
153
|
+
const scope = scopeOf(params.get("scope"));
|
|
154
|
+
const authError = await requireApiKey(ctx, request, scope);
|
|
155
|
+
if (authError)
|
|
156
|
+
return authError;
|
|
157
|
+
const granularity = params.get("granularity") ?? "day";
|
|
158
|
+
if (granularity !== "minute" && granularity !== "hour" && granularity !== "day") {
|
|
159
|
+
return error("granularity must be minute, hour, or day");
|
|
160
|
+
}
|
|
161
|
+
const result = await ctx.runQuery(api.queries.uniques, {
|
|
162
|
+
scope,
|
|
163
|
+
granularity,
|
|
164
|
+
range: range(params) ?? {},
|
|
165
|
+
});
|
|
166
|
+
return json(result);
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* Lean generic HTTP surface. Routes are namespaced under the host's chosen
|
|
170
|
+
* `httpPrefix` when the component is mounted with one. All routes require an
|
|
171
|
+
* `x-api-key` matching the JSON-array config at `(scope, "apiKeys")`.
|
|
172
|
+
*/
|
|
173
|
+
const http = httpRouter();
|
|
174
|
+
http.route({ path: "/track", method: "POST", handler: trackEndpoint });
|
|
175
|
+
http.route({ path: "/metric", method: "GET", handler: metricEndpoint });
|
|
176
|
+
http.route({ path: "/top", method: "GET", handler: topEndpoint });
|
|
177
|
+
http.route({ path: "/timeseries", method: "GET", handler: timeseriesEndpoint });
|
|
178
|
+
http.route({ path: "/uniques", method: "GET", handler: uniquesEndpoint });
|
|
179
|
+
export default http;
|
|
180
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,SAAS,IAAI,CAAC,IAAa,EAAE,MAAM,GAAG,GAAG;IACvC,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACxC,MAAM;QACN,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAChD,CAAC,CAAC;AACL,CAAC;AAED,SAAS,KAAK,CAAC,OAAe,EAAE,MAAM,GAAG,GAAG;IAC1C,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,K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gB,EAAE;QAC9D,KAAK;QACL,WAAW;QACX,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE;KAClB,CAAC,CAAC;IAEZ,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;AAC1B,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;AACvE,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;AACxE,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAClE,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAChF,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;AAE1E,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Delete raw events past `retentionDays` for a scope. Rollups are kept forever. Idempotent. */
|
|
2
|
+
export declare const prune: import("convex/server").RegisteredMutation<"internal", {
|
|
3
|
+
scope?: string | undefined;
|
|
4
|
+
}, Promise<{
|
|
5
|
+
deleted: number;
|
|
6
|
+
}>>;
|
|
7
|
+
/** Close sessions idle past `sessionIdleMs` (set `endTs`). Idempotent. */
|
|
8
|
+
export declare const closeSessions: import("convex/server").RegisteredMutation<"internal", {
|
|
9
|
+
scope?: string | undefined;
|
|
10
|
+
}, Promise<{
|
|
11
|
+
closed: number;
|
|
12
|
+
}>>;
|
|
13
|
+
/**
|
|
14
|
+
* Re-derive rollups from raw events for a `(scope, name)`. Idempotent: deletes
|
|
15
|
+
* existing rollup rows for the name, then recomputes from the retained raw events.
|
|
16
|
+
*/
|
|
17
|
+
export declare const backfill: import("convex/server").RegisteredMutation<"internal", {
|
|
18
|
+
name: string;
|
|
19
|
+
scope: string;
|
|
20
|
+
granularities: ("minute" | "hour" | "day")[];
|
|
21
|
+
dimensions: string[];
|
|
22
|
+
}, Promise<{
|
|
23
|
+
events: number;
|
|
24
|
+
rows: number;
|
|
25
|
+
}>>;
|
|
26
|
+
//# sourceMappingURL=internal_mutations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal_mutations.d.ts","sourceRoot":"","sources":["../../src/component/internal_mutations.ts"],"names":[],"mappings":"AAmCA,gGAAgG;AAChG,eAAO,MAAM,KAAK;;;;GA2BhB,CAAC;AAEH,0EAA0E;AAC1E,eAAO,MAAM,aAAa;;;;GA0BxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;;;;;;GAkEnB,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { internalMutation } from "./_generated/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { granularitiesValidator } from "./validators.js";
|
|
4
|
+
import { bucketStart, valKey } from "../shared.js";
|
|
5
|
+
const PRUNE_CAP = 10000;
|
|
6
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
const DEFAULT_RETENTION_DAYS = 90;
|
|
8
|
+
const DEFAULT_SESSION_IDLE_MS = 30 * 60 * 1000;
|
|
9
|
+
const TOTAL = "";
|
|
10
|
+
/** Read a numeric config value for a scope, falling back to a default. */
|
|
11
|
+
async function readNumber(ctx, scope, key, fallback) {
|
|
12
|
+
const entry = await ctx.db
|
|
13
|
+
.query("config")
|
|
14
|
+
.withIndex("by_scope_key", (q) => q.eq("scope", scope).eq("key", key))
|
|
15
|
+
.unique();
|
|
16
|
+
if (!entry)
|
|
17
|
+
return fallback;
|
|
18
|
+
const n = Number(entry.value);
|
|
19
|
+
return Number.isFinite(n) ? n : fallback;
|
|
20
|
+
}
|
|
21
|
+
/** List every scope that has at least one config row (the scopes a cron should sweep). */
|
|
22
|
+
async function configuredScopes(ctx) {
|
|
23
|
+
const rows = await ctx.db.query("config").collect();
|
|
24
|
+
return [...new Set(rows.map((r) => r.scope))];
|
|
25
|
+
}
|
|
26
|
+
/** Delete raw events past `retentionDays` for a scope. Rollups are kept forever. Idempotent. */
|
|
27
|
+
export const prune = internalMutation({
|
|
28
|
+
args: { scope: v.optional(v.string()) },
|
|
29
|
+
returns: v.object({ deleted: v.number() }),
|
|
30
|
+
handler: async (ctx, args) => {
|
|
31
|
+
const scopes = args.scope !== undefined ? [args.scope] : await configuredScopes(ctx);
|
|
32
|
+
const pruneScope = async (scope) => {
|
|
33
|
+
const retentionDays = await readNumber(ctx, scope, "retentionDays", DEFAULT_RETENTION_DAYS);
|
|
34
|
+
const cutoff = Date.now() - retentionDays * DAY_MS;
|
|
35
|
+
const oldest = await ctx.db
|
|
36
|
+
.query("events")
|
|
37
|
+
.withIndex("by_scope_name_ts", (q) => q.eq("scope", scope))
|
|
38
|
+
.order("asc")
|
|
39
|
+
.take(PRUNE_CAP);
|
|
40
|
+
const toDelete = oldest.filter((e) => e.ts < cutoff);
|
|
41
|
+
await Promise.all(toDelete.map((e) => ctx.db.delete(e._id)));
|
|
42
|
+
return toDelete.length;
|
|
43
|
+
};
|
|
44
|
+
const counts = await Promise.all(scopes.map(pruneScope));
|
|
45
|
+
return { deleted: counts.reduce((a, b) => a + b, 0) };
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
/** Close sessions idle past `sessionIdleMs` (set `endTs`). Idempotent. */
|
|
49
|
+
export const closeSessions = internalMutation({
|
|
50
|
+
args: { scope: v.optional(v.string()) },
|
|
51
|
+
returns: v.object({ closed: v.number() }),
|
|
52
|
+
handler: async (ctx, args) => {
|
|
53
|
+
const scopes = args.scope !== undefined ? [args.scope] : await configuredScopes(ctx);
|
|
54
|
+
const closeScope = async (scope) => {
|
|
55
|
+
const idleMs = await readNumber(ctx, scope, "sessionIdleMs", DEFAULT_SESSION_IDLE_MS);
|
|
56
|
+
const cutoff = Date.now() - idleMs;
|
|
57
|
+
const open = await ctx.db
|
|
58
|
+
.query("sessions")
|
|
59
|
+
.withIndex("by_scope_lastTs", (q) => q.eq("scope", scope).lt("lastTs", cutoff))
|
|
60
|
+
.take(1000);
|
|
61
|
+
const stale = open.filter((s) => s.endTs === undefined);
|
|
62
|
+
await Promise.all(stale.map((s) => ctx.db.patch(s._id, { endTs: s.lastTs })));
|
|
63
|
+
return stale.length;
|
|
64
|
+
};
|
|
65
|
+
const counts = await Promise.all(scopes.map(closeScope));
|
|
66
|
+
return { closed: counts.reduce((a, b) => a + b, 0) };
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Re-derive rollups from raw events for a `(scope, name)`. Idempotent: deletes
|
|
71
|
+
* existing rollup rows for the name, then recomputes from the retained raw events.
|
|
72
|
+
*/
|
|
73
|
+
export const backfill = internalMutation({
|
|
74
|
+
args: {
|
|
75
|
+
scope: v.string(),
|
|
76
|
+
name: v.string(),
|
|
77
|
+
dimensions: v.array(v.string()),
|
|
78
|
+
granularities: granularitiesValidator,
|
|
79
|
+
},
|
|
80
|
+
returns: v.object({ events: v.number(), rows: v.number() }),
|
|
81
|
+
handler: async (ctx, args) => {
|
|
82
|
+
const grans = args.granularities.length > 0 ? args.granularities : ["day"];
|
|
83
|
+
const existing = await ctx.db
|
|
84
|
+
.query("rollups")
|
|
85
|
+
.withIndex("by_scope_name_dim_val", (q) => q.eq("scope", args.scope).eq("name", args.name))
|
|
86
|
+
.collect();
|
|
87
|
+
await Promise.all(existing.map((r) => ctx.db.delete(r._id)));
|
|
88
|
+
const events = await ctx.db
|
|
89
|
+
.query("events")
|
|
90
|
+
.withIndex("by_scope_name_ts", (q) => q.eq("scope", args.scope).eq("name", args.name))
|
|
91
|
+
.take(50000);
|
|
92
|
+
const counts = new Map();
|
|
93
|
+
const meta = new Map();
|
|
94
|
+
const bump = (gran, bucket, dim, val) => {
|
|
95
|
+
const k = `${gran}|${bucket}|${dim}|${val}`;
|
|
96
|
+
counts.set(k, (counts.get(k) ?? 0) + 1);
|
|
97
|
+
if (!meta.has(k))
|
|
98
|
+
meta.set(k, { gran, bucket, dim, val });
|
|
99
|
+
};
|
|
100
|
+
for (const e of events) {
|
|
101
|
+
for (const gran of grans) {
|
|
102
|
+
const bucket = bucketStart(e.ts, gran);
|
|
103
|
+
bump(gran, bucket, TOTAL, TOTAL);
|
|
104
|
+
for (const dim of args.dimensions) {
|
|
105
|
+
if (dim in e.props) {
|
|
106
|
+
bump(gran, bucket, dim, valKey(e.props[dim]));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
await Promise.all([...counts].map(([k, count]) => {
|
|
112
|
+
const m = meta.get(k);
|
|
113
|
+
return ctx.db.insert("rollups", {
|
|
114
|
+
scope: args.scope,
|
|
115
|
+
name: args.name,
|
|
116
|
+
granularity: m.gran,
|
|
117
|
+
bucket: m.bucket,
|
|
118
|
+
dim: m.dim,
|
|
119
|
+
val: m.val,
|
|
120
|
+
count,
|
|
121
|
+
});
|
|
122
|
+
}));
|
|
123
|
+
return { events: events.length, rows: counts.size };
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=internal_mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal_mutations.js","sourceRoot":"","sources":["../../src/component/internal_mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,sBAAsB,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;gBACV,GAAG,EAAE,CAAC,CAAC,GAAG;gBACV,KAAK;aACN,CAAC,CAAC;QACL,CAAC,CAAC,CACH,CAAC;QAEF,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IACtD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const track: import("convex/server").RegisteredMutation<"public", {
|
|
2
|
+
ts?: number | undefined;
|
|
3
|
+
subjectRef?: string | undefined;
|
|
4
|
+
sessionRef?: string | undefined;
|
|
5
|
+
props?: Record<string, string | number | boolean | null> | undefined;
|
|
6
|
+
dedupeKey?: string | undefined;
|
|
7
|
+
sampleRate?: number | undefined;
|
|
8
|
+
name: string;
|
|
9
|
+
scope: string;
|
|
10
|
+
granularities: ("minute" | "hour" | "day")[];
|
|
11
|
+
dimensions: string[];
|
|
12
|
+
}, Promise<"tracked" | "dropped" | "duplicate">>;
|
|
13
|
+
export declare const configSet: import("convex/server").RegisteredMutation<"public", {
|
|
14
|
+
value: string;
|
|
15
|
+
key: string;
|
|
16
|
+
scope: string;
|
|
17
|
+
}, Promise<null>>;
|
|
18
|
+
export declare const configure: import("convex/server").RegisteredMutation<"public", {
|
|
19
|
+
sampleRate?: number | undefined;
|
|
20
|
+
retentionDays?: number | undefined;
|
|
21
|
+
sessionIdleMs?: number | undefined;
|
|
22
|
+
scope: string;
|
|
23
|
+
}, Promise<null>>;
|
|
24
|
+
//# sourceMappingURL=mutations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAgEA,eAAO,MAAM,KAAK;;;;;;;;;;;gDAyIhB,CAAC;AAoBH,eAAO,MAAM,SAAS;;;;iBAOpB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;iBAwBpB,CAAC"}
|