metrickit 0.1.2

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 (50) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +379 -0
  4. package/dist/cache-redis.d.ts +10 -0
  5. package/dist/cache-redis.js +24 -0
  6. package/dist/cache-utils.d.ts +5 -0
  7. package/dist/cache.d.ts +18 -0
  8. package/dist/catalog.d.ts +12 -0
  9. package/dist/define-metric.d.ts +37 -0
  10. package/dist/engine.d.ts +200 -0
  11. package/dist/filters/default-metadata.d.ts +28 -0
  12. package/dist/filters/index.d.ts +3 -0
  13. package/dist/filters/parse.d.ts +7 -0
  14. package/dist/filters/types.d.ts +19 -0
  15. package/dist/frontend/catalog.d.ts +24 -0
  16. package/dist/frontend/dashboard.d.ts +12 -0
  17. package/dist/frontend/format.d.ts +10 -0
  18. package/dist/frontend/index.d.ts +10 -0
  19. package/dist/frontend/markers.d.ts +19 -0
  20. package/dist/frontend/renderers.d.ts +14 -0
  21. package/dist/frontend/requests.d.ts +17 -0
  22. package/dist/frontend/stream-state.d.ts +14 -0
  23. package/dist/frontend/time.d.ts +5 -0
  24. package/dist/frontend/transport.d.ts +19 -0
  25. package/dist/frontend/types.d.ts +108 -0
  26. package/dist/frontend.d.ts +1 -0
  27. package/dist/frontend.js +752 -0
  28. package/dist/helpers/clickhouse.d.ts +27 -0
  29. package/dist/helpers/distribution.d.ts +15 -0
  30. package/dist/helpers/index.d.ts +6 -0
  31. package/dist/helpers/metric-type.d.ts +21 -0
  32. package/dist/helpers/pivot.d.ts +15 -0
  33. package/dist/helpers/prisma.d.ts +20 -0
  34. package/dist/helpers/timeseries.d.ts +6 -0
  35. package/dist/helpers.d.ts +1 -0
  36. package/dist/helpers.js +668 -0
  37. package/dist/index.d.ts +11 -0
  38. package/dist/index.js +1322 -0
  39. package/dist/orpc.d.ts +36 -0
  40. package/dist/orpc.js +1157 -0
  41. package/dist/registry.d.ts +269 -0
  42. package/dist/run-metrics.d.ts +14 -0
  43. package/dist/schemas/index.d.ts +4 -0
  44. package/dist/schemas/inputs.d.ts +19 -0
  45. package/dist/schemas/metric-type.d.ts +7 -0
  46. package/dist/schemas/output.d.ts +842 -0
  47. package/dist/schemas/time.d.ts +24 -0
  48. package/dist/time.d.ts +6 -0
  49. package/dist/type-guards.d.ts +7 -0
  50. package/package.json +91 -0
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const TimeGranularitySchema: z.ZodEnum<{
3
+ hour: "hour";
4
+ day: "day";
5
+ week: "week";
6
+ month: "month";
7
+ quarter: "quarter";
8
+ year: "year";
9
+ }>;
10
+ export type TimeGranularity = z.infer<typeof TimeGranularitySchema>;
11
+ export declare const TimeRangeSchema: z.ZodObject<{
12
+ from: z.ZodOptional<z.ZodDate>;
13
+ to: z.ZodOptional<z.ZodDate>;
14
+ }, z.core.$strip>;
15
+ export type TimeRange = z.infer<typeof TimeRangeSchema>;
16
+ export declare const RequiredTimeRangeSchema: z.ZodObject<{
17
+ from: z.ZodDate;
18
+ to: z.ZodDate;
19
+ }, z.core.$strip>;
20
+ export type RequiredTimeRange = z.infer<typeof RequiredTimeRangeSchema>;
21
+ export declare const CompareSchema: z.ZodObject<{
22
+ compareToPrevious: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
23
+ }, z.core.$strip>;
24
+ export type Compare = z.infer<typeof CompareSchema>;
package/dist/time.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { TimeGranularity, TimeRange } from './schemas/index.ts';
2
+ export declare function getPreviousPeriod(range: TimeRange): TimeRange | null;
3
+ export declare function getBucketStart(date: Date, granularity: TimeGranularity): Date;
4
+ export declare function normalizeUserDate(date: Date): Date;
5
+ export declare function generateBuckets(from: Date, to: Date, granularity: TimeGranularity): Date[];
6
+ export declare function inferGranularity(range: TimeRange): TimeGranularity;
@@ -0,0 +1,7 @@
1
+ import type { MetricOutput, KpiOutput, TimeSeriesOutput, DistributionOutput, TableOutput, LeaderboardOutput, PivotOutput } from './schemas/index.ts';
2
+ export declare function isKpi(output: MetricOutput): output is KpiOutput;
3
+ export declare function isTimeSeries(output: MetricOutput): output is TimeSeriesOutput;
4
+ export declare function isDistribution(output: MetricOutput): output is DistributionOutput;
5
+ export declare function isTable(output: MetricOutput): output is TableOutput;
6
+ export declare function isLeaderboard(output: MetricOutput): output is LeaderboardOutput;
7
+ export declare function isPivot(output: MetricOutput): output is PivotOutput;
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "metrickit",
3
+ "version": "0.1.2",
4
+ "description": "Type-safe metrics and dashboard primitives for TypeScript",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/HansKristoffer/ts-metrics.git"
10
+ },
11
+ "homepage": "https://github.com/HansKristoffer/ts-metrics#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/HansKristoffer/ts-metrics/issues"
14
+ },
15
+ "author": "Kristoffer Hansen",
16
+ "keywords": [
17
+ "metrickit",
18
+ "typescript",
19
+ "metrics",
20
+ "dashboard",
21
+ "analytics",
22
+ "kpi"
23
+ ],
24
+ "engines": {
25
+ "node": ">=18.0.0",
26
+ "bun": ">=1.0.0"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE",
32
+ "CHANGELOG.md"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./orpc": {
41
+ "types": "./dist/orpc.d.ts",
42
+ "import": "./dist/orpc.js",
43
+ "default": "./dist/orpc.js"
44
+ },
45
+ "./cache-redis": {
46
+ "types": "./dist/cache-redis.d.ts",
47
+ "import": "./dist/cache-redis.js",
48
+ "default": "./dist/cache-redis.js"
49
+ },
50
+ "./frontend": {
51
+ "types": "./dist/frontend.d.ts",
52
+ "import": "./dist/frontend.js",
53
+ "default": "./dist/frontend.js"
54
+ },
55
+ "./helpers": {
56
+ "types": "./dist/helpers.d.ts",
57
+ "import": "./dist/helpers.js",
58
+ "default": "./dist/helpers.js"
59
+ }
60
+ },
61
+ "scripts": {
62
+ "clean": "rm -rf ./dist",
63
+ "build": "bun run clean && bun run build:js && bun run build:types",
64
+ "build:js": "bun build ./src/index.ts ./src/orpc.ts ./src/cache-redis.ts ./src/frontend.ts ./src/helpers.ts --outdir ./dist --target node --packages external",
65
+ "build:types": "tsc -p tsconfig.build.json",
66
+ "prepack": "bun run build",
67
+ "test": "bun test",
68
+ "lint": "bun biome check",
69
+ "lint:write": "bun biome check --write",
70
+ "typecheck": "tsc -p tsconfig.build.json --noEmit",
71
+ "smoke:pack": "node ./scripts/smoke-pack.mjs",
72
+ "prepare": "node ./scripts/prepare.mjs",
73
+ "publish:patch": "npm version patch && npm publish",
74
+ "publish:minor": "npm version minor && npm publish",
75
+ "publish:major": "npm version major && npm publish"
76
+ },
77
+ "dependencies": {
78
+ "typedswitch": "^1.0.0"
79
+ },
80
+ "peerDependencies": {
81
+ "zod": "^4.3.6"
82
+ },
83
+ "devDependencies": {
84
+ "@biomejs/biome": "^2.4.6",
85
+ "@types/bun": "latest",
86
+ "@typescript/native-preview": "^7.0.0-dev.20260306.1",
87
+ "husky": "^9.1.7",
88
+ "typescript": "^5.7.0",
89
+ "zod": "^4.3.6"
90
+ }
91
+ }