picoruby-cloudflare-template 0.1.0.rc2 → 0.1.0.rc3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c224b29b75ac222a183233c6af8022623d9530324e9028a76a1056278f07437b
4
- data.tar.gz: a5199135545e2927b66465fb436e846260e3303587140f498c82d341f0f9ce0d
3
+ metadata.gz: d1e94aeb373291700f0509904e30eb78d209a4515eab57d8f2b062e51a73b1d3
4
+ data.tar.gz: d5c5a48c99963645d76396dac918e0a361fb76d1f27b8b05f4d025b9736b901a
5
5
  SHA512:
6
- metadata.gz: db0e353a8dc1e2a0fddd8c8d82bd12ee605416d4b3bde95a0b536991bd4b33a9843a5d99364f865e4afc679b57fa2282cc5b1ec3d2fcce7e578b694a05e30cef
7
- data.tar.gz: fafcf2e5bb8a86065991b0dc388ab9521729ae2a692f458734e824a66ac9a3748c46ab8ff28f6fbb83c87c7eed4caa85c3548c3ba35c5f8337717caac10c1918
6
+ metadata.gz: ee3311b2386d5c2b10dddafdf80f93c07a5b53ab600867c7bf97a06f9f6de5aa57f61653a3cf584b92c88acb9eb85b0d118fa7a804cf63113f2d03d6d29be2d6
7
+ data.tar.gz: 6eee502c73767aba791d4f05c2d7eff0e882943e615418084b65ae2d2966ce1e3f865cea1c4bed1ce57c365a12939227857fa985356ff00dd47d69cc1f5be792
data/README.ja.md CHANGED
@@ -53,7 +53,7 @@ PicoRubyはsubmodule初期化済みのチェックアウトを指定します。
53
53
  src/index.js、package.json、wrangler.jsonc、.gitignore、README.mdを生成します。
54
54
  生成先が存在する場合は空ディレクトリでも上書きしません。Gemfile.lockとpackage-lock.jsonはアプリ側でコミットしてください。
55
55
 
56
- `--bindings` を付けると、KV・Queue・Accessのユーザー情報取得例をapp.rbとwrangler.jsoncへ追加します。
56
+ `--bindings` を付けると、KV・Queue・Durable Object・Accessのユーザー情報取得例をapp.rbとwrangler.jsoncへ追加します。
57
57
  `/access` の例には `CF_ACCESS_TEAM` と `CF_Authorization` Cookieが必要です。
58
58
  同時に生成する `.picoruby-cloudflare-template.json` は、この2つの管理対象例のハッシュを記録します。
59
59
  今後対応bindingが増えた版では、`picoruby-cloudflare bindings PROJECT` を実行すると例を再生成できます。
@@ -91,7 +91,7 @@ Sinatra等のフレームワークはアプリ側で追加します。ABI固有
91
91
  revision属性のデフォルトはこのgemに組み込まれた値です。`nil` を代入するとデフォルトに戻ります。
92
92
  取得先の選択で `PICORUBY_WORKER_WASM_GEM_DIR` / `MRUBY_RACK_GEM_DIR` は参照せず、`worker:` / `rack:` 引数も受け取りません。
93
93
 
94
- 既定のWorker取得先は `67aaa676d8247beaf19cbbeaeecb78115e490529` に固定しています。
94
+ 既定のWorker取得先は `5590e3ff32714ebcec35c53e1fad63156540e425` に固定しています。
95
95
  Rackは `30802024e263a0dde1f3a8467e648a70625adfd4` に固定しています。
96
96
  再現可能な依存関係が必要な場合は、Worker revisionをタグまたはcommit SHAで上書きしてください。
97
97
  gem公開前には、新規チェックアウトから両方の固定取得先を取得できることを確認します。
@@ -112,6 +112,7 @@ generated/worker/
112
112
  index.js # createWorker({ app, bindingTypes })
113
113
  runtime.js
114
114
  host-bridge.js
115
+ durable-object.js
115
116
  picoruby-worker.js
116
117
  picoruby-worker.wasm
117
118
  tools/ # binding registry生成スクリプト
@@ -119,10 +120,11 @@ generated/worker/
119
120
 
120
121
  Ruby/C・HAL・共通JS bridgeは実行時ライブラリが、このgemはテンプレート・CrossBuild DSL・export処理・薄いcreateWorkerエントリを所有します。
121
122
  共通JSとregistry生成スクリプトは、Wasmをビルドした**同じmrbgemチェックアウト**からコピーします。
