mnemonica 0.9.94 → 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.
- package/README.md +40 -13
- package/build/api/errors/bindedMethodErrorHandler.js +50 -50
- package/build/api/errors/exceptionConstructor.js +98 -98
- package/build/api/errors/index.d.ts +1 -1
- package/build/api/errors/index.js +45 -45
- package/build/api/errors/throwModificationError.js +94 -94
- package/build/api/hooks/flowCheckers.d.ts +1 -1
- package/build/api/hooks/flowCheckers.js +9 -9
- package/build/api/hooks/index.js +7 -7
- package/build/api/hooks/invokeHook.js +44 -44
- package/build/api/hooks/registerHook.js +17 -17
- package/build/api/index.d.ts +1 -1
- package/build/api/index.js +9 -9
- package/build/api/types/InstanceCreator.d.ts +1 -1
- package/build/api/types/InstanceCreator.js +237 -237
- package/build/api/types/InstanceModificator.js +8 -8
- package/build/api/types/Mnemosyne.d.ts +2 -2
- package/build/api/types/Mnemosyne.js +127 -127
- package/build/api/types/TypeProxy.js +132 -132
- package/build/api/types/addProps.js +60 -60
- package/build/api/types/compileNewModificatorFunctionBody.d.ts +1 -1
- package/build/api/types/compileNewModificatorFunctionBody.js +37 -27
- package/build/api/types/createInstanceModificator.js +26 -27
- package/build/api/types/createInstanceModificator200XthWay.js +29 -30
- package/build/api/types/index.js +157 -157
- package/build/api/types/obeyConstructor.js +23 -23
- package/build/api/utils/index.d.ts +20 -8
- package/build/api/utils/index.js +122 -122
- package/build/constants/index.js +61 -61
- package/build/descriptors/errors/index.js +7 -7
- package/build/descriptors/index.js +5 -5
- package/build/descriptors/namespaces/index.js +70 -70
- package/build/descriptors/types/index.js +141 -141
- package/build/index.d.ts +39 -5
- package/build/index.js +63 -32
- package/build/types/index.d.ts +16 -17
- package/build/types/index.js +1 -1
- package/build/utils/collectConstructors.js +50 -50
- package/build/utils/defineStackCleaner.js +7 -7
- package/build/utils/extract.js +14 -14
- package/build/utils/hop.js +1 -1
- package/build/utils/index.js +27 -27
- package/build/utils/merge.js +13 -13
- package/build/utils/parent.js +15 -15
- package/build/utils/parse.js +40 -40
- package/build/utils/pick.js +19 -19
- package/build/utils/toJSON.js +25 -25
- package/package.json +92 -92
|
@@ -1,262 +1,262 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
Object.defineProperty(exports,
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InstanceCreator = void 0;
|
|
4
|
-
const constants_1 = require(
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
5
|
const { odp, SymbolConstructorName, } = constants_1.constants;
|
|
6
|
-
const errors_1 = require(
|
|
6
|
+
const errors_1 = require("../../descriptors/errors");
|
|
7
7
|
const { WRONG_MODIFICATION_PATTERN, } = errors_1.ErrorsTypes;
|
|
8
|
-
const utils_1 = require(
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
9
|
const { getModificationConstructor, getExistentAsyncStack, makeFakeModificatorType, } = utils_1.default;
|
|
10
|
-
const errors_2 = require(
|
|
11
|
-
const throwModificationError_1 = require(
|
|
12
|
-
const bindedMethodErrorHandler_1 = require(
|
|
13
|
-
const addProps_1 = require(
|
|
14
|
-
const InstanceModificator_1 = require(
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
143
|
-
|
|
142
|
+
return self.inheritedInstance;
|
|
143
|
+
});
|
|
144
144
|
};
|
|
145
145
|
const makeWaiter = function (type, then) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
|
203
203
|
};
|
|
204
204
|
exports.InstanceCreator = function (type, existentInstance, args, chained) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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;
|
|
261
261
|
};
|
|
262
262
|
Object.assign(exports.InstanceCreator.prototype, InstanceCreatorPrototype);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
Object.defineProperty(exports,
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeInstanceModificator = void 0;
|
|
4
|
-
const addProps_1 = require(
|
|
4
|
+
const addProps_1 = require("./addProps");
|
|
5
5
|
const makeInstanceModificator = (self) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
12
|
};
|
|
13
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:
|
|
5
|
+
[x: symbol]: (() => (this: any, uranus: any) => void) | (() => string);
|
|
6
6
|
extract(): (this: any) => {
|
|
7
7
|
[index: string]: any;
|
|
8
8
|
};
|