From 7da19433f4d1067406ad9f3a1e30a7e957b1497e Mon Sep 17 00:00:00 2001 From: wentout Date: Wed, 8 Nov 2023 21:06:11 +0300 Subject: [PATCH] types improvements --- build/index.d.ts | 12 +++------- build/index.js | 41 +++++++++++++++++--------------- package-lock.json | 4 ++-- package.json | 2 +- src/index.ts | 60 ++++++++++++++++++++++++----------------------- 5 files changed, 59 insertions(+), 60 deletions(-) diff --git a/build/index.d.ts b/build/index.d.ts index 106efcc..79528e7 100644 --- a/build/index.d.ts +++ b/build/index.d.ts @@ -18,6 +18,9 @@ export declare const define: ; }>(this: unknown, TypeName?: string, constructHandler?: IDEF | undefined, proto?: P | undefined, config?: {}) => R; export declare const lookup: TypeLookup; +export declare const apply: >(entity: E, Constructor: IDEF, args?: unknown[]) => { [key in keyof S]: S[key]; }; +export declare const call: >(entity: E, Constructor: IDEF, ...args: unknown[]) => { [key in keyof S]: S[key]; }; +export declare const bind: >(entity: E, Constructor: IDEF) => (...args: unknown[]) => { [key in keyof S]: S[key]; }; export declare const mnemonica: { [index: string]: unknown; }; @@ -26,12 +29,3 @@ export declare const defaultCollection: any; export declare const errors: any; export { utils } from './utils'; export { defineStackCleaner } from './utils'; -export declare function apply>(entity: E, Constructor: IDEF, args?: unknown[]): { - [key in keyof S]: S[key]; -}; -export declare function call>(entity: E, Constructor: IDEF, ...args: unknown[]): { - [key in keyof S]: S[key]; -}; -export declare function bind>(entity: E, Constructor: IDEF): (...args: unknown[]) => { - [key in keyof S]: S[key]; -}; diff --git a/build/index.js b/build/index.js index d5bd2e8..561d546 100644 --- a/build/index.js +++ b/build/index.js @@ -1,6 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); -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; +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.bind = exports.call = exports.apply = exports.lookup = exports.define = exports.defaultTypes = void 0; const constants_1 = require("./constants"); const { odp } = constants_1.constants; const errorsApi = require("./api/errors"); @@ -18,8 +18,28 @@ exports.lookup = function (TypeNestedPath) { const types = checkThis(this) ? exports.defaultTypes : this || exports.defaultTypes; return types.lookup(TypeNestedPath); }; +const apply = function (entity, Constructor, args) { + const result = Constructor.apply(entity, args); + return result; +}; +exports.apply = apply; +const call = function (entity, Constructor, ...args) { + const result = Constructor.call(entity, ...args); + return result; +}; +exports.call = call; +const bind = function (entity, Constructor) { + return (...args) => { + const result = Constructor.call(entity, ...args); + return result; + }; +}; +exports.bind = bind; exports.mnemonica = Object.entries(Object.assign(Object.assign(Object.assign({ define: exports.define, - lookup: exports.lookup }, descriptors_1.descriptors), errorsApi), constants_1.constants)).reduce((acc, entry) => { + lookup: exports.lookup, + apply: exports.apply, + call: exports.call, + bind: exports.bind }, descriptors_1.descriptors), errorsApi), constants_1.constants)).reduce((acc, entry) => { const [name, code] = entry; odp(acc, name, { get() { @@ -36,20 +56,3 @@ var utils_1 = require("./utils"); Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return utils_1.utils; } }); var utils_2 = require("./utils"); Object.defineProperty(exports, "defineStackCleaner", { enumerable: true, get: function () { return utils_2.defineStackCleaner; } }); -function apply(entity, Constructor, args) { - const result = Constructor.apply(entity, args); - return result; -} -exports.apply = apply; -function call(entity, Constructor, ...args) { - const result = Constructor.call(entity, ...args); - return result; -} -exports.call = call; -function bind(entity, Constructor) { - return (...args) => { - const result = Constructor.call(entity, ...args); - return result; - }; -} -exports.bind = bind; diff --git a/package-lock.json b/package-lock.json index d82cca4..808b443 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mnemonica", - "version": "0.9.957", + "version": "0.9.958", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mnemonica", - "version": "0.9.957", + "version": "0.9.958", "license": "MIT", "devDependencies": { "@types/jest": "^29.5.8", diff --git a/package.json b/package.json index 6eea00b..281909e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mnemonica", - "version": "0.9.957", + "version": "0.9.958", "description": "abstract technique that aids information retention : instance inheritance system", "type": "commonjs", "main": "./build/index.js", diff --git a/src/index.ts b/src/index.ts index a0d44a9..273b724 100644 --- a/src/index.ts +++ b/src/index.ts @@ -85,10 +85,41 @@ export const lookup = function (TypeNestedPath) { return types.lookup(TypeNestedPath); } as TypeLookup; +export const apply = function > (entity: E, Constructor: IDEF, args?: unknown[]): { + [key in keyof S]: S[key] +} { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const result = Constructor.apply(entity, args); + return result; +}; + +export const call = function > (entity: E, Constructor: IDEF, ...args: unknown[]): { + [key in keyof S]: S[key] +} { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const result = Constructor.call(entity, ...args); + return result; +}; + +export const bind = function > (entity: E, Constructor: IDEF): (...args: unknown[]) => { + [key in keyof S]: S[key] +} { + return (...args) => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const result = Constructor.call(entity, ...args); + return result; + }; +}; export const mnemonica = Object.entries({ define, lookup, + apply, + call, + bind, ...descriptors, @@ -134,32 +165,3 @@ export const errors = descriptors.ErrorsTypes; export { utils } from './utils'; export { defineStackCleaner } from './utils'; - -export function apply > (entity: E, Constructor: IDEF, args?: unknown[]): { - [key in keyof S]: S[key] -} { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const result = Constructor.apply(entity, args); - return result; -} - -export function call > (entity: E, Constructor: IDEF, ...args: unknown[]): { - [key in keyof S]: S[key] -} { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const result = Constructor.call(entity, ...args); - return result; -} - -export function bind > (entity: E, Constructor: IDEF): (...args: unknown[]) => { - [key in keyof S]: S[key] -} { - return (...args) => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const result = Constructor.call(entity, ...args); - return result; - }; -}