Skip to content

Add FileSystemHandle.prototype.getUniqueId() per WHATWG FS spec#95

Merged
jimmywarting merged 2 commits intomasterfrom
copilot/add-get-unique-id-to-filesystemhandle-js
Apr 6, 2026
Merged

Add FileSystemHandle.prototype.getUniqueId() per WHATWG FS spec#95
jimmywarting merged 2 commits intomasterfrom
copilot/add-get-unique-id-to-filesystemhandle-js

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

Implements FileSystemHandle.prototype.getUniqueId() — a stable, per-entry UUID returned as a UUID v4-format string.

Design

Identity strategy per adapter:

Adapter Strategy
memory.js No change — same-entry handles share the same JS object, so the fallback caches correctly via object identity
node.js SHA-256(kind:path) via node:crypto createHash
deno.js SHA-256(kind:path) via crypto.subtle.digest
indexeddb.js IDB auto-increment key hex-formatted as UUID, prefixed with f/d per kind
cache.js SHA-256(kind:path) via crypto.subtle.digest

FileSystemHandle.js fallback — if the adapter has no getUniqueId(), a random UUID is generated once and cached on the adapter object:

async getUniqueId () {
  const adapter = this[kAdapter]
  if (adapter.getUniqueId) return adapter.getUniqueId()
  if (!adapter._uniqueId) adapter._uniqueId = crypto.randomUUID()
  return adapter._uniqueId
}

Including kind in the hash input is the key correctness detail: it ensures a file and a directory that transiently share the same path produce distinct IDs, satisfying the WPT test "a file and a directory of the same path return different IDs".

Tests

FileSystemBaseHandle-getUniqueId.js moved from SKIP_REASONSSUPPORTED_SCRIPTS in both wpt-node.js and wpt-browser.spec.js. All 11 WPT subtests pass against both the memory and Node.js adapters.

Copilot AI linked an issue Apr 6, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add getUniqueId() to FileSystemHandle.js Add FileSystemHandle.prototype.getUniqueId() per WHATWG FS spec Apr 6, 2026
Copilot AI requested a review from jimmywarting April 6, 2026 19:45
@jimmywarting jimmywarting marked this pull request as ready for review April 6, 2026 22:37
@jimmywarting jimmywarting merged commit c8d7ded into master Apr 6, 2026
4 checks passed
@jimmywarting jimmywarting deleted the copilot/add-get-unique-id-to-filesystemhandle-js branch April 6, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add getUniqueId() to FileSystemHandle.js

2 participants