Changelog
@ogygia/machine
Every release of @ogygia/machine, newest first.
- Latest
- 0.16.0
- Versions
- 3
0.16.0 minor
Dependency updates only @ogygia/machine
0.14.0 minor
Minor Changes
say()in@ogygia/machinesays a thing once per key until it recovers, remembering at most 1024 keys; a machine's warn-once and a plugin'swarnuse it, so a long-lived server no longer keeps every distinct warning text.flights()carries a priority:get(input, { priority })raises a flight in progress to the highest priority of the callers that joined it (never lowers it), and the run readsflight.priorityand hears each raise throughflight.onRaise().flights()now keeps at most 1000 answers by default (the least recently used go first); passmaxto change it. Acache()orflights()maxmust be a finite number.- New
cache(): a keyed store that is always bounded (max,weigh,keep), owned by a scope, and says why it lets each value go (onEvict);flights()keeps its answers in one. - machine:
capability()makes signed, expiring tokens addressed to an audience: length-prefixed messages that name the capability and its version, a lifetime clamped at mint and refused past its bound at check, a random nonce with optional one-time use in bounded memory, and no token from a clock that reads NaN; the signer (HMAC, Ed25519) is the caller's, and a check may bring its own verify (keys in rotation);skewallows for two machines' clocks;nonce: falsemints the same token for the same inputs (not single-use, soreplayis refused with it) - New
clock(clock.mono()for durations,clock.wall()for timestamps). Aflights()keep and a retrypolicy()deadline are now measured on the monotonic clock, so a wall-clock step (an NTP correction, a VM resume) no longer shortens or stretches them. - New
decisions(): a pure decision table whose inputs each take a listed set of values, so its whole input space can be walked.decide()throws on a combinationrefusenames (machine_decision_refused), and in dev on a value outside its list (machine_decision_outside). The test-only entry@ogygia/machine/testingwalks a table:rows,check(named rules, each broken one named with its first row),table(markdown),dead_fieldsandcount, with a 100,000-row guard (machine_decisions_too_many) and seeded sampling. - New
defineRun(id)anddefining(): a plugin's definer calls owned by the run of the module that made them, so a definition deleted from the code leaves at the module's dev reload. - New
noopexport: the one empty function, for a callback or cleanup with nothing to do. - New
queue(): a bounded, first-come queue. At mostmaxjobs hold a place; arelease()hands its place to the next job in the same step. A job can carry a deadline (all deadlines share one timer) or be cancelled, and the queue'sownerclosing makes the waiting jobs stale. - New
registry()andregistry.keyed(): owned entries and definitions that leave with their owner, never evicted;cache()takespinned(value, key)for values in use that never go for size. - New
slot({ name, version, make }): one process-global value per name, shared by every copy of a package a process loads. The version lives only inversion(a name carries none): another version is refused in dev and kept apart in production. trace()in@ogygia/machinewrites every machine move as one short line (visit#3 loading -> answered), the last 500, for a test to print when it fails.queue()serves lines with more rules than first come:priority(job)(read again each pass, ties in the order pushed),ready(job)(a job not ready is passed over, the rest still start),windows: [{ max, holds }](caps over some jobs, besidemax),budget: { ms, yield, defer?, settle? }(a long drain hands the thread back), andrecheck().maxis now optional, and a budgetyieldthat throws is reported (machine_queue_yield_failed).queue()hands each started job its own place:start(job, place), given back withplace.release(), once (a second release frees no other job's place).queue.release()is gone. Astartthat throws now gives its place back, so the jobs after it still get one.- These methods are now typed as function properties, so passing one on by itself (
const { handle } = router) type-checks underunbound-method; none of them usedthis. A method type was bivariant in its parameters and a function property is checked strictly, so code that assigned a narrower function to one of them may now need its parameter types widened. The changed types:ogygiaTransport.Region.encode/.decodeand the ref entry'sencode/decode(@ogygia/core),CapabilitySigner.sign/.verify(@ogygia/core),Router.handle(@ogygia/router),Signer.sign/.verifyandStaging.discard(@ogygia/machine).
Patch Changes
@ogygia/machine: Faster hot reads oncache()andregistry(): agetof the value set or read last no longer moves or looks it up again (a keptflightsanswer read by every island takes about half the steps), a cache with noonEvictqueues no notices, observers are walked from one array kept until they change (registry().snapshot()), andregistry.keyed()walks its definitions without a generator.@ogygia/machine: Acache()set of the value its key already holds keeps it (no'delete'notice, so anonEvictcleanup no longer runs on a value still held),settakes its ownkeep, and a keyedflightsof one field keys by that field's value with no string built.@ogygia/core: A region answer written to the frame store costs about a third fewer steps (one cache write, no lookup before it), and an island warm reads its chunk graph once.observe()keeps its watchers in a registry: each leaves with its stop, and the rest hear moves in the order they started watching.- -
@ogygia/machine:cache()andregistry()are smaller in a bundle (about 240 B brotli off a page's boot), and a bundle that usesregistry()no longer carriesdefineRun()anddefining(). @ogygia/machine:queue()with nonowreads its deadlines onclock.mono(), like every other primitive, so a run that drives the clock drives the queue too.- core: region links are signed through
capability(), naming the islands endpoint they are for and refusing a lifetime longer than the app ever mints; links stay identical between renders, and links signed before (pages cached before the upgrade) still work and are re-signed in the new form when renewed machine:capability().mintUntil()mints a token that expires at a given time, so tokens without a nonce stay identical across a window the caller picks @ogygia/machine: in production, aslot()asked for at a version other than the one held keeps one private value for that version, made once. It made a new value on every ask, so state kept in it was lost.
0.13.0 minor
Minor Changes
- A flights keyed by some fields of its input is made with
flights.keyed<I>()({ key, run });flights()with no options no longer makes one. flights({ retry })takes apolicy()(tries, waits between them, deadline) in place ofretries, run by the same loop as the outbox's; a wait of 0 still tries again at once (#313).flights(): keyed async work that callers share (one flight per key, kept as long askeepsays,max/weigh,drop,freshrevalidation, work stopped when its last caller leaves, and a failure never kept), in place ofonce(), which is a flights with one key.mailbox()runs one owner's events one at a time, in the order they came: a handler's turn lasts until it waits or ends, and the owner closing drops the queue and ends every wait withSTALE.backoffAfter(),MACHINE_ERRORSandMACHINE_WARNINGSare exported from the package index; the./internal/messagesand./internal/policysubpaths are gone.outbox(): work after the response, kept alive (waitUntil), tried again by a named retrypolicy()(attempts, backoff, jitter, deadline), joined byidwhile out, sentinOrderwhen asked, done only once the receiver applied it, and said once with a code when given up (#308).- New package: typed state machines (
machine(),lock()) with checked moves, async work that cannot land late, cleanups that run exactly once, states that end on their own (after), and the definition as data (graph(),paths()). scope(): one owner for listeners, timers, observers, tasks, child scopes and cleanups, all let go together and exactly once onclose(); each visit of a machine to a state is one (m.scope), in place oftask()andonLeave().stage(): a change built off to the side and switched in with one synchronous step, owned by a scope: closing the owner first gives back what the build made, and a commit that throws puts back what it changed (#309).world(): a stamp that only moves forward (stamp(),fresh(s),bump()), split by key withworld.keyed()(bump(keys)puts out of date only what read those keys);flights({ world, touches })drops what a move touches and makes an answer whose world moved on its waySTALEfor every caller that joined it (#311).- A wait gives
STALEwhen anything it waited on is stale:scope.task, a mailbox's waits andask, a flights run andstage().readyturnSTALEor an array withSTALEin it (aPromise.allwith a stale part) intoSTALE, andFresh<T>types the slots after the check (#378). flights.keyed<I>()({ key, ignore, run }): a flights over an object input is keyed by the fieldskeynames, spelled one way, andrunis typed to those fields only, so work that reads a field the key leaves out does not compile unlessignoregives the reason;peekanddropname keys by those fields, and a flights with nokeyis keyed by its whole input (#312).
Patch Changes
- Over its
max, a flights takes out the expired answers before any live one (#356). - A flights
runthat gets its own key before it returns joins its own flight and gets its answer, instead ofSTALE(#354). - A flights run that answers
STALEno longer leaves its key flying: nothing is kept, and the nextgetruns again (#377). - A keyed flights no longer holds every symbol used as a key field forever: a symbol made at run time is freed once nothing else holds it, and a registered one is spelled by its name (#357).
- A flights answer whose
weighis below 0 or not a number is not kept, so a bad weight can no longer lower the total and letmaxcap nothing (#355). - In a production build, a step naming a state that does not exist no longer makes
wait()andpaths()throw: they skip it, as moves already do (#358). - An outbox item whose
idis not a string or a finite number (undefined,NaN) is not sent and is given up, instead of joining every other such item into one send (#350). - A retry that stops because its next wait would end past the deadline fails with a
TimeoutError(the last error in its message), and a policy's wait is always a number, also for a count of 0 or a 0 backoff after very many tries (#359). - The wait between two tries of a send (an outbox's, a
flights({ retry })run's) keeps a Node process alive, so a process with nothing else to do no longer exits mid-retry and loses the send (#351). - An async disposable adopted by a scope that already closed is disposed at once and its failure is said (
machine_dispose_failed), not left unhandled; the closed scope keeps nothing of it (#347). - A scope's
{ once: true }listener lets go of itself when it fires, as a fired timer does, so a long-lived scope no longer piles them up (#348). - A scope whose listener release throws on
close()still lets go of the rest and runs every cleanup, then throws it (#346). - A scope task whose work closes its own scope before it returns (moves its machine on) settles with
STALEinstead of hanging (#349). - A stage whose commit closes its own owner (switching the page in moves the navigation on) keeps what it committed instead of discarding it mid-commit (#343).
- A stage's discard step given after the commit is dropped instead of run at once over the live change (#344).
- A stage that committed or was discarded leaves nothing on its owner, so a long-lived owner of many stages no longer grows (#345).
- A world holds the flights made on it weakly: a flights nobody holds any more is collected and the world forgets it, instead of each one staying until disposed (#352).