ESM
ESM is now the default module system. That breaks some old dependencies that were CommonJS only.- If you use
lodash, you must replace it withlodash-esfor ESM compatibility.
Reflect Metadata Decorators
Decorators were updated to draft v3. Which is not backwards compatible with v2. This means:- You must disable
experimentalDecoratorsin yourtsconfig.json - You must add
"type": "module"to your package.json - You can not use
reflect-metadata. @TypedSchema()@Prop()now always need a type option.
Dependency Injection
We are not usingtypedi anymore, we created our own dependency injection system, very similar to typedi. So:
V4 Syntax
Now without reflect metadata and better type inference with schema, we recommend a new syntax on how to define jobs, echoes, resolvers, routes, etc. This new syntax is less verbose and more type safe. V3 syntax will still work, but it’s not recommended to use it. Each section will have a V4 syntax example.Schema
@orion-js/schema was rewritten to be much more powerful.
Schema and all of the places it’s used, like resolvers, are now type safe.
InferSchemaType
You can nowInfer a typescript type from a Schema definition.
Enum
Enum now don’t provide thetype property, you must use typeof Enum.__tsFieldType to get the type.
Depreaction notice of @TypedSchema() and Model
Old code like Model and TypedSchema() will still work. If you have any TS error, you can set as any to fix it until you migrate to Schema.
AsModel.initItemwas deprecated in v3 and removed in v4, soCollectionsnow can’t accept amodeloption, only aschemaoption.
TypedSchema() now always needs a type option, it became less appealing. We always aim to only write code once.
Usage of TypedSchema() and Model is not recommended anymore and it’s marked as deprecated.
V4 Syntax
schemaWithName() but you won’t be able to use them in GraphQL.
Dogs
- You should now use
createEventJobandcreateRecurrentJobinstead ofdefineJob. - You can now you can pass a params schema to clean and validate params of event jobs.
- To schedule a event job you must call it from the event job definition instad of global
scheduleJob.
runEveryincreateRecurrentJobnow acceptsmsstring.
V4 Syntax
Echoes
- You can now pass a params schema to clean and validate params of echoes.
- You should use
createEchoEventandcreateEchoRequestinstead ofecho.
V4 Syntax
GraphQL
- You should use
createQueryandcreateMutationinsteadcreateResolver. schemaWithNameis preferred overModelandTypedSchema().- You cannot pass just a
Schemato params and returns becauseGraphQLneeds a name. - V3 syntax in subscriptions is not supported anymore.
- In GraphQL subscriptions you must you
canSubscribeoption to check permissions instead ofcheckPermission.
V4 Syntax
Global resolvers:HTTP / Routes
- Route path is now type safe.
- You can pass
bodyParamsto clean and validate body params. - You can pass
queryParamsto clean and validate query params. - You can pass
returnsto clean the return value.
V4 Syntax
MongoDB
modelparam in model was removed, and objects are never “initialized” anymore. This pattern was deprecated in v3 and removed in v4.- Connections are not started until you call any method in the collection or you call
collection.startConnection. - The library will automatically detect
typedIdfrom the schema and use it to create prefixed ids.
V4 Syntax
Paginated MongoDB
V4 Syntax
CLI (@orion-js/core)
Now we are using tsx to run the app. You must install tsx in your project.
pnpm orion devto start in dev mode, it will watch for changes and automatically restart the server.pnpm orion prodto start in prod mode, it will compile the code and then run it.
You must have installed@orion-js/corein your project, you can’t running usingnpxorpnpx.
Recommended TypeScript Configuration
Update yourtsconfig.json to use modern settings:
Removed functionalities and packages
@orion-js/mailing
Mailing package was removed. Just use nodemailer directly.
@orion-js/cache
@orion-js/cache it’s not longer going to be maintained. We are not using it in any package.
If you need a cache system, we recommend using lru-cache.
getCacheKey and cacheProvider were removed from the options of createResolver and createModelResolver.
Permissions checkers
We are not using global permissions checkers anymore.checkPermission and permissionsOptions were removed from the options of createResolver and createModelResolver.
If you need to check permissions, you can do it in the resolve function or in a middleware.