diff --git a/edb/schema/annos.py b/edb/schema/annos.py index fe3e74f5324..3b57584945f 100644 --- a/edb/schema/annos.py +++ b/edb/schema/annos.py @@ -43,12 +43,14 @@ from . import referencing from . import objects as so from . import utils +from .generated import annos as sg_annos if TYPE_CHECKING: from . import schema as s_schema class AnnotationValue( + sg_annos.AnnotationValueMixin, referencing.ReferencedInheritingObject, qlkind=qltypes.SchemaObjectClass.ANNOTATION, reflection=so.ReflectionMethod.AS_LINK, @@ -101,7 +103,7 @@ def get_verbosename( T = TypeVar("T") -class AnnotationSubject(so.Object): +class AnnotationSubject(so.Object, sg_annos.AnnotationSubjectMixin): annotations_refs = so.RefDict( attr='annotations', @@ -180,6 +182,7 @@ class Annotation( so.QualifiedObject, so.InheritingObject, AnnotationSubject, + sg_annos.AnnotationMixin, qlkind=qltypes.SchemaObjectClass.ANNOTATION, data_safe=True, ): diff --git a/edb/schema/casts.py b/edb/schema/casts.py index 09f827db3a8..13091d4b405 100644 --- a/edb/schema/casts.py +++ b/edb/schema/casts.py @@ -36,6 +36,7 @@ from . import types as s_types from . import schema as s_schema from . import utils +from .generated import casts as sg_casts _NOT_REACHABLE = 10000000 @@ -210,6 +211,7 @@ class Cast( s_anno.AnnotationSubject, s_func.VolatilitySubject, s_abc.Cast, + sg_casts.CastMixin, qlkind=qltypes.SchemaObjectClass.CAST, data_safe=True, ): diff --git a/edb/schema/constraints.py b/edb/schema/constraints.py index 478ece8b27b..a42e4dc8473 100644 --- a/edb/schema/constraints.py +++ b/edb/schema/constraints.py @@ -57,6 +57,7 @@ from . import pseudo as s_pseudo from . import referencing from . import utils +from .generated import constraints as sg_constraints if TYPE_CHECKING: @@ -122,8 +123,10 @@ def get_key_for_name( class Constraint( + sg_constraints.ConstraintMixin, referencing.ReferencedInheritingObject, - s_func.CallableObject, s_abc.Constraint, + s_func.CallableObject, + s_abc.Constraint, qlkind=ft.SchemaObjectClass.CONSTRAINT, data_safe=True, ): @@ -367,6 +370,7 @@ class ConsistencySubject( so.QualifiedObject, so.InheritingObject, s_anno.AnnotationSubject, + sg_constraints.ConsistencySubjectMixin, ): constraints_refs = so.RefDict( attr='constraints', diff --git a/edb/schema/database.py b/edb/schema/database.py index aa53f3fce35..0c713d771a9 100644 --- a/edb/schema/database.py +++ b/edb/schema/database.py @@ -32,6 +32,7 @@ from . import delta as sd from . import objects as so from . import schema as s_schema +from .generated import database as sg_database from typing import cast @@ -40,6 +41,7 @@ class Database( so.ExternalObject, s_anno.AnnotationSubject, s_abc.Database, + sg_database.DatabaseMixin, qlkind=qltypes.SchemaObjectClass.DATABASE, data_safe=False, ): diff --git a/edb/schema/expraliases.py b/edb/schema/expraliases.py index 9e83d0d6684..defd9baeedb 100644 --- a/edb/schema/expraliases.py +++ b/edb/schema/expraliases.py @@ -34,6 +34,7 @@ from . import name as sn from . import objects as so from . import types as s_types +from .generated import expraliases as sg_expraliases if TYPE_CHECKING: @@ -42,6 +43,7 @@ class Alias( + sg_expraliases.AliasMixin, so.QualifiedObject, s_anno.AnnotationSubject, qlkind=qltypes.SchemaObjectClass.ALIAS, diff --git a/edb/schema/extensions.py b/edb/schema/extensions.py index 34adb66d398..f4debcbfa28 100644 --- a/edb/schema/extensions.py +++ b/edb/schema/extensions.py @@ -39,11 +39,12 @@ from . import name as sn from . import objects as so from . import schema as s_schema - +from .generated import extensions as sg_extensions class ExtensionPackage( so.GlobalObject, s_anno.AnnotationSubject, + sg_extensions.ExtensionPackageMixin, qlkind=qltypes.SchemaObjectClass.EXTENSION_PACKAGE, data_safe=False, ): @@ -103,6 +104,7 @@ def get_displayname_static(cls, name: sn.Name) -> str: class Extension( so.Object, + sg_extensions.ExtensionMixin, qlkind=qltypes.SchemaObjectClass.EXTENSION, data_safe=False, ): diff --git a/edb/schema/functions.py b/edb/schema/functions.py index 14d3860ac44..95dc6c6c31c 100644 --- a/edb/schema/functions.py +++ b/edb/schema/functions.py @@ -62,6 +62,8 @@ from . import referencing from . import types as s_types from . import utils +from .generated import functions as sg_functions +from .generated import objects as sg_objects if TYPE_CHECKING: @@ -151,32 +153,8 @@ def param_is_inherited( return qualname != param_name.name -class ParameterLike(s_abc.Parameter): - - def get_parameter_name(self, schema: s_schema.Schema) -> str: - raise NotImplementedError - - def get_name(self, schema: s_schema.Schema) -> sn.Name: - raise NotImplementedError - - def get_kind(self, _: s_schema.Schema) -> ft.ParameterKind: - raise NotImplementedError - - def get_default(self, _: s_schema.Schema) -> Optional[s_expr.Expression]: - raise NotImplementedError - - def get_type(self, _: s_schema.Schema) -> s_types.Type: - raise NotImplementedError - - def get_typemod(self, _: s_schema.Schema) -> ft.TypeModifier: - raise NotImplementedError - - def as_str(self, schema: s_schema.Schema) -> str: - raise NotImplementedError - - # Non-schema description of a parameter. -class ParameterDesc(ParameterLike): +class ParameterDesc(s_abc.Parameter): num: int name: sn.Name @@ -366,7 +344,8 @@ def make_func_param( class Parameter( so.ObjectFragment, so.Object, # Help reflection figure out the right db MRO - ParameterLike, + sg_functions.ParameterMixin, + s_abc.Parameter, qlkind=ft.SchemaObjectClass.PARAMETER, data_safe=True, ): @@ -489,6 +468,8 @@ def get_ast(self, schema: s_schema.Schema) -> qlast.FuncParam: ) +ParameterLike = ParameterDesc | Parameter + class CallableCommandContext(sd.ObjectCommandContext['CallableObject'], s_anno.AnnotationSubjectCommandContext): pass @@ -756,7 +737,7 @@ def compare_values( return 1.0 -class VolatilitySubject(so.Object): +class VolatilitySubject(so.Object, sg_functions.VolatilitySubjectMixin): volatility = so.SchemaField( ft.Volatility, default=ft.Volatility.Volatile, @@ -794,6 +775,7 @@ def get_abstract(self, schema: s_schema.Schema) -> bool: class CallableObject( so.QualifiedObject, s_anno.AnnotationSubject, + sg_functions.CallableObjectMixin, CallableLike, ): @@ -1229,6 +1211,7 @@ class Function( CallableObject, VolatilitySubject, s_abc.Function, + sg_functions.FunctionMixin, qlkind=ft.SchemaObjectClass.FUNCTION, data_safe=True, ): diff --git a/edb/schema/futures.py b/edb/schema/futures.py index 2647618e2b3..cb3fc9a260f 100644 --- a/edb/schema/futures.py +++ b/edb/schema/futures.py @@ -29,10 +29,11 @@ from . import objects as so from . import name as sn from . import schema as s_schema - +from .generated import futures as sg_futures class FutureBehavior( so.Object, + sg_futures.FutureBehaviorMixin, qlkind=qltypes.SchemaObjectClass.FUTURE, data_safe=False, ): diff --git a/edb/schema/generated/annos.py b/edb/schema/generated/annos.py new file mode 100644 index 00000000000..d5e7ec3eca7 --- /dev/null +++ b/edb/schema/generated/annos.py @@ -0,0 +1,51 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import annos + + +class AnnotationValueMixin: + + def get_subject( + self, schema: 's_schema.Schema' + ) -> 'objects.Object': + val = s_orm.get_field_value(self, schema, 'subject') + return cast(objects.Object, val) + + def get_annotation( + self, schema: 's_schema.Schema' + ) -> 'annos.Annotation': + val = s_orm.get_field_value(self, schema, 'annotation') + return cast(annos.Annotation, val) + + def get_value( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'value') + return cast(str, val) + + +class AnnotationSubjectMixin: + + def get_annotations( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectIndexByShortname[annos.AnnotationValue]': + val = s_orm.get_field_value(self, schema, 'annotations') + return cast(objects.ObjectIndexByShortname[annos.AnnotationValue], val) + + +class AnnotationMixin: + + def get_inheritable( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'inheritable') + return cast(bool, val) diff --git a/edb/schema/generated/casts.py b/edb/schema/generated/casts.py new file mode 100644 index 00000000000..b29294d15b7 --- /dev/null +++ b/edb/schema/generated/casts.py @@ -0,0 +1,69 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.edgeql import ast +from edb.schema import types + + +class CastMixin: + + def get_from_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'from_type') + return cast(types.Type, val) + + def get_to_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'to_type') + return cast(types.Type, val) + + def get_allow_implicit( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'allow_implicit') + return cast(bool, val) + + def get_allow_assignment( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'allow_assignment') + return cast(bool, val) + + def get_language( + self, schema: 's_schema.Schema' + ) -> 'ast.Language': + val = s_orm.get_field_value(self, schema, 'language') + return cast(ast.Language, val) + + def get_from_function( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'from_function') + return cast(str, val) + + def get_from_expr( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'from_expr') + return cast(bool, val) + + def get_from_cast( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'from_cast') + return cast(bool, val) + + def get_code( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'code') + return cast(str, val) diff --git a/edb/schema/generated/constraints.py b/edb/schema/generated/constraints.py new file mode 100644 index 00000000000..f884aa87f9c --- /dev/null +++ b/edb/schema/generated/constraints.py @@ -0,0 +1,87 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.common import checked +from edb.schema import expr +from edb.schema import constraints +from edb.schema import functions + + +class ConstraintMixin: + + def get_params( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[functions.Parameter]': + val = s_orm.get_field_value(self, schema, 'params') + return cast(objects.ObjectList[functions.Parameter], val) + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_subjectexpr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'subjectexpr') + return cast(expr.Expression, val) + + def get_finalexpr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'finalexpr') + return cast(expr.Expression, val) + + def get_except_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'except_expr') + return cast(expr.Expression, val) + + def get_subject( + self, schema: 's_schema.Schema' + ) -> 'objects.Object': + val = s_orm.get_field_value(self, schema, 'subject') + return cast(objects.Object, val) + + def get_args( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedList[expr.Expression]': + val = s_orm.get_field_value(self, schema, 'args') + return cast(checked.FrozenCheckedList[expr.Expression], val) + + def get_delegated( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'delegated') + return cast(bool, val) + + def get_errmessage( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'errmessage') + return cast(str, val) + + def get_is_aggregate( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'is_aggregate') + return cast(bool, val) + + +class ConsistencySubjectMixin: + + def get_constraints( + self, schema: 's_schema.Schema' + ) -> 'constraints.ObjectIndexByConstraintName[constraints.Constraint]': + val = s_orm.get_field_value(self, schema, 'constraints') + return cast(constraints.ObjectIndexByConstraintName[constraints.Constraint], val) diff --git a/edb/schema/generated/database.py b/edb/schema/generated/database.py new file mode 100644 index 00000000000..8159c5dd8ac --- /dev/null +++ b/edb/schema/generated/database.py @@ -0,0 +1,14 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm + + +class DatabaseMixin: + pass \ No newline at end of file diff --git a/edb/schema/generated/expraliases.py b/edb/schema/generated/expraliases.py new file mode 100644 index 00000000000..c8823d572d9 --- /dev/null +++ b/edb/schema/generated/expraliases.py @@ -0,0 +1,34 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import expr +from edb.schema import types + + +class AliasMixin: + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'type') + return cast(types.Type, val) + + def get_created_types( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectSet[types.Type]': + val = s_orm.get_field_value(self, schema, 'created_types') + return cast(objects.ObjectSet[types.Type], val) diff --git a/edb/schema/generated/extensions.py b/edb/schema/generated/extensions.py new file mode 100644 index 00000000000..18606a50950 --- /dev/null +++ b/edb/schema/generated/extensions.py @@ -0,0 +1,62 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import extensions +from edb.common import checked +from edb.common import verutils + + +class ExtensionPackageMixin: + + def get_version( + self, schema: 's_schema.Schema' + ) -> 'verutils.Version': + val = s_orm.get_field_value(self, schema, 'version') + return cast(verutils.Version, val) + + def get_script( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'script') + return cast(str, val) + + def get_sql_extensions( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedSet[str]': + val = s_orm.get_field_value(self, schema, 'sql_extensions') + return cast(checked.FrozenCheckedSet[str], val) + + def get_ext_module( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'ext_module') + return cast(str, val) + + def get_dependencies( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedSet[str]': + val = s_orm.get_field_value(self, schema, 'dependencies') + return cast(checked.FrozenCheckedSet[str], val) + + +class ExtensionMixin: + + def get_package( + self, schema: 's_schema.Schema' + ) -> 'extensions.ExtensionPackage': + val = s_orm.get_field_value(self, schema, 'package') + return cast(extensions.ExtensionPackage, val) + + def get_dependencies( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[extensions.Extension]': + val = s_orm.get_field_value(self, schema, 'dependencies') + return cast(objects.ObjectList[extensions.Extension], val) diff --git a/edb/schema/generated/functions.py b/edb/schema/generated/functions.py new file mode 100644 index 00000000000..8dcf7cbd1c4 --- /dev/null +++ b/edb/schema/generated/functions.py @@ -0,0 +1,198 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +import uuid +from edb.edgeql import qltypes +from edb.edgeql import ast +from edb.schema import expr +from edb.schema import functions +from edb.schema import types +from edb.schema import globals + + +class ParameterMixin: + + def get_num( + self, schema: 's_schema.Schema' + ) -> 'int': + val = s_orm.get_field_value(self, schema, 'num') + return cast(int, val) + + def get_default( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'default') + return cast(expr.Expression, val) + + def get_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'type') + return cast(types.Type, val) + + def get_typemod( + self, schema: 's_schema.Schema' + ) -> 'qltypes.TypeModifier': + val = s_orm.get_field_value(self, schema, 'typemod') + return cast(qltypes.TypeModifier, val) + + def get_kind( + self, schema: 's_schema.Schema' + ) -> 'qltypes.ParameterKind': + val = s_orm.get_field_value(self, schema, 'kind') + return cast(qltypes.ParameterKind, val) + + +class VolatilitySubjectMixin: + + def get_volatility( + self, schema: 's_schema.Schema' + ) -> 'qltypes.Volatility': + val = s_orm.get_field_value(self, schema, 'volatility') + return cast(qltypes.Volatility, val) + + +class CallableObjectMixin: + + def get_params( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[functions.Parameter]': + val = s_orm.get_field_value(self, schema, 'params') + return cast(objects.ObjectList[functions.Parameter], val) + + def get_return_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'return_type') + return cast(types.Type, val) + + def get_return_typemod( + self, schema: 's_schema.Schema' + ) -> 'qltypes.TypeModifier': + val = s_orm.get_field_value(self, schema, 'return_typemod') + return cast(qltypes.TypeModifier, val) + + def get_abstract( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'abstract') + return cast(bool, val) + + def get_impl_is_strict( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'impl_is_strict') + return cast(bool, val) + + def get_prefer_subquery_args( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'prefer_subquery_args') + return cast(bool, val) + + +class FunctionMixin: + + def get_used_globals( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectSet[globals.Global]': + val = s_orm.get_field_value(self, schema, 'used_globals') + return cast(objects.ObjectSet[globals.Global], val) + + def get_backend_name( + self, schema: 's_schema.Schema' + ) -> 'uuid.UUID': + val = s_orm.get_field_value(self, schema, 'backend_name') + return cast(uuid.UUID, val) + + def get_code( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'code') + return cast(str, val) + + def get_nativecode( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'nativecode') + return cast(expr.Expression, val) + + def get_language( + self, schema: 's_schema.Schema' + ) -> 'ast.Language': + val = s_orm.get_field_value(self, schema, 'language') + return cast(ast.Language, val) + + def get_reflected_language( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'reflected_language') + return cast(str, val) + + def get_from_function( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'from_function') + return cast(str, val) + + def get_from_expr( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'from_expr') + return cast(bool, val) + + def get_force_return_cast( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'force_return_cast') + return cast(bool, val) + + def get_sql_func_has_out_params( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'sql_func_has_out_params') + return cast(bool, val) + + def get_error_on_null_result( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'error_on_null_result') + return cast(str, val) + + def get_preserves_optionality( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'preserves_optionality') + return cast(bool, val) + + def get_preserves_upper_cardinality( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'preserves_upper_cardinality') + return cast(bool, val) + + def get_initial_value( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'initial_value') + return cast(expr.Expression, val) + + def get_has_dml( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'has_dml') + return cast(bool, val) + + def get_fallback( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'fallback') + return cast(bool, val) diff --git a/edb/schema/generated/futures.py b/edb/schema/generated/futures.py new file mode 100644 index 00000000000..5f3db11ef86 --- /dev/null +++ b/edb/schema/generated/futures.py @@ -0,0 +1,20 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import name + + +class FutureBehaviorMixin: + + def get_name( + self, schema: 's_schema.Schema' + ) -> 'name.Name': + val = s_orm.get_field_value(self, schema, 'name') + return cast(name.Name, val) diff --git a/edb/schema/generated/globals.py b/edb/schema/generated/globals.py new file mode 100644 index 00000000000..cf4498d2792 --- /dev/null +++ b/edb/schema/generated/globals.py @@ -0,0 +1,53 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.edgeql import qltypes +from edb.schema import expr +from edb.schema import types + + +class GlobalMixin: + + def get_target( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'target') + return cast(types.Type, val) + + def get_required( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'required') + return cast(bool, val) + + def get_cardinality( + self, schema: 's_schema.Schema' + ) -> 'qltypes.SchemaCardinality': + val = s_orm.get_field_value(self, schema, 'cardinality') + return cast(qltypes.SchemaCardinality, val) + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_default( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'default') + return cast(expr.Expression, val) + + def get_created_types( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectSet[types.Type]': + val = s_orm.get_field_value(self, schema, 'created_types') + return cast(objects.ObjectSet[types.Type], val) diff --git a/edb/schema/generated/indexes.py b/edb/schema/generated/indexes.py new file mode 100644 index 00000000000..c426309e282 --- /dev/null +++ b/edb/schema/generated/indexes.py @@ -0,0 +1,88 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.edgeql import qltypes +from edb.schema import indexes +from edb.common import checked +from edb.schema import expr +from edb.schema import functions + + +class IndexMixin: + + def get_bases( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[indexes.Index]': + val = s_orm.get_field_value(self, schema, 'bases') + return cast(objects.ObjectList[indexes.Index], val) + + def get_subject( + self, schema: 's_schema.Schema' + ) -> 'objects.Object': + val = s_orm.get_field_value(self, schema, 'subject') + return cast(objects.Object, val) + + def get_params( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[functions.Parameter]': + val = s_orm.get_field_value(self, schema, 'params') + return cast(objects.ObjectList[functions.Parameter], val) + + def get_code( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'code') + return cast(str, val) + + def get_kwargs( + self, schema: 's_schema.Schema' + ) -> 'checked.CheckedDict[str, expr.Expression]': + val = s_orm.get_field_value(self, schema, 'kwargs') + return cast(checked.CheckedDict[str, expr.Expression], val) + + def get_type_args( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[objects.Object]': + val = s_orm.get_field_value(self, schema, 'type_args') + return cast(objects.ObjectList[objects.Object], val) + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_except_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'except_expr') + return cast(expr.Expression, val) + + def get_deferrability( + self, schema: 's_schema.Schema' + ) -> 'qltypes.IndexDeferrability': + val = s_orm.get_field_value(self, schema, 'deferrability') + return cast(qltypes.IndexDeferrability, val) + + def get_deferred( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'deferred') + return cast(bool, val) + + +class IndexableSubjectMixin: + + def get_indexes( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectIndexByFullname[indexes.Index]': + val = s_orm.get_field_value(self, schema, 'indexes') + return cast(objects.ObjectIndexByFullname[indexes.Index], val) diff --git a/edb/schema/generated/links.py b/edb/schema/generated/links.py new file mode 100644 index 00000000000..f05a85a58ba --- /dev/null +++ b/edb/schema/generated/links.py @@ -0,0 +1,26 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.edgeql import qltypes + + +class LinkMixin: + + def get_on_target_delete( + self, schema: 's_schema.Schema' + ) -> 'qltypes.LinkTargetDeleteAction': + val = s_orm.get_field_value(self, schema, 'on_target_delete') + return cast(qltypes.LinkTargetDeleteAction, val) + + def get_on_source_delete( + self, schema: 's_schema.Schema' + ) -> 'qltypes.LinkSourceDeleteAction': + val = s_orm.get_field_value(self, schema, 'on_source_delete') + return cast(qltypes.LinkSourceDeleteAction, val) diff --git a/edb/schema/generated/migrations.py b/edb/schema/generated/migrations.py new file mode 100644 index 00000000000..5b4624116f7 --- /dev/null +++ b/edb/schema/generated/migrations.py @@ -0,0 +1,39 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import migrations + + +class MigrationMixin: + + def get_parents( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[migrations.Migration]': + val = s_orm.get_field_value(self, schema, 'parents') + return cast(objects.ObjectList[migrations.Migration], val) + + def get_message( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'message') + return cast(str, val) + + def get_generated_by( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'generated_by') + return cast(str, val) + + def get_script( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'script') + return cast(str, val) diff --git a/edb/schema/generated/modules.py b/edb/schema/generated/modules.py new file mode 100644 index 00000000000..3f5f0c76422 --- /dev/null +++ b/edb/schema/generated/modules.py @@ -0,0 +1,14 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm + + +class ModuleMixin: + pass \ No newline at end of file diff --git a/edb/schema/generated/objects.py b/edb/schema/generated/objects.py new file mode 100644 index 00000000000..a220bfc43af --- /dev/null +++ b/edb/schema/generated/objects.py @@ -0,0 +1,118 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +import uuid +from edb.common import span +from edb.schema import name +from edb.schema import objects +from edb.common import checked + + +class ObjectMixin: + + def get_id( + self, schema: 's_schema.Schema' + ) -> 'uuid.UUID': + val = s_orm.get_field_value(self, schema, 'id') + return cast(uuid.UUID, val) + + def get_internal( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'internal') + return cast(bool, val) + + def get_sourcectx( + self, schema: 's_schema.Schema' + ) -> 'span.Span': + val = s_orm.get_field_value(self, schema, 'sourcectx') + return cast(span.Span, val) + + def get_name( + self, schema: 's_schema.Schema' + ) -> 'name.Name': + val = s_orm.get_field_value(self, schema, 'name') + return cast(name.Name, val) + + def get_builtin( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'builtin') + return cast(bool, val) + + def get_computed_fields( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedSet[str]': + val = s_orm.get_field_value(self, schema, 'computed_fields') + return cast(checked.FrozenCheckedSet[str], val) + + +class InternalObjectMixin: + pass + +class QualifiedObjectMixin: + + def get_name( + self, schema: 's_schema.Schema' + ) -> 'name.QualName': + val = s_orm.get_field_value(self, schema, 'name') + return cast(name.QualName, val) + + +class ObjectFragmentMixin: + pass + +class GlobalObjectMixin: + pass + +class ExternalObjectMixin: + pass + +class DerivableObjectMixin: + pass + +class SubclassableObjectMixin: + + def get_abstract( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'abstract') + return cast(bool, val) + + +class InheritingObjectMixin: + + def get_bases( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[objects.InheritingObject]': + val = s_orm.get_field_value(self, schema, 'bases') + return cast(objects.ObjectList[objects.InheritingObject], val) + + def get_ancestors( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectList[objects.InheritingObject]': + val = s_orm.get_field_value(self, schema, 'ancestors') + return cast(objects.ObjectList[objects.InheritingObject], val) + + def get_inherited_fields( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedSet[str]': + val = s_orm.get_field_value(self, schema, 'inherited_fields') + return cast(checked.FrozenCheckedSet[str], val) + + def get_is_derived( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'is_derived') + return cast(bool, val) + + +class DerivableInheritingObjectMixin: + pass \ No newline at end of file diff --git a/edb/schema/generated/objtypes.py b/edb/schema/generated/objtypes.py new file mode 100644 index 00000000000..a5918229178 --- /dev/null +++ b/edb/schema/generated/objtypes.py @@ -0,0 +1,50 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import triggers +from edb.schema import objtypes +from edb.schema import policies + + +class ObjectTypeRefMixinMixin: + + def get_access_policies( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectIndexByUnqualifiedName[policies.AccessPolicy]': + val = s_orm.get_field_value(self, schema, 'access_policies') + return cast(objects.ObjectIndexByUnqualifiedName[policies.AccessPolicy], val) + + def get_triggers( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectIndexByUnqualifiedName[triggers.Trigger]': + val = s_orm.get_field_value(self, schema, 'triggers') + return cast(objects.ObjectIndexByUnqualifiedName[triggers.Trigger], val) + + +class ObjectTypeMixin: + + def get_union_of( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectSet[objtypes.ObjectType]': + val = s_orm.get_field_value(self, schema, 'union_of') + return cast(objects.ObjectSet[objtypes.ObjectType], val) + + def get_intersection_of( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectSet[objtypes.ObjectType]': + val = s_orm.get_field_value(self, schema, 'intersection_of') + return cast(objects.ObjectSet[objtypes.ObjectType], val) + + def get_is_opaque_union( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'is_opaque_union') + return cast(bool, val) diff --git a/edb/schema/generated/operators.py b/edb/schema/generated/operators.py new file mode 100644 index 00000000000..1f5a1ab42d8 --- /dev/null +++ b/edb/schema/generated/operators.py @@ -0,0 +1,83 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.edgeql import qltypes +from edb.schema import name +from edb.edgeql import ast +from edb.common import checked + + +class OperatorMixin: + + def get_operator_kind( + self, schema: 's_schema.Schema' + ) -> 'qltypes.OperatorKind': + val = s_orm.get_field_value(self, schema, 'operator_kind') + return cast(qltypes.OperatorKind, val) + + def get_language( + self, schema: 's_schema.Schema' + ) -> 'ast.Language': + val = s_orm.get_field_value(self, schema, 'language') + return cast(ast.Language, val) + + def get_from_operator( + self, schema: 's_schema.Schema' + ) -> 'checked.CheckedList[str]': + val = s_orm.get_field_value(self, schema, 'from_operator') + return cast(checked.CheckedList[str], val) + + def get_from_function( + self, schema: 's_schema.Schema' + ) -> 'checked.CheckedList[str]': + val = s_orm.get_field_value(self, schema, 'from_function') + return cast(checked.CheckedList[str], val) + + def get_from_expr( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'from_expr') + return cast(bool, val) + + def get_force_return_cast( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'force_return_cast') + return cast(bool, val) + + def get_code( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'code') + return cast(str, val) + + def get_derivative_of( + self, schema: 's_schema.Schema' + ) -> 'name.QualName': + val = s_orm.get_field_value(self, schema, 'derivative_of') + return cast(name.QualName, val) + + def get_commutator( + self, schema: 's_schema.Schema' + ) -> 'name.QualName': + val = s_orm.get_field_value(self, schema, 'commutator') + return cast(name.QualName, val) + + def get_negator( + self, schema: 's_schema.Schema' + ) -> 'name.QualName': + val = s_orm.get_field_value(self, schema, 'negator') + return cast(name.QualName, val) + + def get_recursive( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'recursive') + return cast(bool, val) diff --git a/edb/schema/generated/pointers.py b/edb/schema/generated/pointers.py new file mode 100644 index 00000000000..aa20d44b84d --- /dev/null +++ b/edb/schema/generated/pointers.py @@ -0,0 +1,121 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.edgeql import qltypes +from edb.schema import pointers +from edb.schema import rewrites +from edb.schema import expr +from edb.schema import types + + +class PointerMixin: + + def get_source( + self, schema: 's_schema.Schema' + ) -> 'objects.InheritingObject': + val = s_orm.get_field_value(self, schema, 'source') + return cast(objects.InheritingObject, val) + + def get_target( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'target') + return cast(types.Type, val) + + def get_required( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'required') + return cast(bool, val) + + def get_readonly( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'readonly') + return cast(bool, val) + + def get_secret( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'secret') + return cast(bool, val) + + def get_protected( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'protected') + return cast(bool, val) + + def get_computable( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'computable') + return cast(bool, val) + + def get_from_alias( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'from_alias') + return cast(bool, val) + + def get_defined_here( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'defined_here') + return cast(bool, val) + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_default( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'default') + return cast(expr.Expression, val) + + def get_cardinality( + self, schema: 's_schema.Schema' + ) -> 'qltypes.SchemaCardinality': + val = s_orm.get_field_value(self, schema, 'cardinality') + return cast(qltypes.SchemaCardinality, val) + + def get_union_of( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectSet[pointers.Pointer]': + val = s_orm.get_field_value(self, schema, 'union_of') + return cast(objects.ObjectSet[pointers.Pointer], val) + + def get_intersection_of( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectSet[pointers.Pointer]': + val = s_orm.get_field_value(self, schema, 'intersection_of') + return cast(objects.ObjectSet[pointers.Pointer], val) + + def get_computed_link_alias_is_backward( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'computed_link_alias_is_backward') + return cast(bool, val) + + def get_computed_link_alias( + self, schema: 's_schema.Schema' + ) -> 'objects.Object': + val = s_orm.get_field_value(self, schema, 'computed_link_alias') + return cast(objects.Object, val) + + def get_rewrites( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectIndexByUnqualifiedName[rewrites.Rewrite]': + val = s_orm.get_field_value(self, schema, 'rewrites') + return cast(objects.ObjectIndexByUnqualifiedName[rewrites.Rewrite], val) diff --git a/edb/schema/generated/policies.py b/edb/schema/generated/policies.py new file mode 100644 index 00000000000..7c264ff7fb9 --- /dev/null +++ b/edb/schema/generated/policies.py @@ -0,0 +1,58 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import expr +from edb.edgeql import qltypes + + +class AccessPolicyMixin: + + def get_condition( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'condition') + return cast(expr.Expression, val) + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_action( + self, schema: 's_schema.Schema' + ) -> 'qltypes.AccessPolicyAction': + val = s_orm.get_field_value(self, schema, 'action') + return cast(qltypes.AccessPolicyAction, val) + + def get_access_kinds( + self, schema: 's_schema.Schema' + ) -> 'objects.MultiPropSet[qltypes.AccessKind]': + val = s_orm.get_field_value(self, schema, 'access_kinds') + return cast(objects.MultiPropSet[qltypes.AccessKind], val) + + def get_subject( + self, schema: 's_schema.Schema' + ) -> 'objects.InheritingObject': + val = s_orm.get_field_value(self, schema, 'subject') + return cast(objects.InheritingObject, val) + + def get_errmessage( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'errmessage') + return cast(str, val) + + def get_owned( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'owned') + return cast(bool, val) diff --git a/edb/schema/generated/properties.py b/edb/schema/generated/properties.py new file mode 100644 index 00000000000..75283db517d --- /dev/null +++ b/edb/schema/generated/properties.py @@ -0,0 +1,14 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm + + +class PropertyMixin: + pass \ No newline at end of file diff --git a/edb/schema/generated/pseudo.py b/edb/schema/generated/pseudo.py new file mode 100644 index 00000000000..775b84c98d8 --- /dev/null +++ b/edb/schema/generated/pseudo.py @@ -0,0 +1,14 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm + + +class PseudoTypeMixin: + pass \ No newline at end of file diff --git a/edb/schema/generated/referencing.py b/edb/schema/generated/referencing.py new file mode 100644 index 00000000000..981675ae05a --- /dev/null +++ b/edb/schema/generated/referencing.py @@ -0,0 +1,32 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm + + +class ReferencedObjectMixin: + + def get_owned( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'owned') + return cast(bool, val) + + +class ReferencedInheritingObjectMixin: + + def get_declared_overloaded( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'declared_overloaded') + return cast(bool, val) + + +class NamedReferencedInheritingObjectMixin: + pass \ No newline at end of file diff --git a/edb/schema/generated/rewrites.py b/edb/schema/generated/rewrites.py new file mode 100644 index 00000000000..9401e1718f7 --- /dev/null +++ b/edb/schema/generated/rewrites.py @@ -0,0 +1,34 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import expr +from edb.edgeql import qltypes + + +class RewriteMixin: + + def get_kind( + self, schema: 's_schema.Schema' + ) -> 'qltypes.RewriteKind': + val = s_orm.get_field_value(self, schema, 'kind') + return cast(qltypes.RewriteKind, val) + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_subject( + self, schema: 's_schema.Schema' + ) -> 'objects.InheritingObject': + val = s_orm.get_field_value(self, schema, 'subject') + return cast(objects.InheritingObject, val) diff --git a/edb/schema/generated/roles.py b/edb/schema/generated/roles.py new file mode 100644 index 00000000000..840e32afbf0 --- /dev/null +++ b/edb/schema/generated/roles.py @@ -0,0 +1,31 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm + + +class RoleMixin: + + def get_superuser( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'superuser') + return cast(bool, val) + + def get_password( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'password') + return cast(str, val) + + def get_password_hash( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'password_hash') + return cast(str, val) diff --git a/edb/schema/generated/scalars.py b/edb/schema/generated/scalars.py new file mode 100644 index 00000000000..4fa804819ea --- /dev/null +++ b/edb/schema/generated/scalars.py @@ -0,0 +1,51 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import expr +from edb.common import checked + + +class ScalarTypeMixin: + + def get_default( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'default') + return cast(expr.Expression, val) + + def get_enum_values( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedList[str]': + val = s_orm.get_field_value(self, schema, 'enum_values') + return cast(checked.FrozenCheckedList[str], val) + + def get_sql_type( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'sql_type') + return cast(str, val) + + def get_sql_type_scheme( + self, schema: 's_schema.Schema' + ) -> 'str': + val = s_orm.get_field_value(self, schema, 'sql_type_scheme') + return cast(str, val) + + def get_num_params( + self, schema: 's_schema.Schema' + ) -> 'int': + val = s_orm.get_field_value(self, schema, 'num_params') + return cast(int, val) + + def get_arg_values( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedList[str]': + val = s_orm.get_field_value(self, schema, 'arg_values') + return cast(checked.FrozenCheckedList[str], val) diff --git a/edb/schema/generated/sources.py b/edb/schema/generated/sources.py new file mode 100644 index 00000000000..8279c06f035 --- /dev/null +++ b/edb/schema/generated/sources.py @@ -0,0 +1,21 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import pointers + + +class SourceMixin: + + def get_pointers( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectIndexByUnqualifiedName[pointers.Pointer]': + val = s_orm.get_field_value(self, schema, 'pointers') + return cast(objects.ObjectIndexByUnqualifiedName[pointers.Pointer], val) diff --git a/edb/schema/generated/triggers.py b/edb/schema/generated/triggers.py new file mode 100644 index 00000000000..d3040397231 --- /dev/null +++ b/edb/schema/generated/triggers.py @@ -0,0 +1,58 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.schema import expr +from edb.edgeql import qltypes + + +class TriggerMixin: + + def get_timing( + self, schema: 's_schema.Schema' + ) -> 'qltypes.TriggerTiming': + val = s_orm.get_field_value(self, schema, 'timing') + return cast(qltypes.TriggerTiming, val) + + def get_kinds( + self, schema: 's_schema.Schema' + ) -> 'objects.MultiPropSet[qltypes.TriggerKind]': + val = s_orm.get_field_value(self, schema, 'kinds') + return cast(objects.MultiPropSet[qltypes.TriggerKind], val) + + def get_scope( + self, schema: 's_schema.Schema' + ) -> 'qltypes.TriggerScope': + val = s_orm.get_field_value(self, schema, 'scope') + return cast(qltypes.TriggerScope, val) + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_condition( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'condition') + return cast(expr.Expression, val) + + def get_subject( + self, schema: 's_schema.Schema' + ) -> 'objects.InheritingObject': + val = s_orm.get_field_value(self, schema, 'subject') + return cast(objects.InheritingObject, val) + + def get_owned( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'owned') + return cast(bool, val) diff --git a/edb/schema/generated/types.py b/edb/schema/generated/types.py new file mode 100644 index 00000000000..97e0b3debad --- /dev/null +++ b/edb/schema/generated/types.py @@ -0,0 +1,144 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +from edb.schema import objects +from edb.common import checked +from edb.schema import expr +from edb.schema import types + + +class TypeMixin: + + def get_expr( + self, schema: 's_schema.Schema' + ) -> 'expr.Expression': + val = s_orm.get_field_value(self, schema, 'expr') + return cast(expr.Expression, val) + + def get_expr_type( + self, schema: 's_schema.Schema' + ) -> 'types.ExprType': + val = s_orm.get_field_value(self, schema, 'expr_type') + return cast(types.ExprType, val) + + def get_from_alias( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'from_alias') + return cast(bool, val) + + def get_from_global( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'from_global') + return cast(bool, val) + + def get_alias_is_persistent( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'alias_is_persistent') + return cast(bool, val) + + def get_rptr( + self, schema: 's_schema.Schema' + ) -> 'objects.Object': + val = s_orm.get_field_value(self, schema, 'rptr') + return cast(objects.Object, val) + + def get_backend_id( + self, schema: 's_schema.Schema' + ) -> 'int': + val = s_orm.get_field_value(self, schema, 'backend_id') + return cast(int, val) + + def get_transient( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'transient') + return cast(bool, val) + + +class QualifiedTypeMixin: + pass + +class InheritingTypeMixin: + pass + +class CollectionMixin: + + def get_is_persistent( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'is_persistent') + return cast(bool, val) + + +class CollectionExprAliasMixin: + pass + +class ArrayMixin: + + def get_element_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'element_type') + return cast(types.Type, val) + + def get_dimensions( + self, schema: 's_schema.Schema' + ) -> 'checked.FrozenCheckedList[int]': + val = s_orm.get_field_value(self, schema, 'dimensions') + return cast(checked.FrozenCheckedList[int], val) + + +class ArrayExprAliasMixin: + pass + +class TupleMixin: + + def get_named( + self, schema: 's_schema.Schema' + ) -> 'bool': + val = s_orm.get_field_value(self, schema, 'named') + return cast(bool, val) + + def get_element_types( + self, schema: 's_schema.Schema' + ) -> 'objects.ObjectDict[str, types.Type]': + val = s_orm.get_field_value(self, schema, 'element_types') + return cast(objects.ObjectDict[str, types.Type], val) + + +class TupleExprAliasMixin: + pass + +class RangeMixin: + + def get_element_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'element_type') + return cast(types.Type, val) + + +class RangeExprAliasMixin: + pass + +class MultiRangeMixin: + + def get_element_type( + self, schema: 's_schema.Schema' + ) -> 'types.Type': + val = s_orm.get_field_value(self, schema, 'element_type') + return cast(types.Type, val) + + +class MultiRangeExprAliasMixin: + pass \ No newline at end of file diff --git a/edb/schema/generated/version.py b/edb/schema/generated/version.py new file mode 100644 index 00000000000..c4c97c23ceb --- /dev/null +++ b/edb/schema/generated/version.py @@ -0,0 +1,27 @@ +# DO NOT EDIT. This file was generated with: +# +# $ gen-schema-mixins + +"""Type definitions for generated methods on schema classes""" + +from typing import cast, TYPE_CHECKING +if TYPE_CHECKING: + from edb.schema import schema as s_schema +from edb.schema import orm as s_orm +import uuid + + +class BaseSchemaVersionMixin: + + def get_version( + self, schema: 's_schema.Schema' + ) -> 'uuid.UUID': + val = s_orm.get_field_value(self, schema, 'version') + return cast(uuid.UUID, val) + + +class SchemaVersionMixin: + pass + +class GlobalSchemaVersionMixin: + pass \ No newline at end of file diff --git a/edb/schema/globals.py b/edb/schema/globals.py index cef6f6d069e..0169c2a868a 100644 --- a/edb/schema/globals.py +++ b/edb/schema/globals.py @@ -36,6 +36,7 @@ from . import objects as so from . import types as s_types from . import utils +from .generated import globals as sg_globals if TYPE_CHECKING: from edb.schema import schema as s_schema @@ -44,6 +45,7 @@ class Global( so.QualifiedObject, s_anno.AnnotationSubject, + sg_globals.GlobalMixin, qlkind=qltypes.SchemaObjectClass.GLOBAL, data_safe=True, ): diff --git a/edb/schema/indexes.py b/edb/schema/indexes.py index ceeee697d5c..dfd38b9681c 100644 --- a/edb/schema/indexes.py +++ b/edb/schema/indexes.py @@ -54,6 +54,7 @@ from . import scalars as s_scalars from . import types as s_types from . import utils +from .generated import indexes as sg_indexes if TYPE_CHECKING: @@ -278,6 +279,7 @@ def merge_deferred( class Index( + sg_indexes.IndexMixin, referencing.ReferencedInheritingObject, so.InheritingObject, # Help reflection figure out the right db MRO s_anno.AnnotationSubject, @@ -538,7 +540,7 @@ def is_defined_here( IndexableSubject_T = TypeVar('IndexableSubject_T', bound='IndexableSubject') -class IndexableSubject(so.InheritingObject): +class IndexableSubject(sg_indexes.IndexableSubjectMixin, so.InheritingObject): indexes_refs = so.RefDict( attr='indexes', ref_cls=Index) diff --git a/edb/schema/links.py b/edb/schema/links.py index b455df2820c..ddd271cb0a2 100644 --- a/edb/schema/links.py +++ b/edb/schema/links.py @@ -41,6 +41,7 @@ from . import unknown_pointers from . import utils from . import expr as s_expr +from .generated import links as sg_links if TYPE_CHECKING: from . import objtypes as s_objtypes @@ -108,6 +109,7 @@ class Link( sources.Source, pointers.Pointer, s_abc.Link, + sg_links.LinkMixin, qlkind=qltypes.SchemaObjectClass.LINK, data_safe=False, ): diff --git a/edb/schema/migrations.py b/edb/schema/migrations.py index 472ab323dc7..c8795030022 100644 --- a/edb/schema/migrations.py +++ b/edb/schema/migrations.py @@ -36,6 +36,7 @@ from . import name as sn from . import objects as so from . import utils as s_utils +from .generated import migrations as sg_migrations if TYPE_CHECKING: from . import schema as s_schema @@ -44,6 +45,7 @@ class Migration( so.Object, s_abc.Migration, + sg_migrations.MigrationMixin, qlkind=qltypes.SchemaObjectClass.MIGRATION, data_safe=False, ): diff --git a/edb/schema/modules.py b/edb/schema/modules.py index d634ca30137..7ab5f1559be 100644 --- a/edb/schema/modules.py +++ b/edb/schema/modules.py @@ -30,6 +30,7 @@ from . import name as sn from . import objects as so from . import schema as s_schema +from .generated import modules as sg_modules RESERVED_MODULE_NAMES = { 'super', @@ -39,6 +40,7 @@ class Module( s_anno.AnnotationSubject, so.Object, # Help reflection figure out the right db MRO + sg_modules.ModuleMixin, qlkind=qltypes.SchemaObjectClass.MODULE, data_safe=False, ): diff --git a/edb/schema/objects.py b/edb/schema/objects.py index 582bf46612e..307dc839f14 100644 --- a/edb/schema/objects.py +++ b/edb/schema/objects.py @@ -67,6 +67,7 @@ from . import abc as s_abc from . import name as sn from . import _types +from .generated import objects as sg_obj if TYPE_CHECKING: @@ -721,89 +722,6 @@ def __new__( for findex, field in enumerate(cls._schema_fields.values()): field.index = findex - getter_name = f'get_{field.name}' - if getter_name in clsdict: - # The getter was defined explicitly, move on. - continue - - ftype = field.type - # The field getters are hot code as they're essentially - # attribute access, so be mindful about what you are adding - # into the callables below. - if issubclass(ftype, s_abc.Reducible): - def reducible_getter( - self: Any, - schema: s_schema.Schema, - *, - _fn: str = field.name, - _fi: int = findex, - _sr: Callable[[Any], s_abc.Reducible] = ( - ftype.schema_restore - ), - _fd: Callable[[], Any] = field.get_default, - ) -> Any: - data = schema.get_obj_data_raw(self) - v = data[_fi] - if v is not None: - return _sr(v) - else: - try: - return _fd() - except ValueError: - pass - - raise FieldValueNotFoundError( - f'{self!r} object has no value ' - f'for field {_fn!r}' - ) - - setattr(cls, getter_name, reducible_getter) - - elif ( - field.default is not NoDefault - and field.default is not DEFAULT_CONSTRUCTOR - ): - def regular_default_getter( - self: Any, - schema: s_schema.Schema, - *, - _fi: int = findex, - _fd: Any = field.default, - ) -> Any: - data = schema.get_obj_data_raw(self) - v = data[_fi] - if v is not None: - return v - else: - return _fd - - setattr(cls, getter_name, regular_default_getter) - - else: - def regular_getter( - self: Any, - schema: s_schema.Schema, - *, - _fn: str = field.name, - _fi: int = findex, - _fd: Callable[[], Any] = field.get_default, - ) -> Any: - data = schema.get_obj_data_raw(self) - v = data[_fi] - if v is not None: - return v - else: - try: - return _fd() - except ValueError: - pass - - raise FieldValueNotFoundError( - f'{self!r} object has no value ' - f'for field {_fn!r}' - ) - - setattr(cls, getter_name, regular_getter) non_schema_fields = {field.name for field in fields.values() if not field.is_schema_field} @@ -994,7 +912,9 @@ class FieldValueNotFoundError(Exception): pass -class Object(s_abc.Object, ObjectContainer, metaclass=ObjectMeta): +class Object( + s_abc.Object, ObjectContainer, sg_obj.ObjectMixin, metaclass=ObjectMeta +): """Base schema item class.""" __slots__ = ('id',) @@ -2078,7 +1998,7 @@ def __repr__(self) -> str: return f'<{type(self).__name__} {self.id} at 0x{id(self):#x}>' -class InternalObject(Object): +class InternalObject(Object, sg_obj.InternalObjectMixin): """A schema object that is used by the system internally. Instances of InternalObject should not appear in schema dumps. @@ -2091,7 +2011,7 @@ def is_abstract(cls) -> bool: return cls is InternalObject -class QualifiedObject(Object): +class QualifiedObject(Object, sg_obj.ObjectMixin): name = SchemaField( # ignore below because Mypy doesn't understand fields which are not @@ -2116,18 +2036,18 @@ def get_shortname(self, schema: s_schema.Schema) -> sn.QualName: QualifiedObject_T = TypeVar('QualifiedObject_T', bound='QualifiedObject') -class ObjectFragment(QualifiedObject): +class ObjectFragment(QualifiedObject, sg_obj.ObjectFragmentMixin): """A part of another object that cannot exist independently.""" -class GlobalObject(Object): +class GlobalObject(Object, sg_obj.GlobalObjectMixin): is_global_object = True GlobalObject_T = TypeVar('GlobalObject_T', bound='GlobalObject') -class ExternalObject(GlobalObject): +class ExternalObject(GlobalObject, sg_obj.ExternalObjectMixin): """An object that is not tracked in a schema, but some external state.""" pass @@ -2135,7 +2055,7 @@ class ExternalObject(GlobalObject): ExternalObject_T = TypeVar('ExternalObject_T', bound='ExternalObject') -class DerivableObject(QualifiedObject): +class DerivableObject(QualifiedObject, sg_obj.DerivableObjectMixin): def derive_name( self, @@ -3014,7 +2934,7 @@ def create( return super().create(schema, data, **kwargs) # type: ignore -class SubclassableObject(Object): +class SubclassableObject(Object, sg_obj.SubclassableObjectMixin): abstract = SchemaField( bool, @@ -3053,7 +2973,7 @@ def issubclass( InheritingObjectT = TypeVar('InheritingObjectT', bound='InheritingObject') -class InheritingObject(SubclassableObject): +class InheritingObject(SubclassableObject, sg_obj.InheritingObjectMixin): bases = SchemaField( ObjectList['InheritingObject'], @@ -3415,7 +3335,9 @@ def compare_obj_field_value( ) -class DerivableInheritingObject(DerivableObject, InheritingObject): +class DerivableInheritingObject( + DerivableObject, InheritingObject, sg_obj.DerivableInheritingObjectMixin +): def get_nearest_non_derived_parent( self: DerivableInheritingObjectT, diff --git a/edb/schema/objtypes.py b/edb/schema/objtypes.py index 8a5bf356acd..95158b7b664 100644 --- a/edb/schema/objtypes.py +++ b/edb/schema/objtypes.py @@ -46,9 +46,10 @@ from . import types as s_types from . import unknown_pointers from . import utils +from .generated import objtypes as sg_objtypes -class ObjectTypeRefMixin(so.Object): +class ObjectTypeRefMixin(so.Object, sg_objtypes.ObjectTypeRefMixinMixin): # We stick access policies and triggers in their own class as a # hack, to allow us to ensure that access_policies comes later in # the refdicts list than pointers does, so that pointers are @@ -81,6 +82,7 @@ class ObjectType( sources.Source, constraints.ConsistencySubject, s_types.InheritingType, + sg_objtypes.ObjectTypeMixin, so.InheritingObject, # Help reflection figure out the right db MRO s_types.Type, # Help reflection figure out the right db MRO diff --git a/edb/schema/operators.py b/edb/schema/operators.py index bc9a3aea770..f2885e061fb 100644 --- a/edb/schema/operators.py +++ b/edb/schema/operators.py @@ -32,6 +32,7 @@ from . import name as sn from . import objects as so from . import utils +from .generated import operators as sg_operators if TYPE_CHECKING: from edb.schema import schema as s_schema @@ -41,6 +42,7 @@ class Operator( s_func.CallableObject, s_func.VolatilitySubject, s_abc.Operator, + sg_operators.OperatorMixin, qlkind=ft.SchemaObjectClass.OPERATOR, data_safe=True, ): diff --git a/edb/schema/orm.py b/edb/schema/orm.py new file mode 100644 index 00000000000..bbbf6e972b1 --- /dev/null +++ b/edb/schema/orm.py @@ -0,0 +1,59 @@ +# +# This source file is part of the EdgeDB open source project. +# +# Copyright 2008-present MagicStack Inc. and the EdgeDB authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +"""Machinery for mapping the schema data onto the model classes.""" + +from typing import TYPE_CHECKING +import typing + +if TYPE_CHECKING: + from edb.schema import schema as s_schema + from edb.schema import objects as s_obj + + +def get_field_value( + self: 's_obj.Object', + schema: 's_schema.Schema', + field_name: str, +) -> typing.Any: + from edb.schema import objects as s_obj + + field = type(self).get_field(field_name) + + if isinstance(field, s_obj.SchemaField): + data = schema.get_obj_data_raw(self) + val = data[field.index] + if val is not None: + if field.is_reducible: + return field.type.schema_restore(val) + else: + return val + else: + try: + return field.get_default() + except ValueError: + pass + else: + try: + return object.__getattribute__(self, field_name) + except AttributeError: + pass + + raise s_obj.FieldValueNotFoundError( + f'{self!r} object has no value for field {field_name!r}' + ) diff --git a/edb/schema/pointers.py b/edb/schema/pointers.py index 97d74cdf04d..e4086309d09 100644 --- a/edb/schema/pointers.py +++ b/edb/schema/pointers.py @@ -63,6 +63,7 @@ from . import schema as s_schema from . import types as s_types from . import utils +from .generated import pointers as sg_pointers if TYPE_CHECKING: @@ -422,10 +423,13 @@ def _get_target_name_in_diff( Pointer_T = TypeVar("Pointer_T", bound="Pointer") -class Pointer(referencing.NamedReferencedInheritingObject, - constraints.ConsistencySubject, - s_anno.AnnotationSubject, - s_abc.Pointer): +class Pointer( + referencing.NamedReferencedInheritingObject, + constraints.ConsistencySubject, + sg_pointers.PointerMixin, + s_anno.AnnotationSubject, + s_abc.Pointer +): source = so.SchemaField( so.InheritingObject, diff --git a/edb/schema/policies.py b/edb/schema/policies.py index 4aeaa0883dc..27e260af3df 100644 --- a/edb/schema/policies.py +++ b/edb/schema/policies.py @@ -37,12 +37,14 @@ from . import schema as s_schema from . import sources as s_sources from . import types as s_types +from .generated import policies as sg_policies if TYPE_CHECKING: from . import objtypes as s_objtypes class AccessPolicy( + sg_policies.AccessPolicyMixin, referencing.NamedReferencedInheritingObject, so.InheritingObject, # Help reflection figure out the right db MRO s_anno.AnnotationSubject, diff --git a/edb/schema/properties.py b/edb/schema/properties.py index b104707ad12..cf9fde44aa3 100644 --- a/edb/schema/properties.py +++ b/edb/schema/properties.py @@ -39,6 +39,7 @@ from . import types as s_types from . import utils from . import expr as s_expr +from .generated import properties as sg_properties if TYPE_CHECKING: from . import schema as s_schema @@ -47,6 +48,7 @@ class Property( pointers.Pointer, s_abc.Property, + sg_properties.PropertyMixin, qlkind=qltypes.SchemaObjectClass.PROPERTY, data_safe=False, ): diff --git a/edb/schema/pseudo.py b/edb/schema/pseudo.py index 353bad1cfd7..16de13afba1 100644 --- a/edb/schema/pseudo.py +++ b/edb/schema/pseudo.py @@ -29,6 +29,7 @@ from . import name as sn from . import objects as so from . import types as s_types +from .generated import pseudo as sg_pseudo if TYPE_CHECKING: from . import schema as s_schema @@ -40,6 +41,7 @@ class PseudoType( so.InheritingObject, s_types.Type, + sg_pseudo.PseudoTypeMixin, qlkind=qltypes.SchemaObjectClass.PSEUDO_TYPE, ): diff --git a/edb/schema/referencing.py b/edb/schema/referencing.py index 1dfb6e87233..7bc60a6bd49 100644 --- a/edb/schema/referencing.py +++ b/edb/schema/referencing.py @@ -47,6 +47,7 @@ from . import schema as s_schema from . import name as sn from . import utils +from .generated import referencing as sg_referencing ReferencedT = TypeVar('ReferencedT', bound='ReferencedObject') @@ -56,7 +57,9 @@ # Q: There are no ReferencedObjects that aren't ReferencedInheritingObject; # should we merge them? -class ReferencedObject(so.DerivableObject): +class ReferencedObject( + so.DerivableObject, sg_referencing.ReferencedObjectMixin +): #: True if the object has an explicit definition and is not #: purely inherited. @@ -88,8 +91,8 @@ def get_verbosename_static( def get_subject(self, schema: s_schema.Schema) -> Optional[so.Object]: # NB: classes that inherit ReferencedObject define a `get_subject` - # method dynamically, with `subject = SchemaField` - raise NotImplementedError + # method dynamically, with `subjet = SchemaField` + raise NotImplementedError(f'get_subject() for {self}') def get_referrer(self, schema: s_schema.Schema) -> Optional[so.Object]: return self.get_subject(schema) @@ -179,6 +182,7 @@ def is_parent_ref( class ReferencedInheritingObject( so.DerivableInheritingObject, ReferencedObject, + sg_referencing.ReferencedInheritingObjectMixin, ): # Indicates that the object has been declared as @@ -1624,6 +1628,7 @@ def _alter_begin( class NamedReferencedInheritingObject( ReferencedInheritingObject, + sg_referencing.NamedReferencedInheritingObjectMixin, ): """A referenced inheriting object that has an explicit local name. diff --git a/edb/schema/rewrites.py b/edb/schema/rewrites.py index 7562eb7b180..2aa9e071d7d 100644 --- a/edb/schema/rewrites.py +++ b/edb/schema/rewrites.py @@ -35,12 +35,14 @@ from . import referencing from . import schema as s_schema from . import types as s_types +from .generated import rewrites as sg_rewrites if TYPE_CHECKING: from . import pointers as s_pointers class Rewrite( + sg_rewrites.RewriteMixin, referencing.NamedReferencedInheritingObject, so.InheritingObject, # Help reflection figure out the right db MRO s_anno.AnnotationSubject, diff --git a/edb/schema/roles.py b/edb/schema/roles.py index 23c191973af..0f7307bbb6f 100644 --- a/edb/schema/roles.py +++ b/edb/schema/roles.py @@ -32,6 +32,7 @@ from . import inheriting from . import objects as so from . import utils +from .generated import roles as sg_roles if TYPE_CHECKING: from edb.schema import schema as s_schema @@ -41,6 +42,7 @@ class Role( so.GlobalObject, so.InheritingObject, s_anno.AnnotationSubject, + sg_roles.RoleMixin, qlkind=qltypes.SchemaObjectClass.ROLE, data_safe=True, ): diff --git a/edb/schema/scalars.py b/edb/schema/scalars.py index fbba1a9d978..9ce916d315c 100644 --- a/edb/schema/scalars.py +++ b/edb/schema/scalars.py @@ -41,12 +41,13 @@ from . import schema as s_schema from . import types as s_types from . import utils as s_utils - +from .generated import scalars as sg_scalars class ScalarType( s_types.InheritingType, constraints.ConsistencySubject, s_abc.ScalarType, + sg_scalars.ScalarTypeMixin, qlkind=qltypes.SchemaObjectClass.SCALAR_TYPE, data_safe=True, ): diff --git a/edb/schema/sources.py b/edb/schema/sources.py index f87eee981b2..b9ed04c2394 100644 --- a/edb/schema/sources.py +++ b/edb/schema/sources.py @@ -37,6 +37,7 @@ from . import name as sn from . import objects as so from . import pointers as s_pointers +from .generated import sources as sg_sources if TYPE_CHECKING: from . import links @@ -61,6 +62,7 @@ class SourceCommand(indexes.IndexSourceCommand[Source_T]): class Source( so.QualifiedObject, indexes.IndexableSubject, + sg_sources.SourceMixin, so.Object, # Help reflection figure out the right db MRO ): pointers_refs = so.RefDict( diff --git a/edb/schema/triggers.py b/edb/schema/triggers.py index cf6d7104af2..503ddbd37cf 100644 --- a/edb/schema/triggers.py +++ b/edb/schema/triggers.py @@ -35,12 +35,14 @@ from . import schema as s_schema from . import sources as s_sources from . import types as s_types +from .generated import triggers as sg_triggers if TYPE_CHECKING: from . import objtypes as s_objtypes class Trigger( + sg_triggers.TriggerMixin, referencing.NamedReferencedInheritingObject, so.InheritingObject, # Help reflection figure out the right db MRO qlkind=qltypes.SchemaObjectClass.TRIGGER, diff --git a/edb/schema/types.py b/edb/schema/types.py index 005942fc543..a17192767db 100644 --- a/edb/schema/types.py +++ b/edb/schema/types.py @@ -43,6 +43,7 @@ from . import objects as so from . import schema as s_schema from . import utils +from .generated import types as sg_types if typing.TYPE_CHECKING: from typing import Any, Dict, Iterable, Iterator, List, Mapping, Optional @@ -86,6 +87,7 @@ class Type( so.SubclassableObject, s_anno.AnnotationSubject, s_abc.Type, + sg_types.TypeMixin, ): """A schema item that is a valid *type*.""" @@ -534,13 +536,15 @@ def as_type_delete_if_unused( return None -class QualifiedType(so.QualifiedObject, Type): +class QualifiedType(so.QualifiedObject, Type, sg_types.QualifiedTypeMixin): @classmethod def get_schema_class_displayname(cls) -> str: return 'type' -class InheritingType(so.DerivableInheritingObject, QualifiedType): +class InheritingType( + so.DerivableInheritingObject, QualifiedType, sg_types.InheritingTypeMixin, +): def material_type( self: InheritingTypeT, @@ -930,7 +934,7 @@ def __init__( _collection_impls: Dict[str, typing.Type[Collection]] = {} -class Collection(Type, s_abc.Collection): +class Collection(Type, s_abc.Collection, sg_types.CollectionMixin): _schema_name: typing.ClassVar[typing.Optional[str]] = None @@ -1159,7 +1163,9 @@ def is_polymorphic(self, schema: s_schema.Schema) -> bool: ) -class CollectionExprAlias(QualifiedType, Collection): +class CollectionExprAlias( + QualifiedType, Collection, sg_types.CollectionExprAliasMixin +): @classmethod def get_schema_class_displayname(cls) -> str: @@ -1202,6 +1208,7 @@ def as_type_delete_if_unused( class Array( Collection, s_abc.Array, + sg_types.ArrayMixin, qlkind=qltypes.SchemaObjectClass.ARRAY_TYPE, schema_name='array', ): @@ -1571,6 +1578,7 @@ def as_create_delta( class ArrayExprAlias( CollectionExprAlias, Array, + sg_types.ArrayExprAliasMixin, qlkind=qltypes.SchemaObjectClass.ALIAS, ): # N.B: Don't add any SchemaFields to this class, they won't be @@ -1588,6 +1596,7 @@ def get_underlying_schema_class(cls) -> typing.Type[Collection]: class Tuple( Collection, s_abc.Tuple, + sg_types.TupleMixin, qlkind=qltypes.SchemaObjectClass.TUPLE_TYPE, schema_name='tuple', ): @@ -2140,6 +2149,7 @@ def _populate_create_delta( class TupleExprAlias( CollectionExprAlias, Tuple, + sg_types.TupleExprAliasMixin, qlkind=qltypes.SchemaObjectClass.ALIAS, ): # N.B: Don't add any SchemaFields to this class, they won't be @@ -2157,6 +2167,7 @@ def get_underlying_schema_class(cls) -> typing.Type[Collection]: class Range( Collection, s_abc.Range, + sg_types.RangeMixin, qlkind=qltypes.SchemaObjectClass.RANGE_TYPE, schema_name='range', ): @@ -2502,6 +2513,7 @@ def as_create_delta( class RangeExprAlias( CollectionExprAlias, Range, + sg_types.RangeExprAliasMixin, qlkind=qltypes.SchemaObjectClass.ALIAS, ): # N.B: Don't add any SchemaFields to this class, they won't be @@ -2520,6 +2532,7 @@ def get_underlying_schema_class(cls) -> typing.Type[Collection]: class MultiRange( Collection, s_abc.MultiRange, + sg_types.MultiRangeMixin, qlkind=qltypes.SchemaObjectClass.MULTIRANGE_TYPE, schema_name='multirange', ): @@ -2836,6 +2849,7 @@ def as_create_delta( class MultiRangeExprAlias( CollectionExprAlias, MultiRange, + sg_types.MultiRangeExprAliasMixin, qlkind=qltypes.SchemaObjectClass.ALIAS, ): # N.B: Don't add any SchemaFields to this class, they won't be diff --git a/edb/schema/version.py b/edb/schema/version.py index b9c9b4e40d6..13267dcc8f5 100644 --- a/edb/schema/version.py +++ b/edb/schema/version.py @@ -22,14 +22,17 @@ from . import delta as sd from . import objects as so +from .generated import version as sg_version -class BaseSchemaVersion(so.Object): +class BaseSchemaVersion(so.Object, sg_version.BaseSchemaVersionMixin): version = so.SchemaField(uuid.UUID) -class SchemaVersion(BaseSchemaVersion, so.InternalObject): +class SchemaVersion( + BaseSchemaVersion, so.InternalObject, sg_version.SchemaVersionMixin +): pass @@ -59,7 +62,10 @@ class AlterSchemaVersion( class GlobalSchemaVersion( - BaseSchemaVersion, so.InternalObject, so.GlobalObject + BaseSchemaVersion, + so.InternalObject, + so.GlobalObject, + sg_version.GlobalSchemaVersionMixin ): pass diff --git a/edb/tools/edb.py b/edb/tools/edb.py index 8898d46d3cb..8d94aa186fd 100644 --- a/edb/tools/edb.py +++ b/edb/tools/edb.py @@ -73,7 +73,7 @@ def server(version=False, **kwargs): from . import wipe # noqa from . import gen_test_dumps # noqa from . import gen_sql_introspection # noqa -from . import gen_schema_types # noqa +from . import gen_schema_mixins # noqa from . import gen_rust_ast # noqa from . import ast_inheritance_graph # noqa from . import parser_demo # noqa diff --git a/edb/tools/gen_schema_types.py b/edb/tools/gen_schema_mixins.py similarity index 60% rename from edb/tools/gen_schema_types.py rename to edb/tools/gen_schema_mixins.py index e11f9e4557e..2755621c907 100644 --- a/edb/tools/gen_schema_types.py +++ b/edb/tools/gen_schema_mixins.py @@ -9,7 +9,7 @@ from edb.tools.edb import edbcommands -@edbcommands.command("gen-schema-types") +@edbcommands.command("gen-schema-mixins") def main() -> None: for name, item in schema.__dict__.items(): @@ -31,31 +31,31 @@ def gen_for_module(mod_name: str, mod: types.ModuleType): fa = '{}.{}_fields'.format(cls.__module__, cls.__name__) my_fields = getattr(cls, fa) - if len(my_fields) == 0: - continue + # if len(my_fields) == 0: + # continue for field in my_fields.values(): - collect_imports(field.type, imports) - - for base in cls.__bases__: - collect_imports(base, imports) + imports.update(collect_imports(field.type, mod.__name__)) schema_object_classes.append(cls) if not schema_object_classes: return - f = open(f'edb/schema/{mod_name}.pyi', 'w') + f = open(f'edb/schema/generated/{mod_name}.py', 'w') f.write( textwrap.dedent( '''\ # DO NOT EDIT. This file was generated with: # - # $ gen-schema-types + # $ gen-schema-mixins """Type definitions for generated methods on schema classes""" - from edb import schema as s_schema + from typing import cast, TYPE_CHECKING + if TYPE_CHECKING: + from edb.schema import schema as s_schema + from edb.schema import orm as s_orm ''' ) ) @@ -68,43 +68,54 @@ def gen_for_module(mod_name: str, mod: types.ModuleType): f.write(f'import {parts[-1]}\n') for cls in schema_object_classes: - - bases = ','.join( - ('\n ' + codegen_ty(base) for base in cls.__bases__) - ) - - f.write(f'\nclass {cls.__name__}({bases}\n):\n') + f.write(f'\n\nclass {cls.__name__}Mixin:\n') fa = '{}.{}_fields'.format(cls.__module__, cls.__name__) my_fields = getattr(cls, fa) for field in my_fields.values(): - getter_name = f'get_{field.name}' + fn = field.name - ty = codegen_ty(field.type) + ty = codegen_ty(field.type, mod.__name__) f.write( '\n' - f' def {getter_name}(\n' - f' self, schema: s_schema.Schema\n' - f' ) -> {ty}: ...\n' + f' def get_{fn}(\n' + f' self, schema: \'s_schema.Schema\'\n' + f' ) -> \'{ty}\':\n' + f' val = s_orm.get_field_value(self, schema, \'{fn}\')\n' + f' return cast({ty}, val)\n' ) + if len(my_fields) == 0: + f.write(' pass\n') + -def collect_imports(ty: type, imports: typing.Set[str]): +def collect_imports(ty: type, current_module: str) -> typing.Set[str]: + r = set() + + if isinstance(ty, str): + r.add(current_module) + return r + if not isinstance(ty, type): - return + return r if ty.__module__ == 'builtins': - return + return r if typing_inspect.is_generic_type(ty): - imports.add(ty.__base__.__module__) + r.add(ty.__base__.__module__) for arg in ty.orig_args: - collect_imports(arg, imports) - return - imports.add(ty.__module__) + r.update(collect_imports(arg, current_module)) + return r + r.add(ty.__module__) + return r + +def codegen_ty(ty: type, current_module: str): + if isinstance(ty, str): + mod_name = current_module.split('.')[-1] + return f"{mod_name}.{ty}" -def codegen_ty(ty: type): if not isinstance(ty, type): return f'\'{ty}\'' @@ -117,7 +128,9 @@ def codegen_ty(ty: type): base_name = base_name.split('[')[0] base = f"{mod_name}.{base_name}" - args = ', '.join((codegen_ty(arg) for arg in ty.orig_args)) + args = ', '.join( + (codegen_ty(arg, current_module) for arg in ty.orig_args) + ) return f'{base}[{args}]' # base case