Commit 9c4294e
committed
better HTTP caching; dom shim anti-collision; other tweaks
---
`package.json`:
Added the missing default entry point `./all.mjs` for the
`.exports` directive which takes priority over `.main`.
---
`http`:
When using bundlers, this pseudo-module now resolves to `http.mjs`
in browsers. This can be convenient for code shared between server
and client.
Revised and improved compression and file resolution tools.
This necessitated some breakage. All changes below are breaking.
Internal changes which shouldn't affect user code are not listed.
`HttpCompressor`:
- Caching support has been moved to `HttpFile`/`HttpDir`.
- The mapping of FS paths to files is now done just once, at the
level of `HttpDirs`, instead of two different mappings before.
- Caching of compressed artifacts per algorithm is done at the
level of `HttpFile`.
- Constructor now accepts algo options, allowing to override
them without subclassing.
- Added a dedicated compression method for each algo.
- Added a dedicated decompression method for each algo.
- Added `.decompress`.
- Compression methods no longer take algo option overrides;
options are defined once, at the constructor level.
- `.compress` now takes an options object instead of multiple args.
`HttpDirs`:
- Renamed `.resolveFile` → `.resolve`.
- Fixed a bug where "not found" paths were cached, which can be a
memory leak. Only "found" paths should be cached now.
- Added `.cacheFiles` for virtual files.
- Caching is now enabled via `.setOpt({caching: true})`.
- When caching is enabled, resolved files are now deduplicated
by `.fsPath`. When multiple URL paths resolve to the same FS
path, only one `HttpFile` is created and stored, and its body
is no longer duplicated in RAM.
`HttpDir`:
- Renamed `.resolveFile` → `.resolve`.
- No longer supports resolving directories; only files.
`HttpFile`:
- Has a bit more focus on caching and deduplication. All "get"-style
methods do their work only once, and reuse previous results whenever
possible. The only exception is `.resOpt`.
- Constructor takes an options object, which must contain `.fsPath`
and `.urlPath`. Any file property can be provided in these options,
including `.text` and `.bytes`. This makes it easy to construct
"virtual" files; those can now be provided to `HttpDirs` and
resolved just like "real" files.
- Renamed `.opt` → `.resOpt`.
- `HttpFile.resolve` now supports only files and returns nil for
directory paths.
- Now integrates compression caching.
- Compressed file responses now always have `vary: accept-encoding`.
Deno sets this automatically, but Bun doesn't.
`ErrHttp` now takes `(msg: string, opt?: Record)`, exactly
like `Error`. Status and/or response can be provided in the options.
Removed `getStatus`.
Renaming:
- `arrHex` → `byteArrHex`
- `uuidArr` → `uuidByteArr`
Added `fileResponse` which conveniently combines a live client if any,
a compressor if any, and an actual file response, in proper order.
Added optional polyfills for Bun:
- `CompressionStreamPolyfill` for `CompressionStream`
- `DecompressionStreamPolyfill` for `DecompressionStream`
Added `toByteArr`.
---
`http_live.mjs`:
- `LiveClient`:
- Breaking: renamed `.withLiveScript` → `.liveResponse`
- Added `.liveHtml`.
- Breaking: dropped `withLiveScript`; use `fileResponse` instead.
Now supports a "hot" mode. When enabled, `LiveClient` now migrates
its set of known served files between hot reloads. At the time of
writing, this only works in Bun with `--hot`.
---
`io`:
Added:
- `mkdirTemp`
- `mkdirTempSync`
- `rename`
- `renameSync`
`io_bun.mjs`: passing `{recursive: true}` to `remove` and `removeSync`
now causes directory removal as expected. Previously, it would try to
remove a file instead.
---
`dom_shim.mjs`:
All internal methods are now namespaced with `domShim_` to avoid
collisions with user-defined methods. Overrides are still possible.
With very few exceptions, internal properties are accessed directly,
bypassing getters and setters. This is more consistent with the
standard DOM API and makes the behavior more predictable for user
code which overrides any of the DOM getters and setters for its own
needs.
Breaking: removed:
- `Element..attributes`
- `NamedNodeMap`
- `Attr`
We never needed those APIs, and they just carry overhead.
Fixed an edge case where the `Element..style` object could become
inconsistent with a style attribute.
Any code which uses only the renderer in `prax.mjs`, avoids using
`Element..attributes`, and avoids accessing / overriding / colliding
with any internals of the DOM shim, should be unaffected.
Breaking: removed `.toJSON` from all DOM classes. There was never
any particular reason for adding that. Reason for removing it:
sometimes it's possible to have an edge case where external code
overrides `.outerHTML` to include additional things into HTML,
which is perfectly valid and sometimes useful, while accidentally
and erroneously trying to JSON-encode some of our shimmed elements,
which used to call `.outerHTML` by default, leading to infinite
recursion and a stack overflow.
---
`dom.mjs`:
Breaking: the following functions now take only one argument,
which must be an options object:
- `eventDispatch`
- `eventListen`
- `ListenRef`
Motivation for `ListenRef`: when a function has 5 arguments, it can
be hard / error-prone / unmaintainable to remember what goes where.
Positional arity should be limited to 1 or 2. Beyond that, functions
should take an options dictionary where every argument is named.
Motivation for the other functions: semantic association.
Restored `ChildDiff`. Its main use case is updating `document.head`
on pushstate transitions, which must be done without removing any
"static" head elements, such as global page styles. Our renderer in
`prax.mjs` is often unsuitable for this since it's order-sensitive.
`document.head` is mostly order-insensitive; by ignoring the order,
its diffing can be done in a very simple manner by this tool.
---
`obs.mjs`:
Added `toObs`.
---
`iter.mjs`:
`indexOf` now prefers native `Array.prototype.indexOf` when possible,
which performs better than a custom loop in modern engines. When not
possible, it falls back on a custom loop.
---
`lang.mjs`:
Breaking: `reset` now returns the target, not the value. We know that
this is inconsistent with `clojure.core.reset!`, on which this was
modeled. The previous behavior returned the provided value, not the
value actually retained by the target reference. Since we implement
`reset` as a property set rather than a method call, within the JS
semantics we can't get the retained value for free; an assignment
expression always returns the provided value, which is available to
the caller in any case. Returning the target reference aligns more
closely with `assign` and `patch`, which is useful because `ObsPh`
implements `reset` as an equivalent of `assign`.
Added `resetOpt`.1 parent 069d181 commit 9c4294e
File tree
72 files changed
+2624
-1901
lines changed- docs
- doc
- http
- test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
72 files changed
+2624
-1901
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
28 | 57 | | |
29 | 58 | | |
30 | 59 | | |
31 | | - | |
| 60 | + | |
32 | 61 | | |
33 | 62 | | |
34 | 63 | | |
35 | 64 | | |
36 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
37 | 72 | | |
38 | 73 | | |
39 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
28 | 57 | | |
29 | 58 | | |
30 | 59 | | |
31 | | - | |
| 60 | + | |
32 | 61 | | |
33 | 62 | | |
34 | 63 | | |
35 | 64 | | |
36 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
37 | 72 | | |
38 | 73 | | |
39 | 74 | | |
| |||
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
| 104 | + | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
| 245 | + | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
0 commit comments