Skip to content

Migrate From Version 0

Overview

Storona aims to provide an API that does not change much between versions. However, there are some breaking changes that you should be aware of when migrating from v0 to v1. This guide will help you to migrate your existing codebase to the latest version.

Explicit Adapter Setting

In v0, you could simply pass an instance and Storona would detect an adapter automatically.

We found this approach to be error-prone and decided to make it explicit in v1.

Since v1, you need to install a separate adapter and set it explicitly for the createRouter function:

ts
import { createRouter } from "storona";
import { adapter } from "@storona/[your-adapter]"; 

createRouter(app, {
  adapter: adapter(), 
});

Removal of prefix Option.

In v0, you could set a prefix for all routes by passing the prefix option to the createRouter function.

Since v1, this option has been removed in favor of web-agnostic routing. Storona aims to be a universal router that can be used in any environment, so we decided to remove this option.

Instead, @storona/express and @storona/fastify adapters provide the same way of setting a prefix for all routes, but the option should be set inside the adapter itself:

ts
import { createRouter } from "storona";
import { adapter } from "@storona/[your-adapter]"; 

createRouter(app, {
  prefix: "/v1", 
  adapter: adapter({ 
    prefix: "/v1", 
  }), 
});

Rename of Signature Functions

In v0, the signature functions were named after the used adapter and its purpose. For example, defineExpressRoute was used for the Express adapter.

Since v1, we decided to make the API more consistent and renamed these functions to define. This decision was made due to the fact that adapters are now released as separate packages:

ts
import { defineExpressRoute } from "storona"; 
import { define } from "@storona/express"; 

export const route = "/hello";
export const method = "get";

export default defineExpressRoute((_req, res) => { 
  res.send("Hello, World!"); 
}); 
export default define((_req, res) => { 
  res.send("Hello, World!"); 
}); 
ts
import { defineFastifyRoute } from "storona"; 
import { define } from "@storona/fastify"; 

export const route = "/hello";
export const method = "get";

export default defineFastifyRoute((_request, reply) => { 
  reply.send("Hello, World!"); 
}); 
export default define((_request, reply) => { 
  reply.send("Hello, World!"); 
}); 

Released under the MIT License.