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,264 +1,262 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InstanceCreator = void 0;
4
- const constants_1 = require('../../constants');
4
+ const constants_1 = require("../../constants");
5
5
  const { odp, SymbolConstructorName, } = constants_1.constants;
6
- const errors_1 = require('../../descriptors/errors');
6
+ const errors_1 = require("../../descriptors/errors");
7
7
  const { WRONG_MODIFICATION_PATTERN, } = errors_1.ErrorsTypes;
8
- const utils_1 = require('../utils');
8
+ const utils_1 = require("../utils");
9
9
  const { getModificationConstructor, getExistentAsyncStack, makeFakeModificatorType, } = utils_1.default;
10
- const errors_2 = require('../errors');
11
- const throwModificationError_1 = require('../errors/throwModificationError');
12
- const bindedMethodErrorHandler_1 = require('../errors/bindedMethodErrorHandler');
13
- const InstanceCreatorProto_1 = require('./InstanceCreatorProto');
14
- const InstanceModificator_1 = require('./InstanceModificator');
10
+ const errors_2 = require("../errors");
11
+ const throwModificationError_1 = require("../errors/throwModificationError");
12
+ const bindedMethodErrorHandler_1 = require("../errors/bindedMethodErrorHandler");
13
+ const addProps_1 = require("./addProps");
14
+ const InstanceModificator_1 = require("./InstanceModificator");
15
15
  const invokePreHooks = function () {
16
- const { type, existentInstance, args, InstanceModificator } = this;
17
- const { namespace, collection, } = type;
18
- const hookData = {
19
- type,
20
- existentInstance,
21
- args,
22
- InstanceModificator
23
- };
24
- namespace.invokeHook('preCreation', hookData);
25
- collection.invokeHook('preCreation', hookData);
26
- type.invokeHook('preCreation', hookData);
16
+ const { type, existentInstance, args, InstanceModificator } = this;
17
+ const { namespace, collection, } = type;
18
+ const hookData = {
19
+ type,
20
+ existentInstance,
21
+ args,
22
+ InstanceModificator
23
+ };
24
+ namespace.invokeHook('preCreation', hookData);
25
+ collection.invokeHook('preCreation', hookData);
26
+ type.invokeHook('preCreation', hookData);
27
27
  };
28
28
  const invokePostHooks = function () {
29
- const creator = this;
30
- const { inheritedInstance, } = creator;
31
- const { __type__: type, __parent__: existentInstance, __args__: args, } = inheritedInstance;
32
- const { namespace, collection, } = type;
33
- const hookType = inheritedInstance instanceof Error ?
34
- 'creationError' : 'postCreation';
35
- const hookData = {
36
- type,
37
- existentInstance,
38
- inheritedInstance,
39
- args,
40
- creator
41
- };
42
- return {
43
- type : type.invokeHook(hookType, hookData),
44
- collection : collection.invokeHook(hookType, hookData),
45
- namespace : namespace.invokeHook(hookType, hookData)
46
- };
29
+ const creator = this;
30
+ const { inheritedInstance, } = creator;
31
+ const { __type__: type, __parent__: existentInstance, __args__: args, } = inheritedInstance;
32
+ const { namespace, collection, } = type;
33
+ const hookType = inheritedInstance instanceof Error ?
34
+ 'creationError' : 'postCreation';
35
+ const hookData = {
36
+ type,
37
+ existentInstance,
38
+ inheritedInstance,
39
+ args,
40
+ creator
41
+ };
42
+ return {
43
+ type: type.invokeHook(hookType, hookData),
44
+ collection: collection.invokeHook(hookType, hookData),
45
+ namespace: namespace.invokeHook(hookType, hookData)
46
+ };
47
47
  };
