diff --git a/src/EdgeDB.Net.QueryBuilder/EdgeQL.g.cs b/src/EdgeDB.Net.QueryBuilder/EdgeQL.g.cs index 6f9e63d..e8babbf 100644 --- a/src/EdgeDB.Net.QueryBuilder/EdgeQL.g.cs +++ b/src/EdgeDB.Net.QueryBuilder/EdgeQL.g.cs @@ -43,7 +43,7 @@ public static IEnumerable AssertDistinct(IEnumerable input, /// Return the element of *array* at the specified *index*. /// [EdgeQLFunction("array_get", "std", "anytype", false, true)] - public static TType? ArrayGet(IEnumerable array, Int64 idx, TType? @default = default) + public static TType? ArrayGet(IEnumerable array, Int64 idx, TType? @default) => default!; /// /// Return array elements as a set. @@ -52,16 +52,16 @@ public static IEnumerable AssertDistinct(IEnumerable input, public static IEnumerable ArrayUnpack(IEnumerable array) => default!; [EdgeQLFunction("DISTINCT", "std", "anytype", true, false)] - public static IEnumerable Distinct(IEnumerable s = default) + public static IEnumerable Distinct(IEnumerable s) => default!; [EdgeQLFunction("UNION", "std", "anytype", true, false)] - public static IEnumerable Union(IEnumerable s1 = default, IEnumerable s2 = default) + public static IEnumerable Union(IEnumerable s1, IEnumerable s2) => default!; [EdgeQLFunction("EXCEPT", "std", "anytype", true, false)] - public static IEnumerable Except(IEnumerable s1 = default, IEnumerable s2 = default) + public static IEnumerable Except(IEnumerable s1, IEnumerable s2) => default!; [EdgeQLFunction("INTERSECT", "std", "anytype", true, false)] - public static IEnumerable Intersect(IEnumerable s1 = default, IEnumerable s2 = default) + public static IEnumerable Intersect(IEnumerable s1, IEnumerable s2) => default!; /// /// Assert that a boolean value is true. @@ -158,25 +158,25 @@ public static Boolean Contains(Range haystack, DateOnly needle) public static Boolean Contains(MultiRange haystack, DateOnly needle) => default!; [EdgeQLFunction("IN", "std", "std::bool", false, false)] - public static Boolean In(TType e = default, IEnumerable s = default) + public static Boolean In(TType e, IEnumerable s) => default!; [EdgeQLFunction("NOT IN", "std", "std::bool", false, false)] - public static Boolean NotIn(TType e = default, IEnumerable s = default) + public static Boolean NotIn(TType e, IEnumerable s) => default!; [EdgeQLFunction("EXISTS", "std", "std::bool", false, false)] - public static Boolean Exists(IEnumerable s = default) + public static Boolean Exists(IEnumerable s) => default!; [EdgeQLFunction("LIKE", "std", "std::bool", false, false)] - public static Boolean Like(String str = null, String pattern = null) + public static Boolean Like(String str, String pattern) => default!; [EdgeQLFunction("ILIKE", "std", "std::bool", false, false)] - public static Boolean ILike(String str = null, String pattern = null) + public static Boolean ILike(String str, String pattern) => default!; [EdgeQLFunction("NOT LIKE", "std", "std::bool", false, false)] - public static Boolean NotLike(String str = null, String pattern = null) + public static Boolean NotLike(String str, String pattern) => default!; [EdgeQLFunction("NOT ILIKE", "std", "std::bool", false, false)] - public static Boolean NotILike(String str = null, String pattern = null) + public static Boolean NotILike(String str, String pattern) => default!; /// /// A polymorphic function to calculate a "length" of its first argument. @@ -293,7 +293,7 @@ public static Int64 SequenceReset(Type seq, Int64 value) /// Create a `int64` value. /// [EdgeQLFunction("to_int64", "std", "std::int64", false, false)] - public static Int64 ToInt64(String s, String? fmt = null) + public static Int64 ToInt64(String s, String? fmt) => default!; [EdgeQLFunction("sequence_reset", "std", "std::int64", false, false)] public static Int64 SequenceReset(Type seq) @@ -329,7 +329,7 @@ public static BigInteger Round(BigInteger val) /// Create a `bigint` value. /// [EdgeQLFunction("to_bigint", "std", "std::bigint", false, false)] - public static BigInteger ToBigint(String s, String? fmt = null) + public static BigInteger ToBigint(String s, String? fmt) => default!; /// /// Round up to the nearest integer. @@ -374,7 +374,7 @@ public static IEnumerable RangeUnpack(Range val, Decimal step) /// Create a `decimal` value. /// [EdgeQLFunction("to_decimal", "std", "std::decimal", false, false)] - public static Decimal ToDecimal(String s, String? fmt = null) + public static Decimal ToDecimal(String s, String? fmt) => default!; /// /// Round up to the nearest integer. @@ -455,7 +455,7 @@ public static IEnumerable RangeUnpack(Range val, Single step) /// Create a `float32` value. /// [EdgeQLFunction("to_float32", "std", "std::float32", false, false)] - public static Single ToFloat32(String s, String? fmt = null) + public static Single ToFloat32(String s, String? fmt) => default!; /// /// Return the sum of the set of numbers. @@ -494,7 +494,7 @@ public static IEnumerable RangeUnpack(Range val, Double step) /// Create a `float64` value. /// [EdgeQLFunction("to_float64", "std", "std::float64", false, false)] - public static Double ToFloat64(String s, String? fmt = null) + public static Double ToFloat64(String s, String? fmt) => default!; /// /// Round up to the nearest integer. @@ -752,37 +752,37 @@ public static String StrReverse(String s) /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(DateTimeOffset dt, String? fmt = null) + public static String ToStr(DateTimeOffset dt, String? fmt) => default!; /// /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(TimeSpan td, String? fmt = null) + public static String ToStr(TimeSpan td, String? fmt) => default!; /// /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(Int64 i, String? fmt = null) + public static String ToStr(Int64 i, String? fmt) => default!; /// /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(Double f, String? fmt = null) + public static String ToStr(Double f, String? fmt) => default!; /// /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(BigInteger d, String? fmt = null) + public static String ToStr(BigInteger d, String? fmt) => default!; /// /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(Decimal d, String? fmt = null) + public static String ToStr(Decimal d, String? fmt) => default!; /// /// Return string representation of the input value. @@ -794,7 +794,7 @@ public static String ToStr(IEnumerable array, String delimiter) /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(Json json, String? fmt = null) + public static String ToStr(Json json, String? fmt) => default!; /// /// Convert a binary UTF-8 string to a text value. @@ -824,13 +824,13 @@ public static String GetCurrentDatabase() /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(DateTime dt, String? fmt = null) + public static String ToStr(DateTime dt, String? fmt) => default!; /// /// Return string representation of the input value. /// [EdgeQLFunction("to_str", "std", "std::str", false, false)] - public static String ToStr(DateOnly d, String? fmt = null) + public static String ToStr(DateOnly d, String? fmt) => default!; /// /// Encode given data as a base64 string @@ -839,7 +839,7 @@ public static String ToStr(DateOnly d, String? fmt = null) public static String Base64Encode(Byte[] data, Base64Alphabet alphabet = Base64Alphabet.standard, Boolean padding = true) => default!; [EdgeQLFunction("CONCAT", "std", "std::str", false, false)] - public static String Concat(String l = null, String r = null) + public static String Concat(String l, String r) => default!; /// /// Return the smallest value of the input set. @@ -884,7 +884,7 @@ public static IEnumerable RangeUnpack(Range val, /// Create a `datetime` value. /// [EdgeQLFunction("to_datetime", "std", "std::datetime", false, false)] - public static DateTimeOffset ToDatetime(String s, String? fmt = null) + public static DateTimeOffset ToDatetime(String s, String? fmt) => default!; /// /// Create a `datetime` value. @@ -1004,7 +1004,7 @@ public static Int16 BitLshift(Int16 val, Int64 n) /// Create a `int16` value. /// [EdgeQLFunction("to_int16", "std", "std::int16", false, false)] - public static Int16 ToInt16(String s, String? fmt = null) + public static Int16 ToInt16(String s, String? fmt) => default!; /// /// Bitwise AND operator for 32-bit integers. @@ -1052,7 +1052,7 @@ public static IEnumerable RangeUnpack(Range val, Int32 step) /// Create a `int32` value. /// [EdgeQLFunction("to_int32", "std", "std::int32", false, false)] - public static Int32 ToInt32(String s, String? fmt = null) + public static Int32 ToInt32(String s, String? fmt) => default!; /// /// Return the array made from all of the input set elements. @@ -1142,13 +1142,13 @@ public static Json JsonObjectPack(IEnumerable> pairs) /// Return the JSON value at the end of the specified path or an empty set. /// [EdgeQLFunction("json_get", "std", "std::json", false, true)] - public static Json? JsonGet(Json json, IEnumerable path, Json? @default = default) + public static Json? JsonGet(Json json, IEnumerable path, Json? @default) => default!; /// /// Return an updated JSON target with a new value. /// [EdgeQLFunction("json_set", "std", "std::json", false, true)] - public static Json? JsonSet(Json target, IEnumerable path, Json? value = default, Boolean create_if_missing = true, JsonEmpty empty_treatment = JsonEmpty.ReturnEmpty) + public static Json? JsonSet(Json target, IEnumerable path, Json? value, Boolean create_if_missing = true, JsonEmpty empty_treatment = JsonEmpty.ReturnEmpty) => default!; /// /// Return JSON value represented by the input *string*. @@ -1157,10 +1157,10 @@ public static Json JsonObjectPack(IEnumerable> pairs) public static Json ToJson(String str) => default!; [EdgeQLFunction("get_config_json", "cfg", "std::json", false, false)] - public static Json GetConfigJson(IEnumerable? sources = null, String? max_source = null) + public static Json GetConfigJson(IEnumerable? sources, String? max_source) => default!; [EdgeQLFunction("CONCAT", "std", "std::json", false, false)] - public static Json Concat(Json l = default, Json r = default) + public static Json Concat(Json l, Json r) => default!; /// /// Return a version 1 UUID. @@ -1175,7 +1175,7 @@ public static Guid UuidGenerateV1mc() public static Guid UuidGenerateV4() => default!; [EdgeQLFunction("range", "std", "range", false, false)] - public static Range Range(TPoint? lower = default, TPoint? upper = default, Boolean inc_lower = true, Boolean inc_upper = false, Boolean empty = false) + public static Range Range(TPoint? lower, TPoint? upper, Boolean inc_lower = true, Boolean inc_upper = false, Boolean empty = false) where TPoint : struct => default!; [EdgeQLFunction("multirange_unpack", "std", "range", true, false)] @@ -1227,7 +1227,7 @@ public static Byte[] ToBytes(String s) public static Byte[] Base64Decode(String data, Base64Alphabet alphabet = Base64Alphabet.standard, Boolean padding = true) => default!; [EdgeQLFunction("CONCAT", "std", "std::bytes", false, false)] - public static Byte[] Concat(Byte[] l = null, Byte[] r = null) + public static Byte[] Concat(Byte[] l, Byte[] r) => default!; /// /// Return the isolation level of the current transaction. @@ -1239,7 +1239,7 @@ public static TransactionIsolation GetTransactionIsolation() /// Create a `cal::local_datetime` value. /// [EdgeQLFunction("to_local_datetime", "cal", "cal::local_datetime", false, false)] - public static DateTime ToLocalDatetime(String s, String? fmt = null) + public static DateTime ToLocalDatetime(String s, String? fmt) => default!; /// /// Create a `cal::local_datetime` value. @@ -1272,7 +1272,7 @@ public static IEnumerable RangeUnpack(Range val, TimeSpan st /// Create a `cal::local_date` value. /// [EdgeQLFunction("to_local_date", "cal", "cal::local_date", false, false)] - public static DateOnly ToLocalDate(String s, String? fmt = null) + public static DateOnly ToLocalDate(String s, String? fmt) => default!; /// /// Create a `cal::local_date` value. @@ -1308,7 +1308,7 @@ public static IEnumerable RangeUnpack(Range val, TimeSpan st /// Create a `cal::local_time` value. /// [EdgeQLFunction("to_local_time", "cal", "cal::local_time", false, false)] - public static TimeSpan ToLocalTime(String s, String? fmt = null) + public static TimeSpan ToLocalTime(String s, String? fmt) => default!; /// /// Create a `cal::local_time` value. diff --git a/tools/EdgeDB.QueryBuilder.StandardLibGenerator/FunctionGenerator.cs b/tools/EdgeDB.QueryBuilder.StandardLibGenerator/FunctionGenerator.cs index b598fdd..59e93a5 100644 --- a/tools/EdgeDB.QueryBuilder.StandardLibGenerator/FunctionGenerator.cs +++ b/tools/EdgeDB.QueryBuilder.StandardLibGenerator/FunctionGenerator.cs @@ -80,7 +80,7 @@ private class ParsedParameter public string? Type { get; init; } public string[] Generics { get; set; } = Array.Empty(); public List GenericConditions { get; set; } = new(); - public string? DefaultValue { get; set; } = "{}"; + public string? DefaultValue { get; set; } public bool Optional { get; set; } } @@ -361,7 +361,9 @@ await TypeUtils.BuildType(_client!, node, TypeModifier.SingletonType, StdLibOutp parsedParameters[i] = await ParseParameter(name, info, x.Parameter.Type!, x.Parameter.TypeModifier, i); - if (!string.IsNullOrEmpty(x.Parameter.Default) && x.Parameter.Default != "{}") + if (parsedParameters[i].Optional) + parsedParameters[i].DefaultValue = "{}"; + else if (!string.IsNullOrEmpty(x.Parameter.Default)) parsedParameters[i].DefaultValue = await ParseDefaultAsync(x.Parameter.Default, info); } @@ -515,6 +517,9 @@ private static async ValueTask ParseParameter(string? name, Typ private static async Task ParseDefaultAsync(string @default, TypeNode node) { + if (@default == "{}") + return "null"; + var result = await _client!.QuerySingleAsync($"select {@default}"); return result switch {