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.
Files changed (48) hide show
  1. package/README.md +40 -13
  2. package/build/api/errors/bindedMethodErrorHandler.js +50 -50
  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 +45 -45
  6. package/build/api/errors/throwModificationError.js +94 -94
  7. package/build/api/hooks/flowCheckers.d.ts +1 -1
  8. package/build/api/hooks/flowCheckers.js +9 -9
  9. package/build/api/hooks/index.js +7 -7
  10. package/build/api/hooks/invokeHook.js +44 -44
  11. package/build/api/hooks/registerHook.js +17 -17
  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 +1 -1
  15. package/build/api/types/InstanceCreator.js +237 -237
  16. package/build/api/types/InstanceModificator.js +8 -8
  17. package/build/api/types/Mnemosyne.d.ts +2 -2
  18. package/build/api/types/Mnemosyne.js +127 -127
  19. package/build/api/types/TypeProxy.js +132 -132
  20. package/build/api/types/addProps.js +60 -60
  21. package/build/api/types/compileNewModificatorFunctionBody.d.ts +1 -1
  22. package/build/api/types/compileNewModificatorFunctionBody.js +37 -27
  23. package/build/api/types/createInstanceModificator.js +26 -27
  24. package/build/api/types/createInstanceModificator200XthWay.js +29 -30
  25. package/build/api/types/index.js +157 -157
  26. package/build/api/types/obeyConstructor.js +23 -23
  27. package/build/api/utils/index.d.ts +20 -8
  28. package/build/api/utils/index.js +122 -122
  29. package/build/constants/index.js +61 -61
  30. package/build/descriptors/errors/index.js +7 -7
  31. package/build/descriptors/index.js +5 -5
  32. package/build/descriptors/namespaces/index.js +70 -70
  33. package/build/descriptors/types/index.js +141 -141
  34. package/build/index.d.ts +39 -5
  35. package/build/index.js +63 -32
  36. package/build/types/index.d.ts +16 -17
  37. package/build/types/index.js +1 -1
  38. package/build/utils/collectConstructors.js +50 -50
  39. package/build/utils/defineStackCleaner.js +7 -7
  40. package/build/utils/extract.js +14 -14
  41. package/build/utils/hop.js +1 -1
  42. package/build/utils/index.js +27 -27
  43. package/build/utils/merge.js +13 -13
  44. package/build/utils/parent.js +15 -15
  45. package/build/utils/parse.js +40 -40
  46. package/build/utils/pick.js +19 -19
  47. package/build/utils/toJSON.js +25 -25
  48. package/package.json +92 -92
package/README.md CHANGED
@@ -10,10 +10,8 @@ abstract technique that aids information retention : instance inheritance system
10
10
 
11
11
  # shortcuts
12
12
 
13
- * ?. : state : **mad science**
14
13
  * ?. : type : **asynchronous monad descriptor** => this
15
14
  * ?. : prod ready : **we wonder about**
16
- * ?. : typescript : **yes, some, starting from 0.9.77**
17
15
  * ?. : example : **git clone && npm run example**
18
16
 
19
17
  ---
@@ -28,17 +26,6 @@ abstract technique that aids information retention : instance inheritance system
28
26
 
29
27
  ---
30
28
 
