@rescript/webapi 0.1.0-experimental-34acf7e → 0.1.0-experimental-3f4e07b

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescript/webapi",
3
- "version": "0.1.0-experimental-34acf7e",
3
+ "version": "0.1.0-experimental-3f4e07b",
4
4
  "description": "Experimental successor to [rescript-webapi](https://github.com/TheSpyder/rescript-webapi)",
5
5
  "homepage": "https://rescript-lang.github.io/experimental-rescript-webapi/",
6
6
  "bugs": "https://github.com/rescript-lang/experimental-rescript-webapi/issues",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "rescript": "^12.0.0-alpha.6"
38
+ "rescript": "^12.0.0-alpha.8"
39
39
  },
40
40
  "devDependencies": {
41
- "@astrojs/starlight": "0.31.1",
41
+ "@astrojs/starlight": "0.32.0",
42
42
  "astro": "^5.1.1",
43
43
  "micromark": "^4.0.1",
44
44
  "prettier": "^3.3.3",
package/src/DOMAPI.res CHANGED
@@ -10,17 +10,14 @@ open MediaCaptureAndStreamsAPI
10
10
  open MediaSessionAPI
11
11
  open PermissionsAPI
12
12
  open ScreenWakeLockAPI
13
+ open WebWorkersAPI
13
14
  open ServiceWorkerAPI
14
15
  open EncryptedMediaExtensionsAPI
15
- open GamepadAPI
16
16
  open FileAPI
17
- open WebMIDIAPI
18
17
  open HistoryAPI
19
18
  open VisualViewportAPI
20
19
  open WebSpeechAPI
21
- open ViewTransitionsAPI
22
20
  open FileAndDirectoryEntriesAPI
23
- open WebVTTAPI
24
21
  open RemotePlaybackAPI
25
22
  open CanvasAPI
26
23
  open StorageAPI
@@ -0,0 +1,20 @@
1
+ open EventAPI
2
+
3
+ module Impl = (
4
+ T: {
5
+ type t
6
+ },
7
+ ) => {
8
+ external asExtendableEvent: T.t => extendableEvent = "%identity"
9
+
10
+ include Event.Impl({
11
+ type t = T.t
12
+ })
13
+
14
+ @send
15
+ external waitUntil: (T.t, promise<'a>) => unit = "waitUntil"
16
+ }
17
+
18
+ include Impl({
19
+ type t = extendableEvent
20
+ })
package/src/EventAPI.res CHANGED
@@ -51,6 +51,7 @@ type eventType =
51
51
  | @as("mouseout") Mouseout
52
52
  | @as("mouseover") Mouseover
53
53
  | @as("mouseup") Mouseup
54
+ | @as("notificationclick") NotificationClick
54
55
  | @as("paste") Paste
55
56
  | @as("pause") Pause
56
57
  | @as("play") Play
@@ -94,6 +95,7 @@ type eventType =
94
95
  | @as("pointercancel") Pointercancel
95
96
  | @as("pointerout") Pointerout
96
97
  | @as("pointerleave") Pointerleave
98
+ | @as("push") Push
97
99
  | @as("gotpointercapture") Gotpointercapture
98
100
  | @as("lostpointercapture") Lostpointercapture
99
101
  | @as("selectstart") Selectstart
@@ -217,3 +219,12 @@ type eventInit = {
217
219
  mutable cancelable?: bool,
218
220
  mutable composed?: bool,
219
221
  }
222
+
223
+ /**
224
+ The ExtendableEvent interface extends the lifetime of the install and activate events dispatched on the global scope as part of the service worker lifecycle.
225
+ [See ExtendableEvent on MDN](https://developer.mozilla.org/docs/Web/API/ExtendableEvent)
226
+ */
227
+ @editor.completeFrom(ExtendableEvent)
228
+ type extendableEvent = {
229
+ ...event,
230
+ }
package/src/Global.res CHANGED
@@ -5,7 +5,7 @@ open WebSpeechAPI
5
5
  open IndexedDBAPI
6
6
  open WebCryptoAPI
7
7
  open PerformanceAPI
8
- open ServiceWorkerAPI
8
+ open WebWorkersAPI
9
9
  open WebStorageAPI
10
10
  open CanvasAPI
11
11
  open FileAPI
@@ -63,7 +63,17 @@ type notification = {
63
63
  /**
64
64
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Notification/data)
65
65
  */
66
- data: JSON.t,
66
+ data?: JSON.t,
67
+ }
68
+
69
+ /**
70
+ An array of actions to display in the notification, for which the default is an empty array.
71
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification#actions)
72
+ */
73
+ type notificationAction = {
74
+ action: string,
75
+ title: string,
76
+ icon?: string,
67
77
  }
68
78
 
69
79
  type notificationOptions = {
@@ -76,8 +86,21 @@ type notificationOptions = {
76
86
  mutable silent?: Null.t<bool>,
77
87
  mutable requireInteraction?: bool,
78
88
  mutable data?: JSON.t,
89
+ mutable actions?: array<notificationAction>,
79
90
  }
80
91
 
81
92
  type getNotificationOptions = {mutable tag?: string}
82
93
 
83
94
  type notificationPermissionCallback = notificationPermission => unit
95
+
96
+ type notificationEvent = {
97
+ ...extendableEvent,
98
+ /**
99
+ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/NotificationEvent/action)
100
+ */
101
+ action: string,
102
+ /**
103
+ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/NotificationEvent/notification)
104
+ */
105
+ notification: notification,
106
+ }
@@ -0,0 +1,4 @@
1
+ open PushAPI
2
+
3
+ external fromString: string => applicationServerKey = "%identity"
4
+ external fromUint8Array: Uint8Array.t => applicationServerKey = "%identity"
@@ -0,0 +1,5 @@
1
+ open PushAPI
2
+
3
+ include ExtendableEvent.Impl({
4
+ type t = pushEvent
5
+ })
@@ -1,4 +1,4 @@
1
- open PushManagerAPI
1
+ open PushAPI
2
2
 
3
3
  /**
4
4
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushManager/subscribe)
@@ -0,0 +1,15 @@
1
+ open PushAPI
2
+
3
+ /**
4
+ The json() method of the PushMessageData interface extracts push message data by parsing it as a JSON string and returning the result.
5
+ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushMessageData/json)
6
+ */
7
+ @send
8
+ external json: pushMessageData => JSON.t = "json"
9
+
10
+ /**
11
+ The text() method of the PushMessageData interface extracts push message data as a plain text string.
12
+ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushMessageData/text)
13
+ */
14
+ @send
15
+ external text: pushMessageData => string = "text"
@@ -1,4 +1,4 @@
1
- open PushManagerAPI
1
+ open PushAPI
2
2
 
3
3
  /**
4
4
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushSubscription/getKey)
@@ -1,6 +1,7 @@
1
1
  @@warning("-30")
2
2
 
3
3
  open Prelude
4
+ open EventAPI
4
5
 
5
6
  type permissionState =
6
7
  | @as("denied") Denied
@@ -23,6 +24,8 @@ type pushManager = {
23
24
  supportedContentEncodings: array<string>,
24
25
  }
25
26
 
27
+ type applicationServerKey
28
+
26
29
  /**
27
30
  [See PushSubscriptionOptions on MDN](https://developer.mozilla.org/docs/Web/API/PushSubscriptionOptions)
28
31
  */
@@ -34,7 +37,7 @@ type pushSubscriptionOptions = {
34
37
  /**
35
38
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushSubscriptionOptions/applicationServerKey)
36
39
  */
37
- applicationServerKey: Null.t<ArrayBuffer.t>,
40
+ applicationServerKey: applicationServerKey,
38
41
  }
39
42
 
40
43
  /**
@@ -59,11 +62,30 @@ type pushSubscription = {
59
62
 
60
63
  type pushSubscriptionOptionsInit = {
61
64
  mutable userVisibleOnly?: bool,
62
- mutable applicationServerKey?: Null.t<unknown>,
65
+ mutable applicationServerKey?: applicationServerKey,
66
+ }
67
+
68
+ type pushSubscriptionJSONKeys = {
69
+ /** Base64URL-encoded ArrayBuffer value */
70
+ p256dh: string,
71
+ /** Base64URL-encoded ArrayBuffer value */
72
+ auth: string,
63
73
  }
64
74
 
65
75
  type pushSubscriptionJSON = {
66
76
  mutable endpoint?: string,
67
77
  mutable expirationTime?: Null.t<int>,
68
- mutable keys?: any,
78
+ mutable keys?: pushSubscriptionJSONKeys,
79
+ }
80
+
81
+ @editor.completeFrom(PushMessageData)
82
+ type pushMessageData
83
+
84
+ @editor.completeFrom(PushEvent)
85
+ type pushEvent = {
86
+ ...extendableEvent,
87
+ /**
88
+ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/PushEvent/data)
89
+ */
90
+ data?: pushMessageData,
69
91
  }
@@ -1,5 +1,5 @@
1
1
  open FetchAPI
2
- open ServiceWorkerAPI
2
+ open WebWorkersAPI
3
3
 
4
4
  /**
5
5
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Cache/match)
@@ -0,0 +1,4 @@
1
+ open ServiceWorkerAPI
2
+
3
+ @send
4
+ external openWindow: (clients, string) => promise<windowClient> = "open"
@@ -1,4 +1,3 @@
1
- open EventAPI
2
1
  open ServiceWorkerAPI
3
2
 
4
3
  include EventTarget.Impl({
@@ -11,7 +10,7 @@ include EventTarget.Impl({
11
10
  @send
12
11
  external register: (
13
12
  serviceWorkerContainer,
14
- ~scriptURL: string,
13
+ string,
15
14
  ~options: registrationOptions=?,
16
15
  ) => promise<serviceWorkerRegistration> = "register"
17
16
 
@@ -0,0 +1,5 @@
1
+ open ServiceWorkerAPI
2
+
3
+ include WorkerGlobalScope.Impl({
4
+ type t = serviceWorkerGlobalScope
5
+ })
@@ -2,10 +2,8 @@
2
2
 
3
3
  open Prelude
4
4
  open EventAPI
5
- open PushManagerAPI
6
- open NotificationAPI
7
- open FetchAPI
8
- open ChannelMessagingAPI
5
+ open PushAPI
6
+ open WebWorkersAPI
9
7
 
10
8
  type serviceWorkerState =
11
9
  | @as("activated") Activated
@@ -101,20 +99,6 @@ type serviceWorkerContainer = {
101
99
  ready: promise<serviceWorkerRegistration>,
102
100
  }
103
101
 
104
- /**
105
- The storage for Cache objects.
106
- [See CacheStorage on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage)
107
- */
108
- @editor.completeFrom(CacheStorage)
109
- type cacheStorage = {}
110
-
111
- /**
112
- Provides a storage mechanism for Request / Response object pairs that are cached, for example as part of the ServiceWorker 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.
113
- [See Cache on MDN](https://developer.mozilla.org/docs/Web/API/Cache)
114
- */
115
- @editor.completeFrom(Cache)
116
- type cache = {}
117
-
118
102
  type navigationPreloadState = {
119
103
  mutable enabled?: bool,
120
104
  mutable headerValue?: string,
@@ -126,15 +110,49 @@ type registrationOptions = {
126
110
  mutable updateViaCache?: serviceWorkerUpdateViaCache,
127
111
  }
128
112
 
129
- type cacheQueryOptions = {
130
- mutable ignoreSearch?: bool,
131
- mutable ignoreMethod?: bool,
132
- mutable ignoreVary?: bool,
113
+ type requestInfo = any
114
+
115
+ /**
116
+ The Clients interface provides access to Client objects. Access it via self.clients within a service worker.
117
+ [See Clients on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Clients)
118
+ */
119
+ @editor.completeFrom(Clients)
120
+ type clients
121
+
122
+ /**
123
+ The ServiceWorkerGlobalScope interface of the Service Worker API represents the global execution context of a service worker.
124
+ [See ServiceWorkerGlobalScope on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope)
125
+ */
126
+ @editor.completeFrom(ServiceWorkerGlobalScope)
127
+ type serviceWorkerGlobalScope = {
128
+ ...workerGlobalScope,
129
+ /**
130
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/clients)
131
+ */
132
+ clients: clients,
133
+ /**
134
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/registration)
135
+ */
136
+ registration: serviceWorkerRegistration,
133
137
  }
134
138
 
135
- type multiCacheQueryOptions = {
136
- ...cacheQueryOptions,
137
- mutable cacheName?: string,
139
+ /**
140
+ The Client interface represents an executable context such as a Worker, or a SharedWorker. Window clients are represented by the more-specific WindowClient.
141
+ [See Client on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Client)
142
+ */
143
+ type client = {
144
+ /**
145
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Client/id)
146
+ */
147
+ id: string,
148
+ /** [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Client/url) */
149
+ url: string,
138
150
  }
139
151
 
140
- type requestInfo = any
152
+ /**
153
+ The WindowClient interface of the ServiceWorker API represents the scope of a service worker client that is a document in a browsing context, controlled by an active worker.
154
+ [See WindowClient on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WindowClient)
155
+ */
156
+ type windowClient = {
157
+ ...client,
158
+ }
@@ -1,5 +1,5 @@
1
1
  open FetchAPI
2
- open ServiceWorkerAPI
2
+ open WebWorkersAPI
3
3
 
4
4
  /**
5
5
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage/match)
@@ -0,0 +1,45 @@
1
+ open WebWorkersAPI
2
+ open FetchAPI
3
+
4
+ module Impl = (
5
+ T: {
6
+ type t
7
+ },
8
+ ) => {
9
+ include EventTarget.Impl({
10
+ type t = T.t
11
+ })
12
+
13
+ /**
14
+ `fetch(workerGlobalScope, string, init)`
15
+
16
+ The fetch() method of the WorkerGlobalScope interface starts the process of fetching a resource from the network,
17
+ returning a promise that is fulfilled once the response is available.
18
+
19
+ ```res
20
+ let response = await self->WorkerGlobalScope.fetch("https://rescript-lang.org")
21
+ ```
22
+
23
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/fetch)
24
+ */
25
+ @send
26
+ external fetch: (T.t, string, ~init: requestInit=?) => promise<response> = "fetch"
27
+
28
+ /**
29
+ `fetch_withRequest(workerGlobalScope, request, init)`
30
+
31
+ The fetch() method of the WorkerGlobalScope interface starts the process of fetching a resource from the network,
32
+ returning a promise that is fulfilled once the response is available.
33
+
34
+ ```res
35
+ let response = await self->WorkerGlobalScope.fetch(myRequest)
36
+ ```
37
+
38
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/fetch)
39
+ */
40
+ external fetch_withRequest: (T.t, request, ~init: requestInit=?) => promise<response> = "fetch"
41
+ }
42
+
43
+ include Impl({
44
+ type t = workerGlobalScope
45
+ })
@@ -0,0 +1,46 @@
1
+ open EventAPI
2
+
3
+ /**
4
+ Provides a storage mechanism for Request / Response object pairs that are cached, for example as part of the ServiceWorker 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.
5
+ [See Cache on MDN](https://developer.mozilla.org/docs/Web/API/Cache)
6
+ */
7
+ @editor.completeFrom(Cache)
8
+ type cache = {}
9
+
10
+ /**
11
+ The storage for Cache objects.
12
+ [See CacheStorage on MDN](https://developer.mozilla.org/docs/Web/API/CacheStorage)
13
+ */
14
+ @editor.completeFrom(CacheStorage)
15
+ type cacheStorage = {}
16
+
17
+ type cacheQueryOptions = {
18
+ mutable ignoreSearch?: bool,
19
+ mutable ignoreMethod?: bool,
20
+ mutable ignoreVary?: bool,
21
+ }
22
+
23
+ type multiCacheQueryOptions = {
24
+ ...cacheQueryOptions,
25
+ mutable cacheName?: string,
26
+ }
27
+
28
+ /**
29
+ The WorkerGlobalScope interface of the Web Workers API is an interface representing the scope of any worker.
30
+ Workers have no browsing context; this scope contains the information usually conveyed by Window objects —
31
+ in this case event handlers, the console or the associated WorkerNavigator object.
32
+ Each WorkerGlobalScope has its own event loop.
33
+ [See WorkerGlobalScope on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope)
34
+ */
35
+ @editor.completeFrom(WorkerGlobalScope)
36
+ type workerGlobalScope = {
37
+ ...eventTarget,
38
+ /**
39
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/caches)
40
+ */
41
+ caches: cacheStorage,
42
+ /**
43
+ [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/crossOriginIsolated)
44
+ */
45
+ crossOriginIsolated: bool,
46
+ }