[1]:Transport SSL must be enabled if security is enabled on a [basic] license. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]
fetch("users.json").then((users: User[]) => { // you can use users here, and type hinting also will be available to you, // but users are not actually instances of User class // this means that you can't use methods of User class });
fetch("users.json").then((users: Object[]) => { const realUsers = plainToClass(User, users); // now each user in realUsers is instance of User class });
const user = new User(); user.id = 1; user.setName("Johny", "Cage"); user._password = 123;
const plainUser = classToPlain(user, { excludePrefixes: ["_"] }); // here plainUser will be equal to // { id: 1, name: "Johny Cage" }
使用组来控制排除的属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import {Exclude, Expose} from "class-transformer";
@Exclude() export class User {
id: number;
name: string;
@Expose({ groups: ["user", "admin"] }) // this means that this data will be exposed only to users and admins email: string;
@Expose({ groups: ["user"] }) // this means that this data will be exposed only to users password: string; }
let user1 = classToPlain(user, { groups: ["user"] }); // will contain id, name, email and password let user2 = classToPlain(user, { groups: ["admin"] }); // will contain id, name and email
import {Exclude, Expose} from "class-transformer";
@Exclude() export class User {
id: number;
name: string;
@Expose({ since: 0.7, until: 1 }) // this means that this property will be exposed for version starting from 0.7 until 1 email: string;
@Expose({ since: 2.1 }) // this means that this property will be exposed for version starting from 2.1 password: string; }
let user1 = classToPlain(user, { version: 0.5 }); // will contain id and name let user2 = classToPlain(user, { version: 0.7 }); // will contain id, name and email let user3 = classToPlain(user, { version: 1 }); // will contain id and name let user4 = classToPlain(user, { version: 2 }); // will contain id and name let user5 = classToPlain(user, { version: 2.1 }); // will contain id, name nad password
/** * result1 will be `{ prop: "1234" }` - notice how the prop value has been converted to string. * result2 will be `{ prop: 1234 }` - default behaviour */
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size yellow open bank ktIRbx9ZTwyDrEHlxiZpqw 1 1 1000 0 379.3kb 379.3kb green open .kibana_task_manager_7.12.0_001 Yi3dSuiVSYWYaFidZxHSJg 1 0 9 26006 2.6mb 2.6mb green open .apm-custom-link DLOQIooBRiWD4O237c8tBA 1 0 0 0 208b 208b green open .apm-agent-configuration zUC91G_oRw63OY54rV2orw 1 0 0 0 208b 208b green open .async-search NkCazI4YQDirjCrnvlEv2Q 1 0 0 24 794.5kb 794.5kb green open .kibana_7.12.0_001 z4vax_yNTq2cOP7JxBphOQ 1 0 63 10 2.1mb 2.1mb green open .kibana-event-log-7.12.0-000001 CYz7KhrsRa-dino1NEPDog 1 0 7 0 32.9kb 32.9kb green open .tasks 6wSie0zSRIW17VNQuxHgNQ 1 0 8 0 42.4kb 42.4kb