mnemonica 0.9.93 → 0.9.98

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.
Files changed (53) hide show
  1. package/README.md +40 -13
  2. package/build/api/errors/bindedMethodErrorHandler.js +52 -51
  3. package/build/api/errors/exceptionConstructor.js +98 -98
  4. package/build/api/errors/index.d.ts +1 -1
  5. package/build/api/errors/index.js +51 -48
  6. package/build/api/errors/throwModificationError.js +96 -95
  7. package/build/api/hooks/flowCheckers.d.ts +1 -1
  8. package/build/api/hooks/flowCheckers.js +11 -10
  9. package/build/api/hooks/index.js +7 -7
  10. package/build/api/hooks/invokeHook.js +46 -45
  11. package/build/api/hooks/registerHook.js +19 -18
  12. package/build/api/index.d.ts +1 -1
  13. package/build/api/index.js +9 -9
  14. package/build/api/types/InstanceCreator.d.ts +2 -4
  15. package/build/api/types/InstanceCreator.js +237 -239
  16. package/build/api/types/InstanceModificator.js +10 -8
  17. package/build/api/types/Mnemosyne.d.ts +3 -2
  18. package/build/api/types/Mnemosyne.js +127 -111
  19. package/build/api/types/TypeProxy.js +132 -132
  20. package/build/api/types/addProps.d.ts +1 -0
  21. package/build/api/types/addProps.js +68 -0
  22. package/build/api/types/compileNewModificatorFunctionBody.d.ts +1 -1
  23. package/build/api/types/compileNewModificatorFunctionBody.js +37 -27
  24. package/build/api/types/createInstanceModificator.js +26 -24
  25. package/build/api/types/createInstanceModificator200XthWay.js +29 -28
  26. package/build/api/types/index.js +161 -159
  27. package/build/api/types/obeyConstructor.d.ts +1 -0
  28. package/build/api/types/obeyConstructor.js +30 -0
  29. package/build/api/utils/index.d.ts +20 -8
  30. package/build/api/utils/index.js +122 -122
  31. package/build/constants/index.d.ts +2 -0
  32. package/build/constants/index.js +62 -57
  33. package/build/descriptors/errors/index.js +7 -7
  34. package/build/descriptors/index.js +5 -5
  35. package/build/descriptors/namespaces/index.js +70 -70
  36. package/build/descriptors/types/index.js +141 -141
  37. package/build/index.d.ts +39 -5
  38. package/build/index.js +63 -31
  39. package/build/types/index.d.ts +16 -17
  40. package/build/types/index.js +1 -1
  41. package/build/utils/collectConstructors.js +52 -51
  42. package/build/utils/defineStackCleaner.js +9 -8
  43. package/build/utils/extract.js +16 -15
  44. package/build/utils/hop.js +3 -2
  45. package/build/utils/index.js +27 -27
  46. package/build/utils/merge.js +15 -14
  47. package/build/utils/parent.js +17 -16
  48. package/build/utils/parse.js +42 -41
  49. package/build/utils/pick.js +21 -20
  50. package/build/utils/toJSON.js +27 -26
  51. package/package.json +92 -92
  52. package/build/api/types/InstanceCreatorProto.d.ts +0 -3
  53. package/build/api/types/InstanceCreatorProto.js +0 -88
