Skip to content

Commit

Permalink
fix: export core Type class
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jun 10, 2019
1 parent 4e0ea5e commit 3e1bdf2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = require('./src').Archetype;

module.exports.Any = require('./src/symbols').Any;
module.exports.CastError = require('./src').CastError;
module.exports.Type = require('./src/type');
module.exports.matchType = require('./src/helpers/matchType');
module.exports.to = require('./src/to');
15 changes: 6 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Path = require('./path');
const Type = require('./type');
const cloneDeep = require('lodash.clonedeep');
const get = require('./get');
const set = require('lodash.set');
Expand All @@ -17,11 +18,7 @@ class Archetype {
const _this = this;
this._paths = visitor(this._obj);

class Type {
constructor(obj, projection) {
Object.assign(this, unmarshal(cloneDeep(obj), _this, projection));
}

class _Type extends Type {
static paths() {
return _this.paths();
}
Expand All @@ -47,13 +44,13 @@ class Archetype {
}
}

Type.schema = this;
_Type.schema = this;
if (name != null) {
Type.toString = () => name;
Object.defineProperty(Type, 'name', { value: name });
_Type.toString = () => name;
Object.defineProperty(_Type, 'name', { value: name });
}

return Type;
return _Type;
}

json() {
Expand Down
12 changes: 12 additions & 0 deletions src/type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const cloneDeep = require('lodash.clonedeep');
const unmarshal = require('./unmarshal');

class Type {
constructor(obj, projection) {
Object.assign(this, unmarshal(cloneDeep(obj), this.constructor.schema, projection));
}
}

module.exports = Type;

0 comments on commit 3e1bdf2

Please sign in to comment.