@stellaris/metrics-shared 0.1.3 → 0.1.6
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/bff-service.d.ts +1394 -172
- package/index.ts +1 -2
- package/package.json +2 -1
- package/schemas/filter.ts +42 -66
- package/schemas/index.ts +1 -0
- package/schemas/metric.ts +6 -75
- package/schemas/rpa-event.ts +41 -0
- package/schemas/time.ts +7 -60
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellaris/metrics-shared",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.ts",
|
|
6
6
|
"types": "./index.ts",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@cubejs-client/core": "^1.6.4",
|
|
14
15
|
"hono": "^4.11.4",
|
|
15
16
|
"zod": "^4.0.0"
|
|
16
17
|
}
|
package/schemas/filter.ts
CHANGED
|
@@ -1,84 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import z from "zod";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const binaryOperatorSchema = z.enum([
|
|
4
4
|
"equals",
|
|
5
5
|
"notEquals",
|
|
6
6
|
"contains",
|
|
7
|
+
"notContains",
|
|
8
|
+
"startsWith",
|
|
9
|
+
"notStartsWith",
|
|
10
|
+
"endsWith",
|
|
11
|
+
"notEndsWith",
|
|
7
12
|
"gt",
|
|
8
|
-
"lt",
|
|
9
13
|
"gte",
|
|
14
|
+
"lt",
|
|
10
15
|
"lte",
|
|
11
|
-
"between",
|
|
12
16
|
"inDateRange",
|
|
17
|
+
"notInDateRange",
|
|
18
|
+
"beforeDate",
|
|
19
|
+
"beforeOrOnDate",
|
|
20
|
+
"afterDate",
|
|
21
|
+
"afterOrOnDate",
|
|
13
22
|
]);
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const FILTER_OPERATOR_LABELS: Record<FilterOperator, string> = {
|
|
18
|
-
equals: "等于",
|
|
19
|
-
notEquals: "不等于",
|
|
20
|
-
contains: "包含",
|
|
21
|
-
gt: "大于",
|
|
22
|
-
lt: "小于",
|
|
23
|
-
gte: "大于等于",
|
|
24
|
-
lte: "小于等于",
|
|
25
|
-
between: "范围内",
|
|
26
|
-
inDateRange: "在时间范围内",
|
|
27
|
-
};
|
|
24
|
+
const unaryOperatorSchema = z.enum(["set", "notSet"]);
|
|
28
25
|
|
|
29
|
-
const
|
|
26
|
+
const baseFilterShape = {
|
|
30
27
|
id: z.string(),
|
|
31
|
-
member: z.string(),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const equalsFilterSchema = baseFilterSchema.extend({
|
|
35
|
-
operator: z.enum(["equals", "notEquals"]),
|
|
36
|
-
value: z.union([z.string(), z.number()]),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export type EqualsFilter = z.infer<typeof equalsFilterSchema>;
|
|
40
|
-
|
|
41
|
-
export const compareFilterSchema = baseFilterSchema.extend({
|
|
42
|
-
operator: z.enum(["gt", "lt", "gte", "lte"]),
|
|
43
|
-
value: z.number(),
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export type CompareFilter = z.infer<typeof compareFilterSchema>;
|
|
28
|
+
member: z.string().optional(),
|
|
29
|
+
dimension: z.string().optional(),
|
|
30
|
+
};
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
const binaryFilterSchema = z.object({
|
|
33
|
+
...baseFilterShape,
|
|
34
|
+
operator: binaryOperatorSchema,
|
|
50
35
|
values: z.array(z.string()),
|
|
51
36
|
});
|
|
52
37
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
operator: z.literal("between"),
|
|
57
|
-
range: z.tuple([z.number(), z.number()]),
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
export type BetweenFilter = z.infer<typeof betweenFilterSchema>;
|
|
61
|
-
|
|
62
|
-
export const dateRangeFilterSchema = baseFilterSchema.extend({
|
|
63
|
-
operator: z.literal("inDateRange"),
|
|
64
|
-
dateRange: z.tuple([z.string(), z.string()]),
|
|
38
|
+
const unaryFilterSchema = z.object({
|
|
39
|
+
...baseFilterShape,
|
|
40
|
+
operator: unaryOperatorSchema,
|
|
65
41
|
});
|
|
66
42
|
|
|
67
|
-
export type
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
43
|
+
export type Filter =
|
|
44
|
+
| {
|
|
45
|
+
id: string;
|
|
46
|
+
member?: string;
|
|
47
|
+
dimension?: string;
|
|
48
|
+
operator: z.infer<typeof binaryOperatorSchema>;
|
|
49
|
+
values: string[];
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
id: string;
|
|
53
|
+
member?: string;
|
|
54
|
+
dimension?: string;
|
|
55
|
+
operator: z.infer<typeof unaryOperatorSchema>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const filterSchema: z.ZodType<Filter> = z.lazy(() =>
|
|
59
|
+
z.union([binaryFilterSchema, unaryFilterSchema]),
|
|
60
|
+
);
|
package/schemas/index.ts
CHANGED
package/schemas/metric.ts
CHANGED
|
@@ -1,84 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { filterSchema } from "./filter";
|
|
3
3
|
import { timeGrainSchema } from "./time";
|
|
4
4
|
|
|
5
5
|
export const metricQueryConfigSchema = z.object({
|
|
6
6
|
table: z.string(),
|
|
7
|
-
|
|
8
|
-
timeDimension: z.string()
|
|
7
|
+
value: z.string(),
|
|
8
|
+
timeDimension: z.string(),
|
|
9
9
|
dimensions: z.array(z.string()),
|
|
10
|
-
filters: z.array(
|
|
11
|
-
timeGrain: timeGrainSchema,
|
|
10
|
+
filters: z.array(filterSchema),
|
|
11
|
+
timeGrain: z.array(timeGrainSchema),
|
|
12
|
+
format: z.enum(["number", "currency", "percent"]),
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
export type MetricQueryConfig = z.infer<typeof metricQueryConfigSchema>;
|
|
15
|
-
|
|
16
|
-
export const DEFAULT_QUERY_CONFIG: MetricQueryConfig = {
|
|
17
|
-
table: "",
|
|
18
|
-
distinctOn: "",
|
|
19
|
-
timeDimension: "",
|
|
20
|
-
dimensions: [],
|
|
21
|
-
filters: [],
|
|
22
|
-
timeGrain: "all",
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const metricVisualConfigSchema = z.object({
|
|
26
|
-
chartType: z.enum([
|
|
27
|
-
"line",
|
|
28
|
-
"bar",
|
|
29
|
-
"area",
|
|
30
|
-
"pie",
|
|
31
|
-
"donut",
|
|
32
|
-
"stacked-bar",
|
|
33
|
-
"combo",
|
|
34
|
-
"radar",
|
|
35
|
-
"funnel",
|
|
36
|
-
"gauge",
|
|
37
|
-
]),
|
|
38
|
-
colors: z.array(z.string()).optional(),
|
|
39
|
-
showLegend: z.boolean().default(true),
|
|
40
|
-
showGrid: z.boolean().default(true),
|
|
41
|
-
xAxis: z
|
|
42
|
-
.object({
|
|
43
|
-
label: z.string().optional(),
|
|
44
|
-
dataKey: z.string().optional(),
|
|
45
|
-
})
|
|
46
|
-
.optional(),
|
|
47
|
-
yAxis: z
|
|
48
|
-
.object({
|
|
49
|
-
label: z.string().optional(),
|
|
50
|
-
unit: z.string().optional(),
|
|
51
|
-
min: z.number().optional(),
|
|
52
|
-
max: z.number().optional(),
|
|
53
|
-
})
|
|
54
|
-
.optional(),
|
|
55
|
-
tooltip: z
|
|
56
|
-
.object({
|
|
57
|
-
show: z.boolean().default(true),
|
|
58
|
-
})
|
|
59
|
-
.optional(),
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export type MetricVisualConfig = z.infer<typeof metricVisualConfigSchema>;
|
|
63
|
-
|
|
64
|
-
export const DEFAULT_VISUAL_CONFIG: MetricVisualConfig = {
|
|
65
|
-
chartType: "line",
|
|
66
|
-
showLegend: true,
|
|
67
|
-
showGrid: true,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export function parseMetricQueryConfig(
|
|
71
|
-
data: unknown,
|
|
72
|
-
): MetricQueryConfig | null {
|
|
73
|
-
const result = metricQueryConfigSchema.safeParse(data);
|
|
74
|
-
if (result.success) {
|
|
75
|
-
return result.data;
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function parseMetricQueryConfigOrDefault(
|
|
81
|
-
data: unknown,
|
|
82
|
-
): MetricQueryConfig {
|
|
83
|
-
return parseMetricQueryConfig(data) ?? DEFAULT_QUERY_CONFIG;
|
|
84
|
-
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
// RPA 事件基础字段
|
|
4
|
+
export const rpaEventBaseSchema = z.object({
|
|
5
|
+
shopId: z.string(),
|
|
6
|
+
agentConfigId: z.string(),
|
|
7
|
+
stage: z.enum(["queued", "executing", "success", "failed"]),
|
|
8
|
+
message: z.string().nullable().optional(),
|
|
9
|
+
timestamp: z.number().optional(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// 回复消息事件
|
|
13
|
+
export const replyMessageEventSchema = rpaEventBaseSchema.extend({
|
|
14
|
+
eventType: z.literal("reply-message"),
|
|
15
|
+
payload: z.record(z.string(), z.unknown()),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// 变更客服状态事件
|
|
19
|
+
export const changeCsStatusEventSchema = rpaEventBaseSchema.extend({
|
|
20
|
+
eventType: z.literal("change-cs-status"),
|
|
21
|
+
payload: z.record(z.string(), z.unknown()),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// 用户消息事件
|
|
25
|
+
export const userMessageEventSchema = rpaEventBaseSchema.extend({
|
|
26
|
+
eventType: z.literal("user-message"),
|
|
27
|
+
payload: z.object({
|
|
28
|
+
platform: z.string(),
|
|
29
|
+
userId: z.string(),
|
|
30
|
+
uid: z.string(),
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// RPA 事件 Schema (Discriminated Union)
|
|
35
|
+
export const rpaEventSchema = z.discriminatedUnion("eventType", [
|
|
36
|
+
replyMessageEventSchema,
|
|
37
|
+
changeCsStatusEventSchema,
|
|
38
|
+
userMessageEventSchema,
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export type RpaEvent = z.infer<typeof rpaEventSchema>;
|
package/schemas/time.ts
CHANGED
|
@@ -1,64 +1,11 @@
|
|
|
1
|
+
import type { TimeDimensionPredefinedGranularity } from "@cubejs-client/core";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"month",
|
|
8
|
-
"quarter",
|
|
9
|
-
"year",
|
|
10
|
-
]);
|
|
4
|
+
const predefinedGrins: [
|
|
5
|
+
TimeDimensionPredefinedGranularity,
|
|
6
|
+
...TimeDimensionPredefinedGranularity[],
|
|
7
|
+
] = ["minute", "hour", "day", "week", "month", "quarter", "year"] as const;
|
|
11
8
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
export const TIME_GRAIN_OPTIONS: { value: TimeGrain; label: string }[] = [
|
|
15
|
-
{ value: "all", label: "全部" },
|
|
16
|
-
{ value: "day", label: "天" },
|
|
17
|
-
{ value: "week", label: "周" },
|
|
18
|
-
{ value: "month", label: "月" },
|
|
19
|
-
{ value: "quarter", label: "季" },
|
|
20
|
-
{ value: "year", label: "年" },
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export const timeRangePresetSchema = z.enum([
|
|
24
|
-
"today",
|
|
25
|
-
"yesterday",
|
|
26
|
-
"last7days",
|
|
27
|
-
"last30days",
|
|
28
|
-
"last90days",
|
|
29
|
-
"last180days",
|
|
30
|
-
"last365days",
|
|
31
|
-
"last730days",
|
|
32
|
-
"last1825days",
|
|
33
|
-
"thisMonth",
|
|
34
|
-
"lastMonth",
|
|
35
|
-
"thisQuarter",
|
|
36
|
-
"thisYear",
|
|
37
|
-
]);
|
|
38
|
-
|
|
39
|
-
export type TimeRangePreset = z.infer<typeof timeRangePresetSchema>;
|
|
9
|
+
export const timeGrainSchema = z.enum(predefinedGrins);
|
|
40
10
|
|
|
41
|
-
export
|
|
42
|
-
preset: timeRangePresetSchema.optional(),
|
|
43
|
-
startDate: z.string().optional(),
|
|
44
|
-
endDate: z.string().optional(),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export type DateRange = z.infer<typeof dateRangeSchema>;
|
|
48
|
-
|
|
49
|
-
export const TIME_RANGE_OPTIONS: {
|
|
50
|
-
value: TimeRangePreset;
|
|
51
|
-
label: string;
|
|
52
|
-
days: number;
|
|
53
|
-
}[] = [
|
|
54
|
-
{ value: "last7days", label: "近 7 天", days: 7 },
|
|
55
|
-
{ value: "last30days", label: "近 30 天", days: 30 },
|
|
56
|
-
{ value: "last90days", label: "近 90 天", days: 90 },
|
|
57
|
-
{ value: "last180days", label: "近半年", days: 180 },
|
|
58
|
-
{ value: "last365days", label: "近 1 年", days: 365 },
|
|
59
|
-
{ value: "last730days", label: "近 2 年", days: 730 },
|
|
60
|
-
{ value: "last1825days", label: "近 5 年", days: 1825 },
|
|
61
|
-
{ value: "thisMonth", label: "本月", days: 30 },
|
|
62
|
-
{ value: "thisQuarter", label: "本季度", days: 90 },
|
|
63
|
-
{ value: "thisYear", label: "本年", days: 365 },
|
|
64
|
-
];
|
|
11
|
+
export type TimeGrain = z.infer<typeof timeGrainSchema>;
|