@stellaris/metrics-shared 0.1.0 → 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.
package/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
3
  export type ReportStatus = "draft" | "published" | "archived";
4
- declare const app: import("hono/hono-base").HonoBase<{}, ({
5
- "*": {};
6
- } & {
4
+ declare const app: import("hono/hono-base").HonoBase<{}, {
7
5
  "/health": {
8
6
  $get: {
9
7
  input: {};
@@ -14,9 +12,7 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
14
12
  status: import("hono/utils/http-status").ContentfulStatusCode;
15
13
  };
16
14
  };
17
- }) | import("hono/types").MergeSchemaPath<{
18
- "*": {};
19
- } & {
15
+ } | import("hono/types").MergeSchemaPath<{
20
16
  "/": {
21
17
  $post: {
22
18
  input: {
@@ -41,7 +37,7 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
41
37
  $get: {
42
38
  input: {
43
39
  query: {
44
- search?: string | string[] | undefined;
40
+ search?: string | undefined;
45
41
  skip?: string | string[] | undefined;
46
42
  take?: string | string[] | undefined;
47
43
  };
@@ -157,17 +153,71 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
157
153
  };
158
154
  };
159
155
  }, "/api/categories"> | import("hono/types").MergeSchemaPath<{
160
- "*": {};
161
- } & {
162
156
  "/": {
163
157
  $post: {
164
158
  input: {
165
159
  json: {
166
160
  name: string;
167
- queryConfig: Record<string, unknown>;
168
- visualConfig: Record<string, unknown>;
161
+ queryConfig: {
162
+ table: string;
163
+ dimensions: string[];
164
+ filters: ({
165
+ id: string;
166
+ member: string;
167
+ operator: "equals" | "notEquals";
168
+ value: string | number;
169
+ } | {
170
+ id: string;
171
+ member: string;
172
+ operator: "gt" | "lt" | "gte" | "lte";
173
+ value: number;
174
+ } | {
175
+ id: string;
176
+ member: string;
177
+ operator: "contains";
178
+ values: string[];
179
+ } | {
180
+ id: string;
181
+ member: string;
182
+ operator: "between";
183
+ range: [
184
+ number,
185
+ number
186
+ ];
187
+ } | {
188
+ id: string;
189
+ member: string;
190
+ operator: "inDateRange";
191
+ dateRange: [
192
+ string,
193
+ string
194
+ ];
195
+ })[];
196
+ timeGrain: "all" | "day" | "week" | "month" | "quarter" | "year";
197
+ distinctOn?: string | undefined;
198
+ timeDimension?: string | undefined;
199
+ };
169
200
  description?: string | undefined;
170
201
  categoryId?: string | undefined;
202
+ visualConfig?: {
203
+ chartType: "line" | "bar" | "area" | "pie" | "donut" | "stacked-bar" | "combo" | "radar" | "funnel" | "gauge";
204
+ colors?: string[] | undefined;
205
+ showLegend?: boolean | undefined;
206
+ showGrid?: boolean | undefined;
207
+ xAxis?: {
208
+ label?: string | undefined;
209
+ dataKey?: string | undefined;
210
+ } | undefined;
211
+ yAxis?: {
212
+ label?: string | undefined;
213
+ unit?: string | undefined;
214
+ min?: number | undefined;
215
+ max?: number | undefined;
216
+ } | undefined;
217
+ tooltip?: {
218
+ show?: boolean | undefined;
219
+ } | undefined;
220
+ } | undefined;
171
221
  };
172
222
  };
173
223
  output: {
@@ -203,10 +253,11 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
203
253
  $get: {
204
254
  input: {
205
255
  query: {
206
- ownerId?: string | string[] | undefined;
207
- categoryId?: string | string[] | undefined;
208
- isArchived?: string | string[] | undefined;
209
- search?: string | string[] | undefined;
256
+ ownerId?: string | undefined;
257
+ uncategorized?: string | undefined;
258
+ categoryId?: string | undefined;
259
+ isArchived?: string | undefined;
260
+ search?: string | undefined;
210
261
  skip?: string | string[] | undefined;
211
262
  take?: string | string[] | undefined;
212
263
  };
@@ -294,8 +345,144 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
294
345
  name?: string | undefined;
295
346
  description?: string | null | undefined;
296
347
  categoryId?: string | null | undefined;
297
- queryConfig?: Record<string, unknown> | undefined;
298
- visualConfig?: Record<string, unknown> | undefined;
348
+ expectedVersion?: number | undefined;
349
+ };
350
+ } & {
351
+ param: {
352
+ id: string;
353
+ };
354
+ };
355
+ output: {
356
+ id: string;
357
+ name: string;
358
+ description: string | null;
359
+ categoryId: string | null;
360
+ ownerId: string;
361
+ isArchived: boolean;
362
+ queryConfig: {
363
+ [x: string]: import("hono/utils/types").JSONValue;
364
+ };
365
+ visualConfig: {
366
+ [x: string]: import("hono/utils/types").JSONValue;
367
+ };
368
+ version: number;
369
+ createdAt: string;
370
+ updatedAt: string;
371
+ category?: {
372
+ id: string;
373
+ name: string;
374
+ description: string | null;
375
+ createdAt: string;
376
+ updatedAt: string;
377
+ } | null | undefined;
378
+ };
379
+ outputFormat: "json";
380
+ status: import("hono/utils/http-status").ContentfulStatusCode;
381
+ };
382
+ };
383
+ } & {
384
+ "/:id/query-config": {
385
+ $patch: {
386
+ input: {
387
+ json: {
388
+ queryConfig: {
389
+ table: string;
390
+ dimensions: string[];
391
+ filters: ({
392
+ id: string;
393
+ member: string;
394
+ operator: "equals" | "notEquals";
395
+ value: string | number;
396
+ } | {
397
+ id: string;
398
+ member: string;
399
+ operator: "gt" | "lt" | "gte" | "lte";
400
+ value: number;
401
+ } | {
402
+ id: string;
403
+ member: string;
404
+ operator: "contains";
405
+ values: string[];
406
+ } | {
407
+ id: string;
408
+ member: string;
409
+ operator: "between";
410
+ range: [
411
+ number,
412
+ number
413
+ ];
414
+ } | {
415
+ id: string;
416
+ member: string;
417
+ operator: "inDateRange";
418
+ dateRange: [
419
+ string,
420
+ string
421
+ ];
422
+ })[];
423
+ timeGrain: "all" | "day" | "week" | "month" | "quarter" | "year";
424
+ distinctOn?: string | undefined;
425
+ timeDimension?: string | undefined;
426
+ };
427
+ expectedVersion?: number | undefined;
428
+ };
429
+ } & {
430
+ param: {
431
+ id: string;
432
+ };
433
+ };
434
+ output: {
435
+ id: string;
436
+ name: string;
437
+ description: string | null;
438
+ categoryId: string | null;
439
+ ownerId: string;
440
+ isArchived: boolean;
441
+ queryConfig: {
442
+ [x: string]: import("hono/utils/types").JSONValue;
443
+ };
444
+ visualConfig: {
445
+ [x: string]: import("hono/utils/types").JSONValue;
446
+ };
447
+ version: number;
448
+ createdAt: string;
449
+ updatedAt: string;
450
+ category?: {
451
+ id: string;
452
+ name: string;
453
+ description: string | null;
454
+ createdAt: string;
455
+ updatedAt: string;
456
+ } | null | undefined;
457
+ };
458
+ outputFormat: "json";
459
+ status: import("hono/utils/http-status").ContentfulStatusCode;
460
+ };
461
+ };
462
+ } & {
463
+ "/:id/visual-config": {
464
+ $patch: {
465
+ input: {
466
+ json: {
467
+ visualConfig: {
468
+ chartType: "line" | "bar" | "area" | "pie" | "donut" | "stacked-bar" | "combo" | "radar" | "funnel" | "gauge";
469
+ colors?: string[] | undefined;
470
+ showLegend?: boolean | undefined;
471
+ showGrid?: boolean | undefined;
472
+ xAxis?: {
473
+ label?: string | undefined;
474
+ dataKey?: string | undefined;
475
+ } | undefined;
476
+ yAxis?: {
477
+ label?: string | undefined;
478
+ unit?: string | undefined;
479
+ min?: number | undefined;
480
+ max?: number | undefined;
481
+ } | undefined;
482
+ tooltip?: {
483
+ show?: boolean | undefined;
484
+ } | undefined;
485
+ };
299
486
  expectedVersion?: number | undefined;
300
487
  };
301
488
  } & {
@@ -419,8 +606,6 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
419
606
  };
420
607
  };
421
608
  }, "/api/metrics"> | import("hono/types").MergeSchemaPath<{
422
- "*": {};
423
- } & {
424
609
  "/": {
425
610
  $post: {
426
611
  input: {
@@ -460,9 +645,9 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
460
645
  $get: {
461
646
  input: {
462
647
  query: {
463
- ownerId?: string | string[] | undefined;
464
- status?: string | string[] | undefined;
465
- search?: string | string[] | undefined;
648
+ ownerId?: string | undefined;
649
+ status?: "draft" | "published" | "archived" | undefined;
650
+ search?: string | undefined;
466
651
  skip?: string | string[] | undefined;
467
652
  take?: string | string[] | undefined;
468
653
  };
@@ -864,7 +1049,7 @@ declare const app: import("hono/hono-base").HonoBase<{}, ({
864
1049
  status: 500;
865
1050
  };
866
1051
  };
867
- }, "/api/notifications">, "/">;
1052
+ }, "/api/notifications">, "/", "/health">;
868
1053
  export type AppType = typeof app;
869
1054
 
870
1055
  export {
package/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { AppType } from ".";
2
1
  export * from "./schemas";
2
+ export type { AppType } from "../src/index";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellaris/metrics-shared",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",
@@ -14,4 +14,4 @@
14
14
  "hono": "^4.11.4",
15
15
  "zod": "^4.0.0"
16
16
  }
17
- }
17
+ }
package/publish.sh ADDED
@@ -0,0 +1,71 @@
1
+ #!/bin/bash
2
+ # @stellaris/metrics-shared npm 发布脚本
3
+ # 用法: ./metrics-shared/publish.sh [patch|minor|major]
4
+ # 必须在 bff-service 根目录运行!
5
+
6
+ set -e
7
+
8
+ # 颜色输出
9
+ RED='\033[0;31m'
10
+ GREEN='\033[0;32m'
11
+ YELLOW='\033[1;33m'
12
+ NC='\033[0m'
13
+
14
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15
+ ROOT_DIR="$(dirname "$SCRIPT_DIR")"
16
+ cd "$ROOT_DIR"
17
+
18
+ echo -e "${GREEN}📦 @stellaris/metrics-shared 发布脚本${NC}"
19
+ echo ""
20
+
21
+ # 检查是否已登录 npm
22
+ echo -e "${YELLOW}检查 npm 登录状态...${NC}"
23
+ if ! npm whoami > /dev/null 2>&1; then
24
+ echo -e "${RED}❌ 未登录 npm,请先运行 'npm login'${NC}"
25
+ exit 1
26
+ fi
27
+ echo -e "${GREEN}✓ 已登录为: $(npm whoami)${NC}"
28
+
29
+ # 获取版本类型
30
+ VERSION_TYPE=${1:-patch}
31
+ if [[ ! "$VERSION_TYPE" =~ ^(patch|minor|major)$ ]]; then
32
+ echo -e "${RED}❌ 无效的版本类型: $VERSION_TYPE${NC}"
33
+ echo "用法: ./metrics-shared/publish.sh [patch|minor|major]"
34
+ exit 1
35
+ fi
36
+
37
+ # Step 1: 生成类型定义
38
+ echo ""
39
+ echo -e "${YELLOW}[1/4] 生成 Prisma 客户端...${NC}"
40
+ pnpm run db:generate
41
+
42
+ echo ""
43
+ echo -e "${YELLOW}[2/4] 生成 API 类型定义 (dts-bundle-generator)...${NC}"
44
+ npx dts-bundle-generator -o metrics-shared/index.d.ts src/index.ts --no-check
45
+ echo -e "${GREEN}✓ 类型已生成到 metrics-shared/index.d.ts${NC}"
46
+
47
+ # Step 2: 进入包目录
48
+ cd "$SCRIPT_DIR"
49
+
50
+ # 显示当前版本
51
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
52
+ echo ""
53
+ echo -e "当前版本: ${YELLOW}$CURRENT_VERSION${NC}"
54
+
55
+ # Step 3: 更新版本号
56
+ echo -e "${YELLOW}[3/4] 更新版本号 ($VERSION_TYPE)...${NC}"
57
+ NEW_VERSION=$(npm version $VERSION_TYPE --no-git-tag-version)
58
+ echo -e "新版本: ${GREEN}$NEW_VERSION${NC}"
59
+
60
+ # Step 4: 发布到 npm
61
+ echo ""
62
+ echo -e "${YELLOW}[4/4] 发布到 npm...${NC}"
63
+ npm publish --access public
64
+
65
+ echo ""
66
+ echo -e "${GREEN}✅ 发布成功!${NC}"
67
+ echo -e "包名: @stellaris/metrics-shared"
68
+ echo -e "版本: $NEW_VERSION"
69
+ echo ""
70
+ echo -e "${YELLOW}提示: 在 myqa-web 中运行以下命令更新依赖:${NC}"
71
+ echo -e " pnpm update @stellaris/metrics-shared"
package/schemas/metric.ts CHANGED
@@ -19,13 +19,54 @@ export const DEFAULT_QUERY_CONFIG: MetricQueryConfig = {
19
19
  timeDimension: "",
20
20
  dimensions: [],
21
21
  filters: [],
22
- timeGrain: "day",
22
+ timeGrain: "all",
23
23
  };
24
24
 
25
- export const metricVisualConfigSchema = z.record(z.string(), z.unknown());
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
+ });
26
61
 
27
62
  export type MetricVisualConfig = z.infer<typeof metricVisualConfigSchema>;
28
63
 
64
+ export const DEFAULT_VISUAL_CONFIG: MetricVisualConfig = {
65
+ chartType: "line",
66
+ showLegend: true,
67
+ showGrid: true,
68
+ };
69
+
29
70
  export function parseMetricQueryConfig(
30
71
  data: unknown,
31
72
  ): MetricQueryConfig | null {
package/schemas/time.ts CHANGED
@@ -26,6 +26,10 @@ export const timeRangePresetSchema = z.enum([
26
26
  "last7days",
27
27
  "last30days",
28
28
  "last90days",
29
+ "last180days",
30
+ "last365days",
31
+ "last730days",
32
+ "last1825days",
29
33
  "thisMonth",
30
34
  "lastMonth",
31
35
  "thisQuarter",
@@ -50,6 +54,10 @@ export const TIME_RANGE_OPTIONS: {
50
54
  { value: "last7days", label: "近 7 天", days: 7 },
51
55
  { value: "last30days", label: "近 30 天", days: 30 },
52
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 },
53
61
  { value: "thisMonth", label: "本月", days: 30 },
54
62
  { value: "thisQuarter", label: "本季度", days: 90 },
55
63
  { value: "thisYear", label: "本年", days: 365 },