Skip to content

Commit

Permalink
chore(types): use faux integer for json schema (#20401)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored Feb 20, 2024
1 parent af5aadb commit 51686aa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 89 deletions.
9 changes: 8 additions & 1 deletion frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,14 @@
"$ref": "#/definitions/BreakdownKeyType"
},
"breakdown_group_type_index": {
"type": "integer"
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
]
},
"breakdown_hide_other_aggregation": {
"type": ["boolean", "null"]
Expand Down
137 changes: 49 additions & 88 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import {
TrendsFilterType,
} from '~/types'

// Type alias for number to be reflected as integer in json-schema.
/** @asType integer */
type integer = number

/**
* PostHog Query Schema definition.
*
Expand Down Expand Up @@ -196,10 +200,8 @@ export interface HogQLQueryResponse {
/** Modifiers used when performing the query */
modifiers?: HogQLQueryModifiers
hasMore?: boolean
/** @asType integer */
limit?: number
/** @asType integer */
offset?: number
limit?: integer
offset?: integer
}

/** Filters object that will be converted to a HogQL {filters} placeholder */
Expand All @@ -221,10 +223,8 @@ export interface HogQLQuery extends DataNode {
}

export interface HogQLNotice {
/** @asType integer */
start?: number
/** @asType integer */
end?: number
start?: integer
end?: integer
message: string
fix?: string
}
Expand Down Expand Up @@ -328,14 +328,12 @@ export interface HogQLAutocomplete extends DataNode {
filters?: HogQLFilters
/**
* Start position of the editor word
* @asType integer
*/
startPosition: number
startPosition: integer
/**
* End position of the editor word
* @asType integer
*/
endPosition: number
endPosition: integer
response?: HogQLAutocompleteResponse
}