122
- 現在の取得場所は `spike/src/` と `spike/scripts/` です。別コピーの実装をこのgemで管理しません。
123
+ 取得元は `templates/runtime/` と `templates/tools/` です。Workerリポジトリのspikeはビルド時に `spike/src/` と `spike/scripts/` へコピーします。
123
124
  レイアウト変更時はexporterと設定済みWorker refを一緒に更新します。
124
125
 
125
126
  `createWorker` はリクエストごとにVMを生成・破棄し、異なるリクエストのenvを共有しません。
127
+ 生成runtimeはWrangler向けに `PicoRubyDurableObject` もexportします。
126
128
  低レベルの `createRuntime` / `dispatch` / `closeRuntime` も再exportします。
127
129
  明示的にVMを再利用した場合、同じVMへのdispatchは実行時ライブラリが直列化します。
128
130
  出力はWranglerでバンドルする前提です。Node.jsがそのまま `.wasm` / `.bin` importできるという意味ではありません。
@@ -134,7 +136,7 @@ registryは環境変更を反映するため毎回検証・生成します。元
134
136
 
135
137
  ## bindings・環境・Wrangler
136
138
 
137
- wrangler.jsoncの `kv_namespaces` / `queues.producers` から型registryを生成します。
139
+ wrangler.jsoncの `kv_namespaces`・`queues.producers`・`durable_objects.bindings` から型registryを生成します。
138
140
  JSONCのコメント・末尾カンマに対応し、不正な設定・重複名・存在しない環境はビルドエラーにします。
139
141
  varsの値やsecretはビルド成果物へ埋め込みません。
140
142
 
@@ -143,9 +145,15 @@ kv = Cloudflare::KV.from_env(env, "CACHE_KV")
143
145
  kv.put("key", "value", ttl: 60)
144
146
  value = env["cloudflare.env"].CACHE_KV.get("key")
145
147
  Cloudflare::Queue.from_env(env, "EVENTS").send("created")
148
+ objects = Cloudflare::DurableObject.from_env(env, "OBJECTS")
149
+ objects.put("counter", { "value" => 1 })
150
+ counter = objects.get("counter")
146
151
  token = ENV["API_TOKEN"]
147
152
  ```
148
153
 
154
+ Durable Objectの `put` は `Cloudflare::DurableObject::POJO`、単純なHash/Array、
155
+ または `to_pojo` に反応するオブジェクトを受け取ります。`get` はJSON objectなら `POJO`、
156
+ JSON arrayなら内部のobjectをPOJO化したArrayを返します。
149
157
  Queueは現行APIに合わせてUTF-8文字列送信のみです。secretは.dev.varsまたは `wrangler secret put` で管理し、Gitへ追加しないでください。
150
158
 
151
159
  AccessにはRackミドルウェア `Rack::Cloudflare::Access`(`Cloudflare::Access` の別名)を使います。
@@ -175,8 +183,8 @@ JWT署名・アプリケーションのaudienceをローカル検証する機能
175
183
  通信・レスポンスの異常なら502を返し、後続アプリを呼びません。
176
184
  生成例では `/access` だけにミドルウェアを適用し、他のサンプル経路は公開のままです。
177
185
 
178
- Access対応はWorkerの `67aaa676d8247beaf19cbbeaeecb78115e490529` とmruby-rackの
179
- `30802024e263a0dde1f3a8467e648a70625adfd4` に反映済みで、このテンプレートは標準でそれらを使用します。
186
+ Workerの `5590e3ff32714ebcec35c53e1fad63156540e425` はAccess・Durable Objectに対応しています。
187
+ mruby-rackの `30802024e263a0dde1f3a8467e648a70625adfd4` はAccessミドルウェアに対応し、このテンプレートは両方を標準で使用します。
180
188
  ローカルmrbgem checkoutの指定は不要です。
181
189
 
182
190
  `npm run dev` / `npm run deploy` ではWranglerのcustom buildがRakeを実行します。
data/README.md CHANGED
@@ -53,7 +53,7 @@ After this release candidate is published, install it with `gem install picoruby
53
53
  src/index.js, package.json, wrangler.jsonc, .gitignore, and README.md.
54
54
  An existing destination is never overwritten, even if it is an empty directory. Commit Gemfile.lock and package-lock.json in your application repository.
55
55
 
56
- Pass `--bindings` to include KV, Queue and Access identity examples in app.rb and wrangler.jsonc.
56
+ Pass `--bindings` to include KV, Queue, Durable Object and Access identity examples in app.rb and wrangler.jsonc.
57
57
  The `/access` example requires `CF_ACCESS_TEAM` and a `CF_Authorization` cookie.