@@ -1,31 +1,41 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getClassConstructor = (ConstructHandler, CreationHandler) => {
4
+ return class extends ConstructHandler {
5
+ constructor(...args) {
6
+ const answer = super(...args);
7
+ return CreationHandler.call(this, answer);
8
+ }
9
+ };
10
+ };
11
+ const getFunctionConstructor = (ConstructHandler, CreationHandler) => {
12
+ return function (...args) {
13
+ const answer = ConstructHandler.call(this, ...args);
14
+ return CreationHandler.call(this, answer);
15
+ };
16
+ };
3
17
  const compileNewModificatorFunctionBody = function (FunctionName, asClass = false) {
4
- const modString = asClass ?
5
- `class ${FunctionName} extends ConstructHandler {
6
- constructor(...args) {
7
- const answer = super(...args);
8
- return CreationHandler.call(this, answer);
9
- }
10
- }`
11
- :
12
- `const ${FunctionName} = function (...args) {
13
- const answer = ConstructHandler.call(this, ...args);
14
- return CreationHandler.call(this, answer);
15
- };`;
16
- return new Function('ConstructHandler', 'CreationHandler', 'SymbolConstructorName', `return function () {
17
-
18
- ${modString}
19
-
20
- Object.defineProperty(${FunctionName}, SymbolConstructorName, {
21
- get () {
22
- return '${FunctionName}';
23
- }
24
- });
25
-
26
- return ${FunctionName};
27
-
28
- };
29
- `);
18
+ return function (ConstructHandler, CreationHandler, SymbolConstructorName) {
19
+ return function () {
20
+ let ModificationBody;
21
+ if (asClass) {
22
+ ModificationBody = getClassConstructor(ConstructHandler, CreationHandler);
23
+ }
24
+ else {
25
+ ModificationBody = getFunctionConstructor(ConstructHandler, CreationHandler);
26
+ }
27
+ ModificationBody.prototype.constructor = ModificationBody;
28
+ Object.defineProperty(ModificationBody.prototype.constructor, 'name', {
29
+ value: FunctionName,
30
+ writable: false
31
+ });
32
+ Object.defineProperty(ModificationBody, SymbolConstructorName, {
33
+ get() {
34
+ return FunctionName;
35
+ }
36
+ });
37
+ return ModificationBody;
38
+ };
39
+ };
30
40
  };
31
41
  exports.default = compileNewModificatorFunctionBody;
