homura-runtime 0.1.5 → 0.1.6
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/CHANGELOG.md +7 -0
- data/bin/cloudflare-workers-build +1 -18
- data/lib/cloudflare_workers/build_support.rb +32 -0
- data/lib/cloudflare_workers/version.rb +1 -1
- data/lib/cloudflare_workers.rb +18 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aae4102ce898507966e1a993b16033cf74ede5f2543d17e56d552c6b3ecfabaf
|
|
4
|
+
data.tar.gz: 16b3be88c09f2189193da02cde5904a18749a74edf80e38927a2e47329ec06a8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57f457bf20205a3bd68d81d5ad616b971892c513023d61dd9b56f575bc0cf70063b9753810abb1163084ebd48d7ae8439bcfd5c72a53e3dd25bdc3f98148b796
|
|
7
|
+
data.tar.gz: 6c69fb69b6c79a3309a9e5796534023ee47066027a97c809034615635b1df49e284ee0c010fce48059f062d43ec94e12f01ace5b39525b5f6e7d64940a4affa2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.6 (2026-04-23)
|
|
4
|
+
|
|
5
|
+
- Teach `cloudflare-workers-build --standalone --with-db` to add the packaged
|
|
6
|
+
`sequel-d1` gem `vendor/` directory to the Opal load path before the gem's
|
|
7
|
+
`lib/`, so `require 'sequel'` resolves to the bundled Opal-compatible Sequel
|
|
8
|
+
subset instead of the CRuby gem.
|
|
9
|
+
|
|
3
10
|
## 0.1.5 (2026-04-23)
|
|
4
11
|
|
|
5
12
|
- Make `auto-await` emit rewritten files for existing hand-written `.__await__`
|
|
@@ -121,24 +121,7 @@ def homura_vendor_from_gemfile(project_root)
|
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
def run_opal_standalone!(root, opal_input, opal_output, with_db:)
|
|
124
|
-
load_paths =
|
|
125
|
-
hv = homura_vendor_from_gemfile(root)
|
|
126
|
-
load_paths << hv.to_s if hv
|
|
127
|
-
runtime_name = CloudflareWorkers::BuildSupport::RUNTIME_GEM_NAME
|
|
128
|
-
sinatra_name = CloudflareWorkers::BuildSupport::SINATRA_GEM_NAME
|
|
129
|
-
|
|
130
|
-
load_paths += ['build/auto_await/app', 'app']
|
|
131
|
-
[
|
|
132
|
-
CloudflareWorkersBuild.gem_lib(runtime_name),
|
|
133
|
-
CloudflareWorkersBuild.gem_vendor(runtime_name),
|
|
134
|
-
CloudflareWorkersBuild.gem_lib(sinatra_name),
|
|
135
|
-
CloudflareWorkersBuild.gem_vendor(sinatra_name)
|
|
136
|
-
].compact.each do |path|
|
|
137
|
-
load_paths << path
|
|
138
|
-
end
|
|
139
|
-
load_paths << CloudflareWorkersBuild.gem_lib('sequel-d1') if with_db
|
|
140
|
-
load_paths << 'vendor' if root.join('vendor').directory?
|
|
141
|
-
load_paths << 'build'
|
|
124
|
+
load_paths = CloudflareWorkers::BuildSupport.standalone_load_paths(root, with_db: with_db)
|
|
142
125
|
|
|
143
126
|
argv = ['bundle', 'exec', 'opal', '-c', '-E', '--esm', '--no-source-map']
|
|
144
127
|
load_paths.each { |p| argv.push('-I', p) }
|
|
@@ -7,6 +7,7 @@ module CloudflareWorkers
|
|
|
7
7
|
module BuildSupport
|
|
8
8
|
RUNTIME_GEM_NAME = 'homura-runtime'
|
|
9
9
|
SINATRA_GEM_NAME = 'sinatra-homura'
|
|
10
|
+
SEQUEL_D1_GEM_NAME = 'sequel-d1'
|
|
10
11
|
|
|
11
12
|
class << self
|
|
12
13
|
def loaded_spec(name, loaded_specs: Gem.loaded_specs)
|
|
@@ -53,6 +54,37 @@ module CloudflareWorkers
|
|
|
53
54
|
target_dir
|
|
54
55
|
end
|
|
55
56
|
|
|
57
|
+
def standalone_load_paths(project_root, with_db:, loaded_specs: Gem.loaded_specs)
|
|
58
|
+
root = Pathname(project_root)
|
|
59
|
+
load_paths = []
|
|
60
|
+
|
|
61
|
+
hv = vendor_from_gemfile(root)
|
|
62
|
+
load_paths << hv.to_s if hv
|
|
63
|
+
|
|
64
|
+
load_paths += ['build/auto_await/app', 'app']
|
|
65
|
+
[
|
|
66
|
+
gem_lib(RUNTIME_GEM_NAME, loaded_specs: loaded_specs),
|
|
67
|
+
gem_vendor(RUNTIME_GEM_NAME, loaded_specs: loaded_specs),
|
|
68
|
+
gem_lib(SINATRA_GEM_NAME, loaded_specs: loaded_specs),
|
|
69
|
+
gem_vendor(SINATRA_GEM_NAME, loaded_specs: loaded_specs)
|
|
70
|
+
].compact.each do |path|
|
|
71
|
+
load_paths << path
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
if with_db
|
|
75
|
+
[
|
|
76
|
+
gem_vendor(SEQUEL_D1_GEM_NAME, loaded_specs: loaded_specs),
|
|
77
|
+
gem_lib(SEQUEL_D1_GEM_NAME, loaded_specs: loaded_specs)
|
|
78
|
+
].compact.each do |path|
|
|
79
|
+
load_paths << path
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
load_paths << 'vendor' if root.join('vendor').directory?
|
|
84
|
+
load_paths << 'build'
|
|
85
|
+
load_paths.uniq
|
|
86
|
+
end
|
|
87
|
+
|
|
56
88
|
def standalone_namespace(project_root, suffix)
|
|
57
89
|
base = Pathname(project_root).basename.to_s
|
|
58
90
|
parts = base.split(/[^A-Za-z0-9]+/).reject(&:empty?)
|
data/lib/cloudflare_workers.rb
CHANGED
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
# style entry point and never sees a Cloudflare-specific symbol.
|
|
21
21
|
#
|
|
22
22
|
# 3. Cloudflare::D1Database / KVNamespace / R2Bucket — tiny Ruby wrappers
|
|
23
|
-
# around the JS bindings.
|
|
24
|
-
#
|
|
25
|
-
#
|
|
23
|
+
# around the JS bindings. At the raw runtime layer they still return
|
|
24
|
+
# Promises, but homura's build-time auto-await pass rewrites the
|
|
25
|
+
# common Sinatra-facing call sites (`db.execute`, `kv.get`, etc.) so
|
|
26
|
+
# app code usually stays sync-shaped.
|
|
26
27
|
#
|
|
27
28
|
# Note: Opal Strings are immutable (they map to JS Strings), so this file
|
|
28
29
|
# uses reassignment (`@buffer = @buffer + str`) instead of `<<` mutation.
|
|
@@ -209,8 +210,10 @@ module Rack
|
|
|
209
210
|
|
|
210
211
|
# Expose D1 / KV / R2 bindings as plain Ruby wrapper objects.
|
|
211
212
|
# The user Sinatra routes reach them via
|
|
212
|
-
# `env['cloudflare.DB']` / `.KV` / `.BUCKET
|
|
213
|
-
# Ruby methods on them
|
|
213
|
+
# `env['cloudflare.DB']` / `.KV` / `.BUCKET` and call ordinary
|
|
214
|
+
# Ruby methods on them. Under the hood those methods are async,
|
|
215
|
+
# but homura's auto-await build step inserts `.__await__` for the
|
|
216
|
+
# common binding/helper patterns so app source usually does not.
|
|
214
217
|
js_db = `#{js_env} && #{js_env}.DB`
|
|
215
218
|
js_kv = `#{js_env} && #{js_env}.KV`
|
|
216
219
|
js_r2 = `#{js_env} && #{js_env}.BUCKET`
|
|
@@ -603,8 +606,10 @@ module Cloudflare
|
|
|
603
606
|
|
|
604
607
|
# ---- sqlite3-ruby compatible high-level API ----------------------
|
|
605
608
|
|
|
606
|
-
# Execute a SQL statement with optional bind parameters
|
|
607
|
-
#
|
|
609
|
+
# Execute a SQL statement with optional bind parameters.
|
|
610
|
+
# Returns a JS Promise resolving to an Array of Hashes; the build-time
|
|
611
|
+
# auto-await pass rewrites the usual Sinatra call sites so app code can
|
|
612
|
+
# stay `db.execute(...)` instead of spelling `.__await__`.
|
|
608
613
|
#
|
|
609
614
|
# db.execute("SELECT * FROM users") → Array<Hash>
|
|
610
615
|
# db.execute("SELECT * FROM users WHERE id = ?", [1]) → Array<Hash>
|
|
@@ -616,6 +621,7 @@ module Cloudflare
|
|
|
616
621
|
end
|
|
617
622
|
|
|
618
623
|
# Execute and return only the first row (or nil).
|
|
624
|
+
# Returns a JS Promise resolving to a Hash or nil.
|
|
619
625
|
#
|
|
620
626
|
# db.get_first_row("SELECT * FROM users WHERE id = ?", [1]) → Hash or nil
|
|
621
627
|
def get_first_row(sql, bind_params = [])
|
|
@@ -626,6 +632,7 @@ module Cloudflare
|
|
|
626
632
|
|
|
627
633
|
# Execute a write statement (INSERT / UPDATE / DELETE) and return
|
|
628
634
|
# a metadata Hash with `changes`, `last_row_id`, `duration`, etc.
|
|
635
|
+
# Returns a JS Promise resolving to that metadata Hash.
|
|
629
636
|
#
|
|
630
637
|
# meta = db.execute_insert("INSERT INTO users (name) VALUES (?)", ["alice"])
|
|
631
638
|
# meta['last_row_id'] # → 7
|
|
@@ -636,7 +643,7 @@ module Cloudflare
|
|
|
636
643
|
end
|
|
637
644
|
|
|
638
645
|
# Execute one or more raw SQL statements separated by semicolons.
|
|
639
|
-
# Useful for schema migrations. Returns the D1 exec result.
|
|
646
|
+
# Useful for schema migrations. Returns the raw async D1 exec result.
|
|
640
647
|
def execute_batch(sql)
|
|
641
648
|
exec(sql)
|
|
642
649
|
end
|
|
@@ -697,6 +704,7 @@ module Cloudflare
|
|
|
697
704
|
end
|
|
698
705
|
|
|
699
706
|
# KV#get returns a JS Promise resolving to a String or nil.
|
|
707
|
+
# In normal Sinatra app code, auto-await usually hides that Promise.
|
|
700
708
|
def get(key)
|
|
701
709
|
js_kv = @js
|
|
702
710
|
err_cls = Cloudflare::KVError
|
|
@@ -705,7 +713,8 @@ module Cloudflare
|
|
|
705
713
|
|
|
706
714
|
# Put a value. `expiration_ttl:` (seconds) maps to the Workers KV
|
|
707
715
|
# `expirationTtl` option so callers can set TTLs without reaching
|
|
708
|
-
# for backticks. Returns a JS Promise
|
|
716
|
+
# for backticks. Returns a JS Promise; common route/helper call sites
|
|
717
|
+
# are auto-awaited during the build.
|
|
709
718
|
def put(key, value, expiration_ttl: nil)
|
|
710
719
|
js_kv = @js
|
|
711
720
|
err_cls = Cloudflare::KVError
|