31
- # TypeScript note
32
-
33
- If you are TypeScript user we have good news for you:
34
- * there is more than one way to annotate the code
35
- * we provide support with some limitations
36
- * and you can help to do better
37
-
38
- Please visit [Mnemonica TypeScript](https://github.com/wentout/mnemonica/blob/master/TypeScript.md) page for explanations.
39
-
40
- ---
41
-
42
29
 
43
30
  # core concept
44
31
 
@@ -49,6 +36,13 @@ This lib might help to create some sort of order or sequence or precedence of ho
49
36
  * [Dead Simple type checker for JavaScript](https://dev.to/wentout/dead-simple-type-checker-for-javascript-4l40)
50
37
 
51
38
 
39
+ ## TypeScript note
40
+
41
+ **define** function now fully supports TypeScript definitions
42
+
43
+ for more easy types writing nested~sub constructors might be applied using just direct apply, call or bind functions
44
+
45
+
52
46
  ## Factory of Constructors
53
47
 
54
48
  As we discrovered from that article, we need some tooling, giving us the best experience with Prototype Chain Inheritance pattern. First of all it must be reproducible and maintainable. And from the first point we have to define some sort of Factory Constructor for start crafting our Instances, it might look like so:
@@ -645,6 +639,39 @@ usingReactAsProto.render("just works", root);
645
639
 
646
640
  ```
647
641
 
642
+
643
+ # call, apply & bind ( existent, ItsNestedType, ...args)
644
+
645
+ mostly for TypeScript purpose you may do this
646
+
647
+ ```js
648
+ const SomeType = define('SomeType', function () {
649
+ // ...
650
+ });
651
+
652
+
653
+ const SomeSubType = SomeType
654
+ .define('SomeSubType', function (...args) {
655
+ // ...
656
+ });
657
+
658
+ const someInstance = new SomeType;
659
+
660
+ const someSubInstance = call(
661
+ someInstance, SomeSubType, ...args);
662
+
663
+ // or for array of args
664
+ const someSubInstance = apply(
665
+ someInstance, SomeSubType, args);
666
+
667
+ // or for delayed construction
668
+ const someSubInstanceConstructor =
669
+ bind( someInstance, SomeSubType );
670
+
671
+ const someSubInstance = someSubInstanceConstructor(...args);
672
+
673
+ ```
674
+
648
675
  # Asynchronous Constructors
649
676
  First of all you should understand what you wish to are doing!
650
677
  Then you should understand what you wish. And only after doing so you might use this technic:
@@ -1,56 +1,56 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bindedMethodErrorHandler = void 0;
4
- const constants_1 = require('../../constants');
4
+ const constants_1 = require("../../constants");
5
5
  const { odp, } = constants_1.constants;
6
6
  const bindedMethodErrorHandler = (exceptionReason) => {
7
- const { applyTo, args, method, asNew, error } = exceptionReason;
8
- const reThrown = error.exceptionReason !== undefined;
9
- if (reThrown) {
10
- error.reasons.push(exceptionReason);
11
- error.surplus.push(error);
12
- return error;
13
- }
14
- else {
15
- odp(error, 'exceptionReason', {
16
- get () {
17
- return exceptionReason;
18
- },
19
- enumerable : true
20
- });
21
- const reasons = [exceptionReason];
22
- odp(error, 'reasons', {
23
- get () {
24
- return reasons;
25
- },
26
- enumerable : true
27
- });
28
- const surplus = [];
29
- odp(error, 'surplus', {
30
- get () {
31
- return surplus;
32
- },
33
- enumerable : true
34
- });
35
- }
36
- if (applyTo && applyTo.exception instanceof Function) {
37
- let preparedException = error;
38
- try {
39
- preparedException = new applyTo.exception(error, {
40
- args,
41
- exceptionReasonMethod : method,
42
- exceptionReasonObject : applyTo,
43
- reasonsIsNew : asNew
44
- });
45
- }
46
- catch (additionalError) {
47
- error.surplus.push(additionalError);
48
- return error;
49
- }
50
- if (preparedException instanceof Error) {
51
- return preparedException;
52
- }
53
- }
54
- return error;
7
+ const { applyTo, args, method, asNew, error } = exceptionReason;
8
+ const reThrown = error.exceptionReason !== undefined;
9
+ if (reThrown) {
10
+ error.reasons.push(exceptionReason);
11
+ error.surplus.push(error);
12
+ return error;
13
+ }
14
+ else {
15
+ odp(error, 'exceptionReason', {
16
+ get() {
17
+ return exceptionReason;
18
+ },
19
+ enumerable: true
20
+ });
21
+ const reasons = [exceptionReason];
22
+ odp(error, 'reasons', {
23
+ get() {
24
+ return reasons;
25
+ },
26
+ enumerable: true
27
+ });
28
+ const surplus = [];
29
+ odp(error, 'surplus', {
30
+ get() {
31
+ return surplus;
32
+ },
33
+ enumerable: true
34
+ });
35
+ }
36
+ if (applyTo && applyTo.exception instanceof Function) {
37
+ let preparedException = error;
38
+ try {
39
+ preparedException = new applyTo.exception(error, {
40
+ args,
41
+ exceptionReasonMethod: method,
42
+ exceptionReasonObject: applyTo,
43
+ reasonsIsNew: asNew
44
+ });
45
+ }
46
+ catch (additionalError) {
47
+ error.surplus.push(additionalError);
48
+ return error;
49
+ }
50
+ if (preparedException instanceof Error) {
51
+ return preparedException;
52
+ }
53
+ }
54
+ return error;
55
55
  };
56
56
  exports.bindedMethodErrorHandler = bindedMethodErrorHandler;
@@ -1,110 +1,110 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
3
- const constants_1 = require('../../constants');
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../../constants");
4
4
  const { odp } = constants_1.constants;
5
- const errors_1 = require('../../descriptors/errors');
5
+ const errors_1 = require("../../descriptors/errors");
6
6
  const { WRONG_ARGUMENTS_USED, WRONG_INSTANCE_INVOCATION } = errors_1.ErrorsTypes;
7
- const errors_2 = require('../errors');
8
- const utils_1 = require('../../utils');
7
+ const errors_2 = require("../errors");
8
+ const utils_1 = require("../../utils");
9
9
  const { parse } = utils_1.utils;
10
- const utils_2 = require('../utils');
10
+ const utils_2 = require("../utils");
11
11
  const { makeFakeModificatorType } = utils_2.default;
12
- const InstanceModificator_1 = require('../types/InstanceModificator');
12
+ const InstanceModificator_1 = require("../types/InstanceModificator");
13
13
  const checkThrowArgs = (instance, target, error, args) => {
14
- let wrongThrow;
15
- if (!target) {
16
- throw new WRONG_INSTANCE_INVOCATION('exception should be made with new keyword');
17
- }
18
- if (!(error instanceof Error)) {
19
- wrongThrow = new WRONG_ARGUMENTS_USED('error must be instanceof Error');
20
- }
21
- if (!(wrongThrow instanceof Error)) {
22
- return;
23
- }
24
- odp(wrongThrow, 'instance', {
25
- get () {
26
- return instance;
27
- }
28
- });
29
- odp(wrongThrow, 'error', {
30
- get () {
31
- return error;
32
- }
33
- });
34
- odp(wrongThrow, 'args', {
35
- get () {
36
- return args;
37
- }
38
- });
39
- throw wrongThrow;
14
+ let wrongThrow;
15
+ if (!target) {
16
+ throw new WRONG_INSTANCE_INVOCATION('exception should be made with new keyword');
17
+ }
18
+ if (!(error instanceof Error)) {
19
+ wrongThrow = new WRONG_ARGUMENTS_USED('error must be instanceof Error');
20
+ }
21
+ if (!(wrongThrow instanceof Error)) {
22
+ return;
23
+ }
24
+ odp(wrongThrow, 'instance', {
25
+ get() {
26
+ return instance;
27
+ }
28
+ });
29
+ odp(wrongThrow, 'error', {
30
+ get() {
31
+ return error;
32
+ }
33
+ });
34
+ odp(wrongThrow, 'args', {
35
+ get() {
36
+ return args;
37
+ }
38
+ });
39
+ throw wrongThrow;
40
40
  };
41
41
  const exceptionConsctructHandler = function (opts) {
42
- const { instance, TypeName, typeStack, args, error } = opts;
43
- const exception = this;
44
- odp(exception, 'args', {
45
- get () {
46
- return args;
47
- }
48
- });
49
- odp(exception, 'originalError', {
50
- get () {
51
- return error;
52
- }
53
- });
54
- odp(exception, 'instance', {
55
- get () {
56
- return instance;
57
- }
58
- });
59
- odp(exception, 'extract', {
60
- get () {
61
- return () => {
62
- return instance.extract();
63
- };
64
- }
65
- });
66
- odp(exception, 'parse', {
67
- get () {
68
- return () => {
69
- return parse(instance);
70
- };
71
- }
72
- });
73
- const errorStack = exception.stack.split('\n');
74
- const stack = [];
75
- const title = `\n<-- lifecycle of [ ${TypeName} ] traced -->`;
76
- errors_2.getStack.call(exception, title, [], prepareException);
77
- stack.push(...exception.stack);
78
- stack.push('<-- with the following error -->');
79
- errorStack.forEach((line) => {
80
- if (!stack.includes(line)) {
81
- stack.push(line);
82
- }
83
- });
84
- stack.push('\n<-- of constructor definitions stack -->');
85
- stack.push(...typeStack);
86
- exception.stack = errors_2.cleanupStack(stack).join('\n');
87
- return exception;
42
+ const { instance, TypeName, typeStack, args, error } = opts;
43
+ const exception = this;
44
+ odp(exception, 'args', {
45
+ get() {
46
+ return args;
47
+ }
48
+ });
49
+ odp(exception, 'originalError', {
50
+ get() {
51
+ return error;
52
+ }
53
+ });
54
+ odp(exception, 'instance', {
55
+ get() {
56
+ return instance;
57
+ }
58
+ });
59
+ odp(exception, 'extract', {
60
+ get() {
61
+ return () => {
62
+ return instance.extract();
63
+ };
64
+ }
65
+ });
66
+ odp(exception, 'parse', {
67
+ get() {
68
+ return () => {
69
+ return parse(instance);
70
+ };
71
+ }
72
+ });
73
+ const errorStack = exception.stack.split('\n');
74
+ const stack = [];
75
+ const title = `\n<-- lifecycle of [ ${TypeName} ] traced -->`;
76
+ errors_2.getStack.call(exception, title, [], prepareException);
77
+ stack.push(...exception.stack);
78
+ stack.push('<-- with the following error -->');
79
+ errorStack.forEach((line) => {
80
+ if (!stack.includes(line)) {
81
+ stack.push(line);
82
+ }
83
+ });
84
+ stack.push('\n<-- of constructor definitions stack -->');
85
+ stack.push(...typeStack);
86
+ exception.stack = (0, errors_2.cleanupStack)(stack).join('\n');
87
+ return exception;
88
88
  };
89
89
  const prepareException = function (target, error, ...args) {
90
- const instance = this;
91
- checkThrowArgs(instance, target, error, args);
92
- const { __type__, __creator__ } = instance;
93
- const { stack: typeStack, TypeName } = __type__;
94
- const ExceptionCreator = Object.create(__creator__);
95
- ExceptionCreator.config = Object.assign({}, __creator__.config);
96
- ExceptionCreator.config.blockErrors = false;
97
- ExceptionCreator.existentInstance = error;
98
- ExceptionCreator.ModificatorType = makeFakeModificatorType(TypeName, function () {
99
- return exceptionConsctructHandler.call(this, {
100
- instance,
101
- TypeName,
102
- typeStack,
103
- args,
104
- error
105
- });
106
- });
107
- ExceptionCreator.InstanceModificator = InstanceModificator_1.makeInstanceModificator(ExceptionCreator);
108
- return new ExceptionCreator.InstanceModificator();
90
+ const instance = this;
91
+ checkThrowArgs(instance, target, error, args);
92
+ const { __type__, __creator__ } = instance;
93
+ const { stack: typeStack, TypeName } = __type__;
94
+ const ExceptionCreator = Object.create(__creator__);
95
+ ExceptionCreator.config = Object.assign({}, __creator__.config);
96
+ ExceptionCreator.config.blockErrors = false;
97
+ ExceptionCreator.existentInstance = error;
98
+ ExceptionCreator.ModificatorType = makeFakeModificatorType(TypeName, function () {
99
+ return exceptionConsctructHandler.call(this, {
100
+ instance,
101
+ TypeName,
102
+ typeStack,
103
+ args,
104
+ error
105
+ });
106
+ });
107
+ ExceptionCreator.InstanceModificator = (0, InstanceModificator_1.makeInstanceModificator)(ExceptionCreator);
108
+ return new ExceptionCreator.InstanceModificator();
109
109
  };
110
110
  exports.default = prepareException;
@@ -1,6 +1,6 @@
1
1
  export declare const stackCleaners: RegExp[];
2
2
  export declare const cleanupStack: (stack: string[]) => string[];
3
- export declare const getStack: (this: any, title: string, stackAddition: string[], tillFunction?: CallableFunction | undefined) => any;
3
+ export declare const getStack: (this: any, title: string, stackAddition: string[], tillFunction?: CallableFunction) => any;
4
4
  export declare class BASE_MNEMONICA_ERROR extends Error {
5
5
  constructor(message: string | undefined, additionalStack: string[]);
6
6
  }
@@ -1,61 +1,61 @@
1
1
  'use strict';
2
- Object.defineProperty(exports, '__esModule', { value : true });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.constructError = exports.BASE_MNEMONICA_ERROR = exports.getStack = exports.cleanupStack = exports.stackCleaners = void 0;
4
- const constants_1 = require('../../constants');
4
+ const constants_1 = require("../../constants");
5
5
  const { odp, SymbolConstructorName, MNEMONICA, ErrorMessages, } = constants_1.constants;
6
6
  const { BASE_ERROR_MESSAGE } = ErrorMessages;
7
7
  exports.stackCleaners = [];
8
8
  const cleanupStack = (stack) => {
9
- const cleaned = stack.reduce((arr, line) => {
10
- exports.stackCleaners.forEach(cleanerRegExp => {
11
- if (!cleanerRegExp.test(line)) {
12
- arr.push(line);
13
- }
14
- });
15
- return arr;
16
- }, []);
17
- return cleaned.length ? cleaned : stack;
9
+ const cleaned = stack.reduce((arr, line) => {
10
+ exports.stackCleaners.forEach(cleanerRegExp => {
11
+ if (!cleanerRegExp.test(line)) {
12
+ arr.push(line);
13
+ }
14
+ });
15
+ return arr;
16
+ }, []);
17
+ return cleaned.length ? cleaned : stack;
18
18
  };
19
19
  exports.cleanupStack = cleanupStack;
20
20
  const getStack = function (title, stackAddition, tillFunction) {
21
- if (Error.captureStackTrace) {
22
- Error.captureStackTrace(this, tillFunction || exports.getStack);
23
- }
24
- else {
25
- this.stack = (new Error()).stack;
26
- }
27
- this.stack = this.stack.split('\n').slice(1);
28
- this.stack = exports.cleanupStack(this.stack);
29
- this.stack.unshift(title);
30
- if (Array.isArray(stackAddition) && stackAddition.length) {
31
- this.stack.push(...stackAddition);
32
- }
33
- this.stack.push('\n');
34
- return this.stack;
21
+ if (Error.captureStackTrace) {
22
+ Error.captureStackTrace(this, tillFunction || exports.getStack);
23
+ }
24
+ else {
25
+ this.stack = (new Error()).stack;
26
+ }
27
+ this.stack = this.stack.split('\n').slice(1);
28
+ this.stack = (0, exports.cleanupStack)(this.stack);
29
+ this.stack.unshift(title);
30
+ if (Array.isArray(stackAddition) && stackAddition.length) {
31
+ this.stack.push(...stackAddition);
32
+ }
33
+ this.stack.push('\n');
34
+ return this.stack;
35
35
  };
36
36
  exports.getStack = getStack;
37
37
  class BASE_MNEMONICA_ERROR extends Error {
38
- constructor (message = BASE_ERROR_MESSAGE, additionalStack) {
39
- super(message);
40
- const BaseStack = this.stack;
41
- odp(this, 'BaseStack', {
42
- get () {
43
- return BaseStack;
44
- }
45
- });
46
- const stack = exports.cleanupStack(BaseStack.split('\n'));
47
- if (additionalStack) {
48
- stack.unshift(...additionalStack);
49
- }
50
- this.stack = stack.join('\n');
51
- }
52
- static get [SymbolConstructorName] () {
53
- return `base of : ${MNEMONICA} : errors`;
54
- }
38
+ constructor(message = BASE_ERROR_MESSAGE, additionalStack) {
39
+ super(message);
40
+ const BaseStack = this.stack;
41
+ odp(this, 'BaseStack', {
42
+ get() {
43
+ return BaseStack;
44
+ }
45
+ });
46
+ const stack = (0, exports.cleanupStack)(BaseStack.split('\n'));
47
+ if (additionalStack) {
48
+ stack.unshift(...additionalStack);
49
+ }
50
+ this.stack = stack.join('\n');
51
+ }
52
+ static get [SymbolConstructorName]() {
53
+ return `base of : ${MNEMONICA} : errors`;
54
+ }
55
55
  }
56
56
  exports.BASE_MNEMONICA_ERROR = BASE_MNEMONICA_ERROR;
57
57
  const constructError = (name, message) => {
58
- const body = `
58
+ const body = `
59
59
  class ${name} extends base {
60
60
  constructor (addition, stack) {
61
61
  super(addition ?
@@ -67,7 +67,7 @@ const constructError = (name, message) => {
67
67
  };
68
68
  return ${name};
69
69
  `;
70
- const ErrorConstructor = (new Function('base', body))(BASE_MNEMONICA_ERROR);
71
- return ErrorConstructor;
70
+ const NamedErrorConstructor = (new Function('base', body))(BASE_MNEMONICA_ERROR);
71
+ return NamedErrorConstructor;
72
72
  };
73
73
  exports.constructError = constructError;