@@ -1,27 +1,29 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
3
- function default_1 () {
4
- const CreateInstanceModificator = function (ModificatorType, ModificatorTypePrototype, addProps) {
5
- const existentInstance = this;
6
- const Mnemosyne = Object.create(existentInstance);
7
- addProps(Mnemosyne);
8
- Object.defineProperty(Mnemosyne, 'constructor', {
9
- get () {
10
- return ModificatorType;
11
- },
12
- enumerable : false
13
- });
14
- Object.entries(ModificatorTypePrototype).forEach((entry) => {
15
- const [name, value] = entry;
16
- if (name !== 'constructor') {
17
- (ModificatorType.prototype[name] = value);
18
- }
19
- });
20
- ModificatorType.prototype.constructor = ModificatorType;
21
- Reflect.setPrototypeOf(ModificatorType.prototype, Mnemosyne);
22
- return ModificatorType;
23
- };
24
- return CreateInstanceModificator;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const obeyConstructor_1 = require("./obeyConstructor");
4
+ function default_1() {
5
+ const CreateInstanceModificator = function (ModificatorType, ModificatorTypePrototype, addProps) {
6
+ const existentInstance = this;
7
+ const Mnemosyne = {};
8
+ Reflect.setPrototypeOf(Mnemosyne, existentInstance);
9
+ addProps(Mnemosyne);
10
+ Object.defineProperty(Mnemosyne, 'constructor', {
11
+ get() {
12
+ return ModificatorType;
13
+ },
14
+ enumerable: false
15
+ });
16
+ Object.entries(ModificatorTypePrototype).forEach((entry) => {
17
+ const [name, value] = entry;
18
+ if (name !== 'constructor') {
19
+ (ModificatorType.prototype[name] = value);
20
+ }
21
+ });
22
+ ModificatorType.prototype.constructor = ModificatorType;
23
+ Reflect.setPrototypeOf(ModificatorType.prototype, Mnemosyne);
24
+ (0, obeyConstructor_1.obey)(existentInstance, ModificatorType);
25
+ return ModificatorType;
26
+ };
27
+ return CreateInstanceModificator;
25
28
  }
26
29
  exports.default = default_1;
27
-
@@ -1,31 +1,32 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
3
- function default_1 () {
4
- const CreateInstanceModificatorAncient200XthWay = function (ModificatorType, ModificatorTypePrototype, addProps) {
5
- const existentInstance = this;
6
- const TripleSchemeClosure = function () {
7
- const Mnemosyne = this;
8
- addProps(Mnemosyne);
9
- const Inherico = function () {
10
- const moreInherited = this;
11
- ModificatorType.prototype = moreInherited;
12
- Object.assign(ModificatorType.prototype, ModificatorTypePrototype);
13
- Object.defineProperty(ModificatorType.prototype, 'constructor', {
14
- get () {
15
- return ModificatorType;
16
- },
17
- enumerable : false
18
- });
19
- return ModificatorType;
20
- };
21
- Inherico.prototype = Mnemosyne;
22
- Inherico.prototype.constructor = ModificatorType;
23
- return new Inherico();
24
- };
25
- TripleSchemeClosure.prototype = existentInstance;
26
- return new TripleSchemeClosure();
27
- };
28
- return CreateInstanceModificatorAncient200XthWay;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const obeyConstructor_1 = require("./obeyConstructor");
4
+ function default_1() {
5
+ const CreateInstanceModificatorAncient200XthWay = function (ModificatorType, ModificatorTypePrototype, addProps) {
6
+ const existentInstance = this;
7
+ const TripleSchemeClosure = function () {
8
+ const Mnemosyne = this;
9
+ addProps(Mnemosyne);
10
+ const Inherico = function () {
11
+ const moreInherited = this;
12
+ ModificatorType.prototype = moreInherited;
13
+ Object.assign(ModificatorType.prototype, ModificatorTypePrototype);
14
+ Object.defineProperty(ModificatorType.prototype, 'constructor', {
15
+ get() {
16
+ return ModificatorType;
17
+ },
18
+ enumerable: false
19
+ });
20
+ (0, obeyConstructor_1.obey)(existentInstance, ModificatorType);
21
+ return ModificatorType;
22
+ };
23
+ Inherico.prototype = Mnemosyne;
24
+ Inherico.prototype.constructor = ModificatorType;
25
+ return new Inherico();
26
+ };
27
+ TripleSchemeClosure.prototype = existentInstance;
28
+ return new TripleSchemeClosure();
29
+ };
30
+ return CreateInstanceModificatorAncient200XthWay;
29
31
  }
30
32
  exports.default = default_1;
31
-
@@ -1,181 +1,183 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lookup = exports.define = void 0;
4
- const hop_1 = require('../../utils/hop');
5
- const constants_1 = require('../../constants');
4
+ const hop_1 = require("../../utils/hop");
5
+ const constants_1 = require("../../constants");
6
6
  const { odp, SymbolSubtypeCollection, SymbolConstructorName, SymbolConfig, TYPE_TITLE_PREFIX, MNEMOSYNE, } = constants_1.constants;
7
- const errors_1 = require('../../descriptors/errors');
7
+ const errors_1 = require("../../descriptors/errors");
8
8
  const { ALREADY_DECLARED, WRONG_TYPE_DEFINITION, TYPENAME_MUST_BE_A_STRING, HANDLER_MUST_BE_A_FUNCTION, } = errors_1.ErrorsTypes;
9
- const hooksApi = require('../hooks');
10
- const TypeProxy_1 = require('./TypeProxy');
11
- const compileNewModificatorFunctionBody_1 = require('./compileNewModificatorFunctionBody');
12
- const utils_1 = require('../utils');
9
+ const hooksApi = require("../hooks");
10
+ const TypeProxy_1 = require("./TypeProxy");
11
+ const compileNewModificatorFunctionBody_1 = require("./compileNewModificatorFunctionBody");
12
+ const utils_1 = require("../utils");
13
13
  const { checkProto, getTypeChecker, CreationHandler, getTypeSplitPath, checkTypeName, isClass, } = utils_1.default;
14
- const errors_2 = require('../errors');
14
+ const errors_2 = require("../errors");
15
15
  const TypeDescriptor = function (defineOrigin, types, TypeName, constructHandler, proto, config) {
16
- const parentType = types[SymbolSubtypeCollection] || null;
17
- const isSubType = parentType ? true : false;
18
- const namespace = isSubType ? parentType.namespace : types.namespace;
19
- const collection = isSubType ? parentType.collection : types[MNEMOSYNE];
20
- if (types.has(TypeName)) {
21
- throw new ALREADY_DECLARED;
22
- }
23
- checkProto(proto);
24
- const subtypes = new Map();
25
- const title = `${TYPE_TITLE_PREFIX}${TypeName}`;
26
- config = Object.assign({}, collection[SymbolConfig], config);
27
- const type = Object.assign(this, {
28
- get constructHandler () {
29
- return constructHandler;
30
- },
31
- TypeName,
32
- proto,
33
- isSubType,
34
- subtypes,
35
- parentType,
36
- namespace,
37
- collection,
38
- title,
39
- config,
40
- hooks : Object.create(null)
41
- });
42
- errors_2.getStack.call(this, `Definition of [ ${TypeName} ] made at:`, [], defineOrigin);
43
- odp(subtypes, SymbolSubtypeCollection, {
44
- get () {
45
- return type;
46
- }
47
- });
48
- types.set(TypeName, new TypeProxy_1.TypeProxy(type));
49
- return types.get(TypeName);
16
+ const parentType = types[SymbolSubtypeCollection] || null;
17
+ const isSubType = parentType ? true : false;
18
+ const namespace = isSubType ? parentType.namespace : types.namespace;
19
+ const collection = isSubType ? parentType.collection : types[MNEMOSYNE];
20
+ if (types.has(TypeName)) {
21
+ throw new ALREADY_DECLARED;
22
+ }
23
+ checkProto(proto);
24
+ const subtypes = new Map();
25
+ const title = `${TYPE_TITLE_PREFIX}${TypeName}`;
26
+ config = Object.assign({}, collection[SymbolConfig], config);
27
+ const type = Object.assign(this, {
28
+ get constructHandler() {
29
+ return constructHandler;
30
+ },
31
+ TypeName,
32
+ proto,
33
+ isSubType,
34
+ subtypes,
35
+ parentType,
36
+ namespace,
37
+ collection,
38
+ title,
39
+ config,
40
+ hooks: Object.create(null)
41
+ });
42
+ errors_2.getStack.call(this, `Definition of [ ${TypeName} ] made at:`, [], defineOrigin);
43
+ odp(subtypes, SymbolSubtypeCollection, {
44
+ get() {
45
+ return type;
46
+ }
47
+ });
48
+ types.set(TypeName, new TypeProxy_1.TypeProxy(type));
49
+ return types.get(TypeName);
50
50
  };
51
51
  Object.assign(TypeDescriptor.prototype, hooksApi);
52
52
  TypeDescriptor.prototype.define = function (...args) {
53
- return exports.define.call(exports.define, this.subtypes, ...args);
53
+ return exports.define.call(exports.define, this.subtypes, ...args);
54
54
  };
55
55
  TypeDescriptor.prototype.lookup = function (...args) {
56
- return exports.lookup.call(this.subtypes, ...args);
56
+ return exports.lookup.call(this.subtypes, ...args);
57
57
  };
58
58
  odp(TypeDescriptor.prototype, Symbol.hasInstance, {
59
- get () {
60
- return getTypeChecker(this.TypeName);
61
- }
59
+ get() {
60
+ return getTypeChecker(this.TypeName);
61
+ }
62
62
  });
63
63
  const defineFromType = function (subtypes, constructHandlerGetter, config) {
64
- const type = constructHandlerGetter();
65
- if (typeof type !== 'function') {
66
- throw new HANDLER_MUST_BE_A_FUNCTION;
67
- }
68
- const TypeName = type.name;
69
- if (!TypeName) {
70
- throw new TYPENAME_MUST_BE_A_STRING;
71
- }
72
- const asClass = isClass(type);
73
- const makeConstructHandler = () => {
74
- const constructHandler = constructHandlerGetter();
75
- odp(constructHandler, SymbolConstructorName, {
76
- get () {
77
- return TypeName;
78
- }
79
- });
80
- const protoDesc = Object
81
- .getOwnPropertyDescriptor(constructHandler, 'prototype');
82
- if (protoDesc.writable) {
83
- constructHandler.prototype = {};
84
- }
85
- return constructHandler;
86
- };
87
- if (typeof config === 'object') {
88
- config = Object.assign({}, config);
89
- config.useOldStyle = false;
90
- }
91
- else {
92
- config = {};
93
- }
94
- config.asClass = asClass;
95
- return new TypeDescriptor(this, subtypes, TypeName, makeConstructHandler, type.prototype, config);
64
+ const type = constructHandlerGetter();
65
+ if (typeof type !== 'function') {
66
+ throw new HANDLER_MUST_BE_A_FUNCTION;
67
+ }
68
+ const TypeName = type.name;
69
+ if (!TypeName) {
70
+ throw new TYPENAME_MUST_BE_A_STRING;
71
+ }
72
+ const asClass = isClass(type);
73
+ const makeConstructHandler = () => {
74
+ const constructHandler = constructHandlerGetter();
75
+ odp(constructHandler, SymbolConstructorName, {
76
+ get() {
77
+ return TypeName;
78
+ }
79
+ });
80
+ const protoDesc = Object
81
+ .getOwnPropertyDescriptor(constructHandler, 'prototype');
82
+ if (protoDesc.writable) {
83
+ constructHandler.prototype = {};
84
+ }
85
+ return constructHandler;
86
+ };
87
+ if (typeof config === 'object') {
88
+ config = Object.assign({}, config);
89
+ config.useOldStyle = false;
90
+ }
91
+ else {
92
+ config = {};
93
+ }
94
+ config.asClass = asClass;
95
+ return new TypeDescriptor(this, subtypes, TypeName, makeConstructHandler, type.prototype, config);
96
96
  };
97
97
  const extractNonEnumerableProps = (_obj) => {
98
- const extracted = Object.entries(Object.getOwnPropertyDescriptors(_obj)).reduce((obj, entry) => {
99
- const [name, { value }] = entry;
100
- odp(obj, name, {
101
- value,
102
- configurable : true,
103
- enumerable : true,
104
- writable : true,
105
- });
106
- return obj;
107
- }, {});
108
- return extracted;
98
+ const extracted = Object.entries(Object.getOwnPropertyDescriptors(_obj)).reduce((obj, entry) => {
99
+ const [name, { value }] = entry;
100
+ odp(obj, name, {
101
+ value,
102
+ configurable: true,
103
+ enumerable: true,
104
+ writable: true,
105
+ });
106
+ return obj;
107
+ }, {});
108
+ return extracted;
109
109
  };
110
110
  const defineFromFunction = function (subtypes, TypeName, constructHandler = function () { }, proto, config = {}) {
111
- if (typeof constructHandler !== 'function') {
112
- throw new HANDLER_MUST_BE_A_FUNCTION;
113
- }
114
- const asClass = isClass(constructHandler);
115
- const modificatorBody = compileNewModificatorFunctionBody_1.default(TypeName, asClass);
116
- const makeConstructHandler = modificatorBody(constructHandler, CreationHandler, SymbolConstructorName);
117
- if (!proto) {
118
- if (hop_1.hop(constructHandler, 'prototype')) {
119
- proto = Object.assign({}, constructHandler.prototype);
120
- }
121
- else {
122
- proto = {};
123
- }
124
- }
125
- if (asClass) {
126
- proto = extractNonEnumerableProps(proto);
127
- }
128
- if (typeof config === 'object') {
129
- config = Object.assign({}, config);
130
- }
131
- if (typeof config === 'boolean') {
132
- config = {
133
- useOldStyle : config
134
- };
135
- }
136
- config.asClass = asClass;
137
- return new TypeDescriptor(this, subtypes, TypeName, makeConstructHandler, proto, config);
111
+ if (typeof constructHandler !== 'function') {
112
+ throw new HANDLER_MUST_BE_A_FUNCTION;
113
+ }
114
+ const asClass = isClass(constructHandler);
115
+ const modificatorBody = (0, compileNewModificatorFunctionBody_1.default)(TypeName, asClass);
116
+ const makeConstructHandler = modificatorBody(constructHandler, CreationHandler, SymbolConstructorName);
117
+ if (!proto) {
118
+ if ((0, hop_1.hop)(constructHandler, 'prototype')) {
119
+ proto = Object.assign({}, constructHandler.prototype);
120
+ }
121
+ else {
122
+ proto = {};
123
+ }
124
+ }
125
+ if (asClass) {
126
+ proto = extractNonEnumerableProps(proto);
127
+ }
128
+ if (typeof config === 'object') {
129
+ config = Object.assign({}, config);
130
+ }
131
+ if (typeof config === 'boolean') {
132
+ config = {
133
+ useOldStyle: config
134
+ };
135
+ }
136
+ config.asClass = asClass;
137
+ return new TypeDescriptor(this, subtypes, TypeName, makeConstructHandler, proto, config);
138
138
  };
139
- exports.define = function (subtypes, TypeOrTypeName, constructHandlerOrConfig, proto, config) {
140
- if (typeof TypeOrTypeName === 'function') {
141
- if (TypeOrTypeName.name) {
142
- return exports.define.call(this, subtypes, TypeOrTypeName.name, TypeOrTypeName, constructHandlerOrConfig || TypeOrTypeName.prototype, config);
143
- }
144
- else {
145
- return defineFromType.call(this, subtypes, TypeOrTypeName, constructHandlerOrConfig);
146
- }
147
- }
148
- if (typeof TypeOrTypeName === 'string') {
149
- checkTypeName(TypeOrTypeName);
150
- const split = getTypeSplitPath(TypeOrTypeName);
151
- const Type = exports.lookup.call(subtypes, split[0]);
152
- if (!Type) {
153
- if (split.length === 1) {
154
- return defineFromFunction.call(this, subtypes, TypeOrTypeName, constructHandlerOrConfig, proto, config);
155
- }
156
- throw new WRONG_TYPE_DEFINITION(`${split[0]} definition is not yet exists`);
157
- }
158
- const TypeName = split.slice(1).join('.');
159
- if (split.length > 1) {
160
- return exports.define.call(this, Type.subtypes, TypeName, constructHandlerOrConfig, proto, config);
161
- }
162
- return exports.define.call(this, Type.subtypes, constructHandlerOrConfig, proto, config);
163
- }
164
- throw new WRONG_TYPE_DEFINITION('definition is not provided');
139
+ const define = function (subtypes, TypeOrTypeName, constructHandlerOrConfig, proto, config) {
140
+ if (typeof TypeOrTypeName === 'function') {
141
+ if (TypeOrTypeName.name) {
142
+ return exports.define.call(this, subtypes, TypeOrTypeName.name, TypeOrTypeName, constructHandlerOrConfig || TypeOrTypeName.prototype, config);
143
+ }
144
+ else {
145
+ return defineFromType.call(this, subtypes, TypeOrTypeName, constructHandlerOrConfig);
146
+ }
147
+ }
148
+ if (typeof TypeOrTypeName === 'string') {
149
+ checkTypeName(TypeOrTypeName);
150
+ const split = getTypeSplitPath(TypeOrTypeName);
151
+ const Type = exports.lookup.call(subtypes, split[0]);
152
+ if (!Type) {
153
+ if (split.length === 1) {
154
+ return defineFromFunction.call(this, subtypes, TypeOrTypeName, constructHandlerOrConfig, proto, config);
155
+ }
156
+ throw new WRONG_TYPE_DEFINITION(`${split[0]} definition is not yet exists`);
157
+ }
158
+ const TypeName = split.slice(1).join('.');
159
+ if (split.length > 1) {
160
+ return exports.define.call(this, Type.subtypes, TypeName, constructHandlerOrConfig, proto, config);
161
+ }
162
+ return exports.define.call(this, Type.subtypes, constructHandlerOrConfig, proto, config);
163
+ }
164
+ throw new WRONG_TYPE_DEFINITION('definition is not provided');
165
165
  };
166
- exports.lookup = function (TypeNestedPath) {
167
- if (typeof TypeNestedPath !== 'string') {
168
- throw new WRONG_TYPE_DEFINITION('arg : type nested path must be a string');
169
- }
170
- if (!TypeNestedPath.length) {
171
- throw new WRONG_TYPE_DEFINITION('arg : type nested path has no path');
172
- }
173
- const split = getTypeSplitPath(TypeNestedPath);
174
- const [name] = split;
175
- const type = this.get(name);
176
- if (split.length === 1) {
177
- return type;
178
- }
179
- const NextNestedPath = split.slice(1).join('.');
180
- return exports.lookup.call(type.subtypes, NextNestedPath);
166
+ exports.define = define;
167
+ const lookup = function (TypeNestedPath) {
168
+ if (typeof TypeNestedPath !== 'string') {
169
+ throw new WRONG_TYPE_DEFINITION('arg : type nested path must be a string');
170
+ }
171
+ if (!TypeNestedPath.length) {
172
+ throw new WRONG_TYPE_DEFINITION('arg : type nested path has no path');
173
+ }
174
+ const split = getTypeSplitPath(TypeNestedPath);
175
+ const [name] = split;
176
+ const type = this.get(name);
177
+ if (split.length === 1) {
178
+ return type;
179
+ }
180
+ const NextNestedPath = split.slice(1).join('.');
181
+ return exports.lookup.call(type.subtypes, NextNestedPath);
181
182
  };
183
+ exports.lookup = lookup;
@@ -0,0 +1 @@
1
+ export declare const obey: (existentInstance: any, ModificatorType: any) => void;
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.obey = void 0;
4
+ const constants_1 = require("../../constants");
5
+ const { SymbolUsed } = constants_1.constants;
6
+ const errors_1 = require("../../descriptors/errors");
7
+ const { PROTOTYPE_USED_TWICE, } = errors_1.ErrorsTypes;
8
+ const obey = (existentInstance, ModificatorType) => {
9
+ let protoConstructor = ModificatorType;
10
+ while (protoConstructor instanceof Function) {
11
+ if (Object.prototype.hasOwnProperty.call(protoConstructor, SymbolUsed) && protoConstructor[SymbolUsed]) {
12
+ const error = new PROTOTYPE_USED_TWICE(`${protoConstructor.name}.prototype > ${ModificatorType.name}`);
13
+ throw error;
14
+ }
15
+ const sample = Reflect.getPrototypeOf(protoConstructor);
16
+ if (sample instanceof Function) {
17
+ protoConstructor = sample;
18
+ }
19
+ else {
20
+ Object.defineProperty(protoConstructor, SymbolUsed, {
21
+ get() {
22
+ return true;
23
+ }
24
+ });
25
+ break;
26
+ }
27
+ }
28
+ Reflect.setPrototypeOf(protoConstructor, existentInstance.constructor);
29
+ };
30
+ exports.obey = obey;
@@ -1,17 +1,29 @@
1
- import { TypeModificator } from '../../types';
1
+ export type asyncStack = {
2
+ __stack__?: string;
3
+ __type__: {
4
+ isSubType: boolean;
5
+ };
6
+ parent: () => asyncStack;
7
+ };
8
+ type parentSub = {
9
+ __type__: {
10
+ subtypes: Map<string, parentSub>;
11
+ };
12
+ __parent__: parentSub;
13
+ };
2
14
  declare const TypesUtils: {
3
15
  isClass: (fn: CallableFunction) => boolean;
4
- CreationHandler: (this: any, constructionAnswer: any) => any;
16
+ CreationHandler: (this: unknown, constructionAnswer: unknown) => unknown;
5
17
  getModificationConstructor: (useOldStyle: boolean) => (this: any, ModificatorType: CallableFunction, ModificatorTypePrototype: {
6
18
  [index: string]: any;
7
19
  }, addProps: CallableFunction) => any;
8
- checkProto: (proto: any) => void;
9
- getTypeChecker: (TypeName: string) => any;
20
+ checkProto: (proto: unknown) => void;
21
+ getTypeChecker: (TypeName: string) => unknown;
10
22
  getTypeSplitPath: (path: string) => string[];
11
- getExistentAsyncStack: (existentInstance: any) => any[];
23
+ getExistentAsyncStack: (existentInstance: asyncStack) => unknown;
12
24
  checkTypeName: (name: string) => void;
13
- findParentSubType: any;
14
- makeFakeModificatorType: (TypeName: string, fakeModificator?: TypeModificator<{}>) => any;
15
- reflectPrimitiveWrappers: (_thisArg: any) => any;
25
+ findParentSubType: (instance: parentSub, prop: string) => parentSub;
26
+ makeFakeModificatorType: (TypeName: string, fakeModificator?: () => void) => any;
27
+ reflectPrimitiveWrappers: (_thisArg: unknown) => unknown;
16
28
  };
17
29
  export default TypesUtils;