48
48
  const bindMethod = function (instance, methodName, MethodItself) {
49
- odp(instance, methodName, {
50
- get () {
51
- const from = this;
52
- return function (...args) {
53
- const applyTo = this !== undefined ? this : from;
54
- const exceptionReason = {
55
- method : MethodItself,
56
- methodName,
57
- this : this,
58
- from,
59
- instance,
60
- applyTo,
61
- asNew : false,
62
- args,
63
- };
64
- try {
65
- let answer;
66
- if (new.target) {
67
- exceptionReason.asNew = true;
68
- answer = new MethodItself(...args);
69
- }
70
- else {
71
- answer = MethodItself.call(applyTo, ...args);
72
- }
73
- if (answer instanceof Promise) {
74
- answer = answer.catch((error) => {
75
- odp(exceptionReason, 'error', {
76
- value : error,
77
- enumerable : true
78
- });
79
- throw bindedMethodErrorHandler_1.bindedMethodErrorHandler(exceptionReason);
80
- });
81
- }
82
- return answer;
83
- }
84
- catch (error) {
85
- odp(exceptionReason, 'error', {
86
- value : error,
87
- enumerable : true
88
- });
89
- throw bindedMethodErrorHandler_1.bindedMethodErrorHandler(exceptionReason);
90
- }
91
- };
92
- },
93
- enumerable : true
94
- });
49
+ odp(instance, methodName, {
50
+ get() {
51
+ const from = this;
52
+ return function (...args) {
53
+ const applyTo = this !== undefined ? this : from;
54
+ const exceptionReason = {
55
+ method: MethodItself,
56
+ methodName,
57
+ this: this,
58
+ from,
59
+ instance,
60
+ applyTo,
61
+ asNew: false,
62
+ args,
63
+ };
64
+ try {
65
+ let answer;
66
+ if (new.target) {
67
+ exceptionReason.asNew = true;
68
+ answer = new MethodItself(...args);
69
+ }
70
+ else {
71
+ answer = MethodItself.call(applyTo, ...args);
72
+ }
73
+ if (answer instanceof Promise) {
74
+ answer = answer.catch((error) => {
75
+ odp(exceptionReason, 'error', {
76
+ value: error,
77
+ enumerable: true
78
+ });
79
+ throw (0, bindedMethodErrorHandler_1.bindedMethodErrorHandler)(exceptionReason);
80
+ });
81
+ }
82
+ return answer;
83
+ }
84
+ catch (error) {
85
+ odp(exceptionReason, 'error', {
86
+ value: error,
87
+ enumerable: true
88
+ });
89
+ throw (0, bindedMethodErrorHandler_1.bindedMethodErrorHandler)(exceptionReason);
90
+ }
91
+ };
92
+ },
93
+ enumerable: true
94
+ });
95
95
  };
96
96
  const bindProtoMethods = function () {
97
- const self = this;
98
- const { inheritedInstance, proto, } = self;
99
- const protoPointer = Reflect.getPrototypeOf(inheritedInstance);
100
- Object.entries(protoPointer).forEach((entry) => {
101
- const [mayBeMethodName, MayBeMethodFunction] = entry;
102
- if (mayBeMethodName === 'constructor') {
103
- return;
104
- }
105
- if (MayBeMethodFunction instanceof Function && proto[mayBeMethodName] instanceof Function) {
106
- bindMethod(protoPointer, mayBeMethodName, MayBeMethodFunction);
107
- }
108
- });
97
+ const self = this;
98
+ const { inheritedInstance, proto, } = self;
99
+ const protoPointer = Reflect.getPrototypeOf(inheritedInstance);
100
+ Object.entries(protoPointer).forEach((entry) => {
101
+ const [mayBeMethodName, MayBeMethodFunction] = entry;
102
+ if (mayBeMethodName === 'constructor') {
103
+ return;
104
+ }
105
+ if (MayBeMethodFunction instanceof Function && proto[mayBeMethodName] instanceof Function) {
106
+ bindMethod(protoPointer, mayBeMethodName, MayBeMethodFunction);
107
+ }
108
+ });
109
109
  };
110
110
  const postProcessing = function (continuationOf) {
111
- const self = this;
112
- const { stack, config: { bindedProto }, } = self;
113
- if (!self.inheritedInstance.constructor) {
114
- const msg = 'should inherit from mnemonica instance';
115
- self.throwModificationError(new WRONG_MODIFICATION_PATTERN(msg, stack));
116
- }
117
- if (!self.inheritedInstance.constructor[SymbolConstructorName]) {
118
- const msg = 'should inherit from mnemonica instance';
119
- self.throwModificationError(new WRONG_MODIFICATION_PATTERN(msg, stack));
120
- }
121
- if (continuationOf && !(self.inheritedInstance instanceof continuationOf)) {
122
- const icn = self.inheritedInstance.constructor.name;
123
- const msg = `should inherit from ${continuationOf.TypeName} but got ${icn}`;
124
- self.throwModificationError(new WRONG_MODIFICATION_PATTERN(msg, stack));
125
- }
126
- odp(self.inheritedInstance, '__self__', {
127
- get () {
128
- return self.inheritedInstance;
129
- }
130
- });
131
- self.invokePostHooks();
132
- if (bindedProto) {
133
- self.bindProtoMethods();
134
- }
111
+ const self = this;
112
+ const { stack, config: { bindedProto }, } = self;
113
+ if (!self.inheritedInstance.constructor) {
114
+ const msg = 'should inherit from mnemonica instance';
115
+ self.throwModificationError(new WRONG_MODIFICATION_PATTERN(msg, stack));
116
+ }
117
+ if (!self.inheritedInstance.constructor[SymbolConstructorName]) {
118
+ const msg = 'should inherit from mnemonica instance';
119
+ self.throwModificationError(new WRONG_MODIFICATION_PATTERN(msg, stack));
120
+ }
121
+ if (continuationOf && !(self.inheritedInstance instanceof continuationOf)) {
122
+ const icn = self.inheritedInstance.constructor.name;
123
+ const msg = `should inherit from ${continuationOf.TypeName} but got ${icn}`;
124
+ self.throwModificationError(new WRONG_MODIFICATION_PATTERN(msg, stack));
125
+ }
126
+ odp(self.inheritedInstance, '__self__', {
127
+ get() {
128
+ return self.inheritedInstance;
129
+ }
130
+ });
131
+ self.invokePostHooks();
132
+ if (bindedProto) {
133
+ self.bindProtoMethods();
134
+ }
135
135
  };
136
136
  const addThen = function (then) {
137
- const self = this;
138
- self.inheritedInstance = self.inheritedInstance
139
- .then(() => {
140
- self.inheritedInstance =
137
+ const self = this;
138
+ self.inheritedInstance = self.inheritedInstance
139
+ .then(() => {
140
+ self.inheritedInstance =
141
141
  new exports.InstanceCreator(then.subtype, self.inheritedInstance, then.args, true);
142
- return self.inheritedInstance;
143
- });
142
+ return self.inheritedInstance;
143
+ });
144
144
  };
145
145
  const makeWaiter = function (type, then) {
146
- const self = this;
147
- self.inheritedInstance = self.inheritedInstance
148
- .then((instance) => {
149
- if (typeof instance !== 'object') {
150
- if (self.config.awaitReturn) {
151
- const msg = `should inherit from ${type.TypeName}: seems async ${type.TypeName} has no return statement`;
152
- throw new WRONG_MODIFICATION_PATTERN(msg, self.stack);
153
- }
154
- else {
155
- return instance;
156
- }
157
- }
158
- if (!(instance instanceof self.type)) {
159
- const icn = instance.constructor.name;
160
- const msg = `should inherit from ${type.TypeName} but got ${icn}`;
161
- throw new WRONG_MODIFICATION_PATTERN(msg, self.stack);
162
- }
163
- self.inheritedInstance = instance;
164
- if (self.inheritedInstance.__self__ !== self.inheritedInstance) {
165
- self.postProcessing(type);
166
- }
167
- return self.inheritedInstance;
168
- })
169
- .catch((error) => {
170
- if (self.config.blockErrors) {
171
- self.throwModificationError(error);
172
- }
173
- else {
174
- throw error;
175
- }
176
- });
177
- if (then) {
178
- self.addThen(then);
179
- }
180
- type.subtypes.forEach((subtype, name) => {
181
- self.inheritedInstance[name] = (...args) => {
182
- self.inheritedInstance = self.makeWaiter(subtype, {
183
- name,
184
- subtype,
185
- args,
186
- });
187
- return self.inheritedInstance;
188
- };
189
- });
190
- return self.inheritedInstance;
146
+ const self = this;
147
+ self.inheritedInstance = self.inheritedInstance
148
+ .then((instance) => {
149
+ if (typeof instance !== 'object') {
150
+ if (self.config.awaitReturn) {
151
+ const msg = `should inherit from ${type.TypeName}: seems async ${type.TypeName} has no return statement`;
152
+ throw new WRONG_MODIFICATION_PATTERN(msg, self.stack);
153
+ }
154
+ else {
155
+ return instance;
156
+ }
157
+ }
158
+ if (!(instance instanceof self.type)) {
159
+ const icn = instance.constructor.name;
160
+ const msg = `should inherit from ${type.TypeName} but got ${icn}`;
161
+ throw new WRONG_MODIFICATION_PATTERN(msg, self.stack);
162
+ }
163
+ self.inheritedInstance = instance;
164
+ if (self.inheritedInstance.__self__ !== self.inheritedInstance) {
165
+ self.postProcessing(type);
166
+ }
167
+ return self.inheritedInstance;
168
+ })
169
+ .catch((error) => {
170
+ if (self.config.blockErrors) {
171
+ self.throwModificationError(error);
172
+ }
173
+ else {
174
+ throw error;
175
+ }
176
+ });
177
+ if (then) {
178
+ self.addThen(then);
179
+ }
180
+ type.subtypes.forEach((subtype, name) => {
181
+ self.inheritedInstance[name] = (...args) => {
182
+ self.inheritedInstance = self.makeWaiter(subtype, {
183
+ name,
184
+ subtype,
185
+ args,
186
+ });
187
+ return self.inheritedInstance;
188
+ };
189
+ });
190
+ return self.inheritedInstance;
191
191
  };
192
192
  const InstanceCreatorPrototype = {
193
- getExistentAsyncStack,
194
- postProcessing,
195
- bindMethod,
196
- bindProtoMethods,
197
- makeWaiter,
198
- proceedProto : InstanceCreatorProto_1.proceedProto,
199
- addProps : InstanceCreatorProto_1.addProps,
200
- addThen,
201
- undefineParentSubTypes : InstanceCreatorProto_1.undefineParentSubTypes,
202
- invokePreHooks,
203
- invokePostHooks,
204
- throwModificationError : throwModificationError_1.throwModificationError
193
+ getExistentAsyncStack,
194
+ postProcessing,
195
+ bindMethod,
196
+ bindProtoMethods,
197
+ makeWaiter,
198
+ addProps: addProps_1.addProps,
199
+ addThen,
200
+ invokePreHooks,
201
+ invokePostHooks,
202
+ throwModificationError: throwModificationError_1.throwModificationError
205
203
  };
206
204
  exports.InstanceCreator = function (type, existentInstance, args, chained) {
207
- const { constructHandler, proto, config, TypeName } = type;
208
- const { useOldStyle, blockErrors, submitStack } = config;
209
- const self = this;
210
- const ModificationConstructor = getModificationConstructor(useOldStyle);
211
- const ModificatorType = constructHandler();
212
- Object.assign(self, {
213
- type,
214
- TypeName,
215
- existentInstance,
216
- get args () {
217
- return args;
218
- },
219
- ModificationConstructor,
220
- ModificatorType,
221
- config,
222
- proto
223
- });
224
- if (submitStack || chained) {
225
- const stackAddition = chained ? self.getExistentAsyncStack(existentInstance) : [];
226
- const title = `\n<-- creation of [ ${TypeName} ] traced -->`;
227
- if (submitStack) {
228
- errors_2.getStack.call(self, title, stackAddition);
229
- }
230
- else {
231
- self.stack = title;
232
- }
233
- }
234
- if (blockErrors && existentInstance instanceof Error) {
235
- self.ModificatorType = makeFakeModificatorType(TypeName);
236
- self.InstanceModificator = InstanceModificator_1.makeInstanceModificator(self);
237
- throw new self.InstanceModificator(...args);
238
- }
239
- self.invokePreHooks();
240
- self.InstanceModificator = InstanceModificator_1.makeInstanceModificator(self);
241
- if (blockErrors) {
242
- try {
243
- self.inheritedInstance = new self.InstanceModificator(...args);
244
- }
245
- catch (error) {
246
- self.throwModificationError(error);
247
- }
248
- }
249
- else {
250
- self.inheritedInstance = new self.InstanceModificator(...args);
251
- }
252
- if (self.inheritedInstance instanceof Promise) {
253
- const waiter = self.makeWaiter(type);
254
- odp(waiter, SymbolConstructorName, {
255
- get () {
256
- return TypeName;
257
- }
258
- });
259
- return waiter;
260
- }
261
- self.postProcessing(type);
262
- return self.inheritedInstance;
205
+ const { constructHandler, proto, config, TypeName } = type;
206
+ const { useOldStyle, blockErrors, submitStack } = config;
207
+ const self = this;
208
+ const ModificationConstructor = getModificationConstructor(useOldStyle);
209
+ const ModificatorType = constructHandler();
210
+ Object.assign(self, {
211
+ type,
212
+ TypeName,
213
+ existentInstance,
214
+ get args() {
215
+ return args;
216
+ },
217
+ ModificationConstructor,
218
+ ModificatorType,
219
+ config,
220
+ proto
221
+ });
222
+ if (submitStack || chained) {
223
+ const stackAddition = chained ? self.getExistentAsyncStack(existentInstance) : [];
224
+ const title = `\n<-- creation of [ ${TypeName} ] traced -->`;
225
+ if (submitStack) {
226
+ errors_2.getStack.call(self, title, stackAddition);
227
+ }
228
+ else {
229
+ self.stack = title;
230
+ }
231
+ }
232
+ if (blockErrors && existentInstance instanceof Error) {
233
+ self.ModificatorType = makeFakeModificatorType(TypeName);
234
+ self.InstanceModificator = (0, InstanceModificator_1.makeInstanceModificator)(self);
235
+ throw new self.InstanceModificator(...args);
236
+ }
237
+ self.invokePreHooks();
238
+ self.InstanceModificator = (0, InstanceModificator_1.makeInstanceModificator)(self);
239
+ if (blockErrors) {
240
+ try {
241
+ self.inheritedInstance = new self.InstanceModificator(...args);
242
+ }
243
+ catch (error) {
244
+ self.throwModificationError(error);
245
+ }
246
+ }
247
+ else {
248
+ self.inheritedInstance = new self.InstanceModificator(...args);
249
+ }
250
+ if (self.inheritedInstance instanceof Promise) {
251
+ const waiter = self.makeWaiter(type);
252
+ odp(waiter, SymbolConstructorName, {
253
+ get() {
254
+ return TypeName;
255
+ }
256
+ });
257
+ return waiter;
258
+ }
259
+ self.postProcessing(type);
260
+ return self.inheritedInstance;
263
261
  };
264
262
  Object.assign(exports.InstanceCreator.prototype, InstanceCreatorPrototype);
@@ -1,11 +1,13 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeInstanceModificator = void 0;
4
- const InstanceCreatorProto_1 = require('./InstanceCreatorProto');
5
- exports.makeInstanceModificator = (self) => {
6
- const { ModificationConstructor, existentInstance, ModificatorType, proto, } = self;
7
- return ModificationConstructor.call(existentInstance, ModificatorType, Object.assign({}, proto), (__proto_proto__) => {
8
- self.__proto_proto__ = __proto_proto__;
9
- InstanceCreatorProto_1.proceedProto.call(self);
10
- });
4
+ const addProps_1 = require("./addProps");
5
+ const makeInstanceModificator = (self) => {
6
+ const { ModificationConstructor, existentInstance, ModificatorType, proto, } = self;
7
+ const result = ModificationConstructor.call(existentInstance, ModificatorType, Object.assign({}, proto), (__proto_proto__) => {
8
+ self.__proto_proto__ = __proto_proto__;
9
+ addProps_1.addProps.call(self);
10
+ });
11
+ return result;
11
12
  };
13
+ exports.makeInstanceModificator = makeInstanceModificator;
@@ -1,8 +1,8 @@
1
1
  import { ConstructorFunction } from '../../types';
2
2
  declare const _default: {
3
- Gaia: ConstructorFunction<{}>;
3
+ Gaia: ConstructorFunction<object>;
4
4
  Mnemosyne: ConstructorFunction<{
5
- [x: string]: (this: any) => any;
5
+ [x: symbol]: (() => (this: any, uranus: any) => void) | (() => string);
6
6
  extract(): (this: any) => {
7
7
  [index: string]: any;
8
8
  };
@@ -13,6 +13,7 @@ declare const _default: {
13
13
  clone(this: any): any;
14
14
  fork(this: any): (this: any, ...forkArgs: any[]) => any;
15
15
  exception(): (error: Error, ...args: any[]) => any;
16
+ sibling(): (SiblingTypeName: string) => any;
16
17
  }>;
17
18
  readonly MnemosynePrototypeKeys: string[];
18
19
  };