Skip to content

Commit

Permalink
Adjust schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie committed Jan 12, 2024
1 parent d97df9d commit c385eb2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"build:esbuild": "node frontend/build.mjs",
"schema:build": "pnpm run schema:build:json && pnpm run schema:build:python",
"schema:build:json": "ts-node bin/build-schema.mjs && prettier --write frontend/src/queries/schema.json",
"schema:build:python": "datamodel-codegen --class-name='SchemaRoot' --collapse-root-models --target-python-version 3.9 --use-schema-description --disable-timestamp --use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum --input frontend/src/queries/schema.json --input-file-type jsonschema --output posthog/schema.py --output-model-type pydantic_v2.BaseModel && ruff format posthog/schema.py",
"schema:build:python": "datamodel-codegen --class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp --use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum --input frontend/src/queries/schema.json --input-file-type jsonschema --output posthog/schema.py --output-model-type pydantic_v2.BaseModel && ruff format posthog/schema.py",
"grammar:build": "npm run grammar:build:python && npm run grammar:build:cpp",
"grammar:build:python": "cd posthog/hogql/grammar && antlr -Dlanguage=Python3 HogQLLexer.g4 && antlr -visitor -no-listener -Dlanguage=Python3 HogQLParser.g4",
"grammar:build:cpp": "cd posthog/hogql/grammar && antlr -o ../../../hogql_parser -Dlanguage=Cpp HogQLLexer.g4 && antlr -o ../../../hogql_parser -visitor -no-listener -Dlanguage=Cpp HogQLParser.g4",
Expand Down
82 changes: 0 additions & 82 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ class ChartDisplayType(str, Enum):


class CohortPropertyFilter(BaseModel):
"""
Sync with plugin-server/src/types.ts
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -175,10 +171,6 @@ class EventType(BaseModel):


class Response(BaseModel):
"""
Return a limited set of data
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -298,10 +290,6 @@ class PersonsOnEventsMode(str, Enum):


class HogQLQueryModifiers(BaseModel):
"""
HogQL Query Options are automatically set per team. However, they can be overriden in the query.
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -355,16 +343,6 @@ class LifecycleToggle(str, Enum):


class NodeKind(str, Enum):
"""
PostHog Query Schema definition.
This file acts as the source of truth for:
- frontend/src/queries/schema.json - generated from typescript via "pnpm run generate:schema:json"
- posthog/schema.py - generated from json the above json via "pnpm run generate:schema:python"
"""

EventsNode = "EventsNode"
ActionsNode = "ActionsNode"
EventsQuery = "EventsQuery"
Expand Down Expand Up @@ -410,10 +388,6 @@ class PathType(str, Enum):


class PathsFilter(BaseModel):
"""
`PathsFilterType` minus everything inherited from `FilterType` and persons modal related params
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -459,10 +433,6 @@ class PropertyMathType(str, Enum):


class PropertyOperator(str, Enum):
"""
Sync with plugin-server/src/types.ts
"""

exact = "exact"
is_not = "is_not"
icontains = "icontains"
Expand Down Expand Up @@ -580,10 +550,6 @@ class StepOrderValue(str, Enum):


class StickinessFilter(BaseModel):
"""
`StickinessFilterType` minus everything inherited from `FilterType` and persons modal related params and `hidden_legend_keys` replaced by `hidden_legend_indexes`
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -645,10 +611,6 @@ class TimelineEntry(BaseModel):


class TrendsFilter(BaseModel):
"""
`TrendsFilterType` minus everything inherited from `FilterType` and `hidden_legend_keys` replaced by `hidden_legend_indexes`
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -698,10 +660,6 @@ class RETENTION(BaseModel):


class VizSpecificOptions(BaseModel):
"""
Chart specific rendering options. Use ChartRenderingMetadata for non-serializable values, e.g. onClick handlers
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -801,10 +759,6 @@ class ActorsQueryResponse(BaseModel):


class AnyResponseType1(BaseModel):
"""
Return a limited set of data
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -853,10 +807,6 @@ class ChartSettings(BaseModel):


class ElementPropertyFilter(BaseModel):
"""
Sync with plugin-server/src/types.ts
"""

model_config = ConfigDict(
extra="forbid",
)
Expand All @@ -868,10 +818,6 @@ class ElementPropertyFilter(BaseModel):


class EventPropertyFilter(BaseModel):
"""
Sync with plugin-server/src/types.ts
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -908,10 +854,6 @@ class FeaturePropertyFilter(BaseModel):


class FunnelsFilter(BaseModel):
"""
`FunnelsFilterType` minus everything inherited from `FilterType` and persons modal related params and `hidden_legend_keys` replaced by `hidden_legend_breakdowns`
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -989,10 +931,6 @@ class HogQLQueryResponse(BaseModel):


class LifecycleFilter(BaseModel):
"""
`LifecycleFilterType` minus everything inherited from `FilterType`
"""

model_config = ConfigDict(
extra="forbid",
)
Expand All @@ -1013,21 +951,13 @@ class LifecycleQueryResponse(BaseModel):


class Node(BaseModel):
"""
Node base class, everything else inherits from here
"""

model_config = ConfigDict(
extra="forbid",
)
kind: NodeKind


class PersonPropertyFilter(BaseModel):
"""
Sync with plugin-server/src/types.ts
"""

model_config = ConfigDict(
extra="forbid",
)
Expand All @@ -1051,10 +981,6 @@ class QueryResponse(BaseModel):


class RetentionFilter(BaseModel):
"""
`RetentionFilterType` minus everything inherited from `FilterType`
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -1404,10 +1330,6 @@ class EventsQuery(BaseModel):


class HogQLFilters(BaseModel):
"""
Filters object that will be converted to a HogQL {filters} placeholder
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -1868,10 +1790,6 @@ class FunnelsQuery(BaseModel):


class InsightsQueryBase(BaseModel):
"""
Base class for insight query nodes. Should not be used directly.
"""

model_config = ConfigDict(
extra="forbid",
)
Expand Down

0 comments on commit c385eb2

Please sign in to comment.