mnemonica 0.9.953 → 0.9.955
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/types/InstanceCreator.d.ts +1 -1
- package/build/api/utils/index.d.ts +20 -8
- package/build/index.d.ts +22 -11
- package/build/index.js +18 -5
- package/build/types/index.d.ts +9 -8
- package/package.json +11 -11
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,6 +1,6 @@
|
|
|
1
1
|
import { ConstructorFunction } from '../../types';
|
|
2
2
|
export declare const InstanceCreator: ConstructorFunction<{
|
|
3
|
-
getExistentAsyncStack: (existentInstance:
|
|
3
|
+
getExistentAsyncStack: (existentInstance: import("../utils").asyncStack) => unknown;
|
|
4
4
|
postProcessing: (this: any, continuationOf: any) => void;
|
|
5
5
|
bindMethod: (this: any, instance: any, methodName: string, MethodItself: any) => void;
|
|
6
6
|
bindProtoMethods: (this: any) => void;
|
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
|
|
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:
|
|
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:
|
|
9
|
-
getTypeChecker: (TypeName: string) =>
|
|
20
|
+
checkProto: (proto: unknown) => void;
|
|
21
|
+
getTypeChecker: (TypeName: string) => unknown;
|
|
10
22
|
getTypeSplitPath: (path: string) => string[];
|
|
11
|
-
getExistentAsyncStack: (existentInstance:
|
|
23
|
+
getExistentAsyncStack: (existentInstance: asyncStack) => unknown;
|
|
12
24
|
checkTypeName: (name: string) => void;
|
|
13
|
-
findParentSubType:
|
|
14
|
-
makeFakeModificatorType: (TypeName: string, fakeModificator?:
|
|
15
|
-
reflectPrimitiveWrappers: (_thisArg:
|
|
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;
|
package/build/index.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TypeLookup, IDEF } from './types';
|
|
2
2
|
export type { IDEF } from './types';
|
|
3
3
|
export declare const defaultTypes: any;
|
|
4
4
|
type Proto<P, T> = Pick<P, Exclude<keyof P, keyof T>> & T;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
define: IDefinitor<M, IN>;
|
|
5
|
+
type RN = Record<string | symbol, unknown>;
|
|
6
|
+
type SN = Record<string | symbol, new () => unknown>;
|
|
7
|
+
interface IDefinitorInstance<N extends RN, S> {
|
|
8
|
+
new (): {
|
|
9
|
+
[key in keyof S]: S[key];
|
|
11
10
|
};
|
|
11
|
+
define: IDefinitor<N, string>;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
interface IDefinitor<P extends RN, SubTypeName extends string> {
|
|
14
|
+
<PP extends RN, T extends RN, M extends Proto<P, Proto<PP, T>>, S extends SN & M>(this: unknown, TypeName: SubTypeName, constructHandler: IDEF<T>, proto?: PP, config?: object): IDefinitorInstance<M, S>;
|
|
15
|
+
}
|
|
16
|
+
export declare const define: <T extends RN, P extends RN, N extends Proto<P, T>, SubTypeName extends string, NC extends SN, S extends NC & N, R extends {
|
|
14
17
|
new (): { [key in keyof S]: S[key]; };
|
|
15
|
-
define: IDefinitor<N,
|
|
16
|
-
};
|
|
17
|
-
export declare const tsdefine: <T>(this: unknown, TypeName: string, constructHandler: IDEF<T>, proto?: object, config?: object) => ITypeClass<T>;
|
|
18
|
+
define: IDefinitor<N, SubTypeName>;
|
|
19
|
+
}>(this: unknown, TypeName: string, constructHandler: IDEF<T>, proto?: P | undefined, config?: {}) => R;
|
|
18
20
|
export declare const lookup: TypeLookup;
|
|
19
21
|
export declare const mnemonica: {
|
|
20
22
|
[index: string]: unknown;
|
|
@@ -24,3 +26,12 @@ export declare const defaultCollection: any;
|
|
|
24
26
|
export declare const errors: any;
|
|
25
27
|
export { utils } from './utils';
|
|
26
28
|
export { defineStackCleaner } from './utils';
|
|
29
|
+
export declare function apply<E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>, args: unknown[]): {
|
|
30
|
+
[key in keyof S]: S[key];
|
|
31
|
+
};
|
|
32
|
+
export declare function call<E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>, ...args: unknown[]): {
|
|
33
|
+
[key in keyof S]: S[key];
|
|
34
|
+
};
|
|
35
|
+
export declare function bind<E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>): (...args: unknown[]) => {
|
|
36
|
+
[key in keyof S]: S[key];
|
|
37
|
+
};
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineStackCleaner = exports.utils = exports.errors = exports.defaultCollection = exports.createTypesCollection = exports.defaultNamespace = exports.namespaces = exports.createNamespace = exports.ErrorMessages = exports.TYPE_TITLE_PREFIX = exports.URANUS = exports.GAIA = exports.MNEMOSYNE = exports.MNEMONICA = exports.SymbolConfig = exports.SymbolDefaultTypesCollection = exports.SymbolDefaultNamespace = exports.SymbolReplaceGaia = exports.SymbolGaia = exports.SymbolConstructorName = exports.SymbolSubtypeCollection = exports.mnemonica = exports.lookup = exports.
|
|
3
|
+
exports.bind = exports.call = exports.apply = exports.defineStackCleaner = exports.utils = exports.errors = exports.defaultCollection = exports.createTypesCollection = exports.defaultNamespace = exports.namespaces = exports.createNamespace = exports.ErrorMessages = exports.TYPE_TITLE_PREFIX = exports.URANUS = exports.GAIA = exports.MNEMOSYNE = exports.MNEMONICA = exports.SymbolConfig = exports.SymbolDefaultTypesCollection = exports.SymbolDefaultNamespace = exports.SymbolReplaceGaia = exports.SymbolGaia = exports.SymbolConstructorName = exports.SymbolSubtypeCollection = exports.mnemonica = exports.lookup = exports.define = exports.defaultTypes = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const { odp } = constants_1.constants;
|
|
6
6
|
const errorsApi = require("./api/errors");
|
|
@@ -14,10 +14,6 @@ const define = function (TypeName, constructHandler, proto, config = {}) {
|
|
|
14
14
|
return types.define(TypeName, constructHandler, proto, config);
|
|
15
15
|
};
|
|
16
16
|
exports.define = define;
|
|
17
|
-
const tsdefine = function (TypeName, constructHandler, proto, config) {
|
|
18
|
-
return exports.defaultTypes.define(TypeName, constructHandler, proto, config);
|
|
19
|
-
};
|
|
20
|
-
exports.tsdefine = tsdefine;
|
|
21
17
|
exports.lookup = function (TypeNestedPath) {
|
|
22
18
|
const types = checkThis(this) ? exports.defaultTypes : this || exports.defaultTypes;
|
|
23
19
|
return types.lookup(TypeNestedPath);
|
|
@@ -40,3 +36,20 @@ var utils_1 = require("./utils");
|
|
|
40
36
|
Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return utils_1.utils; } });
|
|
41
37
|
var utils_2 = require("./utils");
|
|
42
38
|
Object.defineProperty(exports, "defineStackCleaner", { enumerable: true, get: function () { return utils_2.defineStackCleaner; } });
|
|
39
|
+
function apply(entity, Constructor, args) {
|
|
40
|
+
const result = Constructor.apply(entity, args);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
exports.apply = apply;
|
|
44
|
+
function call(entity, Constructor, ...args) {
|
|
45
|
+
const result = Constructor.call(entity, ...args);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
exports.call = call;
|
|
49
|
+
function bind(entity, Constructor) {
|
|
50
|
+
return (...args) => {
|
|
51
|
+
const result = Constructor.call(entity, ...args);
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.bind = bind;
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
type RN = Record<string | symbol, unknown>;
|
|
2
|
+
export type IDEF<T extends RN> = {
|
|
3
|
+
new (): T;
|
|
4
|
+
} | {
|
|
5
|
+
(this: T): void;
|
|
6
|
+
};
|
|
1
7
|
export interface ConstructorFunction<ConstructorInstance extends object> {
|
|
2
8
|
new (...args: unknown[]): ConstructorInstance;
|
|
3
9
|
(this: ConstructorInstance, ...args: unknown[]): ConstructorInstance;
|
|
4
10
|
prototype: ConstructorInstance;
|
|
5
11
|
}
|
|
6
|
-
export type TypeModificator<T extends object> = (...args: unknown[]) => ConstructorFunction<T>;
|
|
7
12
|
export type TypeLookup = (this: Map<string, unknown>, TypeNestedPath: string) => TypeClass;
|
|
8
13
|
export type TypeClass = {
|
|
9
14
|
new (...args: unknown[]): unknown;
|
|
@@ -12,16 +17,12 @@ export type TypeClass = {
|
|
|
12
17
|
registerHook: (type: 'preCreation' | 'postCreation' | 'creationError', hook: CallableFunction) => unknown;
|
|
13
18
|
};
|
|
14
19
|
export type TypeAbsorber = (this: unknown, TypeName: string, constructHandler: CallableFunction, proto?: object, config?: object) => TypeClass;
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
} | {
|
|
18
|
-
(this: T): void;
|
|
19
|
-
};
|
|
20
|
-
export type ITypeAbsorber<T> = (this: unknown, TypeName: string, constructHandler: IDEF<T>, proto?: object, config?: object) => ITypeClass<T>;
|
|
21
|
-
export interface ITypeClass<T> {
|
|
20
|
+
export type ITypeAbsorber<T extends RN> = (this: unknown, TypeName: string, constructHandler: IDEF<T>, proto?: object, config?: object) => ITypeClass<T>;
|
|
21
|
+
export interface ITypeClass<T extends RN> {
|
|
22
22
|
new (...args: unknown[]): T;
|
|
23
23
|
(this: T, ...args: unknown[]): T;
|
|
24
24
|
define: ITypeAbsorber<T>;
|
|
25
25
|
lookup: TypeLookup;
|
|
26
26
|
registerHook: (type: 'preCreation' | 'postCreation' | 'creationError', hook: CallableFunction) => unknown;
|
|
27
27
|
}
|
|
28
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mnemonica",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.955",
|
|
4
4
|
"description": "abstract technique that aids information retention : instance inheritance system",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -63,25 +63,25 @@
|
|
|
63
63
|
},
|
|
64
64
|
"homepage": "https://github.com/wentout/mnemonica#readme",
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@types/jest": "^29.5.
|
|
67
|
-
"@types/node": "^18.
|
|
66
|
+
"@types/jest": "^29.5.7",
|
|
67
|
+
"@types/node": "^18.18.8",
|
|
68
68
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
69
69
|
"@typescript-eslint/parser": "^5.62.0",
|
|
70
|
-
"chai": "^4.3.
|
|
71
|
-
"eslint": "^8.
|
|
72
|
-
"eslint-plugin-import": "^2.
|
|
73
|
-
"eslint-plugin-mocha": "^10.
|
|
70
|
+
"chai": "^4.3.10",
|
|
71
|
+
"eslint": "^8.52.0",
|
|
72
|
+
"eslint-plugin-import": "^2.29.0",
|
|
73
|
+
"eslint-plugin-mocha": "^10.2.0",
|
|
74
74
|
"eslint-plugin-no-arrow-this": "^1.2.0",
|
|
75
75
|
"husky": "^8.0.3",
|
|
76
|
-
"jest": "^29.
|
|
76
|
+
"jest": "^29.7.0",
|
|
77
77
|
"json5": "^2.2.3",
|
|
78
|
-
"lint-staged": "^13.
|
|
78
|
+
"lint-staged": "^13.3.0",
|
|
79
79
|
"mocha": "^10.2.0",
|
|
80
80
|
"mocha-lcov-reporter": "^1.3.0",
|
|
81
81
|
"nyc": "^15.1.0",
|
|
82
82
|
"ts-jest": "^29.1.1",
|
|
83
|
-
"typescript": "^5.
|
|
84
|
-
"yaml": "^2.3.
|
|
83
|
+
"typescript": "^5.2.2",
|
|
84
|
+
"yaml": "^2.3.4"
|
|
85
85
|
},
|
|
86
86
|
"engines": {
|
|
87
87
|
"node": ">=14"
|