Expand All @@ -356,8 +354,7 @@ export interface EventsNode extends EntityNode {
kind: NodeKind.EventsNode
/** The event or `null` for all events. */
event?: string | null
/** @asType integer */
limit?: number
limit?: integer
/** Columns to order by */
orderBy?: string[]
/** Return a limited set of data */
Expand All @@ -369,8 +366,7 @@ export interface EventsNode extends EntityNode {

export interface ActionsNode extends EntityNode {
kind: NodeKind.ActionsNode
/** @asType integer */
id: number
id: integer
}

export type AnyEntityNode = EventsNode | ActionsNode
Expand All @@ -388,10 +384,8 @@ export interface EventsQueryResponse {
hogql: string
hasMore?: boolean
timings?: QueryTiming[]
/** @asType integer */
limit?: number
/** @asType integer */
offset?: number
limit?: integer
offset?: integer
}
export interface EventsQueryPersonColumn {
uuid: string
Expand All @@ -418,19 +412,16 @@ export interface EventsQuery extends DataNode {
event?: string | null
/**
* Number of rows to return
* @asType integer
*/
limit?: number
limit?: integer
/**
* Number of rows to skip before returning rows
* @asType integer
*/
offset?: number
offset?: integer
/**
* Show events matching a given action
* @asType integer
*/
actionId?: number
actionId?: integer
/** Show events for a given person */
personId?: string
/** Only fetch events that happened before this timestamp */
Expand All @@ -446,17 +437,14 @@ export interface EventsQuery extends DataNode {
export interface PersonsNode extends DataNode {
kind: NodeKind.PersonsNode
search?: string
/** @asType integer */
cohort?: number
cohort?: integer
distinctId?: string
/** Properties configurable in the interface */
properties?: AnyPropertyFilter[]
/** Fixed properties in the query, can't be edited in the interface (e.g. scoping down by person) */
fixedProperties?: AnyPropertyFilter[]
/** @asType integer */
limit?: number
/** @asType integer */
offset?: number
limit?: integer
offset?: integer
}

// Data table node
Expand Down Expand Up @@ -606,9 +594,8 @@ export interface InsightsQueryBase extends Node {
properties?: AnyPropertyFilter[] | PropertyGroupFilter
/**
* Groups aggregation
* @asType integer
**/
aggregation_group_type_index?: number
aggregation_group_type_index?: integer
/** Sampling rate */
samplingFactor?: number | null
}
Expand Down Expand Up @@ -670,10 +657,8 @@ export type FunnelsFilterLegacy = Omit<
>

export interface FunnelExclusionSteps {
/** @asType integer */
funnelFromStep: number
/** @asType integer */
funnelToStep: number
funnelFromStep: integer
funnelToStep: integer
}
export interface FunnelExclusionEventsNode extends EventsNode, FunnelExclusionSteps {}
export interface FunnelExclusionActionsNode extends ActionsNode, FunnelExclusionSteps {}
Expand All @@ -685,17 +670,13 @@ export type FunnelsFilter = {
/** @asType integer */
binCount?: FunnelsFilterLegacy['bin_count']
breakdownAttributionType?: FunnelsFilterLegacy['breakdown_attribution_type']
/** @asType integer */
breakdownAttributionValue?: FunnelsFilterLegacy['breakdown_attribution_value']
breakdownAttributionValue?: integer
funnelAggregateByHogQL?: FunnelsFilterLegacy['funnel_aggregate_by_hogql']
/** @asType integer */
funnelToStep?: FunnelsFilterLegacy['funnel_to_step']
/** @asType integer */
funnelFromStep?: FunnelsFilterLegacy['funnel_from_step']
funnelToStep?: integer
funnelFromStep?: integer
funnelOrderType?: FunnelsFilterLegacy['funnel_order_type']
funnelVizType?: FunnelsFilterLegacy['funnel_viz_type']
/** @asType integer */
funnelWindowInterval?: FunnelsFilterLegacy['funnel_window_interval']
funnelWindowInterval?: integer
funnelWindowIntervalUnit?: FunnelsFilterLegacy['funnel_window_interval_unit']
hidden_legend_breakdowns?: FunnelsFilterLegacy['hidden_legend_breakdowns']
funnelStepReference?: FunnelsFilterLegacy['funnel_step_reference']
Expand Down Expand Up @@ -740,8 +721,7 @@ export type RetentionFilter = {
}

export interface RetentionValue {
/** @asType integer */
count: number
count: integer
}

export interface RetentionResult {
Expand Down Expand Up @@ -883,8 +863,7 @@ export type QueryStatus = {
id: string
/** @default true */
query_async: boolean
/** @asType integer */
team_id: number
team_id: integer
/** @default false */
error: boolean
/** @default false */
Expand Down Expand Up @@ -923,12 +902,9 @@ export interface ActorsQueryResponse {
hogql: string
timings?: QueryTiming[]
hasMore?: boolean
/** @asType integer */
limit: number
/** @asType integer */
offset: number
/** @asType integer */
missing_actors_count?: number
limit: integer
offset: integer
missing_actors_count?: integer
}

export interface ActorsQuery extends DataNode {
Expand All @@ -939,10 +915,8 @@ export interface ActorsQuery extends DataNode {
properties?: AnyPropertyFilter[]
fixedProperties?: AnyPropertyFilter[]
orderBy?: string[]
/** @asType integer */
limit?: number
/** @asType integer */
offset?: number
limit?: integer
offset?: integer
response?: ActorsQueryResponse
}

Expand Down Expand Up @@ -1044,8 +1018,7 @@ export interface WebStatsTableQuery extends WebAnalyticsQueryBase {
includeScrollDepth?: boolean // automatically sets includeBounceRate to true
includeBounceRate?: boolean
doPathCleaning?: boolean
/** @asType integer */
limit?: number
limit?: integer
}
export interface WebStatsTableQueryResponse extends QueryResponse {
results: unknown[]
Expand All @@ -1054,10 +1027,8 @@ export interface WebStatsTableQueryResponse extends QueryResponse {
hogql?: string
samplingRate?: SamplingRate
hasMore?: boolean
/** @asType integer */
limit?: number
/** @asType integer */
offset?: number
limit?: integer
offset?: integer
}

export type InsightQueryNode =
Expand Down Expand Up @@ -1088,8 +1059,7 @@ export type InsightFilter =
| StickinessFilter
| LifecycleFilter

/** @asType integer */
export type Day = number
export type Day = integer

export interface InsightActorsQuery<T extends InsightsQueryBase = InsightQuerySource> {
kind: NodeKind.InsightActorsQuery
Expand All @@ -1098,38 +1068,34 @@ export interface InsightActorsQuery<T extends InsightsQueryBase = InsightQuerySo
status?: string
/**
* An interval selected out of available intervals in source query
* @asType integer
*/
interval?: number
/** @asType integer */
series?: number
interval?: integer
series?: integer
breakdown?: string | BreakdownValueInt
compare?: 'current' | 'previous'
// TODO: add fields for other insights (funnels dropdown, compare_previous choice, etc)
response?: ActorsQueryResponse
}

/** @asType integer */
export type BreakdownValueInt = number
export type BreakdownValueInt = integer
export interface InsightActorsQueryOptionsResponse {
day?: { label: string; value: string | Day }[]
status?: { label: string; value: string }[]
interval?: {
label: string
/**
* An interval selected out of available intervals in source query
* @asType integer
*/
value: number
value: integer
}[]
breakdown?: {
label: string
value: string | BreakdownValueInt
}[]
series?: {
label: string
/** @asType integer */
value: number
value: integer
}[]
compare?: {
label: string
Expand Down Expand Up @@ -1162,9 +1128,8 @@ export interface TimeToSeeDataSessionsQuery extends DataNode {

/**
* Project to filter on. Defaults to current project
* @asType integer
*/
teamId?: number
teamId?: integer

response?: TimeToSeeDataSessionsQueryResponse
}
Expand All @@ -1188,9 +1153,8 @@ export interface TimeToSeeDataQuery extends DataNode {

/**
* Project to filter on. Defaults to current project
* @asType integer
*/
teamId?: number
teamId?: integer

/** Project to filter on. Defaults to current session */
sessionId?: string
Expand Down Expand Up @@ -1224,15 +1188,12 @@ export interface DateRange {
export interface BreakdownFilter {
// TODO: unclutter
breakdown_type?: BreakdownType | null
/** @asType integer */
breakdown_limit?: number
breakdown_limit?: integer
breakdown?: BreakdownKeyType
breakdown_normalize_url?: boolean
breakdowns?: Breakdown[]
/** @asType integer */
breakdown_group_type_index?: number | null
/** @asType integer */
breakdown_histogram_bin_count?: number // trends breakdown histogram bin count
breakdown_group_type_index?: integer | null
breakdown_histogram_bin_count?: integer // trends breakdown histogram bin
breakdown_hide_other_aggregation?: boolean | null // hides the "other" field for trends
}

Expand Down

0 comments on commit 51686aa

Please sign in to comment.