58
58
  The generated `.picoruby-cloudflare-template.json` records hashes of those two managed examples.
59
59
  Run `picoruby-cloudflare bindings PROJECT` with a future template version to refresh them as supported bindings expand.
@@ -91,7 +91,7 @@ A directory takes precedence over its revision, and relative directory paths are
91
91
  Revision attributes default to the values bundled in this gem; assigning `nil` restores those defaults.
92
92
  Dependency source selection no longer reads `PICORUBY_WORKER_WASM_GEM_DIR` or `MRUBY_RACK_GEM_DIR`, or accepts `worker:` / `rack:` arguments.
93
93
 
94
- The default Worker source is pinned to `67aaa676d8247beaf19cbbeaeecb78115e490529`.
94
+ The default Worker source is pinned to `5590e3ff32714ebcec35c53e1fad63156540e425`.
95
95
  Rack is pinned to `30802024e263a0dde1f3a8467e648a70625adfd4`.
96
96
  Override the Worker revision with a tag or commit SHA when a reproducible dependency is required.
97
97
  Before publishing this gem, verify that a fresh checkout can fetch both pinned sources.
@@ -112,6 +112,7 @@ generated/worker/
112
112
  index.js # createWorker({ app, bindingTypes })
113
113
  runtime.js
114
114
  host-bridge.js
115
+ durable-object.js
115
116
  picoruby-worker.js
116
117
  picoruby-worker.wasm
117
118
  tools/ # Binding registry generation scripts
@@ -119,10 +120,11 @@ generated/worker/
119
120
 
120
121
  The runtime library owns the Ruby/C code, HAL, and shared JS bridge. This gem owns the templates, CrossBuild DSL, export logic, and thin createWorker entry point.
121
122
  Shared JS and registry generation scripts are copied from **the same mrbgem checkout** used to build Wasm.
122
- Their current locations are `spike/src/` and `spike/scripts/`. This gem does not maintain a separate copy of those implementations.
123
+ Their source locations are `templates/runtime/` and `templates/tools/`. The Worker repository's spike copies them into `spike/src/` and `spike/scripts/` during its build.
123
124
  If that layout changes, update the exporter and configured Worker ref together.
124
125
 
125
126
  `createWorker` creates and closes a VM for each request, without sharing env between requests.
127
+ The generated runtime also exports `PicoRubyDurableObject` for Wrangler.
126
128
  The low-level `createRuntime` / `dispatch` / `closeRuntime` functions are also re-exported.
127
129
  If you explicitly reuse a VM, the runtime library serializes dispatches to that VM.
128
130
  The output is intended to be bundled with Wrangler; it does not make `.wasm` / `.bin` imports directly usable in Node.js.
@@ -134,7 +136,8 @@ However, the tested PicoRuby version rewrites src/version.c on every build, so t
134
136
 
135
137
  ## Bindings, environments, and Wrangler
136
138
 
137
- The type registry is generated from `kv_namespaces` / `queues.producers` in wrangler.jsonc.
139
+ The type registry is generated from `kv_namespaces`, `queues.producers`, and
140
+ `durable_objects.bindings` in wrangler.jsonc.
138
141
  JSONC comments and trailing commas are supported. Invalid configuration, duplicate binding names, and nonexistent environments cause build errors.
139
142
  Variable values and secrets are not embedded in build artifacts.
140
143
 
@@ -143,9 +146,15 @@ kv = Cloudflare::KV.from_env(env, "CACHE_KV")
143
146
  kv.put("key", "value", ttl: 60)
144
147
  value = env["cloudflare.env"].CACHE_KV.get("key")
145
148
  Cloudflare::Queue.from_env(env, "EVENTS").send("created")
149
+ objects = Cloudflare::DurableObject.from_env(env, "OBJECTS")
150
+ objects.put("counter", { "value" => 1 })
151
+ counter = objects.get("counter")
146
152
  token = ENV["API_TOKEN"]
