Skip to content

@effectified/engine 0.4.0

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 27 Nov 14:49

@effectified/engine 0.4.0, built from f7ad170.

pnpm add -D https://github.com/effectified/engine/releases/download/v0.4.0/effectified-engine-0.4.0.tgz

Facades generated by 0.4.0 break code written against 0.3.0's facades in the ways below, each on purpose. Every item says what to do instead.

Breaking changes for facade users

  • Borrowed handles have no release methods. A handle a call finds rather than makes is borrowed: puppeteer's browser.pages(), target.page(), frame.page(), the receiver elementHandle.asElement() gives back, a handle a property holds (nodemailer's Mail.transporter). Its facade has no close, dispose or other release method, in its type or at run time, when the types make it certain the method is no step to another handle: it gives nothing the facade wraps (void, a boolean, a promise of those, any value given as it is), or upstream declares it to return this (Node's Server.close(): this), a promise of it too. A release whose result names a handle by its class stays on a borrowed facade, as every release did in 0.3.0, since the types cannot tell zmq's Socket.close(): Socket (@types/zmq), which closes the socket and returns it, from cheerio's end(): Cheerio<AnyNode>, which steps back to another selection: called on a borrowed facade, such a release releases what the owner holds. Migration: shut the resource down through the facade that owns it (the browser launch gave, the page browser.newPage() gave), or let that facade's scope close it.
  • Freshly acquired handles need a Scope. A call that makes a releasable handle acquires it in the caller's scope and releases it when the scope closes: puppeteer's $$, createCDPSession, evaluateHandle, waitForFunction, Locator.waitHandle and similar now require Scope, as launch and newPage already did. Migration: run them inside Effect.scoped(...) or a layer's scope.
  • nodemailer: Mail.dkim and Transport.mailer are omitted. They keep the DKIM private key and the transport's credentials in shapes the facade cannot show as Redacted. Migration: mail.upstream.dkim, transport.upstream.mailer.
  • sharp: the callback twins of async methods become Effect overloads. 0.3.0 typed toBuffer(callback), toFile(file, callback), metadata(callback) and stats(callback) as returning the Sharp facade while running them as Effects; each method now has only its Effect overloads. Migration: yield* image.toBuffer() (and the like) instead of passing a callback.
  • A facade prints as its handle's name. toString(), toJSON() and inspection of every runtime facade give { _id: "<Handle>" }, never upstream's state, whatever upstream's own toString or toJSON do. Migration: puppeteer's raw JSHandle.toString() is handle.upstream.toString(), bullmq's Job.toJSON() is job.upstream.toJSON().
  • Error causes and structured fields are Redacted. An error's cause, and each field its upstream error class declares that is no primitive (no string, number, boolean or string literal), is a Redacted, printed and encoded nowhere (Cause.pretty, logs, JSON). Migration: Redacted.value(error.cause), Redacted.value(error.<field>). _tag and code are unchanged, and Effect.catchTag matches on _tag as before. The reason field is new in 0.4.0: an error with codes carries them as a tagged union, so Effect.catchReason on it is new too. Its case for a code the error does not list, or none, is named by the first of Other, Unlisted, Unlisted2, Unlisted3, ... that is not one of upstream's codes: Other, Unlisted when Other is an upstream code, Unlisted2 when Unlisted is one too.
  • Secrets are scrubbed from error messages. Every failure of a call given a secret the recipe names, and of the handles that call made, has each such secret of 4 characters or longer replaced by <redacted> in its message and in its declared string fields. Codes are never scrubbed. Migration: tell failures apart by _tag, code or reason, not by message text that may hold a secret.
  • A result that may be absent is an Option. An async method or export whose value upstream types as possibly null or undefined in every overload the facade keeps resolves to an Option, of the facade when the value is a handle (one with an overload that never gives absence keeps upstream's type): puppeteer's page.$ of a selector that matches nothing, bullmq's queue.getJob of an unknown id give Option.none() where 0.3.0 gave null or undefined. Migration: use Option's combinators (Option.match, Option.getOrElse, Option.isSome) instead of comparing with null or undefined.
  • Ids are branded. An id the recipe brands (bullmq's JobId: Job.id, the id Queue.getJob, Queue.remove and their kin take) is a branded string, so a plain string where a brand is expected (queue.getJob(id) with id: string) no longer compiles. Migration: JobId.make(id) for a value you know is an id, Schema.decodeUnknownSync(JobId)(input) for external input.
  • puppeteer: ElementHandle.toElement is an Effect. 0.3.0 ran it as a synchronous call; it now resolves to the element's facade, borrowed: the same element as its receiver, so it has no release methods. Migration: yield* handle.toElement("a"), and release the original handle through its owner (the scope that page.$ acquired it in).
  • A release that fails while its scope closes no longer fails the scope. A handle's release run by its scope's finalizer that fails (a browser that crashed before close) is logged as a warning, and the scope closes successfully; 0.3.0 failed the scope's exit with it. Migration: when a release's failure must affect your program, call the release yourself (yield* browser.close()) and handle its failure. The scope still releases the handle as it closes, as 0.3.0's did: that is a second call, and when it fails (the handle is closed already), it is logged as a warning, <Handle>.<release> failed while its scope closed, with the facade's error as its cause, where 0.3.0 failed the scope's exit with it.
  • A member's value is typed as the runtime gives it. 0.3.0 typed some members' values as a facade where the runtime gave upstream's own object, whenever the checker read a handle in a type the generator reads none in: a union of a handle and its subclass written out (parent(): Base | Derived, load(): Promise<Base | Derived>), a generic result such as ts-morph's asKind(kind) and getChildAtIndexIfKind(index, kind) (KindToNodeMappings[TKind] | undefined), a property such as ts-morph's compilerNode. Such a member is now typed as upstream declares it, which is what it always gave at run time. So is a method whose overloads give one handle or a list of it (ts-morph's addExtends(text) and addExtends(texts)): 0.3.0 wrapped whatever it gave as one facade, a list too, which then had none of the list's members; now it gives either as it is. Migration: use the value as upstream's object (its methods as upstream types them, no .upstream, no yield*); code that compiled against 0.3.0's type there failed at run time.
  • A method whose overloads read a value or set it and return the receiver gives the value it reads as it is. cheerio's html(), text(), val(), attr(), css(), data() and prop() read a value, and with a value set it and return the selection. 0.3.0 wrapped every object such a method returned as the selection's facade, so attr()'s record came back as a facade with none of its fields; now a result is the facade only when it is a selection (it has the selection's methods, those upstream declares optional aside, so a handle whose methods are all optional takes any object, as 0.3.0 did), and any other value is given as it is, as each overload's type says. Migration: none for the setters, which still give the facade; read what a getter gives as the value it is.

Re-exports

0.3.0's facades re-exported only Upstream. 0.4.0's also re-export upstream's types, and the values that need no wrapping, by name; a name Node cannot import from upstream's build is not re-exported, so a facade never fails as it loads. Those are puppeteer's Session, Protocol, PageEvent, BrowserEvent, BrowserContextEvent and AutofillAddressField (bundled declarations and const enums with no value in its module), and sharp's format, versions, block, fit, kernel and the other properties of its CommonJS export, which Node's named-export detection cannot see. Use them as in 0.3.0: types as Upstream.<Name>, sharp's values as Upstream.default.<name>.

A value upstream exports under a string name (ES2022's export { x as "review-sentinel" }) is re-exported by that string: import { "review-sentinel" as sentinel } from "@effectified/<name>". A function or class exported so is not wrapped, since a wrapper is declared under its export's name and a string cannot name a declaration: draft offers none, a recipe that offers one gets a reconcile note, and it stays Upstream["review-sentinel"].

Which values Node can import by name is known only from a surface that 0.4.0's study wrote (it has "runtime": "imported"). A facade generated from a surface studied by 0.3.0 re-exports no value, exactly as 0.3.0's facades did, and reconcile prints a note naming the values it leaves out. Migration, for a maintainer: re-run effectify study <name>@<version> to get the value re-exports, then reconcile.

Changed

  • A scope releases each object it acquired once, however many acquisitions of it there are. 0.3.0's scope called a handle's release once per acquisition as it closed, so two calls that handed back one object, or a list holding it twice, released it twice; 0.4.0's scope releases each object once. As in 0.3.0, and as Effect's acquireRelease does, it releases what it acquired whatever you did with it: your own call of a release (yield* browser.close()) reaches upstream, gives its own value and changes nothing the scope does, so the scope's release as it closes is a second call, logged as a warning if it fails (above). Call a release yourself only when you need its result or its failure. No release of the scope's waits for another, or for yours: a release you started that still runs (a server's shutdown() waiting for a connection a later finalizer of the scope closes) never holds up the scope's closing.
  • An interrupted acquisition aborts its call's signal at once, waits for the call, and leaves what it gave to the scope. As in 0.3.0 and as Effect's acquireRelease does, interrupting a call that makes a releasable handle (an Effect.timeout around browser.newPage(), a race, an interrupted fiber) waits for the call to settle, then hands each releasable handle it gave to the scope, which releases it as it closes, in the scope's order, as it releases what a call that was not interrupted gave: when the interrupter resumes, nothing of the call still runs, and nothing it gave is left without an owner. 0.4.0 aborts the call's signal as the interruption comes, where 0.3.0 aborted it only once the call had settled, so an upstream that honours its signal ends early and the interruption completes promptly; one that ignores it, or a call that takes none (one reporting through its callback), holds the interrupter until it settles, as in 0.3.0. This holds for every acquisition: an async method's, a list's, an exported function's, a constructor's and a call's that reports through its callback. A call that makes no releasable handle (a value, a borrowed handle) is interrupted at once, its signal aborted, as in 0.3.0.
  • A thenable result is adopted as await adopts it. A call whose result is a thenable (postcss's LazyResult, which runs its plugins in its then), a native promise too, has its then called in a microtask of its own, after those queued before the call, never on the caller's stack; 0.3.0's exported functions and constructors called it as the call returned. A native promise's constructor is read once, by its own then, as await reads it once: a getter of upstream's answering a second read otherwise changes nothing.

For engine users

  • study runs the target library's code. It imports the package in Node to see which exports its build has. That runs in a process with only PATH and HOME of your environment, under Node's permission model, within a 60-second deadline: hygiene against accidents, not a sandbox. Migration: run study, and make, draft and sync, which run it, only on a library you would install.
  • verify and release import every entry point of a facade's build in Node. A runtime facade that cannot be imported fails; for a frontend facade the import is a report and never fails, since its bundler resolves it as it ships and its browser tests check it. The entry points are imported in order in one Node process with your whole environment, as the facade's tests run, within a deadline the engine keeps: 120 seconds, or EFFECTIFY_IMPORTS_DEADLINE seconds when that is set (a positive number; anything else fails). The process records each entry point's result as it settles in a results file of its own, never on its stdout, which stays the library's: what an entry point prints as it loads (a line left open, a line shaped like a result) changes no result. However the process ends, every entry point recorded by then keeps its result, and only the others have none: past the deadline the process group is killed, and the one that did not settle (its top level awaits what never resolves under Node while a timer keeps Node running, or blocks it) and those after it are did not settle within <N> s; when the process exits first, they name its exit code (the process exited with code 17 before this entry settled) or the signal that ended it, at once, even while a process an entry point started still holds its output open, which is killed with the process group then. Each is failed for a runtime facade, reported for a frontend facade. study's import reads the names it finds from such a file too. A facade 0.3.0 made that wraps an export Node cannot import by name threw as it loaded, which 0.3.0's verify never saw: protobufjs 7.5.4's Root, Type, Field and load (its CommonJS module gives Node only default); 0.4.0's verify fails it. Migration: a runtime facade's entry points must finish loading in Node; move a wait for something that never comes in Node (a browser event, a connection) out of the module's top level into an Effect its user runs, and raise EFFECTIFY_IMPORTS_DEADLINE for one that loads slowly; leave an export study marks erased out of the recipe's exports.
  • New maintainer checks. reconcile and verify hold every facade's src/ and test/ to the Effect rules (@effect/tsgo's, run by tsrs), and its src/ to the source idioms (an oxlint plugin: Effect.fn for functions that return Effect.gen, a named span, Match for a switch on _tag, branded schemas for id and key fields); any finding fails them. Migration: fix the finding; an intentional exception says why on the line above it, // @effect-diagnostics-next-line <rule>:off <reason> for an Effect rule, // idiom-allow <rule>: <why> for an idiom. Any other @effect-diagnostics directive (a whole file, a lowered severity, no reason) fails too.
  • Every facade checks that its types say what its runtime gives. A generated facade's CheckedGives fails reconcile and verify (TS2344, naming the members) when a member's type gives something else than its spec makes it give at run time (raw, a facade owned or borrowed, a list, an Option, a Stream). Only a generator bug fails it: a member the spec gives as it is is typed as upstream declares it, and each overload of a method that gives its handle or another value is typed by its own result. A method's overloads are intersected one by one: 0.3.0's types made an overloaded method that takes facades of handles sharing that method's name (ts-morph's Directory.getRelativePathTo(sourceFile) and getRelativePathTo(directory)) circular, TS2615 at every call of it, which the check now reaches and 0.4.0 no longer does. Migration: none; report a facade it fails as an engine bug.
  • The draft offers a release only by one rule. draft proposes a handle's release only among close, quit, disconnect, destroy, shutdown, terminate, stop, end, dispose and release, in that order, and only one callable with no argument (a trailing callback it reports through aside), as a scope's finalizer calls it, whatever it gives, as 0.3.0 did: zmq's Socket.close(): Socket and cheerio's end() are offered as 0.3.0 offered them, and whether a borrowed facade keeps one is the borrowed handles' rule above. The analyzer reads a handle's releases (surface.json's releases) by the same rule. 0.3.0 also offered one that takes an argument, which its finalizer called without one: chart.js's Animator.stop(chart), MapLibre's WorkerPool.release(mapId), codemirror's GutterMarker.destroy(dom). A name that also means something else is never offered: postcss's Node.remove() takes a node out of its tree, and protobuf.js's remove(object) takes the child it is given. Migration: a maintainer declares a release under another name (MapLibre's Map.remove) as an agent or person decision, which a redraft keeps; an engine decision for a release that takes an argument becomes none at the next redraft (sync), and a re-study drops it from releases.
  • study records optional methods and calls that return their receiver. A handle's methods upstream declares optional (refresh?()) are listed in its optional, and a mixed result is told by the other methods only; a call upstream declares to return this is "receiver": true (read from the declaration, since the checker prints that this as the handle's own type: chart.js's Chart.stop(): this), which tells whether a borrowed facade leaves out a release. A surface studied without them generates as before: every method counts as required. Migration: re-study a target to get them; only those lines of its surface.json change.
  • The analyzer reads one handle per name. A handle is named by its type's name, so a type named like a handle already read is none: the compiler's ts.ClassDeclaration that ts-morph's compilerNode holds, beside ts-morph's own ClassDeclaration. 0.3.0 wrapped such a value as the other handle's facade, which has none of its members. Migration: re-study a target whose surface reads one (such a property's or method's handle in surface.json goes); the value is then upstream's, typed so.