-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative_backends.go
More file actions
72 lines (53 loc) · 2.59 KB
/
Copy pathnative_backends.go
File metadata and controls
72 lines (53 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//go:build !wasip1
// Package plugin — stub backends for non-WASM builds.
//
// These stubs satisfy the DBBackend/KVBackend/LogBackend/ConfigBackend
// interfaces and the EmitEvent function when compiling for native platforms
// (e.g. go test, go vet). They are intentionally no-ops / error-returners
// so that tests must inject real implementations via plugintest.NewContext().
package plugin
import "errors"
var errNotWASM = errors.New("plugin: this function is only available in a WASM module")
// ── Stubs ─────────────────────────────────────────────────────────────────────
func newWASMDBBackend() DBBackend { return &stubDBBackend{} }
func newWASMKVBackend() KVBackend { return &stubKVBackend{} }
func newWASMLogBackend() LogBackend { return &stubLogBackend{} }
func newWASMConfigBackend() ConfigBackend { return &stubConfigBackend{} }
type stubDBBackend struct{}
func (b *stubDBBackend) Query(_ string, _ []any) (*DBQueryResult, error) {
return nil, errNotWASM
}
func (b *stubDBBackend) Exec(_ string, _ []any) (int64, error) {
return 0, errNotWASM
}
type stubKVBackend struct{}
func (b *stubKVBackend) Get(_ string) (string, bool) { return "", false }
func (b *stubKVBackend) Set(_, _ string) {}
func (b *stubKVBackend) Delete(_ string) {}
type stubLogBackend struct{}
func (b *stubLogBackend) Log(_ int, _ string) {}
type stubConfigBackend struct{}
func (b *stubConfigBackend) Get(_ string) (string, bool) { return "", false }
// EmitEvent is a no-op outside WASM.
func EmitEvent(_ string, _ any) {}
// RecordActivity is a no-op outside WASM.
func RecordActivity(_, _, _, _ string, _ any) {}
// FetchResponse is also defined in wasm_backends.go (wasip1); provide the
// type here so non-WASM consumers can reference it.
type FetchResponse struct {
Status int `json:"status"`
Body string `json:"body"`
Headers map[string]string `json:"headers"`
Error string `json:"error"`
}
// Fetch always returns errNotWASM outside a WASM module.
func Fetch(_, _ string, _ map[string]string, _ string) (*FetchResponse, error) {
return nil, errNotWASM
}
// ptrOf and hostError are used by wasm_backends.go (wasip1 only); provide
// stubs here so the non-WASM build does not need them.
//
//nolint:unused // used in wasm_backends.go in WASM builds
type hostError struct{ msg string }
//nolint:unused // used in wasm_backends.go in WASM builds
func (e *hostError) Error() string { return e.msg }