-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalytics.zod.ts
More file actions
86 lines (73 loc) · 2.58 KB
/
analytics.zod.ts
File metadata and controls
86 lines (73 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { AnalyticsQuerySchema, CubeSchema } from '../data/analytics.zod';
import { BaseResponseSchema } from './contract.zod';
/**
* Analytics API Protocol
*
* Defines the HTTP interface for the Semantic Layer.
* Provides endpoints for executing analytical queries and discovering metadata.
*/
// ==========================================
// 1. API Endpoints
// ==========================================
export const AnalyticsEndpoint = z.enum([
'/api/v1/analytics/query', // Execute analysis
'/api/v1/analytics/meta', // Discover cubes/metrics
'/api/v1/analytics/sql', // Dry-run SQL generation
]);
// ==========================================
// 2. Query Execution
// ==========================================
/**
* Query Request Body
*/
export const AnalyticsQueryRequestSchema = z.object({
query: AnalyticsQuerySchema.describe('The analytic query definition'),
cube: z.string().describe('Target cube name'),
format: z.enum(['json', 'csv', 'xlsx']).default('json').describe('Response format'),
});
/**
* Query Response (JSON)
*/
export const AnalyticsResultResponseSchema = BaseResponseSchema.extend({
data: z.object({
rows: z.array(z.record(z.string(), z.unknown())).describe('Result rows'),
fields: z.array(z.object({
name: z.string(),
type: z.string(),
})).describe('Column metadata'),
sql: z.string().optional().describe('Executed SQL (if debug enabled)'),
}),
});
// ==========================================
// 3. Metadata Discovery
// ==========================================
/**
* Meta Request
*/
export const GetAnalyticsMetaRequestSchema = z.object({
cube: z.string().optional().describe('Optional cube name to filter'),
});
/**
* Meta Response
* Returns available cubes, metrics, and dimensions.
*/
export const AnalyticsMetadataResponseSchema = BaseResponseSchema.extend({
data: z.object({
cubes: z.array(CubeSchema).describe('Available cubes'),
}),
});
// ==========================================
// 4. SQL Dry-Run
// ==========================================
export const AnalyticsSqlResponseSchema = BaseResponseSchema.extend({
data: z.object({
sql: z.string(),
params: z.array(z.unknown()),
}),
});
export type AnalyticsEndpoint = z.infer<typeof AnalyticsEndpoint>;
export type AnalyticsQueryRequest = z.infer<typeof AnalyticsQueryRequestSchema>;
export type AnalyticsMetadataResponse = z.infer<typeof AnalyticsMetadataResponseSchema>;
export type AnalyticsSqlResponse = z.infer<typeof AnalyticsSqlResponseSchema>;