Skip to content

Releases: ItemConsulting/enonic-types

Update XP dependencies to 7.12.1

22 Mar 06:39
570f435
Compare
Choose a tag to compare

Start using official types from Enonic

07 Nov 11:22
92400de
Compare
Choose a tag to compare

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

24 Oct 12:20
aa1fd38
Compare
Choose a tag to compare

Backport nested boolean filters to 0.4 branch

Add global declarations for ContentTypes, XData and SiteConfig

15 Aug 08:41
f5e71e7
Compare
Choose a tag to compare

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 the global declarations for XP.ContentTypes, XP.XData and XP.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

27 Jun 09:49
6cf3652
Compare
Choose a tag to compare

Prepare for XP 7.10.0

Changes

  • Add support for GridLibrary

Full Changelog: 0.3.22...0.4.10

Support new features in lib-menu

22 Mar 13:23
f904cf5
Compare
Choose a tag to compare

Prepare for XP 7.8.0

19 Nov 10:42
Compare
Choose a tag to compare

Changes

  • Add ContextAttributes type in contextLib ed68b30
  • Add types for guillotine context.types f543ba7
  • Add imageSizes to portalLib.processHtml() 549e3bd
  • Add attributes to context 28753a6
  • Add "NONE" as option to LoginParams['scope'] e0c599c

Full Changelog: 0.3.7...0.3.8

Add types for React4XP

28 Oct 07:40
Compare
Choose a tag to compare

New libraries supported

  • React4XP

Add types for Explorer Library

27 Oct 11:59
Compare
Choose a tag to compare

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

21 Oct 10:15
Compare
Choose a tag to compare

New libraries supported

Support has been added for the following libraries:

  • VhostLibrary (XP 7.6.0)