Skip to content

Commit 85b26b0

Browse files
committed
fix: restore WebAPI naming
1 parent f1dd992 commit 85b26b0

13 files changed

Lines changed: 113 additions & 84 deletions

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ and add `@rescript/webapi` to your `rescript.json`:
2020
"@rescript/webapi"
2121
],
2222
"bsc-flags": [
23-
"-open WebApi.DOM.Global"
23+
"-open WebAPI.Global"
2424
]
2525
}
2626
```
2727

28+
## Usage
29+
30+
```rescript
31+
let location = window.location
32+
let href = location.href
33+
location->WebAPI.Location.reload
34+
```
35+
2836
## Documentation
2937

3038
More information can be found on https://rescript-lang.github.io/experimental-rescript-webapi/

docs/content/docs/contributing/api-modelling.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ mutable fillStyle: fillStyle
8888
When we wish to read and write the `fillStyle` property, we can use a helper module to lift the type to an actual ReScript variant:
8989

9090
export const fillStyleModule = `
91-
open WebApi.Canvas
92-
open WebApi.DOM
91+
open WebAPI.Canvas
92+
open WebAPI.DOM
9393
9494
external fromString: string => fillStyle = "%identity"
9595
external fromCanvasGradient: canvasGradient => fillStyle = "%identity"

docs/content/docs/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Getting started
33
description: Learn more about @rescript/webapi.
44
hero:
5-
title: "ReScript WebApi"
5+
title: "ReScript WebAPI"
66
tagline: ReScript bindings for everything you need in the browser.
77
actions:
88
- text: Let's go!
@@ -42,7 +42,7 @@ export const rescriptJson = `
4242
"@rescript/webapi"
4343
],
4444
"bsc-flags": [
45-
"-open WebApi.DOM.Global"
45+
"-open WebAPI.Global"
4646
]
4747
}
4848
`;
@@ -54,14 +54,14 @@ export const rescriptJson = `
5454
After installing the package , you can use bindings for the various Web APIs as defined in [MDN](https://developer.mozilla.org/en-US/docs/Web/API).
5555

5656
export const rescriptSample = `
57-
// Note that this only works when you added the \`-open WebApi.DOM.Global\` bsc flag.
57+
// Note that this only works when you added the \`-open WebAPI.Global\` bsc flag.
5858
let location = window.location
5959
6060
// Access properties using \`.\`
6161
let href = location.href
6262
6363
// Invoke methods using the \`->TypeModule.method\`
64-
location->WebApi.DOM.Location.reload
64+
location->WebAPI.Location.reload
6565
`;
6666

6767
export const compiledSample = `

