openwrangler 0.0.14 → 0.0.16
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.
- package/README.md +57 -58
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
# openwrangler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Cloudflare bindings implementation library that solves miniflare's bugs and limitations
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Background
|
|
6
6
|
|
|
7
|
-
Cloudflare Workers
|
|
7
|
+
Cloudflare Workers development environment uses miniflare internally via `wrangler dev` to simulate bindings like R2, KV, and D1 locally. However, miniflare has critical issues:
|
|
8
8
|
|
|
9
|
-
### miniflare
|
|
9
|
+
### miniflare's Problems
|
|
10
10
|
|
|
11
|
-
1. **R2 Buffer
|
|
12
|
-
2. **remote
|
|
13
|
-
3. **프로덕션 환경과의 차이**: 로컬 시뮬레이션 환경이라 실제 프로덕션과 동작이 다를 수 있음
|
|
11
|
+
1. **R2 Buffer Processing Bug**: Fails to properly handle Node.js Buffer when uploading to R2
|
|
12
|
+
2. **remote Option Errors**: The `remote = true` option in `wrangler.toml` throws errors, making it completely unusable
|
|
14
13
|
|
|
15
|
-
### openwrangler
|
|
14
|
+
### openwrangler's Solution
|
|
16
15
|
|
|
17
|
-
openwrangler
|
|
16
|
+
openwrangler bypasses miniflare and **directly calls Cloudflare REST APIs** to solve these problems:
|
|
18
17
|
|
|
19
|
-
- **R2**:
|
|
20
|
-
- **KV**:
|
|
21
|
-
- **D1**:
|
|
18
|
+
- **R2**: Direct access to actual Cloudflare R2 buckets via S3-compatible API
|
|
19
|
+
- **KV**: Use real KV namespaces via Cloudflare KV REST API
|
|
20
|
+
- **D1**: Query real D1 databases via Cloudflare D1 REST API
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
You can use actual production resources in your development environment, enabling development and testing in an environment identical to production.
|
|
24
23
|
|
|
25
|
-
##
|
|
24
|
+
## Installation
|
|
26
25
|
|
|
27
26
|
```bash
|
|
28
27
|
npm install openwrangler
|
|
@@ -30,9 +29,9 @@ npm install openwrangler
|
|
|
30
29
|
pnpm add openwrangler
|
|
31
30
|
```
|
|
32
31
|
|
|
33
|
-
##
|
|
32
|
+
## Usage
|
|
34
33
|
|
|
35
|
-
### 1.
|
|
34
|
+
### 1. Direct Usage (Node.js)
|
|
36
35
|
|
|
37
36
|
```typescript
|
|
38
37
|
import { createR2Binding, createKVBinding, createD1Binding } from 'openwrangler'
|
|
@@ -44,7 +43,7 @@ const r2 = createR2Binding({
|
|
|
44
43
|
r2SecretAccessKey: 'your-r2-secret-key',
|
|
45
44
|
}, 'bucket-name')
|
|
46
45
|
|
|
47
|
-
await r2.put('image.png', buffer) // ✅ Buffer
|
|
46
|
+
await r2.put('image.png', buffer) // ✅ Buffer works correctly
|
|
48
47
|
const file = await r2.get('image.png')
|
|
49
48
|
|
|
50
49
|
// KV
|
|
@@ -65,17 +64,17 @@ const d1 = createD1Binding({
|
|
|
65
64
|
const result = await d1.prepare('SELECT * FROM users').all()
|
|
66
65
|
```
|
|
67
66
|
|
|
68
|
-
### 2. Nitro/Nuxt
|
|
67
|
+
### 2. Nitro/Nuxt Integration (`@bino0216/nitro-cloudflare-dev`)
|
|
69
68
|
|
|
70
|
-
Nitro
|
|
69
|
+
For Nitro and Nuxt, use the integration module for easier setup.
|
|
71
70
|
|
|
72
|
-
####
|
|
71
|
+
#### Installation
|
|
73
72
|
|
|
74
73
|
```bash
|
|
75
74
|
npm install @bino0216/nitro-cloudflare-dev
|
|
76
75
|
```
|
|
77
76
|
|
|
78
|
-
#### Nuxt
|
|
77
|
+
#### Nuxt Configuration
|
|
79
78
|
|
|
80
79
|
```typescript
|
|
81
80
|
// nuxt.config.ts
|
|
@@ -85,7 +84,7 @@ export default defineNuxtConfig({
|
|
|
85
84
|
nitro: {
|
|
86
85
|
modules: [nitroCloudflareDev],
|
|
87
86
|
cloudflareDev: {
|
|
88
|
-
remote: true, //
|
|
87
|
+
remote: true, // Use actual Cloudflare resources
|
|
89
88
|
remoteCredentials: {
|
|
90
89
|
accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
|
|
91
90
|
apiToken: process.env.CLOUDFLARE_API_TOKEN,
|
|
@@ -99,7 +98,7 @@ export default defineNuxtConfig({
|
|
|
99
98
|
})
|
|
100
99
|
```
|
|
101
100
|
|
|
102
|
-
#### wrangler.toml
|
|
101
|
+
#### wrangler.toml Configuration
|
|
103
102
|
|
|
104
103
|
```toml
|
|
105
104
|
[[r2_buckets]]
|
|
@@ -116,7 +115,7 @@ database_name = "my-database"
|
|
|
116
115
|
database_id = "your-db-id"
|
|
117
116
|
```
|
|
118
117
|
|
|
119
|
-
####
|
|
118
|
+
#### Usage
|
|
120
119
|
|
|
121
120
|
```typescript
|
|
122
121
|
// server/api/example.ts
|
|
@@ -136,83 +135,83 @@ export default defineEventHandler(async (event) => {
|
|
|
136
135
|
})
|
|
137
136
|
```
|
|
138
137
|
|
|
139
|
-
### 3. Buffer
|
|
138
|
+
### 3. Buffer Compatibility Wrapper (When Using miniflare)
|
|
140
139
|
|
|
141
|
-
`remote: false
|
|
140
|
+
If you want to use miniflare with `remote: false` while only fixing the R2 Buffer issue:
|
|
142
141
|
|
|
143
142
|
```typescript
|
|
144
143
|
import { wrapR2BucketForDev } from 'openwrangler'
|
|
145
144
|
|
|
146
|
-
//
|
|
145
|
+
// Wrap the R2 binding from miniflare
|
|
147
146
|
const r2 = wrapR2BucketForDev(miniflareR2Bucket)
|
|
148
147
|
|
|
149
|
-
//
|
|
148
|
+
// Buffer now works correctly
|
|
150
149
|
await r2.put('file.bin', Buffer.from([1, 2, 3]))
|
|
151
150
|
```
|
|
152
151
|
|
|
153
|
-
`@bino0216/nitro-cloudflare-dev
|
|
152
|
+
`@bino0216/nitro-cloudflare-dev` automatically applies this wrapper to all R2 bindings when `remote: false`.
|
|
154
153
|
|
|
155
|
-
##
|
|
154
|
+
## Supported Bindings
|
|
156
155
|
|
|
157
|
-
|
|
|
158
|
-
|
|
159
|
-
| R2 | `R2Bucket` | S3
|
|
156
|
+
| Binding | Type | REST API | Support |
|
|
157
|
+
|---------|------|----------|---------|
|
|
158
|
+
| R2 | `R2Bucket` | S3-compatible API | ✅ |
|
|
160
159
|
| KV | `KVNamespace` | Cloudflare KV API | ✅ |
|
|
161
160
|
| D1 | `D1Database` | Cloudflare D1 API | ✅ |
|
|
162
161
|
|
|
163
|
-
|
|
162
|
+
All types are imported from `@cloudflare/workers-types` to ensure 100% compatibility with actual Cloudflare Workers.
|
|
164
163
|
|
|
165
|
-
##
|
|
164
|
+
## Use Cases
|
|
166
165
|
|
|
167
|
-
###
|
|
168
|
-
|
|
166
|
+
### Development with Real Data
|
|
167
|
+
Access actual production resources during local development for development and debugging
|
|
169
168
|
|
|
170
|
-
### miniflare
|
|
171
|
-
|
|
169
|
+
### Bypass miniflare Bugs
|
|
170
|
+
Work around known miniflare bugs such as R2 Buffer processing
|
|
172
171
|
|
|
173
|
-
###
|
|
174
|
-
|
|
172
|
+
### Integration Testing
|
|
173
|
+
Run integration tests against actual Cloudflare services
|
|
175
174
|
|
|
176
175
|
### CI/CD
|
|
177
|
-
GitHub Actions
|
|
176
|
+
Test with real Cloudflare resources in GitHub Actions and other CI/CD pipelines
|
|
178
177
|
|
|
179
|
-
##
|
|
178
|
+
## Development
|
|
180
179
|
|
|
181
180
|
```bash
|
|
182
|
-
#
|
|
181
|
+
# Install dependencies
|
|
183
182
|
pnpm install
|
|
184
183
|
|
|
185
|
-
#
|
|
184
|
+
# Build
|
|
186
185
|
pnpm build
|
|
187
186
|
|
|
188
|
-
# playground
|
|
187
|
+
# Run playground (Nuxt + Nitro test environment)
|
|
189
188
|
pnpm dev
|
|
190
189
|
```
|
|
191
190
|
|
|
192
|
-
##
|
|
191
|
+
## Project Structure
|
|
193
192
|
|
|
194
193
|
```
|
|
195
194
|
openwrangler/
|
|
196
195
|
├── src/
|
|
197
|
-
│ ├── index.ts #
|
|
196
|
+
│ ├── index.ts # Main export
|
|
198
197
|
│ ├── bindings/
|
|
199
|
-
│ │ ├── r2.ts # R2
|
|
198
|
+
│ │ ├── r2.ts # R2 binding implementation (S3 API)
|
|
200
199
|
│ │ ├── r2.dev.ts # R2 Buffer wrapper
|
|
201
|
-
│ │ ├── kv.ts # KV
|
|
202
|
-
│ │ └── d1.ts # D1
|
|
200
|
+
│ │ ├── kv.ts # KV binding implementation
|
|
201
|
+
│ │ └── d1.ts # D1 binding implementation
|
|
203
202
|
│ └── utils/
|
|
204
|
-
│ ├── http-client.ts # Cloudflare API
|
|
205
|
-
│ └── s3-signer.ts # AWS S3
|
|
203
|
+
│ ├── http-client.ts # Cloudflare API client
|
|
204
|
+
│ └── s3-signer.ts # AWS S3 signing utility
|
|
206
205
|
├── packages/
|
|
207
|
-
│ └── nitro-cloudflare-dev/ # Nitro/Nuxt
|
|
208
|
-
└── playground/ # Nuxt
|
|
206
|
+
│ └── nitro-cloudflare-dev/ # Nitro/Nuxt integration module
|
|
207
|
+
└── playground/ # Nuxt test environment
|
|
209
208
|
```
|
|
210
209
|
|
|
211
|
-
##
|
|
210
|
+
## License
|
|
212
211
|
|
|
213
212
|
MIT
|
|
214
213
|
|
|
215
|
-
##
|
|
214
|
+
## Related Issues
|
|
216
215
|
|
|
217
216
|
- [miniflare R2 Buffer issue](https://github.com/cloudflare/workers-sdk/issues)
|
|
218
|
-
- [wrangler remote binding
|
|
217
|
+
- [wrangler remote binding errors](https://github.com/cloudflare/workers-sdk/issues)
|
package/dist/index.mjs
CHANGED
|
@@ -304,7 +304,7 @@ function createKVBinding$1(client, namespaceId) {
|
|
|
304
304
|
if (data.list_complete) {
|
|
305
305
|
return {
|
|
306
306
|
list_complete: true,
|
|
307
|
-
keys: data.keys.map((k) => ({
|
|
307
|
+
keys: (data.keys || []).map((k) => ({
|
|
308
308
|
name: k.name,
|
|
309
309
|
expiration: k.expiration,
|
|
310
310
|
metadata: k.metadata
|
|
@@ -314,7 +314,7 @@ function createKVBinding$1(client, namespaceId) {
|
|
|
314
314
|
} else {
|
|
315
315
|
return {
|
|
316
316
|
list_complete: false,
|
|
317
|
-
keys: data.keys.map((k) => ({
|
|
317
|
+
keys: (data.keys || []).map((k) => ({
|
|
318
318
|
name: k.name,
|
|
319
319
|
expiration: k.expiration,
|
|
320
320
|
metadata: k.metadata
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openwrangler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.16",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typescript": "^5.7.2",
|
|
24
24
|
"unbuild": "^3.3.1",
|
|
25
25
|
"wrangler": "^4.54.0",
|
|
26
|
-
"@bino0216/nitro-cloudflare-dev": "0.2.
|
|
26
|
+
"@bino0216/nitro-cloudflare-dev": "0.2.17"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"dev": "cd ./playground && pnpm dev",
|