@haxall/haxall
    Preparing search index...

    Class Etc

    Etc is the utility methods for Haystack.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

    • Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:

      this < that   =>  <0
      this == that => 0
      this > that => >0

      This method may also be accessed via the < <= <=> >= and > shortcut operators. If not overridden the default implementation compares the toStr representations. Also see docLang.

      Examples:

      3.compare(8)  =>  -1
      8.compare(3) => 1
      8.compare(8) => 0
      3 <=> 8 => -1 // shortcut for 3.compare(8)

      Parameters

      Returns number

    • Compare this object to the specified for equality. This method may be accessed via the == and != shortcut operators. If not overridden the default implementation compares for reference equality using the === operator. If this method is overridden, then hash() must also be overridden such that any two objects which return true for equals() must return the same value for hash(). This method must accept null and return false.

      Parameters

      Returns boolean

    • Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.

      Returns number

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • Return a string representation of this object.

      Returns string

    • Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:

      a->x        a.trap("x", null)
      a->x() a.trap("x", null)
      a->x = b a.trap("x", [b])
      a->x(b) a.trap("x", [b])
      a->x(b, c) a.trap("x", [b, c])

      The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Parameters

      Returns void

    • Given two display strings, return 1, 0, or -1 if a is less than, equal to, or greater than b. The comparison is case insensitive and takes into account trailing digits so that a dis str such as "Foo-10" is greater than "Foo-2".

      Parameters

      • a: string
      • b: string

      Returns number

    • Empty dict singleton

      Returns Dict

    • Create a Dict with one name/value pair

      Parameters

      Returns Dict

    • Create a Dict with two name/value pairs

      Parameters

      Returns Dict

    • Create a Dict with three name/value pairs

      Parameters

      Returns Dict

    • Create a Dict with four name/value pairs

      Parameters

      Returns Dict

    • Create a Dict with five name/value pairs

      Parameters

      Returns Dict

    • Create a Dict with six name/value pairs

      Parameters

      Returns Dict

    • Return if all of the tag name/value pairs match the given function.

      Parameters

      • d: Dict
      • f: (arg0: JsObj, arg1: string) => boolean

      Returns boolean

    • Return if any of the tag name/value pairs match the given function.

      Parameters

      • d: Dict
      • f: (arg0: JsObj, arg1: string) => boolean

      Returns boolean

    • Return if two dicts are equal with same name/value pairs. Value are compared via the sys::Obj.equals method. Ordering of the dict tags is not considered.

      Parameters

      Returns boolean

    • Return a new Dict containing the name/value pairs for which f returns true. If f returns false for every pair, then return an empty Dict.

      Parameters

      • d: Dict
      • f: (arg0: JsObj, arg1: string) => boolean

      Returns Dict

    • Construct an object which wraps a dict and is suitable to use for a hash key in a sys::Map. The key provides implementations of sys::Obj.hash and sys::Obj.equals based on the the name/value pairs in the dict. Hash keys do not support Dicts which contain anything but scalar values (nested lists, dicts, and grids are silently ignored for hash/equality purposes).

      Parameters

      Returns JsObj

    • Apply the given map function to each name/value pair to construct a new Dict. NOTE: use Dict.map now

      Parameters

      Returns Dict

    • Add/set all the name/value pairs in a with those defined in b. If b defines a remove value then that name/value is removed from a. The b parameter may be any value accepted by makeDict

      Parameters

      Returns Dict

    • Get a read/write list of the dict's name keys.

      Parameters

      Returns List<string>

    • Remove a name/val pair from an exisiting dict, or if the name isn't found then return original dict.

      Parameters

      Returns Dict

    • Remove all names from the given dict. Ignore any name not defined as a tag.

      Parameters

      Returns Dict

    • Rename given name if its defined in the dict, otherwise return original.

      Parameters

      • d: Dict
      • oldName: string
      • newName: string

      Returns Dict

    • Set a name/val pair in an existing dict or d is null then create a new dict with given name/val pair.

      Parameters

      Returns Dict

    • Given a list of dictionaries, find all the common names used. Return the names in standard sorted order. Any null dicts are skipped.

      Parameters

      Returns List<string>

    • Given a dict, attempt to find the best display string:

      1. dis tag
      2. disMacro tag returns macro using dict as scope
      3. disKey maps to qname locale key
      4. name tag
      5. tag tag
      6. id tag
      7. default

      Parameters

      • dict: Dict
      • Optionaldef: string

      Returns string

    • Coerce dict to Haystack types, see toHaystack.

      Parameters

      Returns Dict

    • Convert a Dict to a read/write map. This method is expensive, when possible you should instead use Dict.each.

      Parameters

      Returns Map<string, JsObj>

    • Get all the non-null values mapped by a dictionary.

      Parameters

      Returns List<JsObj>

    • Iterate a discrete period string formatted in base64. Call the iterator function for each period where time is offset in minutes from base timestamp and dur is duration of period in minutes (assuming a minutely interval). This method may also be used discreteEnumPeriods() in which case the dur parameter will be the enum ordinal.

      Parameters

      • str: string
      • f: (arg0: number, arg1: number) => void

      Returns void

    • Write x.toStr to standard output followed by newline. If x is null then print "null". If no argument is provided then print an empty line.

      Parameters

      Returns void

    • Get the emtpy Dict instance.

      Returns Dict

    • Escape tag name into "__{utf-8 hex}" format

      Parameters

      • n: string

      Returns string

    • Flatten a list of grids into a single grid. Each grid's rows are appended to a single grid in the order passed. The resulting grid columns will be the intersection of all the individual grid columns. Grid meta and column merged together.

      Parameters

      Returns Grid

    • Return if tag name starts with "__" as escaped name

      Parameters

      • n: string

      Returns boolean

    • Return if the given string is a legal kind name:

      • first char must be ASCII upper case letter: a - z
      • rest of chars must be ASCII letter or digit: a - z, A - Z, 0
        • 9, or _

      Parameters

      • n: string

      Returns boolean

    • Return if the given string is a legal tag name:

      • first char must be ASCII lower case letter or underbar: a - z or _
      • rest of chars must be ASCII letter,digit, or underbar: a - z, A - Z, 0 - 9, or _
      • if first char is underbar, then it must have a at least one additional alpha-num character
      • or if first two chars are underbar, then must be followed by a hexdecimal characters for a UTF-8 encoded string

      Parameters

      • n: string

      Returns boolean

    • Process macro pattern with given scope of variable name/value pairs. The pattern is a Unicode string with embedded expressions:

      • $tag: resolve tag name from scope, variable name ends with first non-tag character, see Etc.isTagName
      • ${tag}: resolve tag name from scope
      • $<pod::key>: localization key

      Any variables which cannot be resolved in the scope are returned as-is (such $name) in the result string.

      If a tag resolves to Ref, then we use Ref.dis for string.

      Parameters

      • pattern: string
      • scope: Dict

      Returns string

    • Return the list of variable tag names used in the given macro pattern. This includes "$tag" and "${tag}" variables, but does not include "$pod::key" localization keys.

      Parameters

      • pattern: string

      Returns List<string>

    • Parameters

      • ...args: unknown[]

      Returns Etc

    • Make a Dict instance where val is one of the following:

      • Dict: return val
      • null: return emptyDict
      • Str:Obj?: wrap map as Dict
      • Str[]: dictionary of key/Marker value pairs

      Parameters

      Returns Dict

    • Make a Dict with one name/value pair. Backward compatibility only for nullable values, use dict1 now.

      Parameters

      Returns Dict

    • Make a Dict with two name/value pairs. Backward compatibility only for nullable values, use dict2 now.

      Parameters

      Returns Dict

    • Make a Dict with three name/value pairs. Backward compatibility only for nullable values, use dict3 now.

      Parameters

      Returns Dict

    • Make a Dict with four name/value pairs. Backward compatibility only for nullable values, use dict4 now.

      Parameters

      Returns Dict

    • Make a Dict with five name/value pairs. Backward compatibility only for nullable values, use dict5 now.

      Parameters

      Returns Dict

    • Make a Dict with six name/value pairs. Backward compatibility only for nullable values, use dict6 now.

      Parameters

      Returns Dict

    • Construct a grid for a Dict row. The meta parameter can be any makeDict value.

      Parameters

      Returns Grid

    • Make a list of Dict instances using makeDict.

      Parameters

      Returns List<Dict>

    • Construct a grid for a list of Dict rows. The meta parameter can be any makeDict value. Any null dicts result in an empty row of all nulls. If no non-null rows, then return makeEmptyGrid.

      Parameters

      Returns Grid

    • Construct an empty grid with just the given grid level meta-data. The meta parameter can be any makeDict value.

      Parameters

      Returns Grid

    • Construct a grid for an error response.

      Parameters

      Returns Grid

    • Construct a grid with one column for a list. The meta and colMeta parameters can be any makeDict value.

      Parameters

      Returns Grid

    • Construct a grid for a list of rows, where each row is a list of cells. The meta and colMetas parameters can be any makeDict value.

      Parameters

      Returns Grid

    • Get a relative display name. If the child display name starts with the parent, then we can strip that as the common suffix.

      Parameters

      • parent: string
      • child: string

      Returns string

    • Get the localized string for the given tag name for the current locale. See docSkySpark::Localization#tags.

      Parameters

      • name: string

      Returns string

    • Coerce an object to a DateSpan:

      • Func: function which evaluates to date range (must be run in a context)
      • DateSpan: return itself
      • Date: one day range
      • Span: return haystack::Span.toDateSpan
      • Str: evaluates to haystack::DateSpan.fromStr
      • Date..Date: starting and ending date (inclusive)
      • Date..Number: starting date and num of days (day unit required)
      • DateTime..DateTime: use starting/ending dates; if end is midnight, then use previous date
      • Number: convert as year

      Parameters

      Returns DateSpan

    • Map an exception to its standard tags:

      • dis: error display string
      • err: marker
      • errTrace: Str stack dump
      • axonTrace: Axon stack dump (if applicable)
      • errType: exception type qname

      Parameters

      Returns Dict

    • Coerce a value to a Grid:

      • if grid just return it
      • if row in grid of size, return row.grid
      • if scalar return 1x1 grid
      • if dict return grid where dict is only
      • if list of dict return grid where each dict is row
      • if list of non-dicts, return one col grid with rows for each item
      • if non-zinc type return grid with cols val, type

      Parameters

      Returns Grid

    • Coerce a value to one of the Haystack types. Recursively coerce dicts and lists. This method does not support grids. Options:

      • checked: marker to throw err for non-haystack values; coerce otherwise

      Parameters

      Returns JsObj

    • Coerce a value to a Ref identifier:

      • Ref returns itself
      • Row or Dict, return id tag
      • Grid return first row id

      Parameters

      Returns Ref

    • Coerce a value to a list of Ref identifiers:

      • Ref returns itself as list of one
      • Ref[] returns itself
      • Dict return id tag
      • Dict[] return id tags
      • Grid return id column

      Parameters

      Returns List<Ref>

    • Coerce a value to a record Dict:

      • Row or Dict returns itself
      • Grid returns first row (must have at least one row)
      • List returns first item (must have at least one item which is Ref or Dict)
      • Ref will make a call to read database (must be run in a context)

      Parameters

      Returns Dict

    • Coerce a value to a list of record Dicts:

      • null return empty list
      • Ref or Ref[] will read database (must be run in a context)
      • Row or Row[] returns itself
      • Dict or Dict[] returns itself
      • Grid is mapped to list of rows

      Parameters

      Returns List<Dict>

    • Coerce an object to a Span with optional timezone:

      • Span: return itself
      • Span+tz: update timezone using same dates only if aligned to midnight
      • Str: return haystack::Span.fromStr using current timezone
      • Str+tz: return haystack::Span.fromStr using given timezone
      • DateTime..DateTime: range of two DateTimes
      • Date..DateTime: start day for date until the end timestamp
      • DateTime..Date: start timestamp to end of day for end date
      • DateTime: span of a single timestamp
      • DateSpan: anything accepted by toDateSpan in current timezone
      • DateSpan+tz: anything accepted by toDateSpan using given timezone

      Parameters

      Returns Span

    • Take an arbitrary string and convert into a safe tag name. Do not assume any specific conversion algorithm as it might change in the future. The empty string is not supported.

      Parameters

      • n: string

      Returns string

    • Unescape tag name from "__{utf-8 hex}" format

      Parameters

      • n: string

      Returns string