Skip to content

Commit 40cd0c5

Browse files
authored
refactor: clean up shared feature helpers (#340)
Tracking issue: #342 ## Stack context Part 30 of the Option 5 folder-feature stack. - Previous: #339 - Next: feature-graph guardrails and final documentation Review this PR as the incremental diff against #339. ## Summary - split cache-specific support types into internal `src/storage/CacheTypes.res` - return `WebWorkersTypes` to the Workers folder - update Cache, CacheStorage, Window, browser globals, and worker scopes to use the owning helper modules - fold the shared Blob/File type identity into foundational `DOM.res` - remove the internal `BaseFile` helper while preserving `FileTypes.blob` and `FileTypes.file` aliases ## Why this cleanup is last Earlier PRs temporarily kept `WebWorkersTypes` with Storage and `BaseFile` in core so folder moves could remain mechanical. With the complete graph in place, the ownership directions are now explicit: Workers depends on Storage, and File aliases the small foundational identities in DOM. ## Resolved temporary state - cache and worker support types no longer share one misplaced helper module - the standalone `BaseFile` module is removed - no module-slice exception is required ## Review focus - preservation of Blob/File type identity through the new DOM aliases - cache/worker helper ownership - the unchanged public feature closures ## Verification - `node_modules/.bin/rescript build --prod --features WebAPI.DOM` - `node_modules/.bin/rescript build --prod --features WebAPI.Storage` - `node_modules/.bin/rescript build --prod --features WebAPI.Workers` - `node_modules/.bin/rescript build --prod --features WebAPI.Window` - `npm run build` - `npm test` - `npm run format:check` - `git diff --check`
1 parent 7368f63 commit 40cd0c5

9 files changed

Lines changed: 80 additions & 97 deletions

File tree

‎src/core/BaseFile.res‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎src/core/DOM.res‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,29 @@ type predefinedColorSpace =
167167
| @as("display-p3") DisplayP3
168168
| @as("srgb") Srgb
169169

170+
/**
171+
A file-like object of immutable, raw data.
172+
[See Blob on MDN](https://developer.mozilla.org/docs/Web/API/Blob)
173+
*/
174+
type blob = private {
175+
size: int,
176+
@as("type")
177+
type_: string,
178+
}
179+
180+
/**
181+
Provides information about a file selected by or available to the user.
182+
[See File on MDN](https://developer.mozilla.org/docs/Web/API/File)
183+
*/
184+
type file = private {
185+
...blob,
186+
name: string,
187+
lastModified: int,
188+
webkitRelativePath: string,
189+
}
190+
170191
type shareData = {
171-
mutable files?: array<BaseFile.file>,
192+
mutable files?: array<file>,
172193
mutable title?: string,
173194
mutable text?: string,
174195
mutable url?: string,

‎src/file/FileTypes.res‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ A file-like object of immutable, raw data. Blobs represent data that isn't neces
2020
[See Blob on MDN](https://developer.mozilla.org/docs/Web/API/Blob)
2121
*/
2222
@editor.completeFrom(Blob)
23-
type blob = BaseFile.blob = private {
23+
type blob = DOM.blob = private {
2424
/**
2525
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Blob/size)
2626
*/
@@ -71,7 +71,7 @@ Provides information about files and allows JavaScript in a web page to access t
7171
[See WebApiFile on MDN](https://developer.mozilla.org/docs/Web/API/File)
7272
*/
7373
@editor.completeFrom(WebApiFile)
74-
type file = BaseFile.file = private {
74+
type file = DOM.file = private {
7575
...blob,
7676
/**
7777
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/File/name)

‎src/storage/Cache.res‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,65 @@
33
*/
44
@send
55
external match: (
6-
WebWorkersTypes.cache,
6+
CacheTypes.cache,
77
~request: FetchTypes.request,
8-
~options: WebWorkersTypes.cacheQueryOptions=?,
8+
~options: CacheTypes.cacheQueryOptions=?,
99
) => Nullable.t<FetchTypes.response> = "match"
1010

1111
/**
1212
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/match)
1313
*/
1414
@send
1515
external match2: (
16-
WebWorkersTypes.cache,
16+
CacheTypes.cache,
1717
~request: string,
18-
~options: WebWorkersTypes.cacheQueryOptions=?,
18+
~options: CacheTypes.cacheQueryOptions=?,
1919
) => Nullable.t<FetchTypes.response> = "match"
2020

2121
/**
2222
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/matchAll)
2323
*/
2424
@send
2525
external matchAll: (
26-
WebWorkersTypes.cache,
26+
CacheTypes.cache,
2727
~request: FetchTypes.request=?,
28-
~options: WebWorkersTypes.cacheQueryOptions=?,
28+
~options: CacheTypes.cacheQueryOptions=?,
2929
) => promise<array<FetchTypes.response>> = "matchAll"
3030

3131
/**
3232
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/matchAll)
3333
*/
3434
@send
3535
external matchAll2: (
36-
WebWorkersTypes.cache,
36+
CacheTypes.cache,
3737
~request: string=?,
38-
~options: WebWorkersTypes.cacheQueryOptions=?,
38+
~options: CacheTypes.cacheQueryOptions=?,
3939
) => promise<array<FetchTypes.response>> = "matchAll"
4040

4141
/**
4242
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/add)
4343
*/
4444
@send
45-
external add: (WebWorkersTypes.cache, FetchTypes.request) => promise<unit> = "add"
45+
external add: (CacheTypes.cache, FetchTypes.request) => promise<unit> = "add"
4646

4747
/**
4848
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/add)
4949
*/
5050
@send
51-
external add2: (WebWorkersTypes.cache, string) => promise<unit> = "add"
51+
external add2: (CacheTypes.cache, string) => promise<unit> = "add"
5252

5353
/**
5454
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/addAll)
5555
*/
5656
@send
57-
external addAll: (WebWorkersTypes.cache, array<FetchTypes.requestInfo>) => promise<unit> = "addAll"
57+
external addAll: (CacheTypes.cache, array<FetchTypes.requestInfo>) => promise<unit> = "addAll"
5858

5959
/**
6060
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/put)
6161
*/
6262
@send
6363
external put: (
64-
WebWorkersTypes.cache,
64+
CacheTypes.cache,
6565
~request: FetchTypes.request,
6666
~response: FetchTypes.response,
6767
) => promise<unit> = "put"
@@ -71,7 +71,7 @@ external put: (
7171
*/
7272
@send
7373
external put2: (
74-
WebWorkersTypes.cache,
74+
CacheTypes.cache,
7575
~request: string,
7676
~response: FetchTypes.response,
7777
) => promise<unit> = "put"
@@ -81,37 +81,37 @@ external put2: (
8181
*/
8282
@send
8383
external delete: (
84-
WebWorkersTypes.cache,
84+
CacheTypes.cache,
8585
~request: FetchTypes.request,
86-
~options: WebWorkersTypes.cacheQueryOptions=?,
86+
~options: CacheTypes.cacheQueryOptions=?,
8787
) => promise<bool> = "delete"
8888

8989
/**
9090
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/delete)
9191
*/
9292
@send
9393
external delete2: (
94-
WebWorkersTypes.cache,
94+
CacheTypes.cache,
9595
~request: string,
96-
~options: WebWorkersTypes.cacheQueryOptions=?,
96+
~options: CacheTypes.cacheQueryOptions=?,
9797
) => promise<bool> = "delete"
9898

9999
/**
100100
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/keys)
101101
*/
102102
@send
103103
external keys: (
104-
WebWorkersTypes.cache,
104+
CacheTypes.cache,
105105
~request: FetchTypes.request=?,
106-
~options: WebWorkersTypes.cacheQueryOptions=?,
106+
~options: CacheTypes.cacheQueryOptions=?,
107107
) => promise<array<FetchTypes.request>> = "keys"
108108

109109
/**
110110
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/keys)
111111
*/
112112
@send
113113
external keys2: (
114-
WebWorkersTypes.cache,
114+
CacheTypes.cache,
115115
~request: string=?,
116-
~options: WebWorkersTypes.cacheQueryOptions=?,
116+
~options: CacheTypes.cacheQueryOptions=?,
117117
) => promise<array<FetchTypes.request>> = "keys"

‎src/storage/CacheStorage.res‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@
33
*/
44
@send
55
external match: (
6-
WebWorkersTypes.cacheStorage,
6+
CacheTypes.cacheStorage,
77
~request: FetchTypes.request,
8-
~options: WebWorkersTypes.multiCacheQueryOptions=?,
8+
~options: CacheTypes.multiCacheQueryOptions=?,
99
) => Nullable.t<FetchTypes.response> = "match"
1010

1111
/**
1212
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage/match)
1313
*/
1414
@send
1515
external match2: (
16-
WebWorkersTypes.cacheStorage,
16+
CacheTypes.cacheStorage,
1717
~request: string,
18-
~options: WebWorkersTypes.multiCacheQueryOptions=?,
18+
~options: CacheTypes.multiCacheQueryOptions=?,
1919
) => Nullable.t<FetchTypes.response> = "match"
2020

2121
/**
2222
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage/has)
2323
*/
2424
@send
25-
external has: (WebWorkersTypes.cacheStorage, string) => promise<bool> = "has"
25+
external has: (CacheTypes.cacheStorage, string) => promise<bool> = "has"
2626

2727
/**
2828
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage/open)
2929
*/
3030
@send
31-
external open_: (WebWorkersTypes.cacheStorage, string) => promise<WebWorkersTypes.cache> = "open"
31+
external open_: (CacheTypes.cacheStorage, string) => promise<CacheTypes.cache> = "open"
3232

3333
/**
3434
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage/delete)
3535
*/
3636
@send
37-
external delete: (WebWorkersTypes.cacheStorage, string) => promise<bool> = "delete"
37+
external delete: (CacheTypes.cacheStorage, string) => promise<bool> = "delete"
3838

3939
/**
4040
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage/keys)
4141
*/
4242
@send
43-
external keys: WebWorkersTypes.cacheStorage => promise<array<string>> = "keys"
43+
external keys: CacheTypes.cacheStorage => promise<array<string>> = "keys"

‎src/storage/CacheTypes.res‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
Provides a storage mechanism for Request / Response object pairs that are cached, for example as part of the Service Worker life cycle. The Cache interface is also available in window contexts.
3+
[See Cache on MDN](https://developer.mozilla.org/docs/Web/API/Cache)
4+
*/
5+
@editor.completeFrom(Cache)
6+
type cache = private {}
7+
8+
/**
9+
The storage for Cache objects.
10+
[See CacheStorage on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage)
11+
*/
12+
@editor.completeFrom(CacheStorage)
13+
type cacheStorage = private {}
14+
15+
type cacheQueryOptions = {
16+
mutable ignoreSearch?: bool,
17+
mutable ignoreMethod?: bool,
18+
mutable ignoreVary?: bool,
19+
}
20+
21+
type multiCacheQueryOptions = {
22+
...cacheQueryOptions,
23+
mutable cacheName?: string,
24+
}

‎src/window/DomGlobal.res‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ external performance: PerformanceTypes.performance = "performance"
212212
/**
213213
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/caches)
214214
*/
215-
external caches: WebWorkersTypes.cacheStorage = "caches"
215+
external caches: CacheTypes.cacheStorage = "caches"
216216

217217
/**
218218
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage)

‎src/window/Window.res‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ external performance: t => PerformanceTypes.performance = "performance"
266266
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/caches)
267267
*/
268268
@get
269-
external caches: t => WebWorkersTypes.cacheStorage = "caches"
269+
external caches: t => CacheTypes.cacheStorage = "caches"
270270

271271
/**
272272
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage)
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
/**
2-
Provides a storage mechanism for Request / Response object pairs that are cached, for example as part of the WebApiServiceWorker life cycle. Note that the Cache interface is exposed to windowed scopes as well as workers. You don't have to use it in conjunction with service workers, even though it is defined in the service worker spec.
3-
[See Cache on MDN](https://developer.mozilla.org/docs/Web/API/Cache)
4-
*/
5-
@editor.completeFrom(Cache)
6-
type cache = private {}
7-
8-
/**
9-
The storage for Cache objects.
10-
[See CacheStorage on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage)
11-
*/
12-
@editor.completeFrom(CacheStorage)
13-
type cacheStorage = private {}
14-
15-
type cacheQueryOptions = {
16-
mutable ignoreSearch?: bool,
17-
mutable ignoreMethod?: bool,
18-
mutable ignoreVary?: bool,
19-
}
20-
21-
type multiCacheQueryOptions = {
22-
...cacheQueryOptions,
23-
mutable cacheName?: string,
24-
}
25-
261
type sharedWorker
272

283
/**
@@ -38,7 +13,7 @@ type workerGlobalScope = private {
3813
/**
3914
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/caches)
4015
*/
41-
caches: cacheStorage,
16+
caches: CacheTypes.cacheStorage,
4217
/**
4318
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/crossOriginIsolated)
4419
*/

0 commit comments

Comments
 (0)