docs/content/docs/philosophy.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ The bindings are generated from the [MDN Web API documentation](https://develope
1616

1717
In other words, if you are searching for a specific JavaScript binding, begin your journey at the [MDN Web API documentation](https://developer.mozilla.org/en-US/docs/Web/API) and determine which module contains your sample. Ensure that the module is available in the bindings by checking the specific API. Please [open an issue](https://github.com/rescript-lang/experimental-rescript-webapi/issues/new/choose) if you require an API that is not yet present.
1818

19-
Each feature is grouped under a `WebApi.<Feature>` module so related interfaces and helper modules stay together without relying on flat package-wide names.
19+
The bindings are exposed under the `WebAPI` namespace, with feature entry modules such as `WebAPI.DOM` available when you want to scope imports more narrowly.
2020

2121
```ReScript
22-
open WebApi.DOM.Global
22+
open WebAPI.Global
23+
// or WebAPI.DOM
2324
24-
let myElement: WebApi.DOM.Types.element = document->WebApi.DOM.Document.createElement("div")
25+
let myElement: WebAPI.Element.t = document->WebAPI.Document.createElement("div")
2526
```
2627

2728
## Interfaces
@@ -43,10 +44,11 @@ JavaScript supports function overloads, where a function can have multiple signa
4344
In some cases, type conversion will be required. Subtypes can safely be cast to their base type using conversion helpers within their module.
4445

4546
```ReScript
46-
open WebApi.DOM.Global
47+
open WebAPI.Global
48+
// or WebAPI.DOM
4749
48-
let element: WebApi.DOM.Types.element = document->WebApi.DOM.Document.createElement("div")
49-
let node: WebApi.DOM.Types.node = element->WebApi.DOM.Element.asNode
50+
let element: WebAPI.Element.t = document->WebAPI.Document.createElement("div")
51+
let node: WebAPI.Node.t = element->WebAPI.Element.asNode
5052
```
5153

5254
Any other conversions should be treated as unsafe casts and used with caution, because the type system cannot guarantee they are valid at runtime.

docs/llm.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ function moduleNameForFile(relativePath) {
108108
const leafName = path.basename(fileName, ".res");
109109

110110
if (leafName === spec.publicModule) {
111-
return `WebApi.${spec.publicModule}`;
111+
return `WebAPI.${spec.publicModule}`;
112112
}
113113

114-
return `WebApi.${spec.publicModule}.${publicNameForLeafModule(leafName, spec.internalPrefix)}`;
114+
return `WebAPI.${spec.publicModule}.${publicNameForLeafModule(leafName, spec.internalPrefix)}`;
115115
}
116116

117117
const pattern = "../src/*/**/*.res";
@@ -126,9 +126,9 @@ const packageJson = await fs.readFile(path.join(import.meta.dirname, "../package
126126
let version = JSON.parse(packageJson).version;
127127
const sha = await execAsync("git rev-parse --short HEAD").then(({ stdout }) => stdout.trim());
128128
const fullVersion = `${version}-experimental-${sha}`;
129-
const header = `Experimental ReScript WebApi Documentation ${fullVersion}
129+
const header = `Experimental ReScript WebAPI Documentation ${fullVersion}
130130
131-
This is the API documentation for the experimental WebApi module version ${fullVersion}.
131+
This is the API documentation for the experimental WebAPI module version ${fullVersion}.
132132
More information can be found on https://rescript-lang.github.io/experimental-rescript-webapi/
133133
134134
`;

docs/superpowers/specs/2026-04-22-unmonorepo-webapi-design.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Unmonorepo WebApi Design
1+
# Unmonorepo WebAPI Design
22

33
**Date:** 2026-04-22
44
**Status:** Approved in conversation, written for review before implementation
@@ -7,15 +7,15 @@
77

88
The repository was split into npm workspaces so each Web API area could build and publish independently from `packages/*`. The ReScript compiler now supports feature-gated source directories and feature-gated dependencies, so the package split is no longer required to support partial builds.
99

10-
The new target is a single published npm package, `@rescript/webapi`, with a unified internal build and an external API that still preserves feature-level boundaries such as `WebApi.DOM`, `WebApi.Fetch`, and `WebApi.Base`.
10+
The new target is a single published npm package, `@rescript/webapi`, with a unified internal build and an external API that still preserves feature-level boundaries such as `WebAPI.DOM`, `WebAPI.Fetch`, and `WebAPI.Base`.
1111

1212
## Goals
1313

1414
- Remove the monorepo/workspace package split.
1515
- Move all feature sources from `packages/<Pkg>/src` to `src/<Pkg>`.
1616
- Delete every subpackage `package.json` and `rescript.json`.
1717
- Make the root `rescript.json` the single source of truth for sources, features, and ReScript dependencies.
18-
- Preserve the logical public API boundaries as `WebApi.<Feature>`.
18+
- Preserve the logical public API boundaries as `WebAPI.<Feature>`.
1919
- Keep internal helper modules private through the new `public` source setting.
2020
- Publish one npm package: `@rescript/webapi`.
2121
- Let internal builds and downstream consumers compile only the features they need.
@@ -62,13 +62,13 @@ Each former package source directory is listed as its own source entry. Example
6262
{
6363
"dir": "src/DOM",
6464
"subdirs": true,
65-
"feature": "WebApi.DOM",
65+
"feature": "WebAPI.DOM",
6666
"public": ["DOM"]
6767
},
6868
{
6969
"dir": "src/Fetch",
7070
"subdirs": true,
71-
"feature": "WebApi.Fetch",
71+
"feature": "WebAPI.Fetch",
7272
"public": ["Fetch"]
7373
},
7474
{
@@ -83,7 +83,7 @@ Each former package source directory is listed as its own source entry. Example
8383
Rules:
8484

8585
- Every former package gets one root source entry.
86-
- The `feature` value matches the public module name, for example `"WebApi.DOM"` and `"WebApi.Fetch"`.
86+
- The `feature` value matches the public module name, for example `"WebAPI.DOM"` and `"WebAPI.Fetch"`.
8787
- The `public` list exposes only the feature entry module for that source directory.
8888
- Helper modules such as `DomTypes` and `DomGlobal` stay internal because they are not listed in `public`.
8989
- `tests` remains a dev-only source.
@@ -102,7 +102,7 @@ Example:
102102
{
103103
"dependencies": [
104104
"@plain/dep",
105-
{ "name": "@other/heavy", "features": ["WebApi.WebCrypto"] }
105+
{ "name": "@other/heavy", "features": ["WebAPI.WebCrypto"] }
106106
]
107107
}
108108
```
@@ -117,10 +117,10 @@ Migration rule:
117117

118118
The public API remains feature-oriented:
119119

120-
- `WebApi.Base`
121-
- `WebApi.DOM`
122-
- `WebApi.Fetch`
123-
- `WebApi.WebCrypto`
120+
- `WebAPI.Base`
121+
- `WebAPI.DOM`
122+
- `WebAPI.Fetch`
123+
- `WebAPI.WebCrypto`
124124
- and the rest of the former package surfaces
125125

126126
The unified build must not expose raw internal file modules as first-class public API. Consumers should interact with a curated surface through the feature entry modules only.
@@ -240,7 +240,7 @@ The most important regression risks are:
240240

241241
- Use a single package instead of npm workspaces.
242242
- Preserve feature boundaries in the external API.
243-
- Use `WebApi.*` spelling, not `WebAPI.*`.
244-
- Map feature names to public module names such as `"WebApi.DOM"`.
243+
- Use `WebAPI.*` spelling, not `WebApi.*`.
244+
- Map feature names to public module names such as `"WebAPI.DOM"`.
245245
- Rename generic internal modules to feature-qualified names.
246246
- Use source-level `public` settings so only the feature entry module is exposed.

0 commit comments

Comments
 (0)