prosody 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.config/rail.toml +26 -0
  3. data/.release-please-manifest.json +1 -1
  4. data/.ruby-version +1 -1
  5. data/.taplo.toml +1 -1
  6. data/AGENTS.md +29 -15
  7. data/CHANGELOG.md +7 -0
  8. data/CONFIGURATION.md +19 -16
  9. data/Cargo.lock +254 -235
  10. data/Cargo.toml +11 -8
  11. data/README.md +100 -23
  12. data/examples/keyed_state.rb +10 -2
  13. data/examples/keyed_state.rbs +1 -0
  14. data/ext/prosody/Cargo.toml +1 -1
  15. data/ext/prosody/src/admin.rs +36 -36
  16. data/ext/prosody/src/bridge/mod.rs +5 -10
  17. data/ext/prosody/src/client/config/connections.rs +170 -0
  18. data/ext/prosody/src/client/config/middleware.rs +184 -0
  19. data/ext/prosody/src/client/config/mod.rs +396 -0
  20. data/ext/prosody/src/client/config/state.rs +323 -0
  21. data/ext/prosody/src/client/mod.rs +31 -117
  22. data/ext/prosody/src/client/readers.rs +106 -0
  23. data/ext/prosody/src/client/request.rs +2 -2
  24. data/ext/prosody/src/client/support.rs +13 -32
  25. data/ext/prosody/src/gvl.rs +8 -6
  26. data/ext/prosody/src/handler/{context.rs → context/mod.rs} +36 -150
  27. data/ext/prosody/src/handler/context/vending.rs +138 -0
  28. data/ext/prosody/src/handler/message.rs +36 -0
  29. data/ext/prosody/src/handler/mod.rs +18 -8
  30. data/ext/prosody/src/handler/state/deque.rs +144 -0
  31. data/ext/prosody/src/handler/state/mod.rs +163 -268
  32. data/ext/prosody/src/handler/state/query.rs +264 -0
  33. data/ext/prosody/src/handler/state/registration.rs +15 -86
  34. data/ext/prosody/src/handler/state/scan.rs +33 -141
  35. data/ext/prosody/src/handler/state/set.rs +98 -0
  36. data/ext/prosody/src/lib.rs +54 -36
  37. data/ext/prosody/src/logging.rs +6 -6
  38. data/ext/prosody/src/published.rs +171 -152
  39. data/ext/prosody/src/scheduler/result.rs +2 -1
  40. data/ext/prosody/src/util.rs +65 -3
  41. data/lib/prosody/client.rb +32 -0
  42. data/lib/prosody/configuration.rb +20 -12
  43. data/lib/prosody/demand.rb +27 -0
  44. data/lib/prosody/native_stubs/client.rb +157 -0
  45. data/lib/prosody/native_stubs/context.rb +178 -0
  46. data/lib/prosody/native_stubs/message.rb +133 -0
  47. data/lib/prosody/native_stubs.rb +11 -956
  48. data/lib/prosody/state/deque.rb +253 -0
  49. data/lib/prosody/state/map.rb +313 -0
  50. data/lib/prosody/state/set.rb +121 -0
  51. data/lib/prosody/state/value.rb +58 -0
  52. data/lib/prosody/state.rb +157 -677
  53. data/lib/prosody/version.rb +1 -1
  54. data/lib/prosody.rb +2 -1
  55. data/sig/configuration.rbs +19 -10
  56. data/sig/prosody.rbs +37 -4
  57. data/sig/published.rbs +102 -0
  58. data/sig/state.rbs +109 -122
  59. data/typecheck/payload_types.rb +12 -0
  60. data/typecheck/payload_types.rbs +1 -0
  61. metadata +30 -11
  62. data/ext/prosody/src/client/config.rs +0 -1300
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The value collection: the owned {Prosody::ValueState} handle and the
4
+ # {Prosody::PublishedValue} reader.
5
+
6
+ module Prosody
7
+ # A single-value keyed-state handle.
8
+ #
9
+ # Reads return the stored JSON value (or a {Prosody::Message} for message
10
+ # collections), or `nil` when the value is absent. Writes are buffered and
11
+ # made durable by {#commit}. All operations are fiber-yield async: they look
12
+ # blocking but never block the thread.
13
+ class ValueState < State::Handle
14
+ # Reads the current value.
15
+ #
16
+ # @return [Object, nil] the stored value, or `nil` when absent
17
+ def get = @native.get
18
+
19
+ # Buffers a write of the value.
20
+ #
21
+ # @param value [Object] the value to store (JSON, or a message)
22
+ # @return [void]
23
+ # @raise [PermanentStateError] if `value` is `nil` (use {#clear} to delete)
24
+ def set(value) = @native.set(value)
25
+
26
+ # Buffers a clear of the value.
27
+ #
28
+ # @return [void]
29
+ def clear = @native.clear
30
+
31
+ # Reads the current value. Idiomatic alias of {#get}.
32
+ #
33
+ # @return [Object, nil]
34
+ alias_method :value, :get
35
+
36
+ # Buffers a write of the value. Idiomatic alias of {#set}. As with any Ruby
37
+ # writer, `state.value = x` evaluates to `x` regardless of the return.
38
+ #
39
+ # @param value [Object]
40
+ # @return [void]
41
+ alias_method :value=, :set
42
+ end
43
+
44
+ # A read-only view of a published value, opened by
45
+ # +client.state(subsystem, definition)+. Each read takes the user key and
46
+ # sees only committed state. A failed read raises the same state errors as
47
+ # an owned handle. A read in a forked child process raises +RuntimeError+.
48
+ class PublishedValue
49
+ # @param native [Prosody::NativePublishedValue] the native reader
50
+ def initialize(native) = @native = native
51
+
52
+ # Reads the committed value for +key+.
53
+ #
54
+ # @param key [String] the user key
55
+ # @return [Object, nil] the value, or +nil+ when it is absent
56
+ def get(key) = @native.get(key)
57
+ end
58
+ end