datastar 1.0.0.pre.1 → 1.0.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.
- checksums.yaml +4 -4
- data/examples/hello-world/Gemfile +8 -0
- data/examples/hello-world/Gemfile.lock +29 -0
- data/examples/hello-world/hello-world.html +35 -0
- data/examples/hello-world/hello-world.ru +37 -0
- data/examples/test.ru +1 -1
- data/examples/threads/Gemfile +8 -0
- data/examples/threads/Gemfile.lock +29 -0
- data/examples/threads/threads.ru +84 -0
- data/lib/datastar/consts.rb +1 -1
- data/lib/datastar/server_sent_event_generator.rb +1 -1
- data/lib/datastar/version.rb +1 -1
- metadata +25 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be590227c905b287d03dc8bc36a20b1d1e74e1a1dcfa1ae440ef5f61c0f5ab49
|
4
|
+
data.tar.gz: 0d175645c14c9ec133f0ce4b6acf9c5882d935b633b66a58c9aeb071c46e261f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0e8d9952b06338ca703dd39c46bace452728f21688c0f7f996594922412fe188115c23ef441b9d07e2d2d4273b44ebce740f145260b2d29fc48f736a0d32e4a
|
7
|
+
data.tar.gz: 3d162f0bce66bc6b7eeec5ad948d3ab8bfd9ad57138a866a098a2987e35006969fc93d0957d3ffde751b7333e21bc1aef7655652a2823a4d1acbaddcba995a9d
|
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../../../sdk/ruby
|
3
|
+
specs:
|
4
|
+
datastar (1.0.0.beta.3)
|
5
|
+
json
|
6
|
+
logger
|
7
|
+
rack (>= 3.1.14)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
json (2.12.2)
|
13
|
+
logger (1.7.0)
|
14
|
+
nio4r (2.7.4)
|
15
|
+
puma (6.6.0)
|
16
|
+
nio4r (~> 2.0)
|
17
|
+
rack (3.1.16)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
arm64-darwin-24
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
datastar!
|
25
|
+
puma
|
26
|
+
rack
|
27
|
+
|
28
|
+
BUNDLED WITH
|
29
|
+
2.6.3
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<!-- This is auto-generated by Datastar. DO NOT EDIT. -->
|
2
|
+
|
3
|
+
<!DOCTYPE html>
|
4
|
+
<html lang="en">
|
5
|
+
<head>
|
6
|
+
<title>Datastar SDK Demo</title>
|
7
|
+
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
|
8
|
+
<script type="module" src="https://cdn.jsdelivr.net/gh/starfederation/datastar@main/bundles/datastar.js"></script>
|
9
|
+
</head>
|
10
|
+
<body class="bg-white dark:bg-gray-900 text-lg max-w-xl mx-auto my-16">
|
11
|
+
<div data-signals-delay="400" class="bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 rounded-lg px-6 py-8 ring shadow-xl ring-gray-900/5 space-y-2">
|
12
|
+
<div class="flex justify-between items-center">
|
13
|
+
<h1 class="text-gray-900 dark:text-white text-3xl font-semibold">
|
14
|
+
Datastar SDK Demo
|
15
|
+
</h1>
|
16
|
+
<img src="https://data-star.dev/static/images/rocket-64x64.png" alt="Rocket" width="64" height="64"/>
|
17
|
+
</div>
|
18
|
+
<p class="mt-2">
|
19
|
+
SSE events will be streamed from the backend to the frontend.
|
20
|
+
</p>
|
21
|
+
<div class="space-x-2">
|
22
|
+
<label for="delay">
|
23
|
+
Delay in milliseconds
|
24
|
+
</label>
|
25
|
+
<input data-bind-delay id="delay" type="number" step="100" min="0" class="w-36 rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-sky-500 focus:outline focus:outline-sky-500 dark:disabled:border-gray-700 dark:disabled:bg-gray-800/20" />
|
26
|
+
</div>
|
27
|
+
<button data-on-click="@get('/hello-world')" class="rounded-md bg-sky-500 px-5 py-2.5 leading-5 font-semibold text-white hover:bg-sky-700 hover:text-gray-100 cursor-pointer">
|
28
|
+
Start
|
29
|
+
</button>
|
30
|
+
</div>
|
31
|
+
<div class="my-16 text-8xl font-bold text-transparent" style="background: linear-gradient(to right in oklch, red, orange, yellow, green, blue, blue, violet); background-clip: text">
|
32
|
+
<div id="message">Hello, world!</div>
|
33
|
+
</div>
|
34
|
+
</body>
|
35
|
+
</html>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'datastar'
|
4
|
+
|
5
|
+
# This is a test Rack endpoint
|
6
|
+
# with a hello world example using Datastar.
|
7
|
+
# To run:
|
8
|
+
#
|
9
|
+
# # install dependencies
|
10
|
+
# bundle install
|
11
|
+
# # run this endpoint with Puma server
|
12
|
+
# bundle exec puma ./hello-world.ru
|
13
|
+
#
|
14
|
+
# Then open http://localhost:9292
|
15
|
+
#
|
16
|
+
HTML = File.read(File.expand_path('hello-world.html', __dir__))
|
17
|
+
|
18
|
+
run do |env|
|
19
|
+
datastar = Datastar.from_rack_env(env)
|
20
|
+
|
21
|
+
if datastar.sse?
|
22
|
+
delay = (datastar.signals['delay'] || 0).to_i
|
23
|
+
delay /= 1000.0 if delay.positive?
|
24
|
+
message = 'Hello, world!'
|
25
|
+
|
26
|
+
datastar.stream do |sse|
|
27
|
+
message.size.times do |i|
|
28
|
+
sse.patch_elements(%(<div id="message">#{message[0..i]}</div>))
|
29
|
+
sleep delay
|
30
|
+
end
|
31
|
+
end
|
32
|
+
else
|
33
|
+
[200, { 'content-type' => 'text/html' }, [HTML]]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
trap('INT') { exit }
|
data/examples/test.ru
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../../../sdk/ruby
|
3
|
+
specs:
|
4
|
+
datastar (1.0.0.beta.3)
|
5
|
+
json
|
6
|
+
logger
|
7
|
+
rack (>= 3.1.14)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
json (2.12.2)
|
13
|
+
logger (1.7.0)
|
14
|
+
nio4r (2.7.4)
|
15
|
+
puma (6.6.0)
|
16
|
+
nio4r (~> 2.0)
|
17
|
+
rack (3.1.16)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
arm64-darwin-24
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
datastar!
|
25
|
+
puma
|
26
|
+
rack
|
27
|
+
|
28
|
+
BUNDLED WITH
|
29
|
+
2.6.3
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'datastar'
|
4
|
+
|
5
|
+
# This is a test Rack endpoint
|
6
|
+
# to demo streaming Datastar updates from multiple threads.
|
7
|
+
# To run:
|
8
|
+
#
|
9
|
+
# # install dependencies
|
10
|
+
# bundle install
|
11
|
+
# # run this endpoint with Puma server
|
12
|
+
# bundle exec puma threads.ru
|
13
|
+
#
|
14
|
+
# visit http://localhost:9292
|
15
|
+
#
|
16
|
+
INDEX = <<~HTML
|
17
|
+
<!DOCTYPE html>
|
18
|
+
<html>
|
19
|
+
<head>
|
20
|
+
<meta charset="UTF-8">
|
21
|
+
<title>Datastar counter</title>
|
22
|
+
<style>
|
23
|
+
body { padding: 10em; }
|
24
|
+
.counter {#{' '}
|
25
|
+
font-size: 2em;#{' '}
|
26
|
+
span { font-weight: bold; }
|
27
|
+
}
|
28
|
+
</style>
|
29
|
+
<script type="module" src="https://cdn.jsdelivr.net/gh/starfederation/datastar@release-candidate/bundles/datastar.js"></script>
|
30
|
+
</head>
|
31
|
+
<body>
|
32
|
+
<button#{' '}
|
33
|
+
data-on-click="@get('/')"#{' '}
|
34
|
+
data-indicator-heartbeat#{' '}
|
35
|
+
>Start</button>
|
36
|
+
<p class="counter">Slow thread: <span id="slow">waiting</span></p>
|
37
|
+
<p class="counter">Fast thread: <span id="fast">waiting</span></p>
|
38
|
+
<p id="connection">Disconnected...</p>
|
39
|
+
</body>
|
40
|
+
<html>
|
41
|
+
HTML
|
42
|
+
|
43
|
+
trap('INT') { exit }
|
44
|
+
|
45
|
+
run do |env|
|
46
|
+
# Initialize Datastar with callbacks
|
47
|
+
datastar = Datastar
|
48
|
+
.from_rack_env(env)
|
49
|
+
.on_connect do |sse|
|
50
|
+
sse.patch_elements(%(<p id="connection">Connected...</p>))
|
51
|
+
p ['connect', sse]
|
52
|
+
end.on_server_disconnect do |sse|
|
53
|
+
sse.patch_elements(%(<p id="connection">Done...</p>))
|
54
|
+
p ['server disconnect', sse]
|
55
|
+
end.on_client_disconnect do |socket|
|
56
|
+
p ['client disconnect', socket]
|
57
|
+
end.on_error do |error|
|
58
|
+
p ['exception', error]
|
59
|
+
puts error.backtrace.join("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
if datastar.sse?
|
63
|
+
# This will run in its own thread / fiber
|
64
|
+
datastar.stream do |sse|
|
65
|
+
11.times do |i|
|
66
|
+
sleep 1
|
67
|
+
# Raising an error to demonstrate error handling
|
68
|
+
# raise ArgumentError, 'This is an error' if i > 5
|
69
|
+
|
70
|
+
sse.patch_elements(%(<span id="slow">#{i}</span>))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Another thread / fiber
|
75
|
+
datastar.stream do |sse|
|
76
|
+
1000.times do |i|
|
77
|
+
sleep 0.01
|
78
|
+
sse.patch_elements(%(<span id="fast">#{i}</span>))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
else
|
82
|
+
[200, { 'content-type' => 'text/html' }, [INDEX]]
|
83
|
+
end
|
84
|
+
end
|
data/lib/datastar/consts.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
module Datastar
|
5
5
|
module Consts
|
6
6
|
DATASTAR_KEY = 'datastar'
|
7
|
-
VERSION = '1.0.0-RC.
|
7
|
+
VERSION = '1.0.0-RC.1'
|
8
8
|
|
9
9
|
# The default duration for retrying SSE on connection reset. This is part of the underlying retry mechanism of SSE.
|
10
10
|
DEFAULT_SSE_RETRY_DURATION = 1000
|
data/lib/datastar/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datastar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
@@ -51,6 +51,20 @@ dependencies:
|
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: phlex
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
54
68
|
email:
|
55
69
|
- ismaelct@gmail.com
|
56
70
|
executables: []
|
@@ -61,7 +75,14 @@ files:
|
|
61
75
|
- LICENSE.md
|
62
76
|
- README.md
|
63
77
|
- Rakefile
|
78
|
+
- examples/hello-world/Gemfile
|
79
|
+
- examples/hello-world/Gemfile.lock
|
80
|
+
- examples/hello-world/hello-world.html
|
81
|
+
- examples/hello-world/hello-world.ru
|
64
82
|
- examples/test.ru
|
83
|
+
- examples/threads/Gemfile
|
84
|
+
- examples/threads/Gemfile.lock
|
85
|
+
- examples/threads/threads.ru
|
65
86
|
- lib/datastar.rb
|
66
87
|
- lib/datastar/async_executor.rb
|
67
88
|
- lib/datastar/configuration.rb
|
@@ -73,11 +94,11 @@ files:
|
|
73
94
|
- lib/datastar/server_sent_event_generator.rb
|
74
95
|
- lib/datastar/version.rb
|
75
96
|
- sig/datastar.rbs
|
76
|
-
homepage: https://github.com/starfederation/datastar#readme
|
97
|
+
homepage: https://github.com/starfederation/datastar-ruby#readme
|
77
98
|
licenses: []
|
78
99
|
metadata:
|
79
|
-
homepage_uri: https://github.com/starfederation/datastar#readme
|
80
|
-
source_code_uri: https://github.com/starfederation/datastar
|
100
|
+
homepage_uri: https://github.com/starfederation/datastar-ruby#readme
|
101
|
+
source_code_uri: https://github.com/starfederation/datastar-ruby
|
81
102
|
rdoc_options: []
|
82
103
|
require_paths:
|
83
104
|
- lib
|