1 //:build !wasm
2
3 package sw
4
5 // --- Lifecycle ---
6
7 // OnInstall registers the install handler. fn receives the event handle.
8 func OnInstall(fn func(Event)) { panic("jsbridge") }
9
10 // OnActivate registers the activate handler.
11 func OnActivate(fn func(Event)) { panic("jsbridge") }
12
13 // OnFetch registers the fetch handler.
14 func OnFetch(fn func(Event)) { panic("jsbridge") }
15
16 // OnMessage registers the message handler.
17 func OnMessage(fn func(Event)) { panic("jsbridge") }
18
19 // --- Event methods ---
20
21 // WaitUntil extends the event lifetime until done is called.
22 // Call done() when your async work is complete.
23 func WaitUntil(event Event, fn func(done func())) { panic("jsbridge") }
24
25 // RespondWith provides a response for a fetch event.
26 func RespondWith(event Event, resp Response) { panic("jsbridge") }
27
28 // RespondWithNetwork lets the fetch fall through to the network.
29 func RespondWithNetwork(event Event) { panic("jsbridge") }
30
31 // RespondWithCacheFirst tries cache, falls back to network.
32 // Must be called synchronously from the fetch handler.
33 func RespondWithCacheFirst(event Event) { panic("jsbridge") }
34
35 // RespondWithNetworkFirst tries network, falls back to cache.
36 // Updates cache on successful fetch. Use for code files that change on rebuild.
37 func RespondWithNetworkFirst(event Event) { panic("jsbridge") }
38
39 // RespondWithProxyCache handles /proxy/<base64url> requests with a
40 // decoded-URL cache key (so duplicate base64 encodings share one entry)
41 // and an X-Smesh-Cached-At freshness stamp. Cache TTL is 30 days. Must
42 // be called synchronously from the fetch handler.
43 func RespondWithProxyCache(event Event) { panic("jsbridge") }
44
45 // PruneProxyCache deletes /proxy/ cache entries older than maxAgeMs.
46 // Best-effort; calls fn when complete (or on error).
47 func PruneProxyCache(maxAgeMs int64, fn func()) { panic("jsbridge") }
48
49 // GetRequestURL returns the request URL from a fetch event.
50 func GetRequestURL(event Event) (s string) { panic("jsbridge") }
51
52 // GetRequestPath returns just the pathname from a fetch event.
53 func GetRequestPath(event Event) (s string) { panic("jsbridge") }
54
55 // GetMessageData returns the string data from a message event.
56 // If data is not a string, returns JSON.stringify(data).
57 func GetMessageData(event Event) (s string) { panic("jsbridge") }
58
59 // GetMessageClientID returns the source client ID from a message event.
60 func GetMessageClientID(event Event) (s string) { panic("jsbridge") }
61
62 // --- SW globals ---
63
64 // Origin returns self.location.origin (e.g. "https://example.com").
65 func Origin() (s string) { panic("jsbridge") }
66
67 // SkipWaiting forces the waiting service worker to become active.
68 func SkipWaiting() { panic("jsbridge") }
69
70 // ClaimClients takes control of all clients. Calls done when complete.
71 func ClaimClients(done func()) { panic("jsbridge") }
72
73 // MatchClients gets all window clients. Calls fn with each client.
74 func MatchClients(fn func(Client)) { panic("jsbridge") }
75
76 // PostMessage sends a string message to a client.
77 func PostMessage(client Client, msg string) { panic("jsbridge") }
78
79 // PostMessageJSON sends a raw JSON message to a client (parsed by receiver).
80 func PostMessageJSON(client Client, json string) { panic("jsbridge") }
81
82 // GetClientByID looks up a client by ID. Calls fn with (client, true) or (0, false).
83 func GetClientByID(id string, fn func(Client, bool)) { panic("jsbridge") }
84
85 // Navigate navigates a client to a URL.
86 func Navigate(client Client, url string) { panic("jsbridge") }
87
88 // --- Cache ---
89
90 // CacheOpen opens a named cache. Calls fn with the cache handle.
91 func CacheOpen(name string, fn func(Cache)) { panic("jsbridge") }
92
93 // CacheAddAll caches all the given URLs. Calls done when complete.
94 func CacheAddAll(cache Cache, urls []string, done func()) { panic("jsbridge") }
95
96 // CacheFromManifests fetches the app and SW build manifests, combines
97 // them with the given static files, and caches everything. Calls done when complete.
98 func CacheFromManifests(cache Cache, staticFiles []string, done func()) { panic("jsbridge") }
99
100 // CachePut stores a response in the cache. Calls done when complete.
101 func CachePut(cache Cache, url string, resp Response, done func()) { panic("jsbridge") }
102
103 // CacheMatch looks up a URL in all caches. Calls fn with response (0 if miss).
104 func CacheMatch(url string, fn func(Response)) { panic("jsbridge") }
105
106 // CacheDelete deletes a named cache. Calls done when complete.
107 func CacheDelete(name string, done func()) { panic("jsbridge") }
108
109 // --- Fetch ---
110
111 // Fetch fetches a URL. Calls fn with (response, ok).
112 func Fetch(url string, fn func(Response, bool)) { panic("jsbridge") }
113
114 // FetchAll fetches multiple URLs in parallel.
115 // Calls onEach(index, response, ok) for each completed fetch.
116 // Calls onDone() when all fetches have completed.
117 func FetchAll(urls []string, onEach func(int32, Response, bool), onDone func()) { panic("jsbridge") }
118
119 // ResponseOK returns whether the response status is 200-299.
120 func ResponseOK(resp Response) (ok bool) { panic("jsbridge") }
121
122 // --- SSE ---
123
124 // SSEConnect opens an EventSource. Calls onMessage with each data string.
125 func SSEConnect(url string, onMessage func(string)) (s SSE) { panic("jsbridge") }
126
127 // SSEClose closes an EventSource.
128 func SSEClose(id SSE) { panic("jsbridge") }
129
130 // --- Timers ---
131
132 // SetTimeout calls fn after ms milliseconds. Returns timer handle.
133 func SetTimeout(ms int32, fn func()) (t Timer) { panic("jsbridge") }
134
135 // ClearTimeout cancels a timer.
136 func ClearTimeout(t Timer) { panic("jsbridge") }
137
138 // --- Time ---
139
140 // NowSeconds returns current time as Unix seconds.
141 func NowSeconds() (n int64) { panic("jsbridge") }
142
143 // NowMillis returns current time as Unix milliseconds.
144 func NowMillis() (n int64) { panic("jsbridge") }
145
146 // --- Logging ---
147
148 // Log writes to console.log in the SW context.
149 func Log(msg string) { panic("jsbridge") }
150