Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/release-notes/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- `insertGraph()`, `upsertGraph()` and their `*AndFetch()` variants throw an error for unknown graph options like `noInset` instead of ignoring them with a warning, and `insertGraph()` also for the options of `upsertGraph()` that have no effect on an insert, like `noDelete` or `allowMarkers`. See [migration](/release-notes/migration.md#unknown-graph-options-throw) [#84](https://github.com/ditojs/objection/issues/84)
- The type parameter of `RelateQueryBuilder` is the number query builder, e.g. `RelateQueryBuilder<NumberQueryBuilder<this>>` in custom query builders that override `relate()`. See [migration](/release-notes/migration.md#typescript-relatequerybuilder-takes-the-number-query-builder)
- Custom query builders declare one `RebindType` member instead of the five `ArrayQueryBuilderType`, `SingleQueryBuilderType`, `MaybeSingleQueryBuilderType`, `NumberQueryBuilderType` and `PageQueryBuilderType` members, which are removed: `declare RebindType: MyQueryBuilder<this['~M'], this['~R'], this['~X']>`, with the extra types `X` as third type parameter. The helper types `SingleQueryBuilder<QB>` etc. take a query builder, and `WithGraphModelQueryBuilder` and `ReturningMethod` are removed. See [migration](/release-notes/migration.md#typescript-custom-query-builders-declare-rebindtype) [#125](https://github.com/ditojs/objection/issues/125) [#319](https://github.com/Vincit/objection.js/issues/319)
- The internal helper types of the relation expression parser, the `withGraph*()` narrowing and the property names, like `ParseRelationString`, `WithGraph` and `RelationPropertyNames`, are no longer exported, and the unused `ItemType` is removed. See [migration](/release-notes/migration.md#typescript-internal-helper-types-are-no-longer-exported)
- `static jsonSchema` is typed `ReadonlyJSONSchema`, a JSON schema with readonly arrays, so that it takes schemas declared `as const`. A model's schema read through the static type can't be passed where a `JSONSchema` is expected, unless the model declares `static jsonSchema: JSONSchema`. See [migration](/release-notes/migration.md#typescript-model-jsonschema-is-a-readonly-schema) [#16](https://github.com/ditojs/objection/issues/16)
- `insert()`, `patch()`, `update()`, their `*AndFetch*()` and `*ById()` variants, `merge()` and `relate()` reject relation properties, which they ignore at runtime: they take a `PartialModelRow<M>`, a model instance or its properties without relations, instead of `PartialModelObject<M>`. Values whose type includes the relation properties are rejected too, e.g. `Partial<M>`, `ModelObject<M>` or `PartialModelObject<M>` of models with relations. `insertGraph()` and `upsertGraph()` take relations. See [migration](/release-notes/migration.md#typescript-insert-patch-and-update-reject-relation-data) [#53](https://github.com/ditojs/objection/issues/53)
- `distinctOn()` is typed to take column names, `raw()` and `ref()`, like `groupBy()`, instead of any selection, as it doesn't select its columns.
Expand Down
5 changes: 5 additions & 0 deletions doc/release-notes/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This section lists the breaking changes in objection 4.0.
- [typescript: insertGraph() has no allowMarkers option](#typescript-insertgraph-has-no-allowmarkers-option)
- [typescript: RelateQueryBuilder takes the number query builder](#typescript-relatequerybuilder-takes-the-number-query-builder)
- [typescript: Custom query builders declare RebindType](#typescript-custom-query-builders-declare-rebindtype)
- [typescript: Internal helper types are no longer exported](#typescript-internal-helper-types-are-no-longer-exported)
- [typescript: Model.jsonSchema is a readonly schema](#typescript-model-jsonschema-is-a-readonly-schema)
- [typescript: insert(), patch() and update() reject relation data](#typescript-insert-patch-and-update-reject-relation-data)
- [typescript: Property types leave out $ properties](#typescript-property-types-leave-out-properties)
Expand Down Expand Up @@ -370,6 +371,10 @@ The third type parameter `X` holds extra types of the query, which strict mode u

The helper types `SingleQueryBuilder`, `MaybeSingleQueryBuilder`, `ArrayQueryBuilder`, `NumberQueryBuilder` and `PageQueryBuilder` take any query builder, e.g. `MaybeSingleQueryBuilder<this>` as the return type of an overridden `findById()`, and `NumberQueryBuilder<MaybeSingleQueryBuilder<this>>` for `patchById()`, `updateById()` and `deleteById()`, the writes of `findById()`. `WithGraphModelQueryBuilder<M, E>` is removed. Use `QueryBuilderType<WithGraphModel<M, E>>` instead. The `ReturningMethod` interface is removed too, `returning()` is a method of `QueryBuilder`. On query builders with an `any` result, e.g. `AnyQueryBuilder`, it returns `QueryBuilder<any, any> | QueryBuilder<any, any[]>` instead of `QueryBuilder<any, any[]>`.

## typescript: Internal helper types are no longer exported

The helper types of the relation expression parser, the `withGraph*()` narrowing and the property names, like `ParseRelationString`, `WithGraph`, `WithGraphProperty`, `InsertablePropertyNames` and `RelationPropertyNames`, are no longer exported, and the unused `ItemType` is removed. Use `WithGraphModel`, `WithGraphQueryBuilder`, `ModelProps` and `ModelRelations` instead.

## typescript: Model.jsonSchema is a readonly schema

`static jsonSchema` is typed `ReadonlyJSONSchema`, a JSON schema with readonly arrays, so that schemas declared `as const` can be assigned to it, for `FromJSONSchema`. A `JSONSchema` is assignable to it, but not the other way around: a model's schema read through the static type can't be passed to a parameter typed `JSONSchema`, or returned from `$beforeValidate()`. Declare the type on models that are used that way:
Expand Down
Loading
Loading