Releases: ItemConsulting/enonic-types
Update XP dependencies to 7.12.1
Full Changelog: 7.11.0...7.12.1
Start using official types from Enonic
Use the official TypeScript-types from Enonic
Enonic has now released offical TypeScript-types. 🎉 Much of it is based on the previous version of this package. So the migration should be quite easy for the most part.
The purpose of this package has changed to provide types for the packages that does not have official support yet (most
libraries that does not start with "/lib/xp"
).
If you install the newest version of this package, it will pull inn all the official types from Enonic to your "node_modules" folder. So it will provide the same support surface as before. See the README.md file on how to update your tsconfig.json to use this new version.
Change to versioning
This library will now use the same versioning number as the official types from Enonic (7.11.0), to indicate which official version is pulled in.
Individual type packages (e.g. menuLib) will now be released as individual packages with the same versioning as the library. These libraries will be released under the npm organization @item-enonic-types, until official versions of them exist.
Changelog
See CHANGELOG.md for more changes, and tips on upgrading.
Allow nested boolean filters
Backport nested boolean filters to 0.4 branch
Add global declarations for ContentTypes, XData and SiteConfig
New global
maps are used for registering shapes of Content Types, as well as the shape of Site.config
and Content.x
.
Note
If you are using xp-codegen-plugin@2.0.0 theglobal
declarations forXP.ContentTypes
,XP.XData
andXP.SiteConfig
are generated for you based on the xml-files in your project! 🎉
ContentType map
The type system can now look up the content types when using contentLib.query()
with the contentTypes
parameter set.
For the type system to know about the shape of a content type, we first need to register it. This is done in a global declaration.
export type Article = import("./article").Article
export type Employee = import("./employee").Employee
declare global {
namespace XP {
interface ContentTypes {
"com.mysite:article": Article;
"com.mysite:employee": Employee;
}
}
}
This declaration only needs to be done once in your code base, and every XP.ContentTypes
will now be merged to one interface.
Improved type inference + splitting unions with content.type
import { query } from "/lib/xp/content";
export function get(): XP.Response {
const res = query({
count: 100,
contentTypes: ["com.mysite:article", "com.mysite:employee"]
});
// the shape of res.hits is correctly inferred based on `contentTypes`
const contents: Array<Content<Article> | Content<Employee>> = res.hits;
contents.forEach((content) => {
// since we now know which shape of `data` belongs to which `type`, this is now possible
if (content.type === "com.mysite:article") {
// This would have failed earlier, since `content.type` as of type `string`
const article: Article = content.data;
log.info("Article: " + JSON.stringify(article))
} else {
// If it isn't an Article, it has to bee an Employee (based on `contentTypes` above)
const employee: Employee = content.data;
log.info("Employee: " + JSON.stringify(employee))
}
});
}
The shape of Content
has changed
XData
has been made a global variable which is now declared in XP.XData
. This is an improvement since XData
usually has the same shape for all content types (e.g. menu).
The shape of Content
in 0.4.x was:
export interface Content<Data, XData> {
...;
data: Data;
x: XData;
}
The new shape of Content
in 0.5.0 is:
export interface Content<Data, Type = KeyOfContentType<Data>> {
...;
type: Type;
data: Data;
x: XP.XData;
}
We can now see that the second type parameter is named Type
and is a string literal with the name of the content type.
This makes splitting up a discrete union of different content types very easy. We can just use an if
-statement, to separate the different content types on the type
field (the same way we would do it in JavaScript).
Globally declaring XP.XData
and XP.SiteConfig
The shapes of XData and SiteConfig is no longer passed in as type parameters, but declared globally like this:
import { MenuItem } from "../path-to-somewhere";
declare global {
namespace XP {
interface SiteConfig {
footer: string | string[] | undefined;
}
interface XData {
"no-item-www"?: {
"menu-item"?: MenuItem;
}
}
}
}
Add types for gridLib
Support new features in lib-menu
Full Changelog: 0.3.8...0.3.22
Prepare for XP 7.8.0
Add types for React4XP
New libraries supported
- React4XP
Add types for Explorer Library
New libraries supported
- ExplorerLibrary 4.0.0 (XP 7.7.2)
Changes
- Remove
readonly
from parameters in NodeLib - Add
archive()
/restore
() to ContentLib
Bugfixes
- Fix wrong typing of getToolUrl in AdminLib
Add types for Vhost Library
New libraries supported
Support has been added for the following libraries:
- VhostLibrary (XP 7.6.0)