@orion-js/typed-model 3.0.33 → 3.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const models_1 = require("@orion-js/models");
13
+ const schema_1 = require("@orion-js/schema");
14
+ const _1 = require(".");
15
+ describe('Test typed model with Schema', () => {
16
+ it('Should allow passing a typed model to schema', async () => {
17
+ let Point = class Point {
18
+ };
19
+ __decorate([
20
+ (0, _1.Prop)(),
21
+ __metadata("design:type", Number)
22
+ ], Point.prototype, "latitude", void 0);
23
+ __decorate([
24
+ (0, _1.Prop)(),
25
+ __metadata("design:type", Number)
26
+ ], Point.prototype, "longitude", void 0);
27
+ Point = __decorate([
28
+ (0, _1.TypedModel)()
29
+ ], Point);
30
+ const schema = {
31
+ points: {
32
+ type: [Point]
33
+ }
34
+ };
35
+ const result = await (0, schema_1.clean)(schema, { points: [{ latitude: '1', longitude: 2 }] });
36
+ expect(result).toEqual({ points: [{ latitude: 1, longitude: 2 }] });
37
+ await (0, schema_1.validate)(schema, { points: [{ latitude: 1, longitude: 2 }] });
38
+ });
39
+ it('Should allow passing a typed model to a model', async () => {
40
+ let Point = class Point {
41
+ };
42
+ __decorate([
43
+ (0, _1.Prop)(),
44
+ __metadata("design:type", Number)
45
+ ], Point.prototype, "latitude", void 0);
46
+ __decorate([
47
+ (0, _1.Prop)(),
48
+ __metadata("design:type", Number)
49
+ ], Point.prototype, "longitude", void 0);
50
+ Point = __decorate([
51
+ (0, _1.TypedModel)()
52
+ ], Point);
53
+ const Item = (0, models_1.createModel)({
54
+ name: 'Item',
55
+ schema: {
56
+ points: {
57
+ type: [Point]
58
+ }
59
+ }
60
+ });
61
+ const result = await Item.clean({ points: [{ latitude: '1', longitude: 2 }] });
62
+ expect.assertions(2);
63
+ expect(result).toEqual({ points: [{ latitude: 1, longitude: 2 }] });
64
+ try {
65
+ await Item.validate({ points: [{ latitude: '1', longitude: 2 }] });
66
+ }
67
+ catch (error) {
68
+ expect(error.message).toBe('Validation Error: {points.0.latitude: notANumber}');
69
+ }
70
+ });
71
+ it('Should allow cleaning and validating just the typed model', async () => {
72
+ let Point = class Point {
73
+ };
74
+ __decorate([
75
+ (0, _1.Prop)(),
76
+ __metadata("design:type", Number)
77
+ ], Point.prototype, "latitude", void 0);
78
+ __decorate([
79
+ (0, _1.Prop)(),
80
+ __metadata("design:type", Number)
81
+ ], Point.prototype, "longitude", void 0);
82
+ Point = __decorate([
83
+ (0, _1.TypedModel)()
84
+ ], Point);
85
+ const result = await (0, schema_1.clean)(Point, { latitude: '1', longitude: 2 });
86
+ expect(result).toEqual({ latitude: 1, longitude: 2 });
87
+ try {
88
+ await (0, schema_1.validate)(Point, { latitude: '1', longitude: 2 });
89
+ }
90
+ catch (error) {
91
+ expect(error.message).toBe('Validation Error: {latitude: notANumber}');
92
+ }
93
+ });
94
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/typed-model",
3
- "version": "3.0.33",
3
+ "version": "3.0.36",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -17,10 +17,10 @@
17
17
  "test": "jest --config jest.config.js"
18
18
  },
19
19
  "dependencies": {
20
- "@orion-js/helpers": "^3.0.31",
21
- "@orion-js/models": "^3.0.32",
22
- "@orion-js/resolvers": "^3.0.32",
23
- "@orion-js/schema": "^3.0.32",
20
+ "@orion-js/helpers": "^3.0.36",
21
+ "@orion-js/models": "^3.0.36",
22
+ "@orion-js/resolvers": "^3.0.36",
23
+ "@orion-js/schema": "^3.0.36",
24
24
  "lodash": "^4.17.21",
25
25
  "reflect-metadata": "0.1.13"
26
26
  },
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "3ae1a9b2872f026dca2edb6684d87d66151bd71e"
42
+ "gitHead": "7c921dbbf0ec679df743b9278abbf15cfcbac6ce"
43
43
  }