Skip to content

API reference > @kontsedal/olas-codemod

olas-codemod package ​

Functions ​

Function

Description

main(argv, io)

The CLI. Returns the exit code: 0 when the run finished, TODOs or not; 1 for a usage error or a project with no source files.

runCodemod(files, options)

Run the transforms over the files in memory, in order, and report what each did.

selectFiles(project, paths)

The files the codemod may rewrite: the project's own sources, not declaration files, not node_modules, not build output. With paths, only files at or under one of them.

Variables ​

Variable

Description

asyncState

AsyncState.promise() was an alias of firstValue(), and 1.0 removes it.

createField

createField(ctx, initial, validators, options) →createField(ctx, initial, { validators, ...options }), like createForm and createFieldArray.

ctxPrimitives

The lifetime-owned primitives are free functions that take ctx first, and ctx.signal / ctx.computed are the standalone signal / computed. Each rewrite imports the function from @kontsedal/olas-core.

entities

entitiesPlugin takes an options object, and returns a plugin only: the store it used to double as is a scope service. invalidate is renamedremove, because it never refetched.

errorContext

ErrorContext.queryKey → key; MutationDisposedError.mutationName → mutationId.

forms

A Form and a FieldArray are ReadSignals of their value in 1.0, like aField. In 0.8 the signal was their value member, so form.value (the signal) becomes form, and with it form.value.value → form.value,useValue(form.value) → useValue(form) and form.value.subscribe →form.subscribe.

identityMeta

Identity is a required id, and plugin settings live under meta:queryId → id, crossTab → meta.crossTab, mutationId → id,persist → meta.persist. name is dropped. defineMutation stopped persisting by default, so a definition without persist gainsmeta: { persist: true } to keep its behaviour.

mutateContext

A mutation's mutate and a local cache's fetcher receive the same{ signal, deps } context a query fetcher does.

mutationQueue

mutationQueuePlugin({ adapter }) → { storage }; the plugin-held replayNow is a service.

persist

localStorageAdapter is a factory, like indexedDbAdapter().clearPersisted(storage, prefix, onError) takes an options object and refuses to guess its scope.

reactMutation

useMutation returns mutate and run in 1.0. mutateAsync becomesrun. A mutate(...) whose promise the code waits on or passes along becomes run(...) too, since 1.0's mutate returns nothing.

removedApis

Report every import of a core export 1.0 removes. Nothing is rewritten.

renames

Renames of exports whose behaviour is unchanged: the React use →useValue and KeepAlive → SuspendOnUnmount, the use* composables →create*, formFromZod → createZodForm, selection →createSelection, and two type names. A reference follows its import binding, so a local that shadows the import is left alone.

rootApi

A 1.0 root is a handle with the app's api on .api. The type checker tells a 0.8 root apart by its controls, so root.increment() → root.api.increment() rewrites only where the type proves increment is api.

rootOptions

The query engine is explicit, and root-wide query defaults live on it:createRoot(app, { deps, defaultQueryOptions }) →createRoot(app, { deps, queries: queryEngine({ defaults }) }). Every 0.8 root had a query client, so every createRoot gains queries: queryEngine() to keep that. createTestController supplies an engine by default, so it only moves the defaults.

suspendOptions

Every duration option in 1.0 is named for its unit role: maxIdle → maxIdleTime.

transforms

Every 0.8 → 1.0 transform, in the order they must run.

The type-driven transforms run first, on code that still resolves the 0.8 types. A rewrite to a 1.0 name leaves an expression the 0.8 declarations cannot type: after ctx.form(...) becomes createForm(ctx, ...), the form's type is gone, and forms could no longer find form.value.value.root-api is the last of them, because a root.api.x it writes has no 0.8 type either. use-controller runs after root-api, so the .api it writes is not rewritten again.

useController

useController(root) was an identity function over the root, typed as its api. 1.0 removes it; the api is root.api. This runs after root-api, so the .api it writes is not taken for an api member.

Type Aliases ​

Type Alias

Description

CliIO

Where the CLI runs and writes its report.

Rename

One rename the renames transform applies: the export from becomes to.pkg is the package name without its @kontsedal/olas- prefix, such as'react'.

RunOptions

Options for runCodemod(files, options).

RunResult

What runCodemod returns. The run edits the files in memory only, so the caller saves changed and prints todos.

Todo

A site the codemod found but could not rewrite safely.

Transform

One 0.8 → 1.0 rewrite. run edits the given files in place, in memory; the caller decides whether to save them.

TransformContext

Shared settings every transform receives.

TransformResult

What one transform did to the files it was given.

TransformSummary

What one transform did across the run.

Released under the MIT License.