147
153
  ```
148
154
 
155
+ Durable Object `put` accepts a `Cloudflare::DurableObject::POJO`, a simple Hash
156
+ or Array, or an object responding to `to_pojo`; `get` returns a `POJO` for a
157
+ JSON object and an Array containing POJOs for a JSON array.
149
158
  Queue sending currently supports UTF-8 strings only, matching the runtime API. Manage secrets through .dev.vars or `wrangler secret put`, and keep them out of Git.
150
159
 
151
160
  Access uses Rack middleware `Rack::Cloudflare::Access` (an alias of `Cloudflare::Access`):
@@ -175,8 +184,8 @@ The middleware returns 503 for missing/invalid configuration, 401 for a missing/
175
184
  or an Access 401/403 response, and 502 for upstream/protocol failures, without calling the application.
176
185
  The generated example applies middleware only to `/access`; other example routes remain public.
177
186
 
178
- Access support is included in Worker commit `67aaa676d8247beaf19cbbeaeecb78115e490529` and mruby-rack commit
179
- `30802024e263a0dde1f3a8467e648a70625adfd4`, which this template uses by default.
187
+ Worker commit `5590e3ff32714ebcec35c53e1fad63156540e425` includes Access and Durable Object support.
188
+ mruby-rack commit `30802024e263a0dde1f3a8467e648a70625adfd4` includes Access middleware support. This template uses both by default.
180
189
  No local mrbgem checkout overrides are required.
181
190
 
182
191
  With `npm run dev` / `npm run deploy`, Wrangler's custom build runs Rake.
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  module Picoruby::Cloudflare::Template
10
10
  module CrossBuild
11
- WORKER_REVISION = "67aaa676d8247beaf19cbbeaeecb78115e490529".freeze
11
+ WORKER_REVISION = "5590e3ff32714ebcec35c53e1fad63156540e425".freeze
12
12
  RACK_REVISION = "30802024e263a0dde1f3a8467e648a70625adfd4".freeze
13
13
  CORE_GEMS = %w[mruby-array-ext mruby-catch mruby-class-ext mruby-enum-ext
14
14
  mruby-hash-ext mruby-kernel-ext mruby-metaprog mruby-method
@@ -62,15 +62,15 @@ module Picoruby::Cloudflare::Template
62
62
  end
63
63
 
64
64
  def export(runtime_js, runtime_wasm)
65
- %w[runtime.js host-bridge.js].each do |name|
66
- write(File.join("runtime", name), File.binread(File.join(@gem_dir, "spike/src", name)))
65
+ %w[runtime.js host-bridge.js durable-object.js].each do |name|
66
+ write(File.join("runtime", name), File.binread(File.join(@gem_dir, "templates/runtime", name)))
67
67
  end
68
68
  write("runtime/picoruby-worker.js", File.binread(runtime_js))
69
69
  write("runtime/picoruby-worker.wasm", File.binread(runtime_wasm))
70
70
  # Keep parser and runtime from the same mrbgem checkout. Scripts are copied
71
71
  # below the project so Node resolves its jsonc-parser dependency there.
72
72
  %w[cloudflare-binding-registry.mjs generate-bindings.mjs].each do |name|
73
- write(File.join("tools", name), File.binread(File.join(@gem_dir, "spike/scripts", name)))
73
+ write(File.join("tools", name), File.binread(File.join(@gem_dir, "templates/tools", name)))
74
74
  end
75
75
  Tempfile.create(["bindings", ".js"], @output) do |temp|
76
76
  temp.close
@@ -82,7 +82,7 @@ module Picoruby::Cloudflare::Template
82
82
  end
83
83
  write("runtime/index.js", File.read(File.join(templates, "runtime/index.js")))
84
84
  write("package.json", JSON.pretty_generate({ private: true, type: "module", exports: "./runtime/index.js" }) + "\n")
85
- artifacts = %w[app.bin bindings.js package.json runtime/index.js runtime/runtime.js runtime/host-bridge.js runtime/picoruby-worker.js runtime/picoruby-worker.wasm]
85
+ artifacts = %w[app.bin bindings.js package.json runtime/index.js runtime/runtime.js runtime/host-bridge.js runtime/durable-object.js runtime/picoruby-worker.js runtime/picoruby-worker.wasm]
86
86
  write("manifest.json", JSON.pretty_generate({
87
87
  format_version: 1, generator_version: VERSION, environment: @environment,
88
88
  worker_revision: worker_revision,
@@ -97,7 +97,7 @@ module Picoruby::Cloudflare::Template
97
97
  end
98
98
 
99
99
  def check_assets!
100
- %w[spike/src/runtime.js spike/src/host-bridge.js spike/scripts/cloudflare-binding-registry.mjs spike/scripts/generate-bindings.mjs].each do |path|
100
+ %w[templates/runtime/runtime.js templates/runtime/host-bridge.js templates/runtime/durable-object.js templates/tools/cloudflare-binding-registry.mjs templates/tools/generate-bindings.mjs].each do |path|
101
101
  raise Error, "Worker mrbgem is missing export asset #{path}; use the documented runtime revision" unless File.file?(File.join(@gem_dir, path))
102
102
  end
103
103
  end
@@ -12,7 +12,7 @@ module Picoruby::Cloudflare::Template
12
12
  TEMPLATES = File.expand_path("../../../../templates", __dir__)
13
13
  BINDINGS_MANIFEST = ".picoruby-cloudflare-template.json"
14
14
  BINDINGS_FILES = %w[app.rb wrangler.jsonc].freeze
15
- BINDINGS_FEATURES = %w[kv queue access].freeze
15
+ BINDINGS_FEATURES = %w[kv queue durable_object access].freeze
16
16
 
17
17
  def initialize(destination, name: nil, gem_path: nil, bindings: false)
18
18
  @destination = File.expand_path(destination)
@@ -3,7 +3,7 @@
3
3
  module Picoruby
4
4
  module Cloudflare
5
5
  module Template
6
- VERSION = "0.1.0.rc2"
6
+ VERSION = "0.1.0.rc3"
7
7
  end
8
8
  end
9
9
  end
@@ -47,9 +47,12 @@ use Wrangler to bundle them, not a plain Node.js import of `src/index.js`.
47
47
  Configure bindings in `wrangler.jsonc`; the build regenerates `bindings.js`.
48
48
  Ruby can use `env["cloudflare.env"].CACHE_KV` or
49
49
  `Cloudflare::KV.from_env(env, "CACHE_KV")`, and similarly `Cloudflare::Queue.from_env`.
50
+ Durable Objects use `Cloudflare::DurableObject.from_env`; `put` accepts POJO,
51
+ Hash, Array, or an object responding to `to_pojo`.
50
52
  String/JSON vars and secrets are accessible through Ruby `ENV`.
51
53
 
52
- If this project was generated with `--bindings`, app.rb exposes `/kv`, `/queue` and `/access`
54
+ If this project was generated with `--bindings`, app.rb exposes `/kv`, `/queue`,
55
+ `/durable-object` and `/access`
53
56
  examples and `.picoruby-cloudflare-template.json` tracks their generated state.
54
57
  Run `picoruby-cloudflare bindings .` with a newer template to refresh unedited
55
58
  binding examples. The command refuses to overwrite an edited app.rb or wrangler.jsonc.
@@ -9,6 +9,10 @@ app = lambda do |env|
9
9
  when "/queue"
10
10
  Cloudflare::Queue.from_env(env, "EVENTS").send("Hello from PicoRuby!")
11
11
  "Message sent to Cloudflare Queue!"
12
+ when "/durable-object"
13
+ store = Cloudflare::DurableObject.from_env(env, "OBJECTS")
14
+ store.put("example", { "message" => "Hello from a Durable Object!" })
15
+ store.get("example")["message"]
12
16
  when "/access"
13
17
  identity = env["cloudflare.identity"]
14
18
  identity.email || "Access identity has no email"
@@ -2,4 +2,6 @@ import { createWorker } from "../generated/worker/runtime/index.js";
2
2
  import app from "../generated/worker/app.bin";
3
3
  import { cloudflareBindingTypes } from "../generated/worker/bindings.js";
4
4
 
5
+ export { PicoRubyDurableObject } from "../generated/worker/runtime/index.js";
6
+
5
7
  export default createWorker({ app, bindingTypes: cloudflareBindingTypes });
@@ -19,6 +19,14 @@
19
19
  { "binding": "EVENTS", "queue": "events" }
20
20
  ]
21
21
  },
22
+ "durable_objects": {
23
+ "bindings": [
24
+ { "name": "OBJECTS", "class_name": "PicoRubyDurableObject" }
25
+ ]
26
+ },
27
+ "migrations": [
28
+ { "tag": "v1", "new_sqlite_classes": ["PicoRubyDurableObject"] }
29
+ ],
22
30
  <% end -%>
23
31
  "vars": {
24
32
  <% if @bindings -%>
@@ -28,7 +36,7 @@
28
36
  "GREETING": "Hello from PicoRuby on Cloudflare!"
29
37
  }
30
38
  <% unless @bindings -%>
31
- // Add kv_namespaces / queues.producers here, then rebuild.
39
+ // Add kv_namespaces / queues.producers / durable_objects.bindings here, then rebuild.
32
40
  <% end -%>
33
41
  // Keep secrets out of this file; use .dev.vars and wrangler secret put.
34
42
  }
@@ -20,3 +20,4 @@ export function createWorker({ app, bindingTypes }) {
20
20
  }
21
21
 
22
22
  export { createCloudflareBindings, createRuntime, dispatch, closeRuntime } from "./runtime.js";
23
+ export { PicoRubyDurableObject } from "./durable-object.js";
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picoruby-cloudflare-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc2
4
+ version: 0.1.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio Kondo