From 9430c006cdc7f7fd8b6fcd988c40d0b2ff9bf1f5 Mon Sep 17 00:00:00 2001 From: Josh Vlk Date: Mon, 16 Nov 2026 13:42:05 -0500 Subject: [PATCH 1/3] feat(webapi): isolate History and Location features [Codex] --- CHANGELOG.md | 2 +- README.md | 4 +- docs/content/docs/api-surface.mdx | 30 +++- docs/content/docs/contributing/releasing.mdx | 2 +- docs/content/docs/contributing/testing.mdx | 2 +- docs/content/docs/index.mdx | 6 +- docs/content/docs/philosophy.mdx | 2 +- docs/content/docs/project-status.mdx | 4 +- package-lock.json | 157 +++++++++---------- package.json | 4 +- rescript.json | 18 ++- scripts/check-consumer.mjs | 9 +- scripts/check-features.mjs | 4 +- scripts/check-features.test.mjs | 33 +++- src/{window => history}/History.res | 0 src/{window => history}/HistoryTypes.res | 0 src/{window => location}/Location.res | 0 tests/DOMAPI/ImageData__test.res | 2 +- 18 files changed, 175 insertions(+), 104 deletions(-) rename src/{window => history}/History.res (100%) rename src/{window => history}/HistoryTypes.res (100%) rename src/{window => location}/Location.res (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0835093c..a65f23ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ are maintained by the release workflow; see the [alpha release readiness tracker ## 1.0.0-alpha.1 (candidate) -Planned first release in the `1.0.0-alpha.N` series. ReScript `13.0.0-alpha.5` is the tested +Planned first release in the `1.0.0-alpha.N` series. ReScript `13.0.0-alpha.7` is the tested compiler baseline. This alpha is not a stable API; review the migration notes below before upgrading from earlier prereleases. The release workflow is the source of truth for actual versioning and publication. diff --git a/README.md b/README.md index 13fce610..82416a53 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Experimental successor to [rescript-webapi](https://github.com/TheSpyder/rescrip ## Getting started -ReScript `13.0.0-alpha.5` is the tested compiler baseline. Library alpha releases may contain +ReScript `13.0.0-alpha.7` is the tested compiler baseline. Library alpha releases may contain breaking changes. See the [project status](https://rescript-lang.github.io/experimental-rescript-webapi/project-status/) for the accepted peer range and its testing limits. @@ -14,7 +14,7 @@ Install the library and compiler in your application: ```shell npm install @rescript/webapi@alpha -npm install --save-dev rescript@13.0.0-alpha.5 +npm install --save-dev rescript@13.0.0-alpha.7 ``` The `@alpha` command targets the published alpha dist-tag. The planned `1.0.0-alpha.1` candidate diff --git a/docs/content/docs/api-surface.mdx b/docs/content/docs/api-surface.mdx index a43cccb1..48a0f51d 100644 --- a/docs/content/docs/api-surface.mdx +++ b/docs/content/docs/api-surface.mdx @@ -4,13 +4,13 @@ description: A practical summary of how to use the public @rescript/webapi modul slug: "api-surface" --- -The package exposes browser APIs under the `WebAPI` namespace. ReScript `13.0.0-alpha.5` is +The package exposes browser APIs under the `WebAPI` namespace. ReScript `13.0.0-alpha.7` is the tested compiler baseline, and alpha releases may contain breaking changes. See [project status](../project-status/) for the accepted peer range and its testing limits, and the [migration notes](https://github.com/rescript-lang/experimental-rescript-webapi/blob/main/CHANGELOG.md) for API changes. -Install `@rescript/webapi@alpha` and `rescript@13.0.0-alpha.5`, then add the package dependency. +Install `@rescript/webapi@alpha` and `rescript@13.0.0-alpha.7`, then add the package dependency. Feature bundles are optional when consumers need to restrict compiled modules: ```json @@ -81,6 +81,7 @@ WebAPI.URL WebAPI.Fetch WebAPI.UIEvents WebAPI.Observers WebAPI.Media WebAPI.WebAudio WebAPI.Storage WebAPI.Messaging WebAPI.Workers WebAPI.Crypto WebAPI.Performance WebAPI.ViewTransitions +WebAPI.History WebAPI.Location WebAPI.SafeFetch ``` @@ -106,6 +107,31 @@ helpers can select only the safe feature: The `let?` examples below require the experimental `LetUnwrap` setting with the current ReScript 13 alpha compiler. The SafeFetch API itself can also be used with ordinary `switch` expressions. +### DOM types without the Window bundle + +`WebAPI.History` independently exposes `WebAPI.History` and its existing +`WebAPI.History.Types.history` type. `WebAPI.Location` exposes `WebAPI.Location` +and depends only on the core `WebAPI.DOM` feature. `WebAPI.Window` includes both +features, so existing Window consumers keep the same API and type identities. + +For React bindings that need element, event, window, document, history, and location +types without the complete Window API, select: + +```json +{ + "dependencies": [ + { + "name": "@rescript/webapi", + "features": ["WebAPI.DOMNodes", "WebAPI.History", "WebAPI.Location"] + } + ] +} +``` + +DOMNodes already includes DOM transitively. This selection does not expose +`WebAPI.Window` or `WebAPI.Document`; add `WebAPI.Window` if you need their methods. +An unrestricted WebAPI dependency elsewhere in the dependency graph enables all features. + ## Fetch Use `WebAPI.Fetch.fetch` for string URLs and `WebAPI.Fetch.fetchWithRequest` diff --git a/docs/content/docs/contributing/releasing.mdx b/docs/content/docs/contributing/releasing.mdx index 678a60f3..0137a9ad 100644 --- a/docs/content/docs/contributing/releasing.mdx +++ b/docs/content/docs/contributing/releasing.mdx @@ -6,7 +6,7 @@ slug: "08-alpha-releases" The release checklist for `@rescript/webapi` is tracked in [#382](https://github.com/rescript-lang/experimental-rescript-webapi/issues/382). ReScript -`13.0.0-alpha.5` is the tested compiler baseline. A stable compiler is not a prerequisite; +`13.0.0-alpha.7` is the tested compiler baseline. A stable compiler is not a prerequisite; library alpha releases may include breaking changes between versions. ## Prepare a candidate diff --git a/docs/content/docs/contributing/testing.mdx b/docs/content/docs/contributing/testing.mdx index 29571fb5..c2b378f2 100644 --- a/docs/content/docs/contributing/testing.mdx +++ b/docs/content/docs/contributing/testing.mdx @@ -74,7 +74,7 @@ Run `npm run check:consumer` to pack the current package, install that artifact ReScript compiler in a fresh temporary project, and compile representative feature consumers. This verifies the installed tarball rather than copied source files or local compiler links. The development compiler and the exact version exercised by this check are ReScript -`13.0.0-alpha.5`. The peer range `>=13.0.0-alpha.5 <13.0.0` admits later `13.0.0` prereleases; +`13.0.0-alpha.7`. The peer range `>=13.0.0-alpha.7 <13.0.0` admits later `13.0.0` prereleases; it does not claim support for earlier compilers or stable `13.0.0`. ## Why add tests? diff --git a/docs/content/docs/index.mdx b/docs/content/docs/index.mdx index 52a3628c..1b05c90f 100644 --- a/docs/content/docs/index.mdx +++ b/docs/content/docs/index.mdx @@ -23,7 +23,7 @@ import { Tabs, TabItem, Code } from "@astrojs/starlight/components"; ## Installation -ReScript `13.0.0-alpha.5` is the tested compiler baseline, and library alpha releases may +ReScript `13.0.0-alpha.7` is the tested compiler baseline, and library alpha releases may include breaking changes. See [project status](./project-status/) for the accepted peer range and its testing limits. @@ -34,14 +34,14 @@ Install the package and tested compiler: diff --git a/docs/content/docs/philosophy.mdx b/docs/content/docs/philosophy.mdx index 04c156cb..59d6bb48 100644 --- a/docs/content/docs/philosophy.mdx +++ b/docs/content/docs/philosophy.mdx @@ -8,7 +8,7 @@ The core idea of these ReScript bindings is that each interface is modeled as a ## ReScript 13 alpha compatibility -This project currently supports ReScript `13.0.0-alpha.5`. ReScript 13 is still an alpha, and +This project currently supports ReScript `13.0.0-alpha.7`. ReScript 13 is still an alpha, and the library may continue to publish `1.0.0-alpha.N` releases alongside it. Library alpha releases may include breaking API changes; a stable ReScript compiler is not required to use or release this library's alpha versions. See the [API surface](../api-surface/) for the public module layout diff --git a/docs/content/docs/project-status.mdx b/docs/content/docs/project-status.mdx index d7528876..e31c7f74 100644 --- a/docs/content/docs/project-status.mdx +++ b/docs/content/docs/project-status.mdx @@ -10,8 +10,8 @@ varies by API and browser support is determined by the host runtime, not by whet module compiles. `@rescript/webapi` alpha versions can make breaking API changes between releases. ReScript -`13.0.0-alpha.5` is the tested compiler baseline. The package peer range accepts -`>=13.0.0-alpha.5 <13.0.0`, which allows later `13.0.0` prereleases but does not claim each one +`13.0.0-alpha.7` is the tested compiler baseline. The package peer range accepts +`>=13.0.0-alpha.7 <13.0.0`, which allows later `13.0.0` prereleases but does not claim each one is tested; stable ReScript is not currently included in that range or required to ship this alpha. diff --git a/package-lock.json b/package-lock.json index 0f6de392..e20dd3fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,12 +17,12 @@ "oxfmt": "^0.76.0", "prettier": "^3.8.3", "prettier-plugin-astro": "^1.0.0", - "rescript": "13.0.0-alpha.5", + "rescript": "13.0.0-alpha.7", "sharp": "^0.35.3", "ws": "^8.22.1" }, "peerDependencies": { - "rescript": ">=13.0.0-alpha.5 <13.0.0" + "rescript": ">=13.0.0-alpha.7 <13.0.0" } }, "node_modules/@astrojs/compiler-binding": { @@ -1836,89 +1836,79 @@ "license": "MIT" }, "node_modules/@rescript/darwin-arm64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/darwin-arm64/-/darwin-arm64-13.0.0-alpha.5.tgz", - "integrity": "sha512-OCpT4VYLkxTjm56y+CG4SfrqotMLCaqKY5pxGq75hOPRZLZ5n5BG3OvA1rBsmz5+gT7VpKm1Do9YhmO0JvYZfg==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/darwin-arm64/-/darwin-arm64-13.0.0-alpha.7.tgz", + "integrity": "sha512-jAoS+bjMRQ2HEvZAo/I3gETmp5lZ/wOMtj9XklbcJvttDwhZUuZ3r8NFYwhbY+hFiCe5mWKgJaBKzMM1glKKLQ==", "cpu": [ "arm64" ], "dev": true, + "license": "(LGPL-3.0-or-later AND MIT)", "optional": true, "os": [ "darwin" ], "engines": { - "node": ">=20.11.0" - } - }, - "node_modules/@rescript/darwin-x64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/darwin-x64/-/darwin-x64-13.0.0-alpha.5.tgz", - "integrity": "sha512-UT143XnOVmUUayrD/1ceKrXb8rbhNmXKhhfnTnRGRLWp1Hxyiq5uq3OGNorSIW6jHsszsP0VvjKA+Z31h04E6Q==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=20.11.0" + "node": ">=22" } }, "node_modules/@rescript/linux-arm64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/linux-arm64/-/linux-arm64-13.0.0-alpha.5.tgz", - "integrity": "sha512-lQ3trljExrH1uqS3hsjjoi6fnaImG/tYppcF2X4Yk8u0AP1t6AC6LUM0KR2kjctG5b7OVUrujOu91NnjovN46A==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/linux-arm64/-/linux-arm64-13.0.0-alpha.7.tgz", + "integrity": "sha512-wVwmKc64b6dQWuC6bfCh4F/ULSyEwZx7zQx07uQ6lvVJg+VonfEEr1J8R3SVVWvvUycYYCYnaXaCheH1V28Lpw==", "cpu": [ "arm64" ], "dev": true, + "license": "(LGPL-3.0-or-later AND MIT)", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=20.11.0" + "node": ">=22" } }, "node_modules/@rescript/linux-x64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/linux-x64/-/linux-x64-13.0.0-alpha.5.tgz", - "integrity": "sha512-Cu73xGa2nMcSgW274tAJDexlBqJGFKpv/v9wHAxqFxXzIwSkET51N9xkf42GljejeVzwyDEfgQId2Znme/PWkg==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/linux-x64/-/linux-x64-13.0.0-alpha.7.tgz", + "integrity": "sha512-bm2FdxeJe61/5rk7q1qfdX74OjhdIqByKub+hg+t6XgiSXYUx5dW12hBfxzrM+IzoTNeZetuIfjbZKvH8Q9JAQ==", "cpu": [ "x64" ], "dev": true, + "license": "(LGPL-3.0-or-later AND MIT)", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=20.11.0" + "node": ">=22" } }, "node_modules/@rescript/runtime": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/runtime/-/runtime-13.0.0-alpha.5.tgz", - "integrity": "sha512-k0iQhrDasCD5K5orSrps21ZVgvMgOIwh03QjUAxtMkVwyPclg6LbgG5eAAgduyecXXm3ii30o3nDaXvCryu/Tw==", - "dev": true + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/runtime/-/runtime-13.0.0-alpha.7.tgz", + "integrity": "sha512-NUXP0XgObn1lg9p9ZHQqq72xDf0wqh0yUYmQvO3JFrQdeNM6c+LfDoJkFoJob5pWS0C3vSxy77MqTneoYodC+A==", + "dev": true, + "license": "MIT" }, "node_modules/@rescript/win32-x64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/win32-x64/-/win32-x64-13.0.0-alpha.5.tgz", - "integrity": "sha512-7uUkUY0pXDdPB5znHQYWsGml3E2pQ68KSaM7HZoFfnOEIuPqGz/hssgLgsXHkfHxrHB0waX9fsqx2Qckn6IGsw==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/win32-x64/-/win32-x64-13.0.0-alpha.7.tgz", + "integrity": "sha512-9gxxtwYt4N5FbyFnqka6xpwtu4AP7UlvdXK9nz2zNUusjqNmggXOAvSd9zI/RuvG08nEEAXPfF7dkZ/hM9aJ1w==", "cpu": [ - "x64" + "x64", + "arm64" ], "dev": true, + "license": "(LGPL-3.0-or-later AND MIT)", "optional": true, "os": [ "win32" ], "engines": { - "node": ">=20.11.0" + "node": ">=22" } }, "node_modules/@rolldown/binding-android-arm-eabi": { @@ -5228,27 +5218,42 @@ } }, "node_modules/rescript": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/rescript/-/rescript-13.0.0-alpha.5.tgz", - "integrity": "sha512-rv/xA1OQLN5l90/szD82IR8p/bNzwKNPLnEVaR89oiuBZYG7IhHfRxEKAvpOHqlrpnV8zKmc16IXcjCQxlni/w==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-13.0.0-alpha.7.tgz", + "integrity": "sha512-xsQALc6IlT7bUAXDw/I9HEcruE1py7OB0z9GQ/4bp8XSAhCTLhNkGQo9QBkAzl9fUaOji3EymYetJ3TYD1tPVg==", "dev": true, - "dependencies": { - "@rescript/runtime": "13.0.0-alpha.5" + "license": "(LGPL-3.0-or-later AND MIT)", + "workspaces": [ + "packages/dev-playground", + "packages/playground", + "packages/@rescript/*", + "tests/dependencies/**", + "tests/analysis_tests/**", + "tests/docstring_tests", + "tests/belt_tests", + "tests/gentype_tests/**", + "tests/tests", + "tests/tools_tests", + "tests/commonjs_tests", + "scripts/res" + ], + "dependencies": { + "@rescript/runtime": "13.0.0-alpha.7" }, "bin": { "bsc": "cli/bsc.js", "rescript": "cli/rescript.js", + "rescript-rust": "cli/rescript-rust.js", "rescript-tools": "cli/rescript-tools.js" }, "engines": { "node": ">=22" }, "optionalDependencies": { - "@rescript/darwin-arm64": "13.0.0-alpha.5", - "@rescript/darwin-x64": "13.0.0-alpha.5", - "@rescript/linux-arm64": "13.0.0-alpha.5", - "@rescript/linux-x64": "13.0.0-alpha.5", - "@rescript/win32-x64": "13.0.0-alpha.5" + "@rescript/darwin-arm64": "13.0.0-alpha.7", + "@rescript/linux-arm64": "13.0.0-alpha.7", + "@rescript/linux-x64": "13.0.0-alpha.7", + "@rescript/win32-x64": "13.0.0-alpha.7" } }, "node_modules/resolve-pkg-maps": { @@ -7078,43 +7083,36 @@ "dev": true }, "@rescript/darwin-arm64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/darwin-arm64/-/darwin-arm64-13.0.0-alpha.5.tgz", - "integrity": "sha512-OCpT4VYLkxTjm56y+CG4SfrqotMLCaqKY5pxGq75hOPRZLZ5n5BG3OvA1rBsmz5+gT7VpKm1Do9YhmO0JvYZfg==", - "dev": true, - "optional": true - }, - "@rescript/darwin-x64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/darwin-x64/-/darwin-x64-13.0.0-alpha.5.tgz", - "integrity": "sha512-UT143XnOVmUUayrD/1ceKrXb8rbhNmXKhhfnTnRGRLWp1Hxyiq5uq3OGNorSIW6jHsszsP0VvjKA+Z31h04E6Q==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/darwin-arm64/-/darwin-arm64-13.0.0-alpha.7.tgz", + "integrity": "sha512-jAoS+bjMRQ2HEvZAo/I3gETmp5lZ/wOMtj9XklbcJvttDwhZUuZ3r8NFYwhbY+hFiCe5mWKgJaBKzMM1glKKLQ==", "dev": true, "optional": true }, "@rescript/linux-arm64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/linux-arm64/-/linux-arm64-13.0.0-alpha.5.tgz", - "integrity": "sha512-lQ3trljExrH1uqS3hsjjoi6fnaImG/tYppcF2X4Yk8u0AP1t6AC6LUM0KR2kjctG5b7OVUrujOu91NnjovN46A==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/linux-arm64/-/linux-arm64-13.0.0-alpha.7.tgz", + "integrity": "sha512-wVwmKc64b6dQWuC6bfCh4F/ULSyEwZx7zQx07uQ6lvVJg+VonfEEr1J8R3SVVWvvUycYYCYnaXaCheH1V28Lpw==", "dev": true, "optional": true }, "@rescript/linux-x64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/linux-x64/-/linux-x64-13.0.0-alpha.5.tgz", - "integrity": "sha512-Cu73xGa2nMcSgW274tAJDexlBqJGFKpv/v9wHAxqFxXzIwSkET51N9xkf42GljejeVzwyDEfgQId2Znme/PWkg==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/linux-x64/-/linux-x64-13.0.0-alpha.7.tgz", + "integrity": "sha512-bm2FdxeJe61/5rk7q1qfdX74OjhdIqByKub+hg+t6XgiSXYUx5dW12hBfxzrM+IzoTNeZetuIfjbZKvH8Q9JAQ==", "dev": true, "optional": true }, "@rescript/runtime": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/runtime/-/runtime-13.0.0-alpha.5.tgz", - "integrity": "sha512-k0iQhrDasCD5K5orSrps21ZVgvMgOIwh03QjUAxtMkVwyPclg6LbgG5eAAgduyecXXm3ii30o3nDaXvCryu/Tw==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/runtime/-/runtime-13.0.0-alpha.7.tgz", + "integrity": "sha512-NUXP0XgObn1lg9p9ZHQqq72xDf0wqh0yUYmQvO3JFrQdeNM6c+LfDoJkFoJob5pWS0C3vSxy77MqTneoYodC+A==", "dev": true }, "@rescript/win32-x64": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/@rescript/win32-x64/-/win32-x64-13.0.0-alpha.5.tgz", - "integrity": "sha512-7uUkUY0pXDdPB5znHQYWsGml3E2pQ68KSaM7HZoFfnOEIuPqGz/hssgLgsXHkfHxrHB0waX9fsqx2Qckn6IGsw==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/@rescript/win32-x64/-/win32-x64-13.0.0-alpha.7.tgz", + "integrity": "sha512-9gxxtwYt4N5FbyFnqka6xpwtu4AP7UlvdXK9nz2zNUusjqNmggXOAvSd9zI/RuvG08nEEAXPfF7dkZ/hM9aJ1w==", "dev": true, "optional": true }, @@ -9134,17 +9132,16 @@ } }, "rescript": { - "version": "13.0.0-alpha.5", - "resolved": "https://registry.npmjs.org/rescript/-/rescript-13.0.0-alpha.5.tgz", - "integrity": "sha512-rv/xA1OQLN5l90/szD82IR8p/bNzwKNPLnEVaR89oiuBZYG7IhHfRxEKAvpOHqlrpnV8zKmc16IXcjCQxlni/w==", + "version": "13.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-13.0.0-alpha.7.tgz", + "integrity": "sha512-xsQALc6IlT7bUAXDw/I9HEcruE1py7OB0z9GQ/4bp8XSAhCTLhNkGQo9QBkAzl9fUaOji3EymYetJ3TYD1tPVg==", "dev": true, "requires": { - "@rescript/darwin-arm64": "13.0.0-alpha.5", - "@rescript/darwin-x64": "13.0.0-alpha.5", - "@rescript/linux-arm64": "13.0.0-alpha.5", - "@rescript/linux-x64": "13.0.0-alpha.5", - "@rescript/runtime": "13.0.0-alpha.5", - "@rescript/win32-x64": "13.0.0-alpha.5" + "@rescript/darwin-arm64": "13.0.0-alpha.7", + "@rescript/linux-arm64": "13.0.0-alpha.7", + "@rescript/linux-x64": "13.0.0-alpha.7", + "@rescript/runtime": "13.0.0-alpha.7", + "@rescript/win32-x64": "13.0.0-alpha.7" } }, "resolve-pkg-maps": { diff --git a/package.json b/package.json index 8c5e3984..5e19d801 100644 --- a/package.json +++ b/package.json @@ -59,12 +59,12 @@ "oxfmt": "^0.76.0", "prettier": "^3.8.3", "prettier-plugin-astro": "^1.0.0", - "rescript": "13.0.0-alpha.5", + "rescript": "13.0.0-alpha.7", "sharp": "^0.35.3", "ws": "^8.22.1" }, "peerDependencies": { - "rescript": ">=13.0.0-alpha.5 <13.0.0" + "rescript": ">=13.0.0-alpha.7 <13.0.0" }, "overrides": { "mdast-util-to-hast": "^13.2.1", diff --git a/rescript.json b/rescript.json index 8ac1cd9c..83f718c2 100644 --- a/rescript.json +++ b/rescript.json @@ -19,7 +19,11 @@ "DOMNodes" ], "WebAPI.HTML": ["WebAPI.DOMNodes", "WebAPI.File", "HTML"], + "WebAPI.History": ["History"], + "WebAPI.Location": ["WebAPI.DOM", "Location"], "WebAPI.Window": [ + "WebAPI.History", + "WebAPI.Location", "WebAPI.HTML", "WebAPI.Media", "WebAPI.Storage", @@ -294,6 +298,18 @@ "HTMLUnknownElement" ] }, + { + "dir": "src/history", + "subdirs": true, + "feature": "History", + "public": ["History"] + }, + { + "dir": "src/location", + "subdirs": true, + "feature": "Location", + "public": ["Location"] + }, { "dir": "src/window", "subdirs": true, @@ -301,9 +317,7 @@ "public": [ "CustomElementRegistry", "Document", - "History", "IdleDeadline", - "Location", "VisualViewport", "Window", "XPathExpression", diff --git a/scripts/check-consumer.mjs b/scripts/check-consumer.mjs index 9f1ec437..5be3577c 100644 --- a/scripts/check-consumer.mjs +++ b/scripts/check-consumer.mjs @@ -7,10 +7,11 @@ import { validateReleaseArtifact } from "./validate-release-artifact.mjs"; const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const packageJson = JSON.parse(readFileSync(path.join(repoRoot, "package.json"), "utf8")); -const compilerVersion = "13.0.0-alpha.5"; +const compilerVersion = packageJson.devDependencies.rescript; +const compilerPeerRange = `>=${compilerVersion} <13.0.0`; if ( - packageJson.devDependencies.rescript !== compilerVersion || - packageJson.peerDependencies.rescript !== ">=13.0.0-alpha.5 <13.0.0" + !/^13\.0\.0-alpha\.\d+$/.test(compilerVersion) || + packageJson.peerDependencies.rescript !== compilerPeerRange ) { throw new Error("The tested compiler and package peer range are inconsistent."); } @@ -119,7 +120,7 @@ const verifyUnsupportedCompiler = (directory, tarballPath) => { if ( result.status === 0 || !output.includes("@rescript/webapi") || - !output.includes(">=13.0.0-alpha.5 <13.0.0") + !output.includes(compilerPeerRange) ) { throw new Error( `Unsupported compiler installation did not explain the peer constraint:\n${output}`, diff --git a/scripts/check-features.mjs b/scripts/check-features.mjs index 03ddf84b..4b2940d0 100644 --- a/scripts/check-features.mjs +++ b/scripts/check-features.mjs @@ -25,6 +25,8 @@ const expectedFeatureOwners = new Map([ ["WebAPI.DOMNodes", "DOMNodes"], ["WebAPI.File", "File"], ["WebAPI.HTML", "HTML"], + ["WebAPI.History", "History"], + ["WebAPI.Location", "Location"], ["WebAPI.Window", "Window"], ["WebAPI.CSSOM", "CSSOM"], ["WebAPI.CSSFontLoading", "CSSFontLoading"], @@ -237,7 +239,7 @@ const validateCompletionAliases = (sourceEntries) => { ); }; -const validateConfig = (config) => { +export const validateConfig = (config) => { const featureEntries = Object.entries(config.features ?? {}); const sourceEntries = (config.sources ?? []).filter( (source) => source !== null && typeof source === "object" && typeof source.feature === "string", diff --git a/scripts/check-features.test.mjs b/scripts/check-features.test.mjs index 590b42c8..70353ed6 100644 --- a/scripts/check-features.test.mjs +++ b/scripts/check-features.test.mjs @@ -1,7 +1,12 @@ import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; import test from "node:test"; -import { isMissingSafeFetchDiagnostic, parsePublicTypeAlias } from "./check-features.mjs"; +import { + isMissingSafeFetchDiagnostic, + parsePublicTypeAlias, + validateConfig, +} from "./check-features.mjs"; test("parses a public type alias without type parameters", () => { assert.deepEqual(parsePublicTypeAlias("type t = DOMTree.element"), { @@ -17,6 +22,32 @@ test("parses a public type alias with type parameters", () => { }); }); +const config = JSON.parse(readFileSync(new URL("../rescript.json", import.meta.url), "utf8")); + +test("validates independent History and Location feature ownership", () => { + assert.deepEqual(validateConfig(config), []); + assert.deepEqual(config.features["WebAPI.History"], ["History"]); + assert.deepEqual(config.features["WebAPI.Location"], ["WebAPI.DOM", "Location"]); + assert.ok(config.features["WebAPI.Window"].includes("WebAPI.History")); + assert.ok(config.features["WebAPI.Window"].includes("WebAPI.Location")); +}); + +test("rejects a missing History feature", () => { + const features = Object.fromEntries( + Object.entries(config.features).filter(([name]) => name !== "WebAPI.History"), + ); + assert.ok( + validateConfig({ ...config, features }).some((error) => error.includes("Expected exactly")), + ); +}); + +test("rejects duplicate Location public ownership", () => { + const sources = config.sources.map((source) => + source.feature === "Window" ? { ...source, public: [...source.public, "Location"] } : source, + ); + assert.ok(validateConfig({ ...config, sources }).includes("Duplicate public modules: Location")); +}); + test("recognizes the unavailable SafeFetch module diagnostic across line breaks", () => { assert.equal( isMissingSafeFetchDiagnostic("The module or file WebAPI.SafeFetch\ncan't be found."), diff --git a/src/window/History.res b/src/history/History.res similarity index 100% rename from src/window/History.res rename to src/history/History.res diff --git a/src/window/HistoryTypes.res b/src/history/HistoryTypes.res similarity index 100% rename from src/window/HistoryTypes.res rename to src/history/HistoryTypes.res diff --git a/src/window/Location.res b/src/location/Location.res similarity index 100% rename from src/window/Location.res rename to src/location/Location.res diff --git a/tests/DOMAPI/ImageData__test.res b/tests/DOMAPI/ImageData__test.res index 445049b3..38cbaa27 100644 --- a/tests/DOMAPI/ImageData__test.res +++ b/tests/DOMAPI/ImageData__test.res @@ -1,3 +1,3 @@ let imageData = ImageData.makeWithData(~data=Uint8ClampedArray.fromArray([]), ~sw=100, ~sh=100) -imageData.data->TypedArray.length->Console.log +(imageData.data :> TypedArray.t)->TypedArray.length->Console.log From c469e565ba27d5a92a9278defa64a7a5cdaa43a7 Mon Sep 17 00:00:00 2001 From: Josh Vlk Date: Mon, 16 Nov 2026 13:42:36 -0500 Subject: [PATCH 2/3] style(webapi): apply ReScript alpha.7 formatting [Codex] --- src/core/DOM.res | 1 + src/crypto/Crypto.res | 1 + src/crypto/SubtleCrypto.res | 2 + src/cssom/StylePropertyMap.res | 1 + src/cssom/StyleSheet.res | 1 + src/device/GamepadTypes.res | 1 + src/device/GeolocationTypes.res | 1 + src/dom-nodes/Range.res | 1 + src/fetch/FormData.res | 1 + src/fetch/Request.res | 1 + src/fetch/Response.res | 1 + src/file/Blob.res | 2 + src/file/FileSystemDirectoryEntry.res | 1 + src/file/FileSystemDirectoryHandle.res | 1 + src/file/FileSystemFileHandle.res | 1 + src/file/FileSystemWritableFileStream.res | 1 + src/file/FileTypes.res | 1 + src/geometry/DOMMatrix.res | 1 + src/geometry/DOMPoint.res | 1 + src/geometry/DOMRect.res | 1 + src/media/MediaCapabilitiesTypes.res | 1 + src/media/MediaDevices.res | 3 + src/media/MediaMetadata.res | 1 + src/media/MediaSession.res | 2 + src/media/MediaStreamTrack.res | 3 + src/messaging/MessageEvent.res | 1 + src/messaging/Notification.res | 5 + src/navigator/Navigator.res | 8 ++ src/performance/PerformanceMark.res | 1 + src/storage/StorageTypes.res | 1 + tests/BindingByteTypes__test.res | 2 + tests/FetchAPI/FormData__test.res | 2 + tests/FetchAPI/Request__test.res | 1 + tests/FetchAPI/Response__test.res | 1 + tests/FetchAPI/SafeFetch__test.res | 112 +++++++++--------- tests/Fetch__test.res | 3 + .../IntersectionObserver__test.res | 9 +- .../MutationObserver__test.res | 7 +- .../AudioDestinationNode__.test.res | 3 + tests/browser/BindingContracts__test.res | 64 ++++++++-- 40 files changed, 180 insertions(+), 72 deletions(-) diff --git a/src/core/DOM.res b/src/core/DOM.res index 50a9a5cd..931d2252 100644 --- a/src/core/DOM.res +++ b/src/core/DOM.res @@ -37,6 +37,7 @@ type domStringList = { @editor.completeFrom(Window) type window = private {} + external window: window = "window" type autoFillBase = diff --git a/src/crypto/Crypto.res b/src/crypto/Crypto.res index 485e9bd6..f7c8ca7a 100644 --- a/src/crypto/Crypto.res +++ b/src/crypto/Crypto.res @@ -9,4 +9,5 @@ external getRandomValues: (WebCryptoTypes.crypto, 't) => 't = "getRandomValues" */ @send external randomUUID: WebCryptoTypes.crypto => string = "randomUUID" + type t = WebCryptoTypes.crypto diff --git a/src/crypto/SubtleCrypto.res b/src/crypto/SubtleCrypto.res index 9d8f29ad..3c613693 100644 --- a/src/crypto/SubtleCrypto.res +++ b/src/crypto/SubtleCrypto.res @@ -5,10 +5,12 @@ type keyUsage = WebCryptoTypes.keyUsage type keyFormat = WebCryptoTypes.keyFormat type algorithmIdentifier = WebCryptoTypes.algorithmIdentifier type algorithm = WebCryptoTypes.algorithm + type binaryKeyFormat = | @as("raw") Raw | @as("pkcs8") Pkcs8 | @as("spki") Spki + type jwkKeyFormat = | @as("jwk") Jwk type keyAlgorithm = WebCryptoTypes.keyAlgorithm type cryptoKey = WebCryptoTypes.cryptoKey diff --git a/src/cssom/StylePropertyMap.res b/src/cssom/StylePropertyMap.res index 7ec490bf..c87f65ac 100644 --- a/src/cssom/StylePropertyMap.res +++ b/src/cssom/StylePropertyMap.res @@ -7,6 +7,7 @@ type t = private { } external asStylePropertyMapReadOnly: t => StylePropertyMapReadOnly.t = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/getAll) */ diff --git a/src/cssom/StyleSheet.res b/src/cssom/StyleSheet.res index a47fe7a5..4b1b4c70 100644 --- a/src/cssom/StyleSheet.res +++ b/src/cssom/StyleSheet.res @@ -127,6 +127,7 @@ type init = { external make: (~options: init=?) => cssStyleSheet = "CSSStyleSheet" external asStyleSheet: cssStyleSheet => t = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/CSSStyleSheet/insertRule) */ diff --git a/src/device/GamepadTypes.res b/src/device/GamepadTypes.res index 702ff322..84aeffbd 100644 --- a/src/device/GamepadTypes.res +++ b/src/device/GamepadTypes.res @@ -1,4 +1,5 @@ @@warning("-30") + type gamepadMappingType = | @as("standard") Standard | @as("xr-standard") XrStandard diff --git a/src/device/GeolocationTypes.res b/src/device/GeolocationTypes.res index d9149242..f7bb58a0 100644 --- a/src/device/GeolocationTypes.res +++ b/src/device/GeolocationTypes.res @@ -1,4 +1,5 @@ @@warning("-30") + /** An object able to programmatically obtain the position of the device. It gives Web content access to the location of the device. This allows a Web site or app to offer customized results based on the user's location. [See WebApiGeolocation on MDN](https://developer.mozilla.org/docs/Web/API/Geolocation) diff --git a/src/dom-nodes/Range.res b/src/dom-nodes/Range.res index 5b6e2d17..71a4718c 100644 --- a/src/dom-nodes/Range.res +++ b/src/dom-nodes/Range.res @@ -14,6 +14,7 @@ type t = private { external make: unit => t = "Range" external asAbstractRange: t => AbstractRange.t = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Range/setStart) */ diff --git a/src/fetch/FormData.res b/src/fetch/FormData.res index 6920666c..c7388cf9 100644 --- a/src/fetch/FormData.res +++ b/src/fetch/FormData.res @@ -2,6 +2,7 @@ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData) */ type t = FetchTypes.formData = private {...FetchTypes.formData} + type formDataEntryValue = FormDataEntryValue.t /** diff --git a/src/fetch/Request.res b/src/fetch/Request.res index f51ad3fd..632e9904 100644 --- a/src/fetch/Request.res +++ b/src/fetch/Request.res @@ -2,6 +2,7 @@ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Request) */ type t = FetchTypes.request = private {...FetchTypes.request} + type requestInit = FetchTypes.requestInit type bodyInit = BodyInit.t type headersInit = HeadersInit.t diff --git a/src/fetch/Response.res b/src/fetch/Response.res index aa76cfcb..981285bb 100644 --- a/src/fetch/Response.res +++ b/src/fetch/Response.res @@ -2,6 +2,7 @@ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Response) */ type t = FetchTypes.response = private {...FetchTypes.response} + type responseInit = FetchTypes.responseInit type bodyInit = BodyInit.t type headersInit = HeadersInit.t diff --git a/src/file/Blob.res b/src/file/Blob.res index a4142b94..80066357 100644 --- a/src/file/Blob.res +++ b/src/file/Blob.res @@ -2,6 +2,7 @@ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Blob) */ type t = FileTypes.blob = private {...FileTypes.blob} + type blobPart = FileTypes.blobPart type blobPropertyBag = FileTypes.blobPropertyBag @@ -14,6 +15,7 @@ module Impl = ( }, ) => { external asBlob: T.t => t = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Blob/slice) */ diff --git a/src/file/FileSystemDirectoryEntry.res b/src/file/FileSystemDirectoryEntry.res index fb943376..05601b1c 100644 --- a/src/file/FileSystemDirectoryEntry.res +++ b/src/file/FileSystemDirectoryEntry.res @@ -4,6 +4,7 @@ type t = BaseFileAndDirectoryEntries.fileSystemDirectoryEntry = private { external asFileSystemEntry: FileAndDirectoryEntriesTypes.fileSystemDirectoryEntry => FileAndDirectoryEntriesTypes.fileSystemEntry = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FileSystemEntry/getParent) */ diff --git a/src/file/FileSystemDirectoryHandle.res b/src/file/FileSystemDirectoryHandle.res index d1f6ac45..f92d8a46 100644 --- a/src/file/FileSystemDirectoryHandle.res +++ b/src/file/FileSystemDirectoryHandle.res @@ -2,6 +2,7 @@ type t = FileTypes.fileSystemDirectoryHandle = private {...FileTypes.fileSystemD external asFileSystemHandle: FileTypes.fileSystemDirectoryHandle => FileTypes.fileSystemHandle = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FileSystemHandle/isSameEntry) */ diff --git a/src/file/FileSystemFileHandle.res b/src/file/FileSystemFileHandle.res index 3f9bd5b5..e020939d 100644 --- a/src/file/FileSystemFileHandle.res +++ b/src/file/FileSystemFileHandle.res @@ -2,6 +2,7 @@ type t = FileTypes.fileSystemFileHandle = private {...FileTypes.fileSystemFileHa external asFileSystemHandle: FileTypes.fileSystemFileHandle => FileTypes.fileSystemHandle = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FileSystemHandle/isSameEntry) */ diff --git a/src/file/FileSystemWritableFileStream.res b/src/file/FileSystemWritableFileStream.res index 996002ee..ade0c341 100644 --- a/src/file/FileSystemWritableFileStream.res +++ b/src/file/FileSystemWritableFileStream.res @@ -4,6 +4,7 @@ type t = FileTypes.fileSystemWritableFileStream = private { external asWritableStream: FileTypes.fileSystemWritableFileStream => FileTypes.writableStream<'w> = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/WritableStream/abort) */ diff --git a/src/file/FileTypes.res b/src/file/FileTypes.res index d50b7cd1..0772f485 100644 --- a/src/file/FileTypes.res +++ b/src/file/FileTypes.res @@ -132,6 +132,7 @@ type fileSystemWritableFileStream = private { type blobPart = | String(string) | Blob(blob) + // | ArrayBuffer(ArrayBuffer.t) // | TypedArray(TypedArray.t) diff --git a/src/geometry/DOMMatrix.res b/src/geometry/DOMMatrix.res index f9ba24ee..a9f698a9 100644 --- a/src/geometry/DOMMatrix.res +++ b/src/geometry/DOMMatrix.res @@ -43,6 +43,7 @@ let matrix = DOMMatrix.fromArray([1., 0., 0., 1., 0., 0.]) external fromArray: array => DOM.domMatrix = "DOMMatrix" external asDOMMatrixReadOnly: DOM.domMatrix => DOM.domMatrixReadOnly = "%identity" + @scope("DOMMatrix") external fromMatrix: (~other: DOM.domMatrixInit=?) => DOM.domMatrixReadOnly = "fromMatrix" diff --git a/src/geometry/DOMPoint.res b/src/geometry/DOMPoint.res index 34225952..39fa97ef 100644 --- a/src/geometry/DOMPoint.res +++ b/src/geometry/DOMPoint.res @@ -7,6 +7,7 @@ type t = DOM.domPoint = private {...DOM.domPoint} external make: (~x: float=?, ~y: float=?, ~z: float=?, ~w: float=?) => DOM.domPoint = "DOMPoint" external asDOMPointReadOnly: DOM.domPoint => DOM.domPointReadOnly = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DOMPointReadOnly/fromPoint_static) */ diff --git a/src/geometry/DOMRect.res b/src/geometry/DOMRect.res index 96246ce1..2d1974e2 100644 --- a/src/geometry/DOMRect.res +++ b/src/geometry/DOMRect.res @@ -8,6 +8,7 @@ external make: (~x: float=?, ~y: float=?, ~width: float=?, ~height: float=?) => "DOMRect" external asDOMRectReadOnly: DOM.domRect => DOM.domRectReadOnly = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/fromRect_static) */ diff --git a/src/media/MediaCapabilitiesTypes.res b/src/media/MediaCapabilitiesTypes.res index ebedb7ff..935e46a5 100644 --- a/src/media/MediaCapabilitiesTypes.res +++ b/src/media/MediaCapabilitiesTypes.res @@ -1,4 +1,5 @@ @@warning("-30") + type hdrMetadataType = | @as("smpteSt2086") SmpteSt2086 | @as("smpteSt2094-10") SmpteSt209410 diff --git a/src/media/MediaDevices.res b/src/media/MediaDevices.res index 648d964b..6135b48a 100644 --- a/src/media/MediaDevices.res +++ b/src/media/MediaDevices.res @@ -1,12 +1,15 @@ type t = MediaCaptureAndStreamsTypes.mediaDevices = private { ...MediaCaptureAndStreamsTypes.mediaDevices, } + type mediaTrackSupportedConstraints = MediaCaptureAndStreamsTypes.mediaTrackSupportedConstraints = { ...MediaCaptureAndStreamsTypes.mediaTrackSupportedConstraints, } + type mediaStreamConstraints = MediaCaptureAndStreamsTypes.mediaStreamConstraints = { ...MediaCaptureAndStreamsTypes.mediaStreamConstraints, } + type displayMediaStreamOptions = MediaCaptureAndStreamsTypes.displayMediaStreamOptions = { ...MediaCaptureAndStreamsTypes.displayMediaStreamOptions, } diff --git a/src/media/MediaMetadata.res b/src/media/MediaMetadata.res index 4bcd380d..42505373 100644 --- a/src/media/MediaMetadata.res +++ b/src/media/MediaMetadata.res @@ -1,4 +1,5 @@ type t = MediaSessionTypes.mediaMetadata = private {...MediaSessionTypes.mediaMetadata} + type mediaMetadataInit = MediaSessionTypes.mediaMetadataInit = { ...MediaSessionTypes.mediaMetadataInit, } diff --git a/src/media/MediaSession.res b/src/media/MediaSession.res index d9c6e7eb..a6b12c99 100644 --- a/src/media/MediaSession.res +++ b/src/media/MediaSession.res @@ -1,8 +1,10 @@ type t = MediaSessionTypes.mediaSession = private {...MediaSessionTypes.mediaSession} type mediaSessionAction = MediaSessionTypes.mediaSessionAction + type mediaPositionState = MediaSessionTypes.mediaPositionState = { ...MediaSessionTypes.mediaPositionState, } + type mediaSessionActionHandler = MediaSessionTypes.mediaSessionActionHandler /** diff --git a/src/media/MediaStreamTrack.res b/src/media/MediaStreamTrack.res index e31de28d..16ea9660 100644 --- a/src/media/MediaStreamTrack.res +++ b/src/media/MediaStreamTrack.res @@ -1,12 +1,15 @@ type t = MediaCaptureAndStreamsTypes.mediaStreamTrack = private { ...MediaCaptureAndStreamsTypes.mediaStreamTrack, } + type mediaTrackCapabilities = MediaCaptureAndStreamsTypes.mediaTrackCapabilities = { ...MediaCaptureAndStreamsTypes.mediaTrackCapabilities, } + type mediaTrackConstraints = MediaCaptureAndStreamsTypes.mediaTrackConstraints = { ...MediaCaptureAndStreamsTypes.mediaTrackConstraints, } + type mediaTrackSettings = MediaCaptureAndStreamsTypes.mediaTrackSettings = { ...MediaCaptureAndStreamsTypes.mediaTrackSettings, } diff --git a/src/messaging/MessageEvent.res b/src/messaging/MessageEvent.res index 53d5eacb..584b01ca 100644 --- a/src/messaging/MessageEvent.res +++ b/src/messaging/MessageEvent.res @@ -14,6 +14,7 @@ type t<'t> = messageEvent<'t> external make: (~type_: string, ~eventInitDict: messageEventInit<'t>=?) => t<'t> = "MessageEvent" external asEvent: t<'t> => event = "%identity" + /** Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Event/composedPath) diff --git a/src/messaging/Notification.res b/src/messaging/Notification.res index 7a193131..52693c0b 100644 --- a/src/messaging/Notification.res +++ b/src/messaging/Notification.res @@ -1,16 +1,21 @@ type t = NotificationTypes.notification = private {...NotificationTypes.notification} type notificationDirection = NotificationTypes.notificationDirection type notificationPermission = NotificationTypes.notificationPermission + type notificationAction = NotificationTypes.notificationAction = { ...NotificationTypes.notificationAction, } + type notificationOptions = NotificationTypes.notificationOptions = { ...NotificationTypes.notificationOptions, } + type getNotificationOptions = NotificationTypes.getNotificationOptions = { ...NotificationTypes.getNotificationOptions, } + type notificationPermissionCallback = NotificationTypes.notificationPermissionCallback + type notificationEvent = NotificationTypes.notificationEvent = { ...NotificationTypes.notificationEvent, } diff --git a/src/navigator/Navigator.res b/src/navigator/Navigator.res index ef26736c..e9a71196 100644 --- a/src/navigator/Navigator.res +++ b/src/navigator/Navigator.res @@ -64,34 +64,42 @@ type t = DOM.navigator [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/language) */ @get external language: t => string = "language" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/languages) */ @get external languages: t => array = "languages" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/onLine) */ @get external onLine: t => bool = "onLine" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/cookieEnabled) */ @get external cookieEnabled: t => bool = "cookieEnabled" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/pdfViewerEnabled) */ @get external pdfViewerEnabled: t => bool = "pdfViewerEnabled" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/hardwareConcurrency) */ @get external hardwareConcurrency: t => int = "hardwareConcurrency" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/storage) */ @get external storage: t => StorageTypes.storageManager = "storage" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/locks) */ @get external locks: t => WebLocksTypes.lockManager = "locks" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Navigator/webdriver) */ diff --git a/src/performance/PerformanceMark.res b/src/performance/PerformanceMark.res index fb20b47a..6af5e4a0 100644 --- a/src/performance/PerformanceMark.res +++ b/src/performance/PerformanceMark.res @@ -11,6 +11,7 @@ external make: ( external asPerformanceEntry: PerformanceTypes.performanceMark => PerformanceTypes.performanceEntry = "%identity" + /** [Read more on MDN](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/toJSON) */ diff --git a/src/storage/StorageTypes.res b/src/storage/StorageTypes.res index 5556aae6..ebcaf1d5 100644 --- a/src/storage/StorageTypes.res +++ b/src/storage/StorageTypes.res @@ -1,4 +1,5 @@ @@warning("-30") + /** [See StorageManager on MDN](https://developer.mozilla.org/docs/Web/API/StorageManager) */ diff --git a/tests/BindingByteTypes__test.res b/tests/BindingByteTypes__test.res index bfc1eb1c..2ab2113e 100644 --- a/tests/BindingByteTypes__test.res +++ b/tests/BindingByteTypes__test.res @@ -8,10 +8,12 @@ let _analyserFloat: ( WebAudioTypes.analyserNode, Float32Array.t, ) => unit = AnalyserNode.getFloatTimeDomainData + let _analyserByte: ( WebAudioTypes.analyserNode, Uint8Array.t, ) => unit = AnalyserNode.getByteTimeDomainData + let _audioBuffer: (WebAudioTypes.audioBuffer, int) => Float32Array.t = AudioBuffer.getChannelData let _sign: SubtleCrypto.keyUsage = SubtleCrypto.signUsage diff --git a/tests/FetchAPI/FormData__test.res b/tests/FetchAPI/FormData__test.res index 180fa091..b1a99c0d 100644 --- a/tests/FetchAPI/FormData__test.res +++ b/tests/FetchAPI/FormData__test.res @@ -25,6 +25,7 @@ let _ = switch phoneEntry->Null.toOption { // Get all values for a field (useful for multi-select or multiple file inputs) let allImages: array = formData->FormData.getAll("images") + let _ = allImages->Array.forEach(entry => logEntry(~stringPrefix="String value: ", ~filePrefix="WebApiFile: ", entry) @@ -44,6 +45,7 @@ logEntry(~stringPrefix="Unexpected string entry: ", ~filePrefix="File entry: ", // Iterate over all entries in the FormData let entries: iterable<(string, EntryValue.t)> = formData->FormData.entries + let _ = entries ->Array.fromIterable diff --git a/tests/FetchAPI/Request__test.res b/tests/FetchAPI/Request__test.res index d790df70..d326619b 100644 --- a/tests/FetchAPI/Request__test.res +++ b/tests/FetchAPI/Request__test.res @@ -24,6 +24,7 @@ let formDataReq = Request.fromURL( "https://example.com/form", ~init={method: "POST", body: formDataBody->Nullable.make}, ) + let _formData: FormData.t = await formDataReq->Request.formData assert((await req2->Request.text) == "hello") diff --git a/tests/FetchAPI/Response__test.res b/tests/FetchAPI/Response__test.res index 0eb615d7..b7ed927b 100644 --- a/tests/FetchAPI/Response__test.res +++ b/tests/FetchAPI/Response__test.res @@ -19,4 +19,5 @@ let response6 = Response.fromReadableStream(stream) let _blob: Blob.t = await response1 ->Response.clone ->Response.blob + let _formData: FormData.t = await response5->Response.formData diff --git a/tests/FetchAPI/SafeFetch__test.res b/tests/FetchAPI/SafeFetch__test.res index f954f76e..e9ef0c8c 100644 --- a/tests/FetchAPI/SafeFetch__test.res +++ b/tests/FetchAPI/SafeFetch__test.res @@ -5,12 +5,14 @@ let isBytesABC = _bytes => %raw(`_bytes instanceof Uint8Array && _bytes.length === 3 && _bytes[0] === 65 && _bytes[2] === 67`) let okResponse = Response.fromString("ok", ~init={status: 200}) + switch okResponse->SafeFetch.checkOk { | Ok(response) => assert(isSame(response, okResponse)) | Error(#ResponseNotOk(_)) => assert(false) } let notOkResponse = Response.fromString("missing", ~init={status: 404}) + switch notOkResponse->SafeFetch.checkOk { | Error(#ResponseNotOk({response})) => assert(isSame(response, notOkResponse)) | Ok(_) => assert(false) @@ -31,6 +33,7 @@ switch await SafeFetch.fetch( } let customAbortSignal = AbortSignal.abort(~reason=JSON.Encode.string("cancelled")) + switch await SafeFetch.fetch( "https://example.com/aborted", ~init={signal: Nullable.make(customAbortSignal)}, @@ -54,22 +57,20 @@ globalThis.fetch = (_input, init) => { let request = Request.fromURL("https://example.com/request") switch await SafeFetch.fetch("https://example.com/ok", ~init={method: "POST"}) { -| Ok(response) => { - let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) - let method: string = %raw(`globalThis.__safeFetchInit.method`) - assert(isSame(response, expected)) - assert(method == "POST") - } +| Ok(response) => + let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) + let method: string = %raw(`globalThis.__safeFetchInit.method`) + assert(isSame(response, expected)) + assert(method == "POST") | Error(_) => assert(false) } switch await SafeFetch.fetchWithRequest(request, ~init={method: "POST"}) { -| Ok(response) => { - let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) - let method: string = %raw(`globalThis.__safeFetchInit.method`) - assert(isSame(response, expected)) - assert(method == "POST") - } +| Ok(response) => + let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) + let method: string = %raw(`globalThis.__safeFetchInit.method`) + assert(isSame(response, expected)) + assert(method == "POST") | Error(_) => assert(false) } @@ -82,22 +83,20 @@ globalThis.fetch = (_input, init) => { `) switch await SafeFetch.fetch("https://example.com/missing") { -| Error(#ResponseNotOk({response})) => { - let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) - assert(isSame(response, expected)) - let initOmitted: bool = %raw(`globalThis.__safeFetchInit === undefined`) - assert(initOmitted) - } +| Error(#ResponseNotOk({response})) => + let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) + assert(isSame(response, expected)) + let initOmitted: bool = %raw(`globalThis.__safeFetchInit === undefined`) + assert(initOmitted) | Error(#FetchRejected(_)) | Ok(_) => assert(false) } switch await SafeFetch.fetchWithRequest(request) { -| Error(#ResponseNotOk({response})) => { - let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) - assert(isSame(response, expected)) - let initOmitted: bool = %raw(`globalThis.__safeFetchInit === undefined`) - assert(initOmitted) - } +| Error(#ResponseNotOk({response})) => + let expected: Response.t = %raw(`globalThis.__safeFetchResponse`) + assert(isSame(response, expected)) + let initOmitted: bool = %raw(`globalThis.__safeFetchInit === undefined`) + assert(initOmitted) | Error(#FetchRejected(_)) | Ok(_) => assert(false) } @@ -148,24 +147,25 @@ switch await SafeFetch.fetch("https://example.com/synchronous") { } let textResponse = Response.fromString("hello") + switch await textResponse->SafeFetch.text { -| Ok({response, body}) => { - assert(isSame(response, textResponse)) - assert(body == "hello") - } +| Ok({response, body}) => + assert(isSame(response, textResponse)) + assert(body == "hello") | Error(_) => assert(false) } let jsonResponse = Response.fromString(`{"name":"Ada"}`) + switch await jsonResponse->SafeFetch.json { -| Ok({response, body}) => { - let _json: JSON.t = body - assert(isSame(response, jsonResponse)) - } +| Ok({response, body}) => + let _json: JSON.t = body + assert(isSame(response, jsonResponse)) | Error(_) => assert(false) } let malformedResponse = Response.fromString("not json") + switch await malformedResponse->SafeFetch.json { | Error(#BodyReadRejected({response, cause: _})) => assert(isSame(response, malformedResponse)) | Ok(_) => assert(false) @@ -173,17 +173,18 @@ switch await malformedResponse->SafeFetch.json { let consumedResponse = Response.fromString("once") let _ = await consumedResponse->Response.text + switch await consumedResponse->SafeFetch.text { | Error(#BodyReadRejected({response, cause: _})) => assert(isSame(response, consumedResponse)) | Ok(_) => assert(false) } let errorBodyResponse = Response.fromString("details", ~init={status: 500}) + switch await errorBodyResponse->SafeFetch.text { -| Ok({response, body}) => { - assert(isSame(response, errorBodyResponse)) - assert(body == "details") - } +| Ok({response, body}) => + assert(isSame(response, errorBodyResponse)) + assert(body == "details") | Error(_) => assert(false) } @@ -191,24 +192,27 @@ let arrayBufferResult: result< SafeFetch.response, [> SafeFetch.bodyError], > = await Response.fromString("buffer")->SafeFetch.arrayBuffer + assert(arrayBufferResult->Result.isOk) let blobResult: result< SafeFetch.response, [> SafeFetch.bodyError], > = await Response.fromString("blob")->SafeFetch.blob + assert(blobResult->Result.isOk) let bytesResponse = Response.fromString("ABC") + let bytesResult: result< SafeFetch.response, [> SafeFetch.bodyError], > = await bytesResponse->SafeFetch.bytes + switch bytesResult { -| Ok({response, body}) => { - assert(isSame(response, bytesResponse)) - assert(isBytesABC(body)) - } +| Ok({response, body}) => + assert(isSame(response, bytesResponse)) + assert(isBytesABC(body)) | Error(_) => assert(false) } @@ -218,10 +222,12 @@ let formDataResponse = Response.fromString( headers: HeadersInit.fromDict(dict{"Content-Type": "application/x-www-form-urlencoded"}), }, ) + let formDataResult: result< SafeFetch.response, [> SafeFetch.bodyError], > = await formDataResponse->SafeFetch.formData + assert(formDataResult->Result.isOk) type user = {name: string} @@ -272,10 +278,9 @@ globalThis.fetch = () => Promise.resolve(globalThis.__safeFetchResponse) `) switch await loadUser("https://example.com/user", mustNotDecode) { -| Error(#ResponseNotOk({response})) => { - assert(isSame(response, %raw(`globalThis.__safeFetchResponse`))) - assert(!response.bodyUsed) - } +| Error(#ResponseNotOk({response})) => + assert(isSame(response, %raw(`globalThis.__safeFetchResponse`))) + assert(!response.bodyUsed) | Error(#FetchRejected(_) | #BodyReadRejected(_)) | Ok(_) => assert(false) } @@ -285,12 +290,11 @@ globalThis.fetch = () => Promise.resolve(globalThis.__safeFetchResponse) `) switch await loadUser("https://example.com/user", mustNotDecode) { -| Error(#BodyReadRejected({response, cause})) => { - assert(isSame(response, %raw(`globalThis.__safeFetchResponse`))) - switch cause->JsExn.fromException { - | Some(rawCause) => assert(JsExn.name(rawCause) == Some("SyntaxError")) - | None => assert(false) - } +| Error(#BodyReadRejected({response, cause})) => + assert(isSame(response, %raw(`globalThis.__safeFetchResponse`))) + switch cause->JsExn.fromException { + | Some(rawCause) => assert(JsExn.name(rawCause) == Some("SyntaxError")) + | None => assert(false) } | Error(#FetchRejected(_) | #ResponseNotOk(_)) | Ok(_) => assert(false) } @@ -317,10 +321,10 @@ switch await Response.fromString("checked")->readCheckedText { } let uncheckedResponse = Response.fromString("not read", ~init={status: 500}) + switch await uncheckedResponse->readCheckedText { -| Error(#ResponseNotOk({response})) => { - assert(isSame(response, uncheckedResponse)) - assert(!response.bodyUsed) - } +| Error(#ResponseNotOk({response})) => + assert(isSame(response, uncheckedResponse)) + assert(!response.bodyUsed) | Error(#BodyReadRejected(_)) | Ok(_) => assert(false) } diff --git a/tests/Fetch__test.res b/tests/Fetch__test.res index 66f4cf1f..e2642388 100644 --- a/tests/Fetch__test.res +++ b/tests/Fetch__test.res @@ -36,6 +36,7 @@ let registrationResult = await Window.current ->Window.navigator ->Navigator.serviceWorker ->ServiceWorkerContainer.register("/sw.js") + let subscription = await registrationResult.pushManager->PushManager.subscribe( ~options={ userVisibleOnly: true, @@ -44,8 +45,10 @@ let subscription = await registrationResult.pushManager->PushManager.subscribe( ) let pushSubscriptionJSON = subscription->PushSubscription.toJSON + let (auth, p256dh) = switch pushSubscriptionJSON.keys { | None => ("?", "?") | Some(keys) => (keys.auth, keys.p256dh) } + Console.log(`For subscription ${subscription.endpoint}, auth is ${auth} and p256dh is ${p256dh}`) diff --git a/tests/IntersectionObserverAPI/IntersectionObserver__test.res b/tests/IntersectionObserverAPI/IntersectionObserver__test.res index 2604d255..b4756ba8 100644 --- a/tests/IntersectionObserverAPI/IntersectionObserver__test.res +++ b/tests/IntersectionObserverAPI/IntersectionObserver__test.res @@ -27,14 +27,15 @@ switch observer2.root->Null.toOption { } | None => Console.log("Null") } + let rootMargin2 = observer2.rootMargin let targetElement = DomGlobal.document->Document.querySelector("#targetElement")->Null.toOption + switch targetElement { -| Some(e) => { - observer2->IObserver.observe(e) - observer2->IObserver.unobserve(e) - } +| Some(e) => + observer2->IObserver.observe(e) + observer2->IObserver.unobserve(e) | _ => Console.log("Target element not found.") } diff --git a/tests/MutationObserverAPI/MutationObserver__test.res b/tests/MutationObserverAPI/MutationObserver__test.res index aa6c636e..e342f6a2 100644 --- a/tests/MutationObserverAPI/MutationObserver__test.res +++ b/tests/MutationObserverAPI/MutationObserver__test.res @@ -3,10 +3,9 @@ module MObserver = MutationObserver let observer = MObserver.make((mutations, obs) => { let button = DomGlobal.document->Document.querySelector("button") switch button->Null.toOption { - | Some(button) => { - Console.log(button) - obs->MObserver.disconnect - } + | Some(button) => + Console.log(button) + obs->MObserver.disconnect | None => () } Console.log(mutations) diff --git a/tests/WebAudioAPI/AudioDestinationNode__.test.res b/tests/WebAudioAPI/AudioDestinationNode__.test.res index 85246252..0063ed74 100644 --- a/tests/WebAudioAPI/AudioDestinationNode__.test.res +++ b/tests/WebAudioAPI/AudioDestinationNode__.test.res @@ -10,13 +10,16 @@ let osc = OscillatorNode.make( frequency: 440.0, }, ) + let gain = GainNode.make( ~context, ~options={ gain: 0.3, }, ) + let _ = gain->GainNode.connect(~destinationNode) + let _ = osc ->OscillatorNode.asAudioScheduledSourceNode diff --git a/tests/browser/BindingContracts__test.res b/tests/browser/BindingContracts__test.res index abc7d9b6..6803e803 100644 --- a/tests/browser/BindingContracts__test.res +++ b/tests/browser/BindingContracts__test.res @@ -23,25 +23,34 @@ let withResolver = (_run: (unit => unit) => unit): promise => let hasResizeCallbackArgs = (_entries, _observer) => %raw(`_entries.length > 0 && _observer instanceof ResizeObserver`) + let createResizeSignals = () => %raw(`({count: 0, resolvers: []})`) + let waitForResizeSignal = (_signals: unknown): promise => %raw(`new Promise(resolve => _signals.resolvers.push(resolve))`) + let resolveNextResizeSignal = (_signals: unknown): unit => %raw(`_signals.resolvers.shift()()`) let incrementResizeCount = (_signals: unknown): int => %raw(`++_signals.count`) + let setSize = (_target: DOMTree.element, _pixels: int): unit => %raw(`(_target.style.width = _pixels + "px", _target.style.height = _pixels + "px")`) let isNull = _value => %raw(`_value === null`) let isUndefined = _value => %raw(`_value === undefined`) + let isKnownNotificationPermission = _permission => %raw(`_permission === "default" || _permission === "denied" || _permission === "granted"`) + let containsABCByteChunk = _result => %raw(`_result.value instanceof Uint8Array && _result.value.length === 3 && _result.value[0] === 65 && _result.value[1] === 66 && _result.value[2] === 67`) + let appendChild = (_parent, _child) => %raw(`_parent.appendChild(_child)`) let appendToDocument = _target => %raw(`document.body.appendChild(_target)`) + let onSuccess = (_request, _callback) => %raw(`_request.addEventListener("success", _callback, {once: true})`) + let releaseLock = () => %raw(`globalThis.__releaseBindingLock()`) let isUint8ArrayWithABC = _bytes => @@ -62,6 +71,7 @@ let requestBytes = await Request.fromURL( "https://example.invalid/", ~init={method: "POST", body: Nullable.make(BodyInit.fromString("ABC"))}, )->Request.bytes + assert(isUint8ArrayWithABC(requestBytes)) let emptyStateRequest = Request.fromURL("https://example.invalid/") @@ -75,13 +85,16 @@ let byteStreamReader = byteStream->ReadableStream.getReader let firstChunk = await byteStreamReader->readByteStreamChunk assert(containsABCByteChunk(firstChunk)) await byteStreamReader->cancelByteStreamReader + let responseFromByteStream = Response.fromReadableStream( Blob.make(~blobParts=[String("ABC")])->Blob.stream, ) + let responseStreamBytes = await responseFromByteStream->Response.bytes assert(isUint8ArrayWithABC(responseStreamBytes)) let audio: HTMLAudioElement.t = %raw(`document.createElement("audio")`) + assert(audio->HTMLAudioElement.canPlayType("application/x-webapi-unsupported") == DomHTMLMediaElement.Empty) @@ -89,16 +102,15 @@ let permission = Notification.permission assert(isKnownNotificationPermission(permission)) switch Document.createElement(document, "canvas")->HTMLCanvasElement.classify { -| Some(canvas) => { - canvas.width = 0 - canvas.height = 0 - await withResolver(resolve => - canvas->HTMLCanvasElement.toBlob(~callback=_blob => { - assert(isNull(_blob)) - resolve() - }) - ) - } +| Some(canvas) => + canvas.width = 0 + canvas.height = 0 + await withResolver(resolve => + canvas->HTMLCanvasElement.toBlob(~callback=_blob => { + assert(isNull(_blob)) + resolve() + }) + ) | None => assert(false) } @@ -111,11 +123,13 @@ external customElements: DOM.customElementRegistry = "customElements" external bindingContractsConstructor: DOM.customElementConstructor = "BindingContractsElement" let customElementName = "webapi-binding-contracts" + CustomElementRegistry.define( customElements, ~name=customElementName, ~constructor=bindingContractsConstructor, ) + let customElement = Document.createElement(document, customElementName) assert(%raw(`customElement instanceof globalThis.BindingContractsElement`)) @@ -140,10 +154,12 @@ let htmlParent: HTMLDivElement.t = %raw(`document.createElement("div")`) htmlParent->HTMLDivElement.setAttribute(~qualifiedName="class", ~value="binding-contracts-html") assert(htmlParent.className == "binding-contracts-html") let htmlChild: HTMLSpanElement.t = %raw(`document.createElement("span")`) + htmlChild->HTMLSpanElement.setAttribute( ~qualifiedName="class", ~value="binding-contracts-html-child", ) + appendChild(htmlParent, htmlChild) let broadHtmlResult = htmlParent->HTMLDivElement.querySelector(".binding-contracts-html-child") assert(%raw(`broadHtmlResult !== null && typeof broadHtmlResult.className === "string"`)) @@ -153,12 +169,14 @@ let audioContext = OfflineAudioContext.fromChannelCountLengthAndSampleRate( ~length=128, ~sampleRate=44100., ) + let audioBuffer = audioContext->OfflineAudioContext.createBuffer( ~numberOfChannels=1, ~length=128, ~sampleRate=44100., ) + let sourceChannel: Float32Array.t = %raw(`new Float32Array([0.5, -0.25])`) audioBuffer->AudioBuffer.copyToChannel(~source=sourceChannel, ~channelNumber=0) let channelData = audioBuffer->AudioBuffer.getChannelData(0) @@ -180,27 +198,33 @@ let filter = audioContext->OfflineAudioContext.createBiquadFilter let frequencies: Float32Array.t = %raw(`new Float32Array([440, 880])`) let magnitudes: Float32Array.t = %raw(`new Float32Array([-123, -123])`) let phases: Float32Array.t = %raw(`new Float32Array([-456, -456])`) + filter->BiquadFilterNode.getFrequencyResponse( ~frequencyHz=frequencies, ~magResponse=magnitudes, ~phaseResponse=phases, ) + assert(%raw(`magnitudes instanceof Float32Array && phases instanceof Float32Array && magnitudes.length === 2 && phases.length === 2 && magnitudes[0] !== -123 && phases[0] !== -456 && !Number.isNaN(magnitudes[0])`)) let iirFilter = IIRFilterNode.make( ~context=audioContext->OfflineAudioContext.asBaseAudioContext, ~options={feedforward: [1.], feedback: [1.]}, ) + let iirMagnitudes: Float32Array.t = %raw(`new Float32Array([-123, -123])`) let iirPhases: Float32Array.t = %raw(`new Float32Array([-456, -456])`) + iirFilter->IIRFilterNode.getFrequencyResponse( ~frequencyHz=frequencies, ~magResponse=iirMagnitudes, ~phaseResponse=iirPhases, ) + assert(%raw(`iirMagnitudes instanceof Float32Array && iirMagnitudes[0] !== -123 && !Number.isNaN(iirMagnitudes[0]) && iirPhases instanceof Float32Array && iirPhases[0] !== -456`)) let deleteRequest = IDBFactory.deleteDatabase(indexedDB, "binding-contracts-regression") + await withResolver(resolve => onSuccess(deleteRequest, () => { assert(isUndefined(deleteRequest.result)) @@ -209,6 +233,7 @@ await withResolver(resolve => ) let lockManager = navigator->Navigator.locks + await withResolver(resolve => { let _heldRequest = lockManager->LockManager.request( ~name="binding-contracts-contended-lock", @@ -219,6 +244,7 @@ await withResolver(resolve => { }, ) }) + let _contendedRequest = await lockManager->LockManager.request2( ~name="binding-contracts-contended-lock", ~options={ifAvailable: true}, @@ -227,6 +253,7 @@ let _contendedRequest = await lockManager->LockManager.request2( %raw(`Promise.resolve(null)`) }, ) + releaseLock() let matrixValues = Float32Array.fromArray([2., 0., 0., 3., 4., 5.]) @@ -241,6 +268,7 @@ let resizeSignals = createResizeSignals() let initialResize = waitForResizeSignal(resizeSignals) let resizedAgain = waitForResizeSignal(resizeSignals) setSize(target, 10) + let observer = ResizeObserver.make((entries, observer) => { assert(hasResizeCallbackArgs(entries, observer)) if incrementResizeCount(resizeSignals) == 2 { @@ -248,6 +276,7 @@ let observer = ResizeObserver.make((entries, observer) => { } resolveNextResizeSignal(resizeSignals) }) + observer->ResizeObserver.observe(~target) await initialResize setSize(target, 20) @@ -255,32 +284,39 @@ await resizedAgain target->Element.remove let subtle = crypto.subtle + let digest = await subtle->SubtleCrypto.digest( ~algorithm=SubtleCrypto.algorithmObject({name: "SHA-256"}), ~data=Uint8Array.fromArray([65, 66, 67])->SubtleCrypto.binaryDataFromUint8Array, ) + let digestBytes: Uint8Array.t = %raw(`new Uint8Array(digest)`) assert(%raw(`digest.byteLength === 32 && digestBytes instanceof Uint8Array && digestBytes.length === 32 && digestBytes.buffer === digest`)) let data = Uint8Array.fromArray([65, 66, 67])->SubtleCrypto.binaryDataFromUint8Array + let hmacKey = await subtle->SubtleCrypto.generateKeySymmetric( ~hash=SubtleCrypto.algorithmObject({name: "SHA-256"}), ~length=256, ~extractable=true, ~keyUsages=[SubtleCrypto.signUsage, SubtleCrypto.verifyUsage], ) + let _publicHmacKey: SubtleCrypto.cryptoKey = hmacKey + let signature = await subtle->SubtleCrypto.sign( ~algorithm=SubtleCrypto.algorithmObject({name: "HMAC"}), ~key=hmacKey, ~data, ) + let verified = await subtle->SubtleCrypto.verify( ~algorithm=SubtleCrypto.algorithmObject({name: "HMAC"}), ~key=hmacKey, ~signature=SubtleCrypto.binaryDataFromArrayBuffer(signature), ~data, ) + assert(verified) let rawKey = await subtle->SubtleCrypto.exportKeyBinary(~format=SubtleCrypto.Raw, ~key=hmacKey) @@ -292,12 +328,15 @@ let keyPair = await subtle->SubtleCrypto.generateEcdsaKeyPair( ~extractable=true, ~keyUsages=[SubtleCrypto.signUsage, SubtleCrypto.verifyUsage], ) + let _publicKeyPair: SubtleCrypto.cryptoKeyPair = keyPair + let pairSignature = await subtle->SubtleCrypto.sign( ~algorithm=SubtleCrypto.algorithmObject({name: "ECDSA", hash: {name: "SHA-256"}}), ~key=keyPair.privateKey, ~data, ) + assert(await subtle->SubtleCrypto.verify( ~algorithm=SubtleCrypto.algorithmObject({name: "ECDSA", hash: {name: "SHA-256"}}), ~key=keyPair.publicKey, @@ -324,6 +363,7 @@ let aesKeyData = 14, 15, ])->SubtleCrypto.binaryDataFromUint8Array + let aesKey = await subtle->SubtleCrypto.importKey( ~format=SubtleCrypto.rawKeyFormat, ~keyData=aesKeyData, @@ -331,6 +371,7 @@ let aesKey = await subtle->SubtleCrypto.importKey( ~extractable=true, ~keyUsages=[SubtleCrypto.encryptUsage, SubtleCrypto.decryptUsage], ) + let aesIv = Uint8Array.fromArray([ 1, @@ -346,12 +387,15 @@ let aesIv = 11, 12, ])->SubtleCrypto.binaryDataFromUint8Array + let aesAlgorithm = SubtleCrypto.algorithmObject({name: "AES-GCM", iv: aesIv, tagLength: 128}) let ciphertext = await subtle->SubtleCrypto.encrypt(~algorithm=aesAlgorithm, ~key=aesKey, ~data) + let plaintext = await subtle->SubtleCrypto.decrypt( ~algorithm=aesAlgorithm, ~key=aesKey, ~data=SubtleCrypto.binaryDataFromArrayBuffer(ciphertext), ) + let plaintextBytes: Uint8Array.t = %raw(`new Uint8Array(plaintext)`) assert(isUint8ArrayWithABC(plaintextBytes)) From 625b8687db9f30cd4510584e641bb5718361610f Mon Sep 17 00:00:00 2001 From: Josh Vlk Date: Mon, 16 Nov 2026 13:47:05 -0500 Subject: [PATCH 3/3] fix(docs): handle ReScript alpha.7 signature metadata [Codex] --- docs/components/value.astro | 9 ++-- docs/signatureTypes.js | 22 +++++++++ scripts/check-doc-type-links.test.mjs | 64 +++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 docs/signatureTypes.js diff --git a/docs/components/value.astro b/docs/components/value.astro index 25c7b64a..d0c3fda5 100644 --- a/docs/components/value.astro +++ b/docs/components/value.astro @@ -1,12 +1,9 @@ --- import { Code } from "@astrojs/starlight/components"; import SignatureItem from "./signatureItem.astro"; +import { getLinkedSignature } from "../signatureTypes.js"; const { value, typesInOwnModule } = Astro.props; -const details = value.detail?.details || null; - -function showValue(detail) { - return detail?.kind === "signature" && detail.details?.parameters?.length > 0; -} +const details = getLinkedSignature(value.detail); --- @@ -15,7 +12,7 @@ function showValue(detail) {
{ - showValue(value.detail) && ( + details && (

Parameters

{details.parameters.map((p) => ( diff --git a/docs/signatureTypes.js b/docs/signatureTypes.js new file mode 100644 index 00000000..457c8071 --- /dev/null +++ b/docs/signatureTypes.js @@ -0,0 +1,22 @@ +const isLinkedType = (type) => + typeof type?.path === "string" && + Array.isArray(type.genericTypeParameters ?? []) && + (type.genericTypeParameters ?? []).every(isLinkedType); + +// The full compiler-rendered signature is always shown by value.astro. +// Only add the linked summary when every type can be represented faithfully. +export const getLinkedSignature = (detail) => { + if ( + detail?.kind !== "signature" || + !Array.isArray(detail.details?.parameters) || + detail.details.parameters.length === 0 + ) { + return null; + } + + const parameters = detail.details.parameters.map((parameter) => parameter?.type); + const returnType = detail.details.returnType; + return parameters.every(isLinkedType) && isLinkedType(returnType) + ? { parameters, returnType } + : null; +}; diff --git a/scripts/check-doc-type-links.test.mjs b/scripts/check-doc-type-links.test.mjs index 2321ec5f..834bab2e 100644 --- a/scripts/check-doc-type-links.test.mjs +++ b/scripts/check-doc-type-links.test.mjs @@ -2,6 +2,70 @@ import assert from "node:assert/strict"; import test from "node:test"; import { createPublicTypeTargets, parsePublicTypeAliases } from "../docs/typeLinks.js"; +import { getLinkedSignature } from "../docs/signatureTypes.js"; + +test("unwraps compiler parameter metadata before linking signature types", () => { + const controller = { + kind: "constructor", + path: "WebAPI.DOM.abortController", + genericTypeParameters: [], + }; + const json = { kind: "constructor", path: "JSON.t", genericTypeParameters: [] }; + const unit = { kind: "constructor", path: "unit", genericTypeParameters: [] }; + assert.deepEqual( + getLinkedSignature({ + kind: "signature", + details: { + parameters: [ + { optional: false, type: controller }, + { label: "reason", optional: true, type: json }, + ], + returnType: unit, + }, + }), + { parameters: [controller, json], returnType: unit }, + ); +}); + +test("keeps recursively linkable generic return types", () => { + const type = { kind: "constructor", path: "WebAPI.Element.t", genericTypeParameters: [] }; + const result = { kind: "constructor", path: "option", genericTypeParameters: [type] }; + assert.deepEqual( + getLinkedSignature({ + kind: "signature", + details: { parameters: [{ type }], returnType: result }, + }), + { parameters: [type], returnType: result }, + ); +}); + +test("falls back to the full signature for unsupported or absent type detail", () => { + const unit = { path: "unit", genericTypeParameters: [] }; + for (const type of [ + { kind: "function" }, + { path: "array", genericTypeParameters: [{ kind: "variable" }] }, + ]) { + assert.equal( + getLinkedSignature({ + kind: "signature", + details: { parameters: [{ type }], returnType: unit }, + }), + null, + ); + assert.equal( + getLinkedSignature({ + kind: "signature", + details: { parameters: [{ type: unit }], returnType: type }, + }), + null, + ); + } + assert.equal(getLinkedSignature(undefined), null); + assert.equal( + getLinkedSignature({ kind: "signature", details: { parameters: [], returnType: unit } }), + null, + ); +}); test("parses public aliases to backing module types, including generic aliases", () => { assert.deepEqual(