Repository navigation
@effectified/engine 0.4.0
Pre-release@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.tgzFacades 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 receiverelementHandle.asElement()gives back, a handle a property holds (nodemailer'sMail.transporter). Its facade has noclose,disposeor 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 returnthis(Node'sServer.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'sSocket.close(): Socket(@types/zmq), which closes the socket and returns it, from cheerio'send(): 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 browserlaunchgave, the pagebrowser.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.waitHandleand similar now requireScope, aslaunchandnewPagealready did. Migration: run them insideEffect.scoped(...)or a layer's scope. - nodemailer:
Mail.dkimandTransport.mailerare omitted. They keep the DKIM private key and the transport's credentials in shapes the facade cannot show asRedacted. 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)andstats(callback)as returning theSharpfacade 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 owntoStringortoJSONdo. Migration: puppeteer's rawJSHandle.toString()ishandle.upstream.toString(), bullmq'sJob.toJSON()isjob.upstream.toJSON(). - Error causes and structured fields are
Redacted. An error'scause, and each field its upstream error class declares that is no primitive (no string, number, boolean or string literal), is aRedacted, printed and encoded nowhere (Cause.pretty, logs, JSON). Migration:Redacted.value(error.cause),Redacted.value(error.<field>)._tagandcodeare unchanged, andEffect.catchTagmatches on_tagas before. Thereasonfield is new in 0.4.0: an error with codes carries them as a tagged union, soEffect.catchReasonon it is new too. Its case for a code the error does not list, or none, is named by the first ofOther,Unlisted,Unlisted2,Unlisted3, ... that is not one of upstream's codes:Other,UnlistedwhenOtheris an upstream code,Unlisted2whenUnlistedis 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 itsmessageand in its declared string fields. Codes are never scrubbed. Migration: tell failures apart by_tag,codeorreason, 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 possiblynullorundefinedin every overload the facade keeps resolves to anOption, of the facade when the value is a handle (one with an overload that never gives absence keeps upstream's type): puppeteer'spage.$of a selector that matches nothing, bullmq'squeue.getJobof an unknown id giveOption.none()where 0.3.0 gavenullorundefined. Migration: useOption's combinators (Option.match,Option.getOrElse,Option.isSome) instead of comparing withnullorundefined. - Ids are branded. An id the recipe brands (bullmq's
JobId:Job.id, the idQueue.getJob,Queue.removeand their kin take) is a branded string, so a plain string where a brand is expected (queue.getJob(id)withid: 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.toElementis 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 thatpage.$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'sasKind(kind)andgetChildAtIndexIfKind(index, kind)(KindToNodeMappings[TKind] | undefined), a property such as ts-morph'scompilerNode. 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'saddExtends(text)andaddExtends(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, noyield*); 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()andprop()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, soattr()'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
acquireReleasedoes, 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'sshutdown()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
acquireReleasedoes, interrupting a call that makes a releasable handle (anEffect.timeoutaroundbrowser.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
awaitadopts it. A call whose result is a thenable (postcss'sLazyResult, which runs its plugins in itsthen), a native promise too, has itsthencalled 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'sconstructoris read once, by its ownthen, asawaitreads it once: a getter of upstream's answering a second read otherwise changes nothing.
For engine users
studyruns the target library's code. It imports the package in Node to see which exports its build has. That runs in a process with onlyPATHandHOMEof your environment, under Node's permission model, within a 60-second deadline: hygiene against accidents, not a sandbox. Migration: runstudy, andmake,draftandsync, which run it, only on a library you would install.verifyandreleaseimport 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, orEFFECTIFY_IMPORTS_DEADLINEseconds 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 aredid 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'sverifynever saw: protobufjs 7.5.4'sRoot,Type,Fieldandload(its CommonJS module gives Node onlydefault); 0.4.0'sverifyfails 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 raiseEFFECTIFY_IMPORTS_DEADLINEfor one that loads slowly; leave an exportstudymarkserasedout of the recipe'sexports.- New maintainer checks.
reconcileandverifyhold every facade'ssrc/andtest/to the Effect rules (@effect/tsgo's, run by tsrs), and itssrc/to the source idioms (an oxlint plugin:Effect.fnfor functions that returnEffect.gen, a named span,Matchfor aswitchon_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-diagnosticsdirective (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
CheckedGivesfailsreconcileandverify(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, anOption, aStream). 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'sDirectory.getRelativePathTo(sourceFile)andgetRelativePathTo(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.
draftproposes a handle's release only amongclose,quit,disconnect,destroy,shutdown,terminate,stop,end,disposeandrelease, 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'sSocket.close(): Socketand cheerio'send()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'sreleases) by the same rule. 0.3.0 also offered one that takes an argument, which its finalizer called without one: chart.js'sAnimator.stop(chart), MapLibre'sWorkerPool.release(mapId), codemirror'sGutterMarker.destroy(dom). A name that also means something else is never offered: postcss'sNode.remove()takes a node out of its tree, and protobuf.js'sremove(object)takes the child it is given. Migration: a maintainer declares a release under another name (MapLibre'sMap.remove) as anagentorpersondecision, which a redraft keeps; anenginedecision for a release that takes an argument becomesnoneat the next redraft (sync), and a re-studydrops it fromreleases. studyrecords optional methods and calls that return their receiver. A handle's methods upstream declares optional (refresh?()) are listed in itsoptional, and amixedresult is told by the other methods only; a call upstream declares to returnthisis"receiver": true(read from the declaration, since the checker prints thatthisas the handle's own type: chart.js'sChart.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-studya target to get them; only those lines of itssurface.jsonchange.- 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.ClassDeclarationthat ts-morph'scompilerNodeholds, beside ts-morph's ownClassDeclaration. 0.3.0 wrapped such a value as the other handle's facade, which has none of its members. Migration: re-studya target whose surface reads one (such a property's or method'shandleinsurface.jsongoes); the value is then upstream's, typed so.