Skip to content

Commit

Permalink
Linting and Widgets (#11551)
Browse files Browse the repository at this point in the history
- Fix any issues identified by the doc writer.
- Alter all `default_widget` functions: all now take display and all use the type check signature.
- Review widgets on AWS APIs and make sure display is correct.
  • Loading branch information
jdunkerley authored Nov 14, 2024
1 parent 5b79f67 commit 7363377
Show file tree
Hide file tree
Showing 50 changed files with 111 additions and 118 deletions.
6 changes: 3 additions & 3 deletions distribution/lib/Standard/AWS/0.0.0-dev/src/AWS.enso
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type AWS
- region_service: The region and service to use for signing the request.
Defaults to the region and service parsed from the URI.
@uri (Text_Input display=..Always)
@format File_Format.default_widget
@headers Header.default_widget
@format File_Format.default_widget
@credentials AWS_Credential.default_widget
signed_fetch : URI -> HTTP_Method -> (Vector (Header | Pair Text Text)) -> File_Format -> AWS_Credential -> AWS_Region_Service -> Any
signed_fetch (uri:URI=(Missing_Argument.throw "uri")) (method:HTTP_Method=..Get) (headers:(Vector (Header | Pair Text Text))=[]) (format = Auto_Detect) credentials:AWS_Credential=..Default (region_service:AWS_Region_Service=(AWS.resolve_region_and_service uri)) = if_fetch_method method <|
Expand Down Expand Up @@ -71,10 +71,10 @@ type AWS
- region_service: The region and service to use for signing the request.
Defaults to the region and service parsed from the URI.
@uri (Text_Input display=..Always)
@format File_Format.default_widget
@headers Header.default_widget
@format File_Format.default_widget
@credentials AWS_Credential.default_widget
signed_post : (URI | Text) -> Request_Body -> HTTP_Method -> Vector (Header | Pair Text Text) -> Response ! Request_Error | HTTP_Error
signed_post : URI -> Request_Body -> HTTP_Method -> Vector (Header | Pair Text Text) -> Any -> AWS_Credential -> AWS_Region_Service -> Response ! Request_Error | HTTP_Error
signed_post (uri:URI=(Missing_Argument.throw "uri")) (body:Request_Body=..Empty) (method:HTTP_Method=..Post) (headers:(Vector (Header | Pair Text Text))=[]) (response_format = Auto_Detect) credentials:AWS_Credential=..Default (region_service:AWS_Region_Service=(AWS.resolve_region_and_service uri)) = if_post_method method <|
request = Request.new method uri (Header.unify_vector headers) body
http = with_hash_and_client HTTP.new hash_method=AWS.hash_bytes make_client=(_make_client credentials region_service)
Expand Down
13 changes: 7 additions & 6 deletions distribution/lib/Standard/AWS/0.0.0-dev/src/AWS_Credential.enso
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ type AWS_Credential

Arguments:
- profile: AWS profile name (if empty uses default).
@profile (make_single_choice AWS_Credential.profile_names)
@profile (make_single_choice AWS_Credential.profile_names display=..Always)
Profile profile:Text='default'

## Access using IAM via an AWS access key ID and secret access key.

Arguments:
- access_key_id: AWS access key ID.
- secret_access_key: AWS secret access key.
@access_key_id make_text_secret_selector
@secret_access_key make_text_secret_selector
@access_key_id (make_text_secret_selector display=..Always)
@secret_access_key (make_text_secret_selector display=..Always)
Key (access_key_id : (Text|Enso_Secret) = (Missing_Argument.throw "access_key_id")) (secret_access_key : (Text|Enso_Secret) = (Missing_Argument.throw "secret_access_key"))

## PRIVATE
Expand All @@ -40,7 +40,8 @@ type AWS_Credential
Default, Profile, Key.
- default_region: The default region to use for operations that may
require a region but it is not explicitly specified.
@default_region AWS_Region.default_widget
@base_credential (AWS_Credential.default_widget display=..Always)
@default_region (AWS_Region.default_widget display=..Always)
With_Configuration (base_credential : AWS_Credential) (default_region : AWS_Region)

## ICON cloud
Expand Down Expand Up @@ -68,8 +69,8 @@ type AWS_Credential
## ICON metadata
Sets the default region for operations that need it but do not specify it
explicitly.
@region AWS_Region.default_widget
with_default_region self (region : AWS_Region) -> AWS_Credential = case self of
@region (AWS_Region.default_widget display=..Always)
with_default_region self (region : AWS_Region = (Missing_Argument.throw "region")) -> AWS_Credential = case self of
AWS_Credential.With_Configuration base_credential _ ->
AWS_Credential.With_Configuration base_credential region
_ -> AWS_Credential.With_Configuration self region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type AWS_Region
Java_Region.regions.map .id

## PRIVATE
default_widget (display : Display = Display.When_Modified) -> Widget =
default_widget (display : Display = ..When_Modified) -> Widget =
options = [Option "Default" ("..Default")] + AWS_Region.all_region_ids.map id->
code = "(..Region "+id.pretty+")"
Option id code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from Standard.Table import Aggregate_Column, Value_Type
import Standard.Database.Connection.Connection.Connection
import Standard.Database.DB_Column.DB_Column
import Standard.Database.Dialect
import Standard.Database.Dialect_Flag.Dialect_Flag
import Standard.Database.Feature.Feature
import Standard.Database.Internal.Base_Generator
import Standard.Database.Internal.Column_Fetcher as Column_Fetcher_Module
Expand All @@ -24,7 +25,6 @@ import Standard.Database.Internal.Postgres.Postgres_Type_Mapping.Postgres_Type_M
import Standard.Database.Internal.SQL_Type_Mapping.SQL_Type_Mapping
import Standard.Database.Internal.SQL_Type_Reference.SQL_Type_Reference
import Standard.Database.Internal.Statement_Setter.Statement_Setter
import Standard.Database.Dialect_Flag.Dialect_Flag
import Standard.Database.SQL.SQL_Builder
import Standard.Database.SQL_Statement.SQL_Statement
import Standard.Database.SQL_Type.SQL_Type
Expand Down
2 changes: 1 addition & 1 deletion distribution/lib/Standard/AWS/0.0.0-dev/src/S3/S3.enso
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ get_object bucket key credentials:AWS_Credential=AWS_Credential.Default delimite
- If the object does not exist, an `S3_Key_Not_Found` error is thrown.
@credentials AWS_Credential.default_widget
head : Text -> Text -> AWS_Credential -> Dictionary Text Any ! S3_Error
head (bucket : Text = Missing_Argument.throw "bucket") key:Text="" credentials:AWS_Credential=AWS_Credential.Default =
head (bucket : Text = Missing_Argument.throw "bucket") key:Text="" credentials:AWS_Credential=..Default =
response = raw_head bucket key credentials
pairs = response.sdkFields.map f-> [f.memberName, f.getValueOrDefault response]
Dictionary.from_vector pairs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ type Base_64
## ICON convert
Converts a string to bytes using the specified encoding, and encodes that
to base64.
@encoding Encoding.default_widget
encode_text (text : Text) (encoding : Encoding = Encoding.utf_8) -> Text =
Base64.getEncoder.encodeToString (text.bytes encoding)

## ICON convert
Decodes a base64 encoded string, using the provided encoding.
@encoding Encoding.default_widget
decode_text (encoded_text : Text) (encoding : Encoding = Encoding.utf_8) -> Text ! Encoding_Error =
Text.from_bytes (Base64.getDecoder.decode encoded_text) encoding
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,8 @@ type Decimal

Decimal.parse "(123,456,789.654)" format="###,###.##;(###,###.##)"
# => -123456789.654
parse : Text -> Locale | Nothing -> Decimal ! Number_Parse_Error ! Illegal_Argument
parse text locale:Locale=Locale.default format:Text="" -> Decimal ! Number_Parse_Error ! Illegal_Argument =
parse : Text -> Locale -> Text -> Decimal ! Number_Parse_Error ! Illegal_Argument
parse text:Text locale:Locale=Locale.default format:Text="" -> Decimal ! Number_Parse_Error ! Illegal_Argument =
Illegal_Argument.handle_java_exception <|
# `getInstance` returns `DecimalFormat` or a subclass of `DecimalFormat`.
decimal_format = NumberFormat.getInstance locale.java_locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ type Filter_Condition

## PRIVATE
Creates a Single_Choice Widget for delimiters.
default_widget : Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Widget
default_widget include_comparable=True include_text=True include_boolean=True include_nullable=True include_numeric=True include_date=True include_time=True include_date_time=True =
default_widget include_comparable:Boolean=True include_text:Boolean=True include_boolean:Boolean=True include_nullable:Boolean=True include_numeric:Boolean=True include_date:Boolean=True include_time:Boolean=True include_date_time:Boolean=True display:Display=..When_Modified -> Widget =
options = Vector.build builder->
equatable_types = make_any_selector add_text=include_text add_boolean=include_boolean add_number=include_numeric add_date=include_date add_time=include_time add_date_time=include_date_time
builder.append (Option "Equals" "..Equal" [["to", equatable_types]])
Expand Down Expand Up @@ -297,7 +296,7 @@ type Filter_Condition
value_editor = Widget.Vector_Editor item_editor=equatable_types display=Display.Always item_default='""'
builder.append (Option "Is In" "..Is_In" [["values", value_editor]])

make_single_choice options
make_single_choice options display=display

## Specifies the action of a Filter_Condition.
type Filter_Action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ type Index_Sub_Range
[o1, o2, o4, o5, o6, o7, o3]

## PRIVATE
default_widget : (Integer|Nothing) -> Widget
default_widget count:(Integer|Nothing)=Nothing =
Single_Choice display=Display.Always (Index_Sub_Range.default_options count)
default_widget count:(Integer|Nothing)=Nothing display:Display=..Always -> Widget =
Single_Choice display=display (Index_Sub_Range.default_options count)

## PRIVATE
Resolves a vector of ranges or indices into a vector of ranges that fit
Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Locale.enso
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ type Locale

## PRIVATE
Gets the default drop down option for Locale.
default_widget : Widget
default_widget = Widget.Single_Choice values=Locale.widget_options display=Display.When_Modified
default_widget display:Display=..When_Modified -> Widget =
Widget.Single_Choice values=Locale.widget_options display=display

## PRIVATE
predefined_locale_fields : Vector Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,8 @@ type Float

Float.parse "(123,456,789.654)" format="###,###.##;(###,###.##)"
# => -123456789.654
parse : Text -> Locale | Nothing -> Float ! Number_Parse_Error ! Illegal_Argument
parse text (locale : Locale | Nothing = Nothing) (format : Text | Nothing = Nothing) -> Float ! Number_Parse_Error ! Illegal_Argument =
parse : Text -> Locale | Nothing -> Text | Nothing -> Float ! Number_Parse_Error ! Illegal_Argument
parse text:Text (locale : Locale | Nothing = Nothing) (format : Text | Nothing = Nothing) -> Float ! Number_Parse_Error ! Illegal_Argument =
case locale.is_nothing && format.is_nothing of
True ->
Panic.catch NumberFormatException (Double.parseDouble text) _->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import project.Any.Any
import project.Data.Text.Text
import project.Data.Read.Many_Files_List.Many_Files_List
import project.Data.Text.Text
import project.Data.Vector.Vector
import project.Error.Error
import project.Errors.Common.Type_Error
Expand Down Expand Up @@ -49,10 +49,9 @@ type Return_As
_ -> Panic.throw (Type_Error.Error Return_As value "Expected `return` to be a Return_As type, but got {got}.")

## PRIVATE
default_widget : Widget
default_widget =
default_widget display:Display=..When_Modified -> Widget =
options = _get_known_return_classes.map .get_dropdown_options
Single_Choice display=Display.Always values=options
Single_Choice display=display values=options

## PRIVATE
type Return_As_Base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ polyglot java import org.enso.base.Text_Utils
## Represents a character encoding.
type Encoding
## PRIVATE
Gets the default drop down option for this encoding.
default_widget : Widget
default_widget =
Gets the default drop down option for Encoding.
default_widget display:Display=..When_Modified -> Widget =
fqn = Meta.get_qualified_type_name Encoding
values = [Option "UTF-8" fqn+".utf_8", Option "ASCII" fqn+".ascii", Option "UTF-16LE" fqn+".utf_16_le", Option "UTF-16BE" fqn+".utf_16_be", Option "UTF-32LE" fqn+".utf_32_le", Option "UTF-32BE" fqn+".utf_32_be", Option "Windows-1250" fqn+".windows_1250", Option "Windows-1251" fqn+".windows_1251", Option "Windows-1252" fqn+".windows_1252", Option "Windows-1253" fqn+".windows_1253", Option "Windows-1254" fqn+".windows_1254", Option "Windows-1255" fqn+".windows_1255", Option "Windows-1256" fqn+".windows_1256", Option "Windows-1257" fqn+".windows_1257", Option "Windows-1258" fqn+".windows_1258"]
Single_Choice values=values display=Display.When_Modified
Single_Choice values=values display=display

## PRIVATE
ADVANCED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Text.find_all self pattern:Text|Regex=".*" case_sensitivity:Case_Sensitivity=..S
# Evaluates to true
"CONTACT@enso.org".match regex Case_Sensitivity.Insensitive
Text.match : Text|Regex -> Case_Sensitivity -> Boolean ! Regex_Syntax_Error | Illegal_Argument
Text.match self pattern:Text|Regex=".*" case_sensitivity:Case_Sensitivity=..Sensitive -> Boolean =
Text.match self pattern:Text|Regex=".*" case_sensitivity:Case_Sensitivity=..Sensitive -> Boolean ! Regex_Syntax_Error | Illegal_Argument =
case_insensitive = case_sensitivity.is_case_insensitive_in_memory
compiled_pattern = Regex.compile pattern case_insensitive=case_insensitive
compiled_pattern.matches self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ type Text_Sub_Range
The widget for `Text_Sub_Range` also displays options for
`Index_Sub_Range` since the former is supposed to 'expand' the latter and
is always used together with it.
default_widget : Widget
default_widget =
default_widget display:Display=..When_Modified -> Widget =
options = Index_Sub_Range.default_options + Text_Sub_Range.default_options
Single_Choice display=Display.Always options
Single_Choice display=display options

type Codepoint_Ranges
## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,9 @@ type Date

## PRIVATE
Gets the default drop down option for Date.
default_widget : Boolean -> Widget
default_widget (include_today:Boolean=False) =
default_widget (include_today:Boolean=False) display:Display=..When_Modified -> Widget =
options = [Option "<Fixed Date>" "Date.new"] + (if include_today then [Option "<Today>" "Date.today"] else [])
Widget.Single_Choice values=options display=Display.When_Modified
Widget.Single_Choice values=options display=display

## PRIVATE
week_days_between start end =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,9 @@ type Time_Of_Day

## PRIVATE
Gets the default drop down option for Time_Of_Day.
default_widget : Boolean -> Widget
default_widget (include_now:Boolean=False) =
default_widget (include_now:Boolean=False) display:Display=..When_Modified -> Widget =
options = [Option "<Fixed Time>" "Time_Of_Day.new"] + (if include_now then [Option "<Now>" "Time_Of_Day.now"] else [])
Widget.Single_Choice values=options display=Display.When_Modified
Widget.Single_Choice values=options display=display

## PRIVATE
Time_Of_Day.from (that:JS_Object) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,9 @@ type Time_Zone

## PRIVATE
Gets the default drop down option for Time_Zone.
default_widget : Widget
default_widget =
default_widget display:Display=..When_Modified -> Widget =
options = [Option "System" "Time_Zone.system", Option "Local" "Time_Zone.local", Option "UTC" "Time_Zone.utc", Option "Named" "(Time_Zone.parse 'UTC')", Option "custom" "(Time_Zone.new 1 0 0)"]
Widget.Single_Choice values=options display=Display.When_Modified
Widget.Single_Choice values=options display=display

## ICON time
Gets a list of all the time zone names that are predefined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ type Map_Error
Indicates that a method should not wrap thrown errors in `Map_Error`.
@Builtin_Type
type No_Wrap
## PRIVATE
Value

## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ type Enso_File
Arguments:
- name: The name of the label to create.
- color: The color of the label to create.
create_label : Text -> Text -> Nothing
create_label : Text -> Color -> Nothing
create_label (name : Text) (color : Color) -> Nothing =
# TODO once cloud also checks for tag existance, if the Write context is enabled we could avoid this check as cloud will do it anyway - then we'll have only one request instead of 2 each time
# Cloud ticket: https://github.com/enso-org/cloud-v2/issues/1544
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Enso_Secret
private Value internal_name:Text id:Text internal_path:Enso_Path

## GROUP Metadata
ICON metadata
The name of the secret.
ICON metadata
The name of the secret.
name : Text
name self = self.internal_name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import project.Runtime.Context
from project.Data.Boolean import Boolean, False, True
from project.Data.Text.Extensions import all
from project.Enso_Cloud.Data_Link_Helpers import data_link_extension
from project.Enso_Cloud.Public_Utils import get_required_field, get_optional_field
from project.Enso_Cloud.Public_Utils import get_optional_field, get_required_field

## PRIVATE
Currently, most of the Cloud API relies on asset IDs and not paths.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ from project.Data.Boolean import Boolean, False, True
polyglot java import java.lang.ArithmeticException
polyglot java import java.lang.ClassCastException
polyglot java import java.lang.OutOfMemoryError
polyglot java import org.enso.base.CompareException
polyglot java import org.enso.base.cache.ResponseTooLargeException
polyglot java import org.enso.base.CompareException

## An error indicating that no value was found.
type Not_Found
Expand Down
3 changes: 1 addition & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Metadata.enso
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ type Widget
JS_Object.from_pairs (type_pair + cons_pair + field_pairs)

## PRIVATE
make_single_choice : Vector -> Display -> Widget
make_single_choice values display:Display=..Always =
make_single_choice values:Vector display:Display=..Always -> Widget =
make_option value = case value of
_ : Vector -> Choice.Option value.first value.second
_ : Text -> Choice.Option value value.pretty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ from project.Data.Boolean import Boolean, False, True
from project.Data.Json.Extensions import all
from project.Data.Text.Extensions import all

polyglot java import java.lang.IllegalArgumentException
polyglot java import java.io.IOException
polyglot java import java.lang.IllegalArgumentException
polyglot java import java.net.http.HttpClient
polyglot java import java.net.http.HttpClient.Builder as ClientBuilder
polyglot java import java.net.http.HttpClient.Redirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Cache_Policy
## Don't use the response cache.
No_Cache

# Default to using the cache for GET requests, unless explicitly disabled
## Default to using the cache for GET requests, unless explicitly disabled
should_use_cache self request:Request -> Boolean = case self of
Cache_Policy.Default -> if request.method == HTTP_Method.Get then True else False
Cache_Policy.Use_Cache -> True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ type File_Format
format_types.flat_map .get_name_patterns . flat_map .patterns . distinct

## PRIVATE
default_widget : Widget
default_widget =
default_widget display:Display=..When_Modified -> Widget =
options = ([Auto_Detect]+format_types).flat_map .get_dropdown_options
Single_Choice display=Display.Always values=options
Single_Choice display=display values=options

## PRIVATE
Builds a widget intended to be used for `name_filter` of `File.list` and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ from project.Metadata.Choice import Option

## PRIVATE
Creates a Single_Choice Widget for text or secret value.
make_text_secret_selector : Widget
make_text_secret_selector =
make_text_secret_selector display:Display=..When_Modified -> Widget =
fqn = Meta.get_qualified_type_name Enso_Secret
make_single_choice [['<Text Value>', '""'], ['<Secret Value>', fqn+".get"]]
make_single_choice [['<Text Value>', '""'], ['<Secret Value>', fqn+".get"]] display=display

## PRIVATE
Creates a Regex / Text Widget for search and replace.
Expand Down
Loading

0 comments on commit 7363377

Please sign in to comment.