Skip to content

Commit

Permalink
Merge pull request #150 from wentout/proto
Browse files Browse the repository at this point in the history
types improvements
  • Loading branch information
wentout authored Nov 8, 2023
2 parents d375a14 + 7da1943 commit 7cf81af
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 60 deletions.
12 changes: 3 additions & 9 deletions build/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export declare const define: <T extends RN, P extends object, N extends Proto<P,
define: IDefinitor<N, SubTypeName>;
}>(this: unknown, TypeName?: string, constructHandler?: IDEF<T> | undefined, proto?: P | undefined, config?: {}) => R;
export declare const lookup: TypeLookup;
export declare const apply: <E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>, args?: unknown[]) => { [key in keyof S]: S[key]; };
export declare const call: <E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>, ...args: unknown[]) => { [key in keyof S]: S[key]; };
export declare const bind: <E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>) => (...args: unknown[]) => { [key in keyof S]: S[key]; };
export declare const mnemonica: {
[index: string]: unknown;
};
Expand All @@ -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<E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>, args?: unknown[]): {
[key in keyof S]: S[key];
};
export declare function call<E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>, ...args: unknown[]): {
[key in keyof S]: S[key];
};
export declare function bind<E extends RN, T extends RN, S extends Proto<E, T>>(entity: E, Constructor: IDEF<T>): (...args: unknown[]) => {
[key in keyof S]: S[key];
};
41 changes: 22 additions & 19 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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() {
Expand All @@ -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;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
60 changes: 31 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,41 @@ export const lookup = function (TypeNestedPath) {
return types.lookup(TypeNestedPath);
} as TypeLookup;

export const apply = function <E extends RN, T extends RN, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>, 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 <E extends RN, T extends RN, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>, ...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 <E extends RN, T extends RN, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>): (...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,

Expand Down Expand Up @@ -134,32 +165,3 @@ export const errors = descriptors.ErrorsTypes;

export { utils } from './utils';
export { defineStackCleaner } from './utils';

export function apply <E extends RN, T extends RN, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>, 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 <E extends RN, T extends RN, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>, ...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 <E extends RN, T extends RN, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>): (...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;
};
}

0 comments on commit 7cf81af

Please sign in to comment.