enonic-types
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -149,5 +149,5 @@ import { ByteSource, Content, Site } from "./content"; | ||
readonly name: string; | ||
readonly fileName: string; | ||
readonly contentType: string; | ||
readonly fileName?: string; | ||
readonly contentType?: string; | ||
readonly size: number; | ||
} |
{ | ||
"name": "enonic-types", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "TypeScript types for Enonic XP", | ||
@@ -10,3 +10,3 @@ "main": "lib/index.js", | ||
"build": "npm run clean && tsc", | ||
"lint:ts": "eslint --fix 'src/**/*.ts'" | ||
"lint": "eslint --fix 'src/**/*.ts'" | ||
}, | ||
@@ -27,9 +27,9 @@ "repository": { | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^2.6.0", | ||
"@typescript-eslint/parser": "^2.6.0", | ||
"@typescript-eslint/eslint-plugin": "^2.7.0", | ||
"@typescript-eslint/parser": "^2.7.0", | ||
"eslint": "^6.6.0", | ||
"husky": "^3.0.9", | ||
"lint-staged": "^9.4.2", | ||
"lint-staged": "^9.4.3", | ||
"rimraf": "^3.0.0", | ||
"typescript": "^3.6.4" | ||
"typescript": "^3.7.2" | ||
}, | ||
@@ -36,0 +36,0 @@ "husky": { |
# TypeScript types for Enonic XP | ||
This library contains TypeScript types written out for Enonic XP. | ||
[![npm version](https://badge.fury.io/js/enonic-types.svg)](https://badge.fury.io/js/enonic-types) | ||
This library contains TypeScript types for Enonic XP. | ||
## Code generation | ||
We recommend using this library together with its sister library: [enonic-ts-codegen](https://github.com/ItemConsulting/enonic-ts-codegen). *enonic-ts-codegen* will create TypeScript `interfaces` for your content-types. Those interfaces will be very useful together with this library. | ||
## Example | ||
We have an Enonic service that returns an article by id. | ||
```typescript | ||
import { Request, Response } from "enonic-types/lib/common"; | ||
import { Request, Response } from "enonic-types/lib/controller"; | ||
import { ContentLibrary } from "enonic-types/lib/content"; | ||
import { Article } from "../../site/content-types/article/article"; // 1 | ||
const contentLib: ContentLibrary = __non_webpack_require__("/lib/xp/content"); | ||
const contentLib: ContentLibrary = __non_webpack_require__("/lib/xp/content"); // 2 | ||
export function get(req: Request): Response { | ||
export function get(req: Request): Response { // 3 | ||
const content = contentLib.get<Article>({ key: req.params.id! }); | ||
if (content !== null) { | ||
if (content !== null) { // 4 | ||
const article: Article = content.data; | ||
@@ -24,7 +33,19 @@ | ||
} | ||
``` | ||
interface Article { | ||
readonly title: string; | ||
readonly test: string; | ||
} | ||
``` | ||
1. We import an `interface Article { ... }` generated by [enonic-ts-codegen](https://github.com/ItemConsulting/enonic-ts-codegen). | ||
2. When we import something with `__non_webpack_require__`, we can give the library a type. In this case the type is `ContentLibrary`. | ||
3. We use the imported `Request` and `Response` to control the shape of our controller. | ||
4. `content` is of the type `Content<Article> | null`, so we have to do a null check before proceiding. | ||
## Supported libraries | ||
* [AuthLibrary](./src/auth.ts) | ||
* [ContentLibrary](./src/content.ts) | ||
* [ContextLibrary](./src/context.ts) | ||
* [I18nLibrary](./src/i18n.ts) | ||
* [MailLibrary](./src/mail.ts) | ||
* [NodeLibrary](./src/node.ts) | ||
* [PortalLibrary](./src/portal.ts) | ||
* [RepoLibrary](./src/repo.ts) | ||
* [ThymeleafLibrary](./src/thymeleaf.ts) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31584
51