aboutsummaryrefslogtreecommitdiffstats
path: root/util
Commit message (Collapse)AuthorAgeFilesLines
...
* | renamening: Fix newly added imports to use the new namespaceKim Alvefur2023-06-183-4/+4
| |
* | util.jsonschema: Remove wrapper functionKim Alvefur2023-06-171-7/+0
| | | | | | | | This was to silence some Teal warning that seems to have gone away.
* | util.jsonschema: Silence Teal warnings about utf8 libraryKim Alvefur2023-06-171-2/+2
| | | | | | | | | | | | Teal worries that we redefine the global. Also that the fallback was missing type information.
* | util.jsonschema: Silence Teal warnings about counting items in tablesKim Alvefur2023-06-171-4/+4
| | | | | | | | | | Teal thinks that these are key-value maps which are always of length zero, but that is not the case.
* | util.argparse: Add support for repeatable parametersKim Alvefur2022-01-051-2/+11
| | | | | | | | These are gathered into arrays
* | util.sqlite3: Don't cache prepared statements for one-off queriesKim Alvefur2023-06-101-10/+8
| | | | | | | | | | | | | | | | | | The :execute method is mainly used for one-off queries such as creating tables and indices. There is no need to cache this prepared statement, as those queries are only done on startup. Further, prepared statements can't be reused without being reset, so this was likely broken anyway.
* | util.sqlite3: Deduplicate query methodsKim Alvefur2023-06-101-34/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | There were 3 very similar methods: - :execute() - :execute_query() - :execute_update() The first one returns the prepared statement and is mainly used internally in the library for CREATE statements. The later two only really differ in how the results are returned. Those two are one main method and one small one that only picks out the iterator.
* | util.sqlite3: Fix indentationKim Alvefur2023-06-101-5/+7
| |
* | Merge 0.12->trunkKim Alvefur2023-06-101-0/+2
|\|
| * util.array: Expose new() on module tableKim Alvefur2023-06-101-0/+2
| | | | | | | | | | | | For consistency with other utils. Consistency is good.
* | util.datamanager: Halve size of list indexKim Alvefur2021-05-141-11/+15
| | | | | | | | | | Instead of storing (start, length) tuples, store the offset to the end of items and derive length using the previous entry.
* | util.datamanager: Add O(1) list indexing with on-disk indexKim Alvefur2021-05-111-0/+191
| | | | | | | | | | | | | | | | | | | | | | | | Index file contains offsets and lengths of each item() which allows seeking directly to each item and reading it without parsing the entire file. Also allows tricks like binary search, assuming items have some defined order. We take advantage of the 1-based indexing in tables to store a magic header in the 0 position, so that table index 1 ends up at file index 1.
* | util.serialization: Add a "pretty" presetKim Alvefur2023-06-091-0/+4
| | | | | | | | | | This is the config I want 90% of the time when just showing data in the console or so.
* | util.http: Implement parser for RFC 7239 Forwarded headerKim Alvefur2023-06-031-0/+33
| | | | | | | | | | | | | | | | Standardized and structured replacement for the X-Forwarded-For, X-Forwarded-Proto set of headers. Notably, this allows per-hop protocol information, unlike X-Forwarded-Proto which is always a single value for some reason.
* | util.set: Remove duplicate __freeze metamethodKim Alvefur2023-06-011-9/+0
| | | | | | | | Backs out 895a82c5d8d4 beacuse __freeze already added in a96a2fbcc6c0
* | Merge 0.12->trunkKim Alvefur2023-05-311-4/+5
|\|
| * util.prosodyctl.check: Fix error where hostname can't be turned into A labelKim Alvefur2023-05-311-4/+5
| | | | | | | | | | | | | | | | | | Where gethostname or tohostname returns an invalid name, e.g. containing underscores or something, to_ascii would reject this and return nil, which triggers an error in the dns lookup. Reported by prova2 in the chat, for whom tohostname returned a long name containing underscores.
* | util.startup: Record current version in a metricKim Alvefur2023-05-311-1/+1
| | | | | | | | | | Useful to have this info available when juggling metrics, e.g. to see if things changed between versions.
* | util.startup: Remove componentmanager backwards compatibilityKim Alvefur2023-05-311-5/+0
| | | | | | | | Module was removed in 0.8.0 in c52b06de9b27
* | util.dependencies: Print tables itself to reduce number of importsKim Alvefur2023-05-261-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rationale: See diffstat When this module is imported, it ends up calling stty via term_width() in util.human.io.table(). When this happens outside of a terminal, the following message is sent to stdout: stty: 'standard input': Inappropriate ioctl for device Not importing this module avoids that. Furthermore three is value in this module having minimal dependencies as they might not be available when it does the checks. Ref a1fed82c44b9
* | util.sasl.oauthbearer: Tighter parsing of SASL messageKim Alvefur2023-05-261-1/+3
| | | | | | | | | | Previously the kvsep before and after the kvpairs would have been included in kvpairs, which is incorrect but should be harmless.
* | util.jsonschema: Fix UTF-8ness of 'minLength' and 'maxLength'Kim Alvefur2023-04-231-2/+8
| |
* | util.jsonschema: Implement 'minContains' and 'maxContains'Kim Alvefur2023-04-231-4/+3
| |
* | util.jsonschema: Implement 'luaPattern' - Lua variant of 'pattern'Kim Alvefur2023-04-221-0/+3
| | | | | | | | | | Like 'pattern' but uses Lua patterns instead of Regular Expressions, since only a subset of regex are also valid Lua patterns.
* | util.jsonschema: Implement 'luaPatternProperties' as Lua variant of ↵Kim Alvefur2023-04-221-1/+18
| | | | | | | | | | | | | | | | 'patternProperties' Previous version of this patch used 'patternProperties' but that would only work with simpler ECMA-262 regular expressions are also valid Lua patterns.
* | Merge 0.12->trunkKim Alvefur2023-04-191-1/+1
|\|
| * util.error: Fix error on conversion of invalid error stanza, fix #1805Kim Alvefur2023-04-191-1/+1
| | | | | | | | | | | | | | | | | | Error stanzas should have an <error> element, but if you pass a stanza without one to util.error.from_stanza() it triggers an attempt to index a nil value, which this patch avoids. In the conditional, it should be safe to assume error_tag is non-nil since condition can't have those values then.
* | util.human.io: Fix column width miscalculationKim Alvefur2023-04-091-3/+0
| | | | | | | | | | | | Fixes that the more fixed width columns there are, the narrower the resulting table becomes. A right-aligned variable-width column at the last position should always be flush to the right side of the terminal.
* | util.human.io: Fix error with ellipsis to negative lengthKim Alvefur2023-04-091-1/+1
| | | | | | | | | | Can happen if you resize the terminal too narrow that the space left for variable width columns end up negative.
* | util.sasl: Fix a singularsKim Alvefur2023-04-071-1/+1
| | | | | | | | | | Thanks timeless, your mere existence inspires us to improve our spelling, tho this was more syntax.
* | util.argparse: Translate '-' to '_' in long option names for convenienceMatthew Wild2023-04-071-0/+1
| | | | | | | | A review of existing code suggests nothing will break. So, here we go...
* | util.human.io: Add parse_duration() method to parse a duration stringMatthew Wild2023-04-071-0/+12
| | | | | | | | | | Similar logic occurs throughout various modules in the codebase. We might even want a module:get_option_duration()??
* | util.prosodyctl.shell: Fix sending terminal width with single argumentKim Alvefur2023-04-071-1/+1
| | | | | | | | | | E.g. when you do 'prosodyctl shell "s2s:show()"', this is the case that triggers, and it was missing the @width argument, causing confusion.
* | util.human.io: Coerce $COLUMNS to numberKim Alvefur2023-04-071-1/+1
| | | | | | | | os.getenv() returns a string but term_width() should return a number
* | util.prosodyctl.shell: Coerce terminal width to string (for util.stanza)Kim Alvefur2023-04-071-1/+1
| | | | | | | | Fixes invalid attribute value: expected string, got number
* | util.human.io: table: don't read $COLUMNS directly, just use term_width()Matthew Wild2023-04-071-1/+1
| | | | | | | | ...which now reads $COLUMNS for us and does the right thing.
* | util.human.io: table: Return determined width as a second resultMatthew Wild2023-04-071-1/+1
| | | | | | | | | | This allows callers to adjust other things based on the width of the rows (such as header lines).
* | util.human.io: Prefer using the $COLUMNS environment variable if set (by ↵Kim Alvefur2023-04-072-1/+3
| | | | | | | | | | | | readline) Feels like it should be faster.
* | util.prosodyctl.shell: Use new term_width() for widthKim Alvefur2023-04-071-1/+2
| | | | | | | | | | Kicks in if/when readline hasn't set $COLUMNS, e.g. when using the `prosodyctl shell command like this` form.
* | util.human.io: table: use term_width() to discover terminal widthMatthew Wild2023-04-071-1/+1
| |
* | util.human.io: Add term_width() method to discover the terminal widthMatthew Wild2023-04-071-0/+12
| | | | | | | | | | This is not standard POSIX, but apparently very widely supported. For reference: https://www.austingroupbugs.net/view.php?id=1053
* | util.human.io: Pass the whole column definition to mapper functionKim Alvefur2023-04-071-1/+1
| | | | | | | | | | | | I forget why I wanted this, but it may allow doing things like pull settings from the column, especially when the mapper function is reused among many columns.
* | util.human.io: Allow defining per column ellipsis functionKim Alvefur2023-04-071-1/+1
| | | | | | | | | | | | As an alternative to doing it in the mapper function. Could be useful in cases where one may want to put the ellipsis in the middle or beginning instead of the start.
* | util.human.io: Pass expected width to mapper functionKim Alvefur2023-04-071-1/+1
| | | | | | | | | | In order to allow it to adjust its output to available space, apply its own ellipsis method or other compacting method.
* | util.set: Change tostring format to {a, b, c}Kim Alvefur2023-04-061-1/+1
| | | | | | | | | | | | | | | | Makes it easier to make out where the set starts and ends in cases where it may get embedded and tostring()-ed in a log message. { } taken over from util.array for consistency with some other systems syntax for Sets, e.g. Python
* | util.array: Change tostring format to [a,b,c]Kim Alvefur2023-04-061-1/+1
| | | | | | | | | | | | | | Arrays in Lua do use { } but since __tostring is often user-facing it seems sensible to use [ ] instead for consistency with many other systems; as well as to allow the {a,b,c} formatting to be used by util.set without being confused with util.array.
* | util.human.io: Fix pattern to support fractional proportionsMatthew Wild2023-04-061-2/+2
| |
* | util.human.io: Support for dynamic "proportional" columnsMatthew Wild2023-04-061-4/+14
| | | | | | | | | | | | | | | | Instead of a percentage, this allows you to specify e.g. `width="[N]p"`, where a width="2p" will be twice the width of a width="1p" column. Compatibility with the old %-based widths is preserved, and percentages adding up to more than 100 are handled more gracefully.
* | util.fsm: New utility lib for finite state machinesMatthew Wild2022-03-171-0/+154
| |
* | util.startup: Add prosody.started promise to easily execute code after startupMatthew Wild2023-04-011-3/+14
| | | | | | | | | | | | | | | | | | To avoid a race where server-started fires before the promise function body is run (on next tick), I moved server-started to fire on the next tick, which seems sensible anyway. Errors are logged, I'm not sure if we ought to be doing something more here. I'm sure we'll find out.