@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.
- package/LICENSE +21 -0
- package/README.md +198 -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 +46 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +181 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +133 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +80 -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 +121 -0
- package/src/client/index.ts +259 -0
- package/src/client/types.ts +121 -0
- package/src/component/_generated/api.ts +62 -0
- package/src/component/_generated/component.ts +196 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +169 -0
- package/src/component/convex.config.ts +12 -0
- package/src/component/http.ts +204 -0
- package/src/component/internal_mutations.ts +167 -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,72 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { propsValidator, granularityValidator } from "./validators.js";
|
|
4
|
+
/**
|
|
5
|
+
* Generic, domain-neutral analytics schema. Zero hardcoded web fields, zero `v.any()`.
|
|
6
|
+
*
|
|
7
|
+
* - `events` — raw event log (TTL-pruned).
|
|
8
|
+
* - `rollups` — rollup-on-write counts per (scope, name, granularity, bucket, dim, val).
|
|
9
|
+
* - `subjects` — per-subject lifecycle for uniques/retention.
|
|
10
|
+
* - `sessions` — optional generic session aggregates for idle-close + session reads.
|
|
11
|
+
* - `config` — cron-relevant config (retention/sampling) keyed by scope.
|
|
12
|
+
*/
|
|
13
|
+
export default defineSchema({
|
|
14
|
+
events: defineTable({
|
|
15
|
+
scope: v.string(),
|
|
16
|
+
name: v.string(),
|
|
17
|
+
subjectRef: v.optional(v.string()),
|
|
18
|
+
sessionRef: v.optional(v.string()),
|
|
19
|
+
props: propsValidator,
|
|
20
|
+
ts: v.number(),
|
|
21
|
+
seq: v.number(),
|
|
22
|
+
dedupeKey: v.optional(v.string()),
|
|
23
|
+
})
|
|
24
|
+
.index("by_scope_name_ts", ["scope", "name", "ts"])
|
|
25
|
+
.index("by_scope_subject_ts", ["scope", "subjectRef", "ts"])
|
|
26
|
+
.index("by_scope_session_ts", ["scope", "sessionRef", "ts"])
|
|
27
|
+
.index("by_dedupe", ["scope", "dedupeKey"]),
|
|
28
|
+
rollups: defineTable({
|
|
29
|
+
scope: v.string(),
|
|
30
|
+
name: v.string(),
|
|
31
|
+
granularity: granularityValidator,
|
|
32
|
+
bucket: v.number(),
|
|
33
|
+
dim: v.string(),
|
|
34
|
+
val: v.string(),
|
|
35
|
+
count: v.number(),
|
|
36
|
+
})
|
|
37
|
+
.index("by_scope_name_gran_bucket_dim", [
|
|
38
|
+
"scope",
|
|
39
|
+
"name",
|
|
40
|
+
"granularity",
|
|
41
|
+
"bucket",
|
|
42
|
+
"dim",
|
|
43
|
+
"val",
|
|
44
|
+
])
|
|
45
|
+
.index("by_scope_name_dim_val", ["scope", "name", "dim", "val"]),
|
|
46
|
+
subjects: defineTable({
|
|
47
|
+
scope: v.string(),
|
|
48
|
+
subjectRef: v.string(),
|
|
49
|
+
firstSeen: v.number(),
|
|
50
|
+
lastSeen: v.number(),
|
|
51
|
+
eventCount: v.number(),
|
|
52
|
+
})
|
|
53
|
+
.index("by_scope_subject", ["scope", "subjectRef"])
|
|
54
|
+
.index("by_scope_firstSeen", ["scope", "firstSeen"]),
|
|
55
|
+
sessions: defineTable({
|
|
56
|
+
scope: v.string(),
|
|
57
|
+
sessionRef: v.string(),
|
|
58
|
+
subjectRef: v.optional(v.string()),
|
|
59
|
+
startTs: v.number(),
|
|
60
|
+
endTs: v.optional(v.number()),
|
|
61
|
+
lastTs: v.number(),
|
|
62
|
+
eventCount: v.number(),
|
|
63
|
+
})
|
|
64
|
+
.index("by_scope_session", ["scope", "sessionRef"])
|
|
65
|
+
.index("by_scope_lastTs", ["scope", "lastTs"]),
|
|
66
|
+
config: defineTable({
|
|
67
|
+
scope: v.string(),
|
|
68
|
+
key: v.string(),
|
|
69
|
+
value: v.string(),
|
|
70
|
+
}).index("by_scope_key", ["scope", "key"]),
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvE;;;;;;;;GAQG;AACH,eAAe,YAAY,CAAC;IAC1B,MAAM,EAAE,WAAW,CAAC;QAClB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAClC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE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pB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;KACvB,CAAC;SACC,KAAK,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;SAClD,KAAK,CAAC,oBAAoB,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAEtD,QAAQ,EAAE,WAAW,CAAC;QACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;KACvB,CAAC;SACC,KAAK,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;SAClD,KAAK,CAAC,iBAAiB,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEhD,MAAM,EAAE,WAAW,CAAC;QAClB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;QACf,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAC3C,CAAC,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/** A single property value — string, number, boolean, or null. No nested objects/arrays. */
|
|
2
|
+
export declare const scalarValidator: 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>;
|
|
3
|
+
/** Event properties: a flat record of scalar values. The generic, typed default — never `v.any()`. */
|
|
4
|
+
export declare const propsValidator: 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>;
|
|
5
|
+
/** A time range in epoch millis. */
|
|
6
|
+
export declare const rangeValidator: import("convex/values").VObject<{
|
|
7
|
+
from?: number | undefined;
|
|
8
|
+
to?: number | undefined;
|
|
9
|
+
}, {
|
|
10
|
+
from: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
11
|
+
to: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
12
|
+
}, "required", "from" | "to">;
|
|
13
|
+
/** A dimension filter: count only events whose `dim` prop equals `val`. */
|
|
14
|
+
export declare const whereValidator: import("convex/values").VObject<{
|
|
15
|
+
dim: string;
|
|
16
|
+
val: string | number | boolean | null;
|
|
17
|
+
}, {
|
|
18
|
+
dim: import("convex/values").VString<string, "required">;
|
|
19
|
+
val: 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>;
|
|
20
|
+
}, "required", "dim" | "val">;
|
|
21
|
+
/** Rollup bucket granularity. `minute` is opt-in for short live windows. */
|
|
22
|
+
export declare const granularityValidator: 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>;
|
|
23
|
+
/** Array of granularities (the `granularities` config, shared by `track` + `backfill`). */
|
|
24
|
+
export declare const granularitiesValidator: import("convex/values").VArray<("day" | "hour" | "minute")[], 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>, "required">;
|
|
25
|
+
/** A raw event as returned by reads. */
|
|
26
|
+
export declare const eventView: import("convex/values").VObject<{
|
|
27
|
+
_creationTime: number;
|
|
28
|
+
_id: string;
|
|
29
|
+
dedupeKey?: string | undefined;
|
|
30
|
+
name: string;
|
|
31
|
+
props: Record<string, string | number | boolean | null>;
|
|
32
|
+
scope: string;
|
|
33
|
+
seq: number;
|
|
34
|
+
sessionRef?: string | undefined;
|
|
35
|
+
subjectRef?: string | undefined;
|
|
36
|
+
ts: number;
|
|
37
|
+
}, {
|
|
38
|
+
_id: import("convex/values").VString<string, "required">;
|
|
39
|
+
_creationTime: import("convex/values").VFloat64<number, "required">;
|
|
40
|
+
scope: import("convex/values").VString<string, "required">;
|
|
41
|
+
name: import("convex/values").VString<string, "required">;
|
|
42
|
+
subjectRef: import("convex/values").VString<string | undefined, "optional">;
|
|
43
|
+
sessionRef: import("convex/values").VString<string | undefined, "optional">;
|
|
44
|
+
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>;
|
|
45
|
+
ts: import("convex/values").VFloat64<number, "required">;
|
|
46
|
+
seq: import("convex/values").VFloat64<number, "required">;
|
|
47
|
+
dedupeKey: import("convex/values").VString<string | undefined, "optional">;
|
|
48
|
+
}, "required", "_creationTime" | "_id" | "dedupeKey" | "name" | "props" | "scope" | "seq" | "sessionRef" | "subjectRef" | "ts" | `props.${string}`>;
|
|
49
|
+
/** A `(value, count)` pair for `top` breakdowns. */
|
|
50
|
+
export declare const topRow: import("convex/values").VObject<{
|
|
51
|
+
count: number;
|
|
52
|
+
value: string;
|
|
53
|
+
}, {
|
|
54
|
+
value: import("convex/values").VString<string, "required">;
|
|
55
|
+
count: import("convex/values").VFloat64<number, "required">;
|
|
56
|
+
}, "required", "count" | "value">;
|
|
57
|
+
/** A `(bucket, count)` pair for `timeseries`. */
|
|
58
|
+
export declare const timeseriesPoint: import("convex/values").VObject<{
|
|
59
|
+
bucket: number;
|
|
60
|
+
count: number;
|
|
61
|
+
}, {
|
|
62
|
+
bucket: import("convex/values").VFloat64<number, "required">;
|
|
63
|
+
count: import("convex/values").VFloat64<number, "required">;
|
|
64
|
+
}, "required", "bucket" | "count">;
|
|
65
|
+
/** DAU/WAU/MAU rollup of distinct subjects. */
|
|
66
|
+
export declare const uniquesView: import("convex/values").VObject<{
|
|
67
|
+
dau: number;
|
|
68
|
+
mau: number;
|
|
69
|
+
trend: {
|
|
70
|
+
bucket: number;
|
|
71
|
+
uniques: number;
|
|
72
|
+
}[];
|
|
73
|
+
wau: number;
|
|
74
|
+
}, {
|
|
75
|
+
dau: import("convex/values").VFloat64<number, "required">;
|
|
76
|
+
wau: import("convex/values").VFloat64<number, "required">;
|
|
77
|
+
mau: import("convex/values").VFloat64<number, "required">;
|
|
78
|
+
trend: import("convex/values").VArray<{
|
|
79
|
+
bucket: number;
|
|
80
|
+
uniques: number;
|
|
81
|
+
}[], import("convex/values").VObject<{
|
|
82
|
+
bucket: number;
|
|
83
|
+
uniques: number;
|
|
84
|
+
}, {
|
|
85
|
+
bucket: import("convex/values").VFloat64<number, "required">;
|
|
86
|
+
uniques: import("convex/values").VFloat64<number, "required">;
|
|
87
|
+
}, "required", "bucket" | "uniques">, "required">;
|
|
88
|
+
}, "required", "dau" | "mau" | "trend" | "wau">;
|
|
89
|
+
/** A single funnel step result. */
|
|
90
|
+
export declare const funnelStep: import("convex/values").VObject<{
|
|
91
|
+
count: number;
|
|
92
|
+
name: string;
|
|
93
|
+
rate: number;
|
|
94
|
+
}, {
|
|
95
|
+
name: import("convex/values").VString<string, "required">;
|
|
96
|
+
count: import("convex/values").VFloat64<number, "required">;
|
|
97
|
+
rate: import("convex/values").VFloat64<number, "required">;
|
|
98
|
+
}, "required", "count" | "name" | "rate">;
|
|
99
|
+
/** A single retention cohort row. */
|
|
100
|
+
export declare const retentionCohort: import("convex/values").VObject<{
|
|
101
|
+
cohort: number;
|
|
102
|
+
retained: number[];
|
|
103
|
+
size: number;
|
|
104
|
+
}, {
|
|
105
|
+
cohort: import("convex/values").VFloat64<number, "required">;
|
|
106
|
+
size: import("convex/values").VFloat64<number, "required">;
|
|
107
|
+
retained: import("convex/values").VArray<number[], import("convex/values").VFloat64<number, "required">, "required">;
|
|
108
|
+
}, "required", "cohort" | "retained" | "size">;
|
|
109
|
+
/** Paginated raw-event page (Convex pagination result shape). */
|
|
110
|
+
export declare const eventPage: import("convex/values").VObject<{
|
|
111
|
+
continueCursor: string;
|
|
112
|
+
isDone: boolean;
|
|
113
|
+
page: {
|
|
114
|
+
_creationTime: number;
|
|
115
|
+
_id: string;
|
|
116
|
+
dedupeKey?: string | undefined;
|
|
117
|
+
name: string;
|
|
118
|
+
props: Record<string, string | number | boolean | null>;
|
|
119
|
+
scope: string;
|
|
120
|
+
seq: number;
|
|
121
|
+
sessionRef?: string | undefined;
|
|
122
|
+
subjectRef?: string | undefined;
|
|
123
|
+
ts: number;
|
|
124
|
+
}[];
|
|
125
|
+
}, {
|
|
126
|
+
page: import("convex/values").VArray<{
|
|
127
|
+
_creationTime: number;
|
|
128
|
+
_id: string;
|
|
129
|
+
dedupeKey?: string | undefined;
|
|
130
|
+
name: string;
|
|
131
|
+
props: Record<string, string | number | boolean | null>;
|
|
132
|
+
scope: string;
|
|
133
|
+
seq: number;
|
|
134
|
+
sessionRef?: string | undefined;
|
|
135
|
+
subjectRef?: string | undefined;
|
|
136
|
+
ts: number;
|
|
137
|
+
}[], import("convex/values").VObject<{
|
|
138
|
+
_creationTime: number;
|
|
139
|
+
_id: string;
|
|
140
|
+
dedupeKey?: string | undefined;
|
|
141
|
+
name: string;
|
|
142
|
+
props: Record<string, string | number | boolean | null>;
|
|
143
|
+
scope: string;
|
|
144
|
+
seq: number;
|
|
145
|
+
sessionRef?: string | undefined;
|
|
146
|
+
subjectRef?: string | undefined;
|
|
147
|
+
ts: number;
|
|
148
|
+
}, {
|
|
149
|
+
_id: import("convex/values").VString<string, "required">;
|
|
150
|
+
_creationTime: import("convex/values").VFloat64<number, "required">;
|
|
151
|
+
scope: import("convex/values").VString<string, "required">;
|
|
152
|
+
name: import("convex/values").VString<string, "required">;
|
|
153
|
+
subjectRef: import("convex/values").VString<string | undefined, "optional">;
|
|
154
|
+
sessionRef: import("convex/values").VString<string | undefined, "optional">;
|
|
155
|
+
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>;
|
|
156
|
+
ts: import("convex/values").VFloat64<number, "required">;
|
|
157
|
+
seq: import("convex/values").VFloat64<number, "required">;
|
|
158
|
+
dedupeKey: import("convex/values").VString<string | undefined, "optional">;
|
|
159
|
+
}, "required", "_creationTime" | "_id" | "dedupeKey" | "name" | "props" | "scope" | "seq" | "sessionRef" | "subjectRef" | "ts" | `props.${string}`>, "required">;
|
|
160
|
+
isDone: import("convex/values").VBoolean<boolean, "required">;
|
|
161
|
+
continueCursor: import("convex/values").VString<string, "required">;
|
|
162
|
+
}, "required", "continueCursor" | "isDone" | "page">;
|
|
163
|
+
/** A single histogram bin: events whose measure falls at or below `upper`. */
|
|
164
|
+
export declare const distributionBin: import("convex/values").VObject<{
|
|
165
|
+
count: number;
|
|
166
|
+
upper: number;
|
|
167
|
+
}, {
|
|
168
|
+
upper: import("convex/values").VFloat64<number, "required">;
|
|
169
|
+
count: import("convex/values").VFloat64<number, "required">;
|
|
170
|
+
}, "required", "count" | "upper">;
|
|
171
|
+
/** Histogram of a numeric measure: ascending upper-bound bins + an overflow bucket. */
|
|
172
|
+
export declare const distributionView: import("convex/values").VObject<{
|
|
173
|
+
bins: {
|
|
174
|
+
count: number;
|
|
175
|
+
upper: number;
|
|
176
|
+
}[];
|
|
177
|
+
count: number;
|
|
178
|
+
overflow: number;
|
|
179
|
+
sum: number;
|
|
180
|
+
}, {
|
|
181
|
+
bins: import("convex/values").VArray<{
|
|
182
|
+
count: number;
|
|
183
|
+
upper: number;
|
|
184
|
+
}[], import("convex/values").VObject<{
|
|
185
|
+
count: number;
|
|
186
|
+
upper: number;
|
|
187
|
+
}, {
|
|
188
|
+
upper: import("convex/values").VFloat64<number, "required">;
|
|
189
|
+
count: import("convex/values").VFloat64<number, "required">;
|
|
190
|
+
}, "required", "count" | "upper">, "required">;
|
|
191
|
+
overflow: import("convex/values").VFloat64<number, "required">;
|
|
192
|
+
count: import("convex/values").VFloat64<number, "required">;
|
|
193
|
+
sum: import("convex/values").VFloat64<number, "required">;
|
|
194
|
+
}, "required", "bins" | "count" | "overflow" | "sum">;
|
|
195
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,eAAO,MAAM,eAAe,0SAK3B,CAAC;AAEF,sGAAsG;AACtG,eAAO,MAAM,cAAc,scAAwC,CAAC;AAEpE,oCAAoC;AACpC,eAAO,MAAM,cAAc;;;;;;6BAGzB,CAAC;AAEH,2EAA2E;AAC3E,eAAO,MAAM,cAAc;;;;;;6BAGzB,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,mPAIhC,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,sBAAsB,8TAAgC,CAAC;AAEpE,wCAAwC;AACxC,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;mJAWpB,CAAC;AAEH,oDAAoD;AACpD,eAAO,MAAM,MAAM;;;;;;iCAAqD,CAAC;AAEzE,iDAAiD;AACjD,eAAO,MAAM,eAAe;;;;;;kCAAsD,CAAC;AAEnF,+CAA+C;AAC/C,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;+CAKtB,CAAC;AAEH,mCAAmC;AACnC,eAAO,MAAM,UAAU;;;;;;;;yCAIrB,CAAC;AAEH,qCAAqC;AACrC,eAAO,MAAM,eAAe;;;;;;;;8CAI1B,CAAC;AAEH,iEAAiE;AACjE,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAIpB,CAAC;AAEH,8EAA8E;AAC9E,eAAO,MAAM,eAAe;;;;;;iCAAqD,CAAC;AAElF,uFAAuF;AACvF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;qDAK3B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
/** A single property value — string, number, boolean, or null. No nested objects/arrays. */
|
|
3
|
+
export const scalarValidator = v.union(v.string(), v.number(), v.boolean(), v.null());
|
|
4
|
+
/** Event properties: a flat record of scalar values. The generic, typed default — never `v.any()`. */
|
|
5
|
+
export const propsValidator = v.record(v.string(), scalarValidator);
|
|
6
|
+
/** A time range in epoch millis. */
|
|
7
|
+
export const rangeValidator = v.object({
|
|
8
|
+
from: v.optional(v.number()),
|
|
9
|
+
to: v.optional(v.number()),
|
|
10
|
+
});
|
|
11
|
+
/** A dimension filter: count only events whose `dim` prop equals `val`. */
|
|
12
|
+
export const whereValidator = v.object({
|
|
13
|
+
dim: v.string(),
|
|
14
|
+
val: scalarValidator,
|
|
15
|
+
});
|
|
16
|
+
/** Rollup bucket granularity. `minute` is opt-in for short live windows. */
|
|
17
|
+
export const granularityValidator = v.union(v.literal("minute"), v.literal("hour"), v.literal("day"));
|
|
18
|
+
/** Array of granularities (the `granularities` config, shared by `track` + `backfill`). */
|
|
19
|
+
export const granularitiesValidator = v.array(granularityValidator);
|
|
20
|
+
/** A raw event as returned by reads. */
|
|
21
|
+
export const eventView = v.object({
|
|
22
|
+
_id: v.string(),
|
|
23
|
+
_creationTime: v.number(),
|
|
24
|
+
scope: v.string(),
|
|
25
|
+
name: v.string(),
|
|
26
|
+
subjectRef: v.optional(v.string()),
|
|
27
|
+
sessionRef: v.optional(v.string()),
|
|
28
|
+
props: propsValidator,
|
|
29
|
+
ts: v.number(),
|
|
30
|
+
seq: v.number(),
|
|
31
|
+
dedupeKey: v.optional(v.string()),
|
|
32
|
+
});
|
|
33
|
+
/** A `(value, count)` pair for `top` breakdowns. */
|
|
34
|
+
export const topRow = v.object({ value: v.string(), count: v.number() });
|
|
35
|
+
/** A `(bucket, count)` pair for `timeseries`. */
|
|
36
|
+
export const timeseriesPoint = v.object({ bucket: v.number(), count: v.number() });
|
|
37
|
+
/** DAU/WAU/MAU rollup of distinct subjects. */
|
|
38
|
+
export const uniquesView = v.object({
|
|
39
|
+
dau: v.number(),
|
|
40
|
+
wau: v.number(),
|
|
41
|
+
mau: v.number(),
|
|
42
|
+
trend: v.array(v.object({ bucket: v.number(), uniques: v.number() })),
|
|
43
|
+
});
|
|
44
|
+
/** A single funnel step result. */
|
|
45
|
+
export const funnelStep = v.object({
|
|
46
|
+
name: v.string(),
|
|
47
|
+
count: v.number(),
|
|
48
|
+
rate: v.number(),
|
|
49
|
+
});
|
|
50
|
+
/** A single retention cohort row. */
|
|
51
|
+
export const retentionCohort = v.object({
|
|
52
|
+
cohort: v.number(),
|
|
53
|
+
size: v.number(),
|
|
54
|
+
retained: v.array(v.number()),
|
|
55
|
+
});
|
|
56
|
+
/** Paginated raw-event page (Convex pagination result shape). */
|
|
57
|
+
export const eventPage = v.object({
|
|
58
|
+
page: v.array(eventView),
|
|
59
|
+
isDone: v.boolean(),
|
|
60
|
+
continueCursor: v.string(),
|
|
61
|
+
});
|
|
62
|
+
/** A single histogram bin: events whose measure falls at or below `upper`. */
|
|
63
|
+
export const distributionBin = v.object({ upper: v.number(), count: v.number() });
|
|
64
|
+
/** Histogram of a numeric measure: ascending upper-bound bins + an overflow bucket. */
|
|
65
|
+
export const distributionView = v.object({
|
|
66
|
+
bins: v.array(distributionBin),
|
|
67
|
+
overflow: v.number(),
|
|
68
|
+
count: v.number(),
|
|
69
|
+
sum: v.number(),
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CACpC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,OAAO,EAAE,EACX,CAAC,CAAC,IAAI,EAAE,CACT,CAAC;AAEF,sGAAsG;AACtG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC;AAEpE,oCAAoC;AACpC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC5B,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAC3B,CAAC,CAAC;AAEH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,eAAe;CACrB,CAAC,CAAC;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CACzC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EACnB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EACjB,CAAC,CAAC,OAAO,CA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C;IAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional React hooks for `@vllnt/convex-analytics`.
|
|
3
|
+
*
|
|
4
|
+
* Thin, tree-shakeable wrappers over `convex/react`'s `useQuery` for the
|
|
5
|
+
* component's **aggregate** read verbs (metric, timeseries, top, uniques).
|
|
6
|
+
* The backend core installs and runs with zero React — these hooks are an
|
|
7
|
+
* opt-in `./react` entry; `react` and `convex` are optional peer deps.
|
|
8
|
+
*
|
|
9
|
+
* No-leak: aggregates ONLY (no raw events) and every call is scope-gated, so a
|
|
10
|
+
* hook can never surface another scope's rows or a raw event payload on the
|
|
11
|
+
* client.
|
|
12
|
+
*
|
|
13
|
+
* The component never owns the host's `api`. The host re-exports the analytics
|
|
14
|
+
* query refs from its own Convex functions and passes the matching ref into
|
|
15
|
+
* each hook — these wrappers forward the host's exact args and the reactive
|
|
16
|
+
* return, while pinning the aggregate return type for ergonomics.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
import type { OptionalRestArgsOrSkip } from "convex/react";
|
|
21
|
+
import type { FunctionReference, DefaultFunctionArgs } from "convex/server";
|
|
22
|
+
import type { Range, Where, Granularity, TopRow, TimeseriesPoint, UniquesView } from "../client/types.js";
|
|
23
|
+
export type { Range, Where, Granularity, TopRow, TimeseriesPoint, UniquesView };
|
|
24
|
+
/** A host-re-exported public analytics query ref returning `R`. */
|
|
25
|
+
type QueryRef<R> = FunctionReference<"query", "public", DefaultFunctionArgs, R>;
|
|
26
|
+
/** The args a host's re-exported `metric` query is expected to accept. */
|
|
27
|
+
export interface MetricArgs {
|
|
28
|
+
scope?: string;
|
|
29
|
+
name: string;
|
|
30
|
+
range?: Range;
|
|
31
|
+
where?: Where;
|
|
32
|
+
}
|
|
33
|
+
/** The args a host's re-exported `top` query is expected to accept. */
|
|
34
|
+
export interface TopArgs {
|
|
35
|
+
scope?: string;
|
|
36
|
+
name: string;
|
|
37
|
+
dimension: string;
|
|
38
|
+
range?: Range;
|
|
39
|
+
limit?: number;
|
|
40
|
+
}
|
|
41
|
+
/** The args a host's re-exported `timeseries` query is expected to accept. */
|
|
42
|
+
export interface TimeseriesArgs {
|
|
43
|
+
scope?: string;
|
|
44
|
+
name: string;
|
|
45
|
+
granularity: Granularity;
|
|
46
|
+
range: Range;
|
|
47
|
+
where?: Where;
|
|
48
|
+
}
|
|
49
|
+
/** The args a host's re-exported `uniques` query is expected to accept. */
|
|
50
|
+
export interface UniquesArgs {
|
|
51
|
+
scope?: string;
|
|
52
|
+
range: Range;
|
|
53
|
+
granularity: Granularity;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Reactive total count for an event over a range (optionally filtered).
|
|
57
|
+
*
|
|
58
|
+
* @param ref - The host's re-exported `metric` query reference.
|
|
59
|
+
* @param args - The query args (`{ name, scope?, range?, where? }`), or
|
|
60
|
+
* `"skip"` to defer until ready. The host ref's own validator is the
|
|
61
|
+
* contract; {@link MetricArgs} documents the expected shape.
|
|
62
|
+
* @returns The count, or `undefined` while loading.
|
|
63
|
+
*/
|
|
64
|
+
export declare function useMetric<Ref extends QueryRef<number>>(ref: Ref, ...args: OptionalRestArgsOrSkip<Ref>): number | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Reactive breakdown — top values of a dimension for an event.
|
|
67
|
+
*
|
|
68
|
+
* @param ref - The host's re-exported `top` query reference.
|
|
69
|
+
* @param args - `{ name, dimension, scope?, range?, limit? }`, or `"skip"`.
|
|
70
|
+
* @returns The rows, or `undefined` while loading.
|
|
71
|
+
*/
|
|
72
|
+
export declare function useTop<Ref extends QueryRef<TopRow[]>>(ref: Ref, ...args: OptionalRestArgsOrSkip<Ref>): TopRow[] | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Reactive bucketed counts for an event over a range.
|
|
75
|
+
*
|
|
76
|
+
* @param ref - The host's re-exported `timeseries` query reference.
|
|
77
|
+
* @param args - `{ name, granularity, range, scope?, where? }`, or `"skip"`.
|
|
78
|
+
* @returns The points, or `undefined` while loading.
|
|
79
|
+
*/
|
|
80
|
+
export declare function useTimeseries<Ref extends QueryRef<TimeseriesPoint[]>>(ref: Ref, ...args: OptionalRestArgsOrSkip<Ref>): TimeseriesPoint[] | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Reactive DAU/WAU/MAU + trend from subjects.
|
|
83
|
+
*
|
|
84
|
+
* @param ref - The host's re-exported `uniques` query reference.
|
|
85
|
+
* @param args - `{ range, granularity, scope? }`, or `"skip"`.
|
|
86
|
+
* @returns The uniques view, or `undefined` while loading.
|
|
87
|
+
*/
|
|
88
|
+
export declare function useUniques<Ref extends QueryRef<UniquesView>>(ref: Ref, ...args: OptionalRestArgsOrSkip<Ref>): UniquesView | undefined;
|
|
89
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,MAAM,EACN,eAAe,EACf,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,CAAC;AAEhF,mEAAmE;AACnE,KAAK,QAAQ,CAAC,CAAC,IAAI,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,mBAAmB,E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AG,EAAE,GAAG,EACR,GAAG,IAAI,EAAE,sBAAsB,CAAC,GAAG,CAAC,GACnC,eAAe,EAAE,GAAG,SAAS,CAE/B;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,SAAS,QAAQ,CAAC,WAAW,CAAC,EAC1D,GAAG,EAAE,GAAG,EACR,GAAG,IAAI,EAAE,sBAAsB,CAAC,GAAG,CAAC,GACnC,WAAW,GAAG,SAAS,CAEzB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional React hooks for `@vllnt/convex-analytics`.
|
|
3
|
+
*
|
|
4
|
+
* Thin, tree-shakeable wrappers over `convex/react`'s `useQuery` for the
|
|
5
|
+
* component's **aggregate** read verbs (metric, timeseries, top, uniques).
|
|
6
|
+
* The backend core installs and runs with zero React — these hooks are an
|
|
7
|
+
* opt-in `./react` entry; `react` and `convex` are optional peer deps.
|
|
8
|
+
*
|
|
9
|
+
* No-leak: aggregates ONLY (no raw events) and every call is scope-gated, so a
|
|
10
|
+
* hook can never surface another scope's rows or a raw event payload on the
|
|
11
|
+
* client.
|
|
12
|
+
*
|
|
13
|
+
* The component never owns the host's `api`. The host re-exports the analytics
|
|
14
|
+
* query refs from its own Convex functions and passes the matching ref into
|
|
15
|
+
* each hook — these wrappers forward the host's exact args and the reactive
|
|
16
|
+
* return, while pinning the aggregate return type for ergonomics.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
import { useQuery } from "convex/react";
|
|
21
|
+
/**
|
|
22
|
+
* Reactive total count for an event over a range (optionally filtered).
|
|
23
|
+
*
|
|
24
|
+
* @param ref - The host's re-exported `metric` query reference.
|
|
25
|
+
* @param args - The query args (`{ name, scope?, range?, where? }`), or
|
|
26
|
+
* `"skip"` to defer until ready. The host ref's own validator is the
|
|
27
|
+
* contract; {@link MetricArgs} documents the expected shape.
|
|
28
|
+
* @returns The count, or `undefined` while loading.
|
|
29
|
+
*/
|
|
30
|
+
export function useMetric(ref, ...args) {
|
|
31
|
+
return useQuery(ref, ...args);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reactive breakdown — top values of a dimension for an event.
|
|
35
|
+
*
|
|
36
|
+
* @param ref - The host's re-exported `top` query reference.
|
|
37
|
+
* @param args - `{ name, dimension, scope?, range?, limit? }`, or `"skip"`.
|
|
38
|
+
* @returns The rows, or `undefined` while loading.
|
|
39
|
+
*/
|
|
40
|
+
export function useTop(ref, ...args) {
|
|
41
|
+
return useQuery(ref, ...args);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reactive bucketed counts for an event over a range.
|
|
45
|
+
*
|
|
46
|
+
* @param ref - The host's re-exported `timeseries` query reference.
|
|
47
|
+
* @param args - `{ name, granularity, range, scope?, where? }`, or `"skip"`.
|
|
48
|
+
* @returns The points, or `undefined` while loading.
|
|
49
|
+
*/
|
|
50
|
+
export function useTimeseries(ref, ...args) {
|
|
51
|
+
return useQuery(ref, ...args);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reactive DAU/WAU/MAU + trend from subjects.
|
|
55
|
+
*
|
|
56
|
+
* @param ref - The host's re-exported `uniques` query reference.
|
|
57
|
+
* @param args - `{ range, granularity, scope? }`, or `"skip"`.
|
|
58
|
+
* @returns The uniques view, or `undefined` while loading.
|
|
59
|
+
*/
|
|
60
|
+
export function useUniques(ref, ...args) {
|
|
61
|
+
return useQuery(ref, ...args);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAkDxC;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACvB,GAAQ,EACR,GAAG,IAAiC;IAEpC,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACpB,GAAQ,EACR,GAAG,IAAiC;IAEpC,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAQ,EACR,GAAG,IAAiC;IAEpC,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,GAAQ,EACR,GAAG,IAAiC;IAEpC,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Shared pure helpers + types for the generic analytics component. */
|
|
2
|
+
/** A single property value. */
|
|
3
|
+
export type Scalar = string | number | boolean | null;
|
|
4
|
+
/** Event properties: a flat record of scalar values. */
|
|
5
|
+
export type Props = Record<string, Scalar>;
|
|
6
|
+
/** Rollup bucket granularity. `minute` is opt-in for short live windows. */
|
|
7
|
+
export type Granularity = "minute" | "hour" | "day";
|
|
8
|
+
/** Bucket size in millis for a granularity. */
|
|
9
|
+
export declare function bucketSize(granularity: Granularity): number;
|
|
10
|
+
/** Truncate an epoch-millis timestamp to the start of its `granularity` bucket. */
|
|
11
|
+
export declare function bucketStart(ts: number, granularity: Granularity): number;
|
|
12
|
+
/** Coerce a scalar prop value to the string form used as a rollup `val` key. */
|
|
13
|
+
export declare function valKey(value: Scalar): string;
|
|
14
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAEvE,+BAA+B;AAC/B,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAEtD,wDAAwD;AACxD,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE3C,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AAMpD,+CAA+C;AAC/C,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAE3D;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM,CAGxE;AAED,gFAAgF;AAChF,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Shared pure helpers + types for the generic analytics component. */
|
|
2
|
+
const MINUTE_MS = 60 * 1000;
|
|
3
|
+
const HOUR_MS = 60 * MINUTE_MS;
|
|
4
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
5
|
+
/** Bucket size in millis for a granularity. */
|
|
6
|
+
export function bucketSize(granularity) {
|
|
7
|
+
return granularity === "minute" ? MINUTE_MS : granularity === "hour" ? HOUR_MS : DAY_MS;
|
|
8
|
+
}
|
|
9
|
+
/** Truncate an epoch-millis timestamp to the start of its `granularity` bucket. */
|
|
10
|
+
export function bucketStart(ts, granularity) {
|
|
11
|
+
const size = bucketSize(granularity);
|
|
12
|
+
return Math.floor(ts / size) * size;
|
|
13
|
+
}
|
|
14
|
+
/** Coerce a scalar prop value to the string form used as a rollup `val` key. */
|
|
15
|
+
export function valKey(value) {
|
|
16
|
+
return value === null ? "null" : String(value);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAWvE,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5B,MAAM,OAAO,GAAG,EAAE,GAAG,SAAS,CAAC;AAC/B,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC;AAE5B,+CAA+C;AAC/C,MAAM,UAAU,UAAU,CAAC,WAAwB;IACjD,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1F,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,WAAW,CAAC,EAAU,EAAE,WAAwB;IAC9D,MAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AACtC,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC"}
|