UNPKG

@calf/serializable

Version:

Serializable module of Calf framework.

60 lines (59 loc) 2.28 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); // Import library var serializable_1 = require("../lib/serializable"); var Human = /** @class */ (function () { function Human() { this.height = 0; } __decorate([ serializable_1.Property(serializable_1.PropertyType.DOUBLE) ], Human.prototype, "height", void 0); return Human; }()); var Thing = /** @class */ (function () { function Thing() { this.weight = 0; } __decorate([ serializable_1.Property(serializable_1.PropertyType.DOUBLE) ], Thing.prototype, "weight", void 0); return Thing; }()); var Person = /** @class */ (function () { function Person() { this.age = 0; this.name = undefined; this.hobbies = []; } __decorate([ serializable_1.Required(), serializable_1.Unique(), serializable_1.Property(serializable_1.PropertyType.DOUBLE) ], Person.prototype, "age", void 0); __decorate([ serializable_1.Property("name", serializable_1.PropertyType.TEXT), serializable_1.Default("Mr Smith") ], Person.prototype, "name", void 0); __decorate([ serializable_1.Property([serializable_1.PropertyType.TEXT]) ], Person.prototype, "hobbies", void 0); Person = __decorate([ serializable_1.Entity("Person"), serializable_1.Extends(Thing, Human), serializable_1.Timestamp() ], Person); return Person; }()); // EXPORT TEST describe("Serializable", function () { // Init parser var parser = new serializable_1.SchemaParser(); console.log(parser.parse(Person)); });