Socket
Socket
Sign inDemoInstall

@deepkit/core

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deepkit/core - npm Package Compare versions

Comparing version 1.0.1-alpha.1 to 1.0.1-alpha.3

dist/src/parameter-names.d.ts

3

dist/index.d.ts

@@ -6,3 +6,2 @@ export * from './src/core';

export * from './src/timer';
export * from './src/meta-data';
export * from './src/process-locker';

@@ -14,1 +13,3 @@ export * from './src/network';

export * from './src/emitter';
export * from './src/reactive';
export * from './src/reflection';

@@ -1,25 +0,14 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./src/core"), exports);
__exportStar(require("./src/decorators"), exports);
__exportStar(require("./src/enum"), exports);
__exportStar(require("./src/iterators"), exports);
__exportStar(require("./src/timer"), exports);
__exportStar(require("./src/meta-data"), exports);
__exportStar(require("./src/process-locker"), exports);
__exportStar(require("./src/network"), exports);
__exportStar(require("./src/perf"), exports);
__exportStar(require("./src/compiler"), exports);
__exportStar(require("./src/string"), exports);
__exportStar(require("./src/emitter"), exports);
export * from './src/core';
export * from './src/decorators';
export * from './src/enum';
export * from './src/iterators';
export * from './src/timer';
export * from './src/process-locker';
export * from './src/network';
export * from './src/perf';
export * from './src/compiler';
export * from './src/string';
export * from './src/emitter';
export * from './src/reactive';
export * from './src/reflection';
//# sourceMappingURL=index.js.map
export declare class CompilerContext {
readonly context: Map<string, any>;
maxReservedVariable: number;
/**
* Code that is executed in the context, but before the actual function is generated.
* This helps for example to initialize dynamically some context variables.
*/
preCode: string;
reserveVariable(name?: string, value?: any): string;
build(functionCode: string, ...args: string[]): Function;
raw(functionCode: string): Function;
build(functionCode: string, ...args: string[]): any;
buildAsync(functionCode: string, ...args: string[]): Function;
}

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,8 +10,11 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompilerContext = void 0;
class CompilerContext {
export class CompilerContext {
constructor() {
this.context = new Map();
this.maxReservedVariable = 10000;
/**
* Code that is executed in the context, but before the actual function is generated.
* This helps for example to initialize dynamically some context variables.
*/
this.preCode = '';
}

@@ -29,20 +31,34 @@ reserveVariable(name = 'var', value) {

}
raw(functionCode) {
return new Function(...this.context.keys(), functionCode)(...this.context.values());
}
build(functionCode, ...args) {
functionCode = `
return function(${args.join(', ')}){
${this.preCode}
return function self(${args.join(', ')}){
${functionCode}
};
`;
return new Function(...this.context.keys(), functionCode)(...this.context.values());
try {
return new Function(...this.context.keys(), functionCode)(...this.context.values());
}
catch (error) {
throw new Error('Could not build function: ' + error + functionCode);
}
}
buildAsync(functionCode, ...args) {
functionCode = `
return async function(${args.join(', ')}){
${this.preCode}
return async function self(${args.join(', ')}){
${functionCode}
};
`;
return new Function(...this.context.keys(), functionCode)(...this.context.values());
try {
return new Function(...this.context.keys(), functionCode)(...this.context.values());
}
catch (error) {
throw new Error('Could not build function: ' + error + functionCode);
}
}
}
exports.CompilerContext = CompilerContext;
//# sourceMappingURL=compiler.js.map

@@ -14,3 +14,6 @@ /**

export declare class CustomError extends Error {
constructor(message: string);
message: string;
name: string;
stack?: string;
constructor(message?: string);
}

@@ -23,3 +26,11 @@ /**

}
export declare type ExtractClassType<T> = T extends ClassType<infer K> ? K : never;
/**
* This type maintains the actual type, but erases the decoratorMetadata, which is requires in a circular reference for ECMAScript modules.
* Basically fixes like "ReferenceError: Cannot access 'MyClass' before initialization"
*/
export declare type Forward<T> = T & {
__forward?: true;
};
/**
* Returns the class name either of the class definition or of the class of an instance.

@@ -79,3 +90,3 @@ *

*/
export declare function isPromise(obj: any): obj is Promise<any>;
export declare function isPromise<T>(obj: any | Promise<T>): obj is Promise<T>;
/**

@@ -220,3 +231,3 @@ * Returns true if given obj is a ES6 class (ES5 fake classes are not supported).

/**
* A better alternative to "new Promise()" that supports error handling and maintains the stack trace.
* A better alternative to "new Promise()" that supports error handling and maintains the stack trace for Error.stack.
*

@@ -254,2 +265,3 @@ * When you use `new Promise()` you need to wrap your code inside a try-catch to call `reject` on error.

export declare function mergeStack(error: Error, stack: string): void;
export declare function collectForMicrotask<T>(callback: (args: T[]) => void): (arg: T) => void;
/**

@@ -272,2 +284,6 @@ * Returns the current time as seconds.

/**
* @public
*/
export declare function deletePathValue(bag: object, parameterPath: string): void;
/**
* Returns the human readable byte representation.

@@ -282,1 +298,3 @@ *

export declare function getObjectKeysSize(obj: object): number;
export declare function isConstructable(fn: any): boolean;
export declare function isPrototypeOfBase(prototype: ClassType | undefined, base: ClassType): boolean;

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,25 +10,4 @@ * Deepkit Framework

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getObjectKeysSize = exports.humanBytes = exports.setPathValue = exports.getPathValue = exports.time = exports.mergeStack = exports.createStack = exports.mergePromiseStack = exports.asyncOperation = exports.appendObject = exports.prependObjectKeys = exports.average = exports.arrayRemoveItem = exports.arrayClear = exports.last = exports.first = exports.lastKey = exports.firstKey = exports.size = exports.empty = exports.copy = exports.sleep = exports.indexOf = exports.arrayHasItem = exports.isString = exports.isNumber = exports.isSet = exports.isUndefined = exports.isNull = exports.isArray = exports.isObject = exports.isClass = exports.isPromise = exports.isFunction = exports.isPlainObject = exports.typeOf = exports.applyDefaults = exports.getClassPropertyName = exports.getClassName = exports.CustomError = void 0;
const iterators_1 = require("./iterators");
const dotProp = __importStar(require("dot-prop"));
import dotProp from 'dot-prop';
import { eachPair } from './iterators';
/**

@@ -47,9 +25,9 @@ * Makes sure the error once printed using console.log contains the actual class name.

*/
class CustomError extends Error {
constructor(message) {
export class CustomError extends Error {
constructor(message = '') {
super(message);
this.message = message;
this.name = this.constructor.name;
}
}
exports.CustomError = CustomError;
/**

@@ -71,7 +49,8 @@ * Returns the class name either of the class definition or of the class of an instance.

*/
function getClassName(classTypeOrInstance) {
export function getClassName(classTypeOrInstance) {
if (!classTypeOrInstance)
return 'undefined';
const proto = classTypeOrInstance['prototype'] ? classTypeOrInstance['prototype'] : classTypeOrInstance;
return proto.constructor.name;
}
exports.getClassName = getClassName;
/**

@@ -81,13 +60,12 @@ * Same as getClassName but appends the propertyName.

*/
function getClassPropertyName(classType, propertyName) {
export function getClassPropertyName(classType, propertyName) {
const name = getClassName(classType);
return `${name}::${propertyName}`;
}
exports.getClassPropertyName = getClassPropertyName;
/**
* @public
*/
function applyDefaults(classType, target) {
export function applyDefaults(classType, target) {
const classInstance = new classType();
for (const [i, v] of iterators_1.eachPair(target)) {
for (const [i, v] of eachPair(target)) {
classInstance[i] = v;

@@ -97,10 +75,8 @@ }

}
exports.applyDefaults = applyDefaults;
/**
* Tries to identify the object by normalised result of Object.toString(obj).
*/
function typeOf(obj) {
export function typeOf(obj) {
return ((({}).toString.call(obj).match(/\s([a-zA-Z]+)/) || [])[1] || '').toLowerCase();
}
exports.typeOf = typeOf;
/**

@@ -114,6 +90,5 @@ * Returns true if the given obj is a plain object, and no class instance.

*/
function isPlainObject(obj) {
export function isPlainObject(obj) {
return Boolean(obj && typeof obj === 'object' && obj.constructor instanceof obj.constructor);
}
exports.isPlainObject = isPlainObject;
/**

@@ -124,3 +99,3 @@ * Returns true if given obj is a function.

*/
function isFunction(obj) {
export function isFunction(obj) {
if ('function' === typeof obj) {

@@ -131,3 +106,2 @@ return !obj.toString().startsWith('class ');

}
exports.isFunction = isFunction;
/**

@@ -141,7 +115,6 @@ * Returns true if given obj is a promise like object.

*/
function isPromise(obj) {
export function isPromise(obj) {
return obj !== null && typeof obj === "object" && typeof obj.then === "function"
&& typeof obj.catch === "function" && typeof obj.finally === "function";
}
exports.isPromise = isPromise;
/**

@@ -152,3 +125,3 @@ * Returns true if given obj is a ES6 class (ES5 fake classes are not supported).

*/
function isClass(obj) {
export function isClass(obj) {
if ('function' === typeof obj) {

@@ -159,3 +132,2 @@ return obj.toString().startsWith('class ') || obj.toString().startsWith('class{');

}
exports.isClass = isClass;
/**

@@ -166,3 +138,3 @@ * Returns true for real objects: object literals ({}) or class instances (new MyClass).

*/
function isObject(obj) {
export function isObject(obj) {
if (obj === null) {

@@ -173,24 +145,20 @@ return false;

}
exports.isObject = isObject;
/**
* @public
*/
function isArray(obj) {
export function isArray(obj) {
return !!(obj && 'number' === typeof obj.length && 'function' === typeof obj.reduce);
}
exports.isArray = isArray;
/**
* @public
*/
function isNull(obj) {
export function isNull(obj) {
return null === obj;
}
exports.isNull = isNull;
/**
* @public
*/
function isUndefined(obj) {
export function isUndefined(obj) {
return undefined === obj;
}
exports.isUndefined = isUndefined;
/**

@@ -201,31 +169,27 @@ * Checks if obj is not null and not undefined.

*/
function isSet(obj) {
export function isSet(obj) {
return !isNull(obj) && !isUndefined(obj);
}
exports.isSet = isSet;
/**
* @public
*/
function isNumber(obj) {
export function isNumber(obj) {
return 'number' === typeOf(obj);
}
exports.isNumber = isNumber;
/**
* @public
*/
function isString(obj) {
export function isString(obj) {
return 'string' === typeOf(obj);
}
exports.isString = isString;
/**
* @public
*/
function arrayHasItem(array, item) {
export function arrayHasItem(array, item) {
return -1 !== array.indexOf(item);
}
exports.arrayHasItem = arrayHasItem;
/**
* @public
*/
function indexOf(array, item) {
export function indexOf(array, item) {
if (!array) {

@@ -236,10 +200,8 @@ return -1;

}
exports.indexOf = indexOf;
/**
* @public
*/
async function sleep(seconds) {
export async function sleep(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
exports.sleep = sleep;
/**

@@ -250,3 +212,3 @@ * Creates a shallow copy of given array.

*/
function copy(v) {
export function copy(v) {
if (isArray(v)) {

@@ -257,3 +219,2 @@ return v.slice(0);

}
exports.copy = copy;
/**

@@ -264,3 +225,3 @@ * Checks whether given array or object is empty (no keys). If given object is falsy, returns false.

*/
function empty(value) {
export function empty(value) {
if (!value)

@@ -278,3 +239,2 @@ return true;

}
exports.empty = empty;
/**

@@ -285,3 +245,3 @@ * Returns the size of given array or object.

*/
function size(array) {
export function size(array) {
if (!array) {

@@ -297,3 +257,2 @@ return 0;

}
exports.size = size;
/**

@@ -304,6 +263,5 @@ * Returns the first key of a given object.

*/
function firstKey(v) {
export function firstKey(v) {
return Object.keys(v)[0];
}
exports.firstKey = firstKey;
/**

@@ -314,3 +272,3 @@ * Returns the last key of a given object.

*/
function lastKey(v) {
export function lastKey(v) {
const keys = Object.keys(v);

@@ -322,3 +280,2 @@ if (keys.length) {

}
exports.lastKey = lastKey;
/**

@@ -329,3 +286,3 @@ * Returns the first value of given array or object.

*/
function first(v) {
export function first(v) {
if (isArray(v)) {

@@ -340,3 +297,2 @@ return v[0];

}
exports.first = first;
/**

@@ -347,3 +303,3 @@ * Returns the last value of given array or object.

*/
function last(v) {
export function last(v) {
if (isArray(v)) {

@@ -361,3 +317,2 @@ if (v.length > 0) {

}
exports.last = last;
/**

@@ -368,6 +323,5 @@ * Clears the array so its empty. Returns the amount of removed items.

*/
function arrayClear(array) {
export function arrayClear(array) {
return array.splice(0, array.length).length;
}
exports.arrayClear = arrayClear;
/**

@@ -378,3 +332,3 @@ * Removes on particular item by reference of an array.

*/
function arrayRemoveItem(array, item) {
export function arrayRemoveItem(array, item) {
const index = array.indexOf(item);

@@ -387,3 +341,2 @@ if (-1 !== index) {

}
exports.arrayRemoveItem = arrayRemoveItem;
/**

@@ -394,3 +347,3 @@ * Returns the average of a number array.

*/
function average(array) {
export function average(array) {
let sum = 0;

@@ -402,7 +355,6 @@ for (const n of array) {

}
exports.average = average;
/**
* @public
*/
function prependObjectKeys(o, prependText) {
export function prependObjectKeys(o, prependText) {
const converted = {};

@@ -416,15 +368,13 @@ for (const i in o) {

}
exports.prependObjectKeys = prependObjectKeys;
/**
* @public
*/
function appendObject(origin, extend, prependKeyName = '') {
export function appendObject(origin, extend, prependKeyName = '') {
const no = prependObjectKeys(extend, prependKeyName);
for (const [i, v] of iterators_1.eachPair(no)) {
for (const [i, v] of eachPair(no)) {
origin[i] = v;
}
}
exports.appendObject = appendObject;
/**
* A better alternative to "new Promise()" that supports error handling and maintains the stack trace.
* A better alternative to "new Promise()" that supports error handling and maintains the stack trace for Error.stack.
*

@@ -449,17 +399,27 @@ * When you use `new Promise()` you need to wrap your code inside a try-catch to call `reject` on error.

*/
function asyncOperation(executor) {
return mergePromiseStack(new Promise(async (resolve, reject) => {
try {
await executor(resolve, reject);
}
catch (e) {
reject(e);
}
}));
export async function asyncOperation(executor) {
let error, async;
try {
async = await new Promise(async (resolve, reject) => {
try {
await executor(resolve, reject);
}
catch (e) {
reject(e);
}
});
}
catch (e) {
error = e;
}
if (error) {
mergeStack(error, createStack());
throw error;
}
return async;
}
exports.asyncOperation = asyncOperation;
/**
* @public
*/
function mergePromiseStack(promise, stack) {
export function mergePromiseStack(promise, stack) {
stack = stack || createStack();

@@ -472,7 +432,6 @@ promise.then(() => {

}
exports.mergePromiseStack = mergePromiseStack;
/**
* @beta
*/
function createStack(removeCallee = true) {
export function createStack(removeCallee = true) {
if (Error.stackTraceLimit === 10)

@@ -497,7 +456,6 @@ Error.stackTraceLimit = 100;

}
exports.createStack = createStack;
/**
* @beta
*/
function mergeStack(error, stack) {
export function mergeStack(error, stack) {
if (error instanceof Error && error.stack) {

@@ -507,3 +465,17 @@ error.stack += '\n' + stack;

}
exports.mergeStack = mergeStack;
export function collectForMicrotask(callback) {
let items = [];
let taskScheduled = false;
return (arg) => {
items.push(arg);
if (!taskScheduled) {
taskScheduled = true;
queueMicrotask(() => {
taskScheduled = false;
callback(items);
items.length = 0;
});
}
};
}
/**

@@ -514,10 +486,9 @@ * Returns the current time as seconds.

*/
function time() {
export function time() {
return Date.now() / 1000;
}
exports.time = time;
/**
* @public
*/
function getPathValue(bag, parameterPath, defaultValue) {
export function getPathValue(bag, parameterPath, defaultValue) {
if (isSet(bag[parameterPath])) {

@@ -529,11 +500,15 @@ return bag[parameterPath];

}
exports.getPathValue = getPathValue;
/**
* @public
*/
function setPathValue(bag, parameterPath, value) {
export function setPathValue(bag, parameterPath, value) {
dotProp.set(bag, parameterPath, value);
}
exports.setPathValue = setPathValue;
/**
* @public
*/
export function deletePathValue(bag, parameterPath) {
dotProp.delete(bag, parameterPath);
}
/**
* Returns the human readable byte representation.

@@ -543,3 +518,3 @@ *

*/
function humanBytes(bytes, si = false) {
export function humanBytes(bytes, si = false) {
const thresh = si ? 1000 : 1024;

@@ -559,7 +534,6 @@ if (Math.abs(bytes) < thresh) {

}
exports.humanBytes = humanBytes;
/**
* Returns the number of properties on `obj`. This is 20x faster than Object.keys(obj).length.
*/
function getObjectKeysSize(obj) {
export function getObjectKeysSize(obj) {
let size = 0;

@@ -571,3 +545,25 @@ for (let i in obj)

}
exports.getObjectKeysSize = getObjectKeysSize;
export function isConstructable(fn) {
try {
new new Proxy(fn, { construct: () => ({}) });
return true;
}
catch (err) {
return false;
}
}
;
export function isPrototypeOfBase(prototype, base) {
if (!prototype)
return false;
if (prototype === base)
return true;
let currentProto = Object.getPrototypeOf(prototype);
while (currentProto && currentProto !== Object.prototype) {
if (currentProto === base)
return true;
currentProto = Object.getPrototypeOf(currentProto);
}
return false;
}
//# sourceMappingURL=core.js.map

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,6 +10,4 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.singleStack = exports.stack = exports.log = void 0;
const core_1 = require("./core");
const perf_1 = require("./perf");
import { getClassName } from './core';
import { toFastProperties } from './perf';
/**

@@ -21,3 +18,3 @@ * Logs every call to this method on stdout.

*/
function log() {
export function log() {
return function (target, propertyKey, descriptor) {

@@ -27,3 +24,3 @@ const orig = descriptor.value;

const a = args.map(v => typeof v).join(',');
console.info(core_1.getClassName(target) + '::' + String(propertyKey) + '(' + a + ')');
console.info(getClassName(target) + '::' + String(propertyKey) + '(' + a + ')');
return orig.apply(this, args);

@@ -34,3 +31,2 @@ };

}
exports.log = log;
/**

@@ -41,3 +37,3 @@ * Makes sure that calls to this async method are stacked up and are called one after another and not parallel.

*/
function stack() {
export function stack() {
return function (target, propertyKey, descriptor) {

@@ -50,3 +46,3 @@ const orig = descriptor.value;

this[name] = null;
perf_1.toFastProperties(this);
toFastProperties(this);
}

@@ -66,3 +62,2 @@ while (this[name]) {

}
exports.stack = stack;
/**

@@ -74,3 +69,3 @@ * Makes sure that this async method is only running once at a time. When this method is running and it is tried

*/
function singleStack() {
export function singleStack() {
return function (target, propertyKey, descriptor) {

@@ -82,3 +77,3 @@ const orig = descriptor.value;

this[name] = null;
perf_1.toFastProperties(this);
toFastProperties(this);
}

@@ -98,3 +93,2 @@ if (this[name]) {

}
exports.singleStack = singleStack;
//# sourceMappingURL=decorators.js.map

@@ -8,3 +8,12 @@ declare type AsyncSubscriber<T> = (event: T) => Promise<void> | void;

stopped: boolean;
propagationStopped: boolean;
/**
* Stop propagating the event to subsequent event listeners.
*/
stopPropagation(): void;
/**
* Signal the emitter that you want to abort.
* Subsequent event listeners will still be called.
*/
stop(): void;
}

@@ -11,0 +20,0 @@ export declare class AsyncEventEmitter<T extends AsyncEmitterEvent> {

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,17 +10,25 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncEventEmitter = exports.AsyncEmitterEvent = void 0;
const core_1 = require("./core");
import { arrayRemoveItem } from './core';
let asyncId = 0;
class AsyncEmitterEvent {
export class AsyncEmitterEvent {
constructor() {
this.id = asyncId++;
this.stopped = false;
this.propagationStopped = false;
}
/**
* Stop propagating the event to subsequent event listeners.
*/
stopPropagation() {
this.propagationStopped = true;
}
/**
* Signal the emitter that you want to abort.
* Subsequent event listeners will still be called.
*/
stop() {
this.stopped = true;
}
}
exports.AsyncEmitterEvent = AsyncEmitterEvent;
class AsyncEventEmitter {
export class AsyncEventEmitter {
constructor(parent) {

@@ -35,3 +42,3 @@ this.parent = parent;

unsubscribe: () => {
core_1.arrayRemoveItem(this.subscribers, callback);
arrayRemoveItem(this.subscribers, callback);
}

@@ -43,7 +50,7 @@ };

await this.parent.emit(event);
if (event.stopped)
if (event.propagationStopped)
return;
for (const subscriber of this.subscribers) {
await subscriber(event);
if (event.stopped)
if (event.propagationStopped)
return;

@@ -56,3 +63,2 @@ }

}
exports.AsyncEventEmitter = AsyncEventEmitter;
//# sourceMappingURL=emitter.js.map

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,5 +10,3 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getValidEnumValue = exports.isValidEnumValue = exports.getEnumValues = exports.getEnumLabels = exports.getEnumLabel = void 0;
const iterators_1 = require("./iterators");
import { eachKey } from './iterators';
const cacheEnumLabels = new Map();

@@ -21,4 +18,4 @@ /**

*/
function getEnumLabel(enumType, id) {
for (const i of iterators_1.eachKey(enumType)) {
export function getEnumLabel(enumType, id) {
for (const i of eachKey(enumType)) {
if (id === enumType[i]) {

@@ -29,3 +26,2 @@ return i;

}
exports.getEnumLabel = getEnumLabel;
/**

@@ -36,3 +32,3 @@ * Returns all possible enum labels.

*/
function getEnumLabels(enumDefinition) {
export function getEnumLabels(enumDefinition) {
let value = cacheEnumLabels.get(enumDefinition);

@@ -45,3 +41,2 @@ if (!value) {

}
exports.getEnumLabels = getEnumLabels;
const cacheEnumKeys = new Map();

@@ -53,3 +48,3 @@ /**

*/
function getEnumValues(enumDefinition) {
export function getEnumValues(enumDefinition) {
let value = cacheEnumKeys.get(enumDefinition);

@@ -65,3 +60,2 @@ if (!value) {

}
exports.getEnumValues = getEnumValues;
/**

@@ -72,3 +66,3 @@ * Checks whether given enum value is valid.

*/
function isValidEnumValue(enumDefinition, value, allowLabelsAsValue = false) {
export function isValidEnumValue(enumDefinition, value, allowLabelsAsValue = false) {
if (allowLabelsAsValue) {

@@ -83,7 +77,6 @@ const labels = getEnumLabels(enumDefinition);

}
exports.isValidEnumValue = isValidEnumValue;
/**
* @public
*/
function getValidEnumValue(enumDefinition, value, allowLabelsAsValue = false) {
export function getValidEnumValue(enumDefinition, value, allowLabelsAsValue = false) {
if (allowLabelsAsValue) {

@@ -106,3 +99,2 @@ const labels = getEnumLabels(enumDefinition);

}
exports.getValidEnumValue = getValidEnumValue;
//# sourceMappingURL=enum.js.map

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,6 +10,4 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.eachPair = exports.each = exports.eachKey = void 0;
/** @public */
function* eachKey(object) {
export function* eachKey(object) {
if (Array.isArray(object)) {

@@ -29,3 +26,2 @@ for (let i = 0; i < object.length; i++) {

}
exports.eachKey = eachKey;
/**

@@ -44,3 +40,3 @@ * Iterator for each value of an array or object.

*/
function* each(object) {
export function* each(object) {
if (Array.isArray(object)) {

@@ -59,5 +55,4 @@ for (let i = 0; i < object.length; i++) {

}
exports.each = each;
/** @public */
function* eachPair(object) {
export function* eachPair(object) {
if (Array.isArray(object)) {

@@ -76,3 +71,2 @@ for (let i = 0; i < object.length; i++) {

}
exports.eachPair = eachPair;
//# sourceMappingURL=iterators.js.map

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,5 +10,3 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseHost = exports.ParsedHost = void 0;
class ParsedHost {
export class ParsedHost {
constructor() {

@@ -47,4 +44,3 @@ this.host = '127.0.0.1';

}
exports.ParsedHost = ParsedHost;
function parseHost(hostWithIpOrUnixPath) {
export function parseHost(hostWithIpOrUnixPath) {
const parsedHost = new ParsedHost();

@@ -69,3 +65,2 @@ if (hostWithIpOrUnixPath.includes('/') || hostWithIpOrUnixPath.includes('\\') || hostWithIpOrUnixPath.endsWith('.sock')) {

}
exports.parseHost = parseHost;
//# sourceMappingURL=network.js.map

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,12 +10,6 @@ * Deepkit Framework

*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toFastProperties = void 0;
const to_fast_properties_1 = __importDefault(require("to-fast-properties"));
function toFastProperties(obj) {
to_fast_properties_1.default(obj);
import toFastPropertiesOri from 'to-fast-properties';
export function toFastProperties(obj) {
toFastPropertiesOri(obj);
}
exports.toFastProperties = toFastProperties;
//# sourceMappingURL=perf.js.map

@@ -12,6 +12,7 @@ /**

private holding;
protected ttlTimeout: any;
constructor(id: string);
acquire(ttl?: number, timeout?: number): Promise<void>;
isLocked(): boolean;
tryLock(timeout?: number): boolean;
tryLock(ttl?: number): boolean;
unlock(): void;

@@ -27,4 +28,4 @@ }

acquireLock(id: string, ttl?: number, timeout?: number): Promise<ProcessLock>;
tryLock(id: string, timeout?: number): Promise<ProcessLock | undefined>;
isLocked(id: string): Promise<boolean>;
tryLock(id: string, ttl?: number): Promise<ProcessLock | undefined>;
isLocked(id: string): boolean;
}

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,5 +10,3 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProcessLocker = exports.ProcessLock = void 0;
const core_1 = require("./core");
import { arrayRemoveItem } from './core';
const LOCKS = {};

@@ -24,3 +21,3 @@ /**

*/
class ProcessLock {
export class ProcessLock {
constructor(id) {

@@ -40,3 +37,3 @@ this.id = id;

if (ttl) {
setTimeout(() => {
this.ttlTimeout = setTimeout(() => {
this.unlock();

@@ -49,3 +46,3 @@ }, ttl * 1000);

if (LOCKS[this.id])
core_1.arrayRemoveItem(LOCKS[this.id].queue, ourTake);
arrayRemoveItem(LOCKS[this.id].queue, ourTake);
//reject is never handled when resolve is called first

@@ -66,3 +63,3 @@ reject('Lock timed out ' + this.id);

if (ttl) {
setTimeout(() => {
this.ttlTimeout = setTimeout(() => {
this.unlock();

@@ -77,3 +74,3 @@ }, ttl * 1000);

}
tryLock(timeout) {
tryLock(ttl = 0) {
this.holding = false;

@@ -86,6 +83,6 @@ if (!LOCKS[this.id]) {

this.holding = true;
if (timeout) {
setTimeout(() => {
if (ttl) {
this.ttlTimeout = setTimeout(() => {
this.unlock();
}, timeout * 1000);
}, ttl * 1000);
}

@@ -96,2 +93,3 @@ }

unlock() {
clearTimeout(this.ttlTimeout);
if (!this.holding) {

@@ -113,4 +111,3 @@ return;

}
exports.ProcessLock = ProcessLock;
class ProcessLocker {
export class ProcessLocker {
/**

@@ -127,5 +124,5 @@ *

}
async tryLock(id, timeout) {
async tryLock(id, ttl = 0) {
const lock = new ProcessLock(id);
if (lock.tryLock(timeout)) {
if (lock.tryLock(ttl)) {
return lock;

@@ -135,7 +132,6 @@ }

}
async isLocked(id) {
isLocked(id) {
return !!LOCKS[id];
}
}
exports.ProcessLocker = ProcessLocker;
//# sourceMappingURL=process-locker.js.map
export declare function indent(indentation: number): (str: string) => string;
export declare function capitalize(string: string): string;

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,5 +10,3 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.indent = void 0;
function indent(indentation) {
export function indent(indentation) {
return (str) => {

@@ -19,3 +16,5 @@ return ' '.repeat(indentation) + str.replace(/\n/g, '\n' + (' '.repeat(indentation)));

}
exports.indent = indent;
export function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
//# sourceMappingURL=string.js.map

@@ -1,2 +0,1 @@

"use strict";
/*

@@ -11,5 +10,3 @@ * Deepkit Framework

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Timer = void 0;
class Timer {
export class Timer {
constructor() {

@@ -32,3 +29,2 @@ this.timeoutTimers = []; //any necessary to be compatible with NodeJS/Browser env

}
exports.Timer = Timer;
//# sourceMappingURL=timer.js.map

@@ -1,1 +0,1 @@

import 'jest';
export {};

@@ -1,7 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("jest");
const compiler_1 = require("../src/compiler");
import { expect, test } from '@jest/globals';
import { CompilerContext } from '../src/compiler';
test('compiler', () => {
const compiler = new compiler_1.CompilerContext();
const compiler = new CompilerContext();
expect(compiler.reserveVariable('a')).toBe('a_0');

@@ -23,3 +21,3 @@ expect(compiler.reserveVariable('a')).toBe('a_1');

test('compiler code', () => {
const compiler = new compiler_1.CompilerContext();
const compiler = new CompilerContext();
expect(compiler.build('return 123;')()).toBe(123);

@@ -26,0 +24,0 @@ expect(compiler.build('return a;', 'a')(444)).toBe(444);

@@ -1,1 +0,1 @@

import 'jest-extended';
export {};

@@ -1,5 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("jest-extended");
const core_1 = require("../src/core");
import { expect, test } from '@jest/globals';
import { asyncOperation, collectForMicrotask, getClassName, getObjectKeysSize, getPathValue, isArray, isClass, isConstructable, isFunction, isObject, isPlainObject, isPromise, isPrototypeOfBase, isUndefined, setPathValue, sleep } from '../src/core';
class SimpleClass {

@@ -18,36 +16,36 @@ constructor(name) {

}
expect(core_1.getClassName(new User('peter'))).toBe('User');
expect(core_1.getClassName(User)).toBe('User');
expect(core_1.getClassName(MyError)).toBe('MyError');
expect(core_1.getClassName(new MyError)).toBe('MyError');
expect(getClassName(new User('peter'))).toBe('User');
expect(getClassName(User)).toBe('User');
expect(getClassName(MyError)).toBe('MyError');
expect(getClassName(new MyError)).toBe('MyError');
});
test('helper isObject', () => {
expect(core_1.isObject([])).toBeFalse();
expect(core_1.isObject(false)).toBeFalse();
expect(core_1.isObject(true)).toBeFalse();
expect(core_1.isObject(null)).toBeFalse();
expect(core_1.isObject(undefined)).toBeFalse();
expect(core_1.isObject(() => { })).toBeFalse();
expect(core_1.isObject(function () { })).toBeFalse();
expect(core_1.isObject(1)).toBeFalse();
expect(core_1.isObject('1')).toBeFalse();
expect(core_1.isObject({})).toBeTrue();
expect(core_1.isObject(new Date())).toBeTrue();
expect(core_1.isObject(new SimpleClass('asd'))).toBeTrue();
expect(isObject([])).toBe(false);
expect(isObject(false)).toBe(false);
expect(isObject(true)).toBe(false);
expect(isObject(null)).toBe(false);
expect(isObject(undefined)).toBe(false);
expect(isObject(() => { })).toBe(false);
expect(isObject(function () { })).toBe(false);
expect(isObject(1)).toBe(false);
expect(isObject('1')).toBe(false);
expect(isObject({})).toBe(true);
expect(isObject(new Date())).toBe(true);
expect(isObject(new SimpleClass('asd'))).toBe(true);
});
test('helper isPromise', async () => {
expect(core_1.isPromise([])).toBeFalse();
expect(core_1.isPromise(false)).toBeFalse();
expect(core_1.isPromise(true)).toBeFalse();
expect(core_1.isPromise(null)).toBeFalse();
expect(core_1.isPromise(undefined)).toBeFalse();
expect(core_1.isPromise(() => { })).toBeFalse();
expect(core_1.isPromise(function () { })).toBeFalse();
expect(core_1.isPromise(1)).toBeFalse();
expect(core_1.isPromise('1')).toBeFalse();
expect(isPromise([])).toBe(false);
expect(isPromise(false)).toBe(false);
expect(isPromise(true)).toBe(false);
expect(isPromise(null)).toBe(false);
expect(isPromise(undefined)).toBe(false);
expect(isPromise(() => { })).toBe(false);
expect(isPromise(function () { })).toBe(false);
expect(isPromise(1)).toBe(false);
expect(isPromise('1')).toBe(false);
function foo1() {
}
const foo2 = () => { };
expect(core_1.isPromise(foo1())).toBeFalse();
expect(core_1.isPromise(foo2())).toBeFalse();
expect(isPromise(foo1())).toBe(false);
expect(isPromise(foo2())).toBe(false);
async function foo3() {

@@ -60,95 +58,95 @@ }

}
expect(core_1.isObject(foo3())).toBeTrue();
expect(core_1.isObject(foo4())).toBeTrue();
expect(core_1.isObject(await foo4())).toBeFalse();
expect(core_1.isObject((async () => { })())).toBeTrue();
expect(isObject(foo3())).toBe(true);
expect(isObject(foo4())).toBe(true);
expect(isObject(await foo4())).toBe(false);
expect(isObject((async () => { })())).toBe(true);
});
test('helper isFunction', () => {
expect(core_1.isFunction([])).toBeFalse();
expect(core_1.isFunction(false)).toBeFalse();
expect(core_1.isFunction(true)).toBeFalse();
expect(core_1.isFunction(null)).toBeFalse();
expect(core_1.isFunction(undefined)).toBeFalse();
expect(core_1.isFunction(1)).toBeFalse();
expect(core_1.isFunction('1')).toBeFalse();
expect(core_1.isFunction({})).toBeFalse();
expect(core_1.isFunction(new Date())).toBeFalse();
expect(core_1.isFunction(new SimpleClass('asd'))).toBeFalse();
expect(core_1.isFunction(core_1.isFunction)).toBeTrue();
expect(core_1.isFunction(() => { })).toBeTrue();
expect(core_1.isFunction(async () => { })).toBeTrue();
expect(core_1.isFunction(function () { })).toBeTrue();
expect(core_1.isFunction(async function () { })).toBeTrue();
expect(isFunction([])).toBe(false);
expect(isFunction(false)).toBe(false);
expect(isFunction(true)).toBe(false);
expect(isFunction(null)).toBe(false);
expect(isFunction(undefined)).toBe(false);
expect(isFunction(1)).toBe(false);
expect(isFunction('1')).toBe(false);
expect(isFunction({})).toBe(false);
expect(isFunction(new Date())).toBe(false);
expect(isFunction(new SimpleClass('asd'))).toBe(false);
expect(isFunction(isFunction)).toBe(true);
expect(isFunction(() => { })).toBe(true);
expect(isFunction(async () => { })).toBe(true);
expect(isFunction(function () { })).toBe(true);
expect(isFunction(async function () { })).toBe(true);
});
test('helper isClass', () => {
expect(core_1.isClass([])).toBeFalse();
expect(core_1.isClass(false)).toBeFalse();
expect(core_1.isClass(true)).toBeFalse();
expect(core_1.isClass(null)).toBeFalse();
expect(core_1.isClass(undefined)).toBeFalse();
expect(core_1.isClass(1)).toBeFalse();
expect(core_1.isClass('1')).toBeFalse();
expect(core_1.isClass({})).toBeFalse();
expect(core_1.isClass(new Date())).toBeFalse();
expect(core_1.isClass(new SimpleClass('asd'))).toBeFalse();
expect(core_1.isClass(core_1.isFunction)).toBeFalse();
expect(core_1.isClass(() => { })).toBeFalse();
expect(core_1.isClass(async () => { })).toBeFalse();
expect(core_1.isClass(function () { })).toBeFalse();
expect(core_1.isClass(async function () { })).toBeFalse();
expect(core_1.isClass(SimpleClass)).toBeTrue();
expect(isClass([])).toBe(false);
expect(isClass(false)).toBe(false);
expect(isClass(true)).toBe(false);
expect(isClass(null)).toBe(false);
expect(isClass(undefined)).toBe(false);
expect(isClass(1)).toBe(false);
expect(isClass('1')).toBe(false);
expect(isClass({})).toBe(false);
expect(isClass(new Date())).toBe(false);
expect(isClass(new SimpleClass('asd'))).toBe(false);
expect(isClass(isFunction)).toBe(false);
expect(isClass(() => { })).toBe(false);
expect(isClass(async () => { })).toBe(false);
expect(isClass(function () { })).toBe(false);
expect(isClass(async function () { })).toBe(false);
expect(isClass(SimpleClass)).toBe(true);
});
test('helper isPlainObject', () => {
expect(core_1.isPlainObject([])).toBeFalse();
expect(core_1.isPlainObject(false)).toBeFalse();
expect(core_1.isPlainObject(true)).toBeFalse();
expect(core_1.isPlainObject(null)).toBeFalse();
expect(core_1.isPlainObject(undefined)).toBeFalse();
expect(core_1.isPlainObject(1)).toBeFalse();
expect(core_1.isPlainObject('1')).toBeFalse();
expect(core_1.isPlainObject(() => { })).toBeFalse();
expect(core_1.isPlainObject(function () { })).toBeFalse();
expect(core_1.isPlainObject(new Date())).toBeFalse();
expect(core_1.isPlainObject(new SimpleClass('asd'))).toBeFalse();
expect(isPlainObject([])).toBe(false);
expect(isPlainObject(false)).toBe(false);
expect(isPlainObject(true)).toBe(false);
expect(isPlainObject(null)).toBe(false);
expect(isPlainObject(undefined)).toBe(false);
expect(isPlainObject(1)).toBe(false);
expect(isPlainObject('1')).toBe(false);
expect(isPlainObject(() => { })).toBe(false);
expect(isPlainObject(function () { })).toBe(false);
expect(isPlainObject(new Date())).toBe(false);
expect(isPlainObject(new SimpleClass('asd'))).toBe(false);
class O extends Object {
}
expect(core_1.isPlainObject(new O)).toBeFalse();
expect(core_1.isPlainObject({})).toBeTrue();
expect(core_1.isPlainObject(new Object)).toBeTrue();
expect(isPlainObject(new O)).toBe(false);
expect(isPlainObject({})).toBe(true);
expect(isPlainObject(new Object)).toBe(true);
});
test('helper is array', () => {
expect(core_1.isArray({})).toBeFalse();
expect(core_1.isArray(new Date())).toBeFalse();
expect(core_1.isArray(new SimpleClass('asd'))).toBeFalse();
expect(core_1.isArray(false)).toBeFalse();
expect(core_1.isArray(true)).toBeFalse();
expect(core_1.isArray(null)).toBeFalse();
expect(core_1.isArray(undefined)).toBeFalse();
expect(core_1.isArray(1)).toBeFalse();
expect(core_1.isArray('1')).toBeFalse();
expect(core_1.isArray([])).toBeTrue();
expect(isArray({})).toBe(false);
expect(isArray(new Date())).toBe(false);
expect(isArray(new SimpleClass('asd'))).toBe(false);
expect(isArray(false)).toBe(false);
expect(isArray(true)).toBe(false);
expect(isArray(null)).toBe(false);
expect(isArray(undefined)).toBe(false);
expect(isArray(1)).toBe(false);
expect(isArray('1')).toBe(false);
expect(isArray([])).toBe(true);
});
test('helper is isUndefined', () => {
expect(core_1.isUndefined({})).toBeFalse();
expect(core_1.isUndefined(new Date())).toBeFalse();
expect(core_1.isUndefined(new SimpleClass('asd'))).toBeFalse();
expect(core_1.isUndefined(false)).toBeFalse();
expect(core_1.isUndefined(true)).toBeFalse();
expect(core_1.isUndefined(null)).toBeFalse();
expect(core_1.isUndefined(1)).toBeFalse();
expect(core_1.isUndefined('1')).toBeFalse();
expect(core_1.isUndefined([])).toBeFalse();
expect(core_1.isUndefined(undefined)).toBeTrue();
expect(isUndefined({})).toBe(false);
expect(isUndefined(new Date())).toBe(false);
expect(isUndefined(new SimpleClass('asd'))).toBe(false);
expect(isUndefined(false)).toBe(false);
expect(isUndefined(true)).toBe(false);
expect(isUndefined(null)).toBe(false);
expect(isUndefined(1)).toBe(false);
expect(isUndefined('1')).toBe(false);
expect(isUndefined([])).toBe(false);
expect(isUndefined(undefined)).toBe(true);
});
test('test getPathValue', () => {
expect(core_1.getPathValue({
expect(getPathValue({
bla: 3
}, 'bla')).toBe(3);
expect(core_1.getPathValue({
expect(getPathValue({
bla: 3
}, 'bla2', null)).toBe(null);
expect(core_1.getPathValue({}, 'bla', 'another')).toBe('another');
expect(getPathValue({}, 'bla', 'another')).toBe('another');
});
test('test getPathValue deep', () => {
expect(core_1.getPathValue({
expect(getPathValue({
bla: {

@@ -158,6 +156,6 @@ mowla: 5

}, 'bla.mowla')).toBe(5);
expect(core_1.getPathValue({
expect(getPathValue({
'bla.mowla': 5
}, 'bla.mowla')).toBe(5);
expect(core_1.getPathValue({
expect(getPathValue({
bla: {

@@ -169,3 +167,3 @@ mowla: {

}, 'bla.mowla.evenDeeper')).toBe(true);
expect(core_1.getPathValue({
expect(getPathValue({
bla: {

@@ -181,3 +179,3 @@ mowla: {

const obj = {};
core_1.setPathValue(obj, 'bla2', 5);
setPathValue(obj, 'bla2', 5);
expect(obj['bla2']).toBe(5);

@@ -187,3 +185,3 @@ }

const obj = {};
core_1.setPathValue(obj, 'bla.mowla', 6);
setPathValue(obj, 'bla.mowla', 6);
expect(obj['bla']['mowla']).toBe(6);

@@ -193,13 +191,19 @@ }

test('asyncOperation', async () => {
class MyError extends Error {
}
let fetched = false;
try {
await core_1.asyncOperation(async (resolve) => {
await core_1.sleep(0.2);
throw new Error('MyError1');
});
async function doIt() {
await asyncOperation(async (resolve) => {
await sleep(0.2);
throw new MyError('MyError1');
});
}
await doIt();
}
catch (error) {
fetched = true;
expect(error).toBeInstanceOf(MyError);
expect(error.stack).toContain('MyError1');
expect(error.stack).toContain('Object.asyncOperation');
expect(error.stack).toContain('doIt');
}

@@ -211,15 +215,22 @@ expect(fetched).toBe(true);

try {
await core_1.asyncOperation(async (resolve) => {
await core_1.sleep(0.2);
await core_1.asyncOperation(async (resolve) => {
await core_1.sleep(0.2);
throw new Error('MyError2');
async function doIt1() {
await asyncOperation(async (resolve) => {
await sleep(0.2);
async function doIt2() {
await asyncOperation(async (resolve) => {
await sleep(0.2);
throw new Error('MyError2');
});
}
;
await doIt2();
});
});
}
await doIt1();
}
catch (error) {
fetched = true;
console.log(error);
expect(error.stack).toContain('MyError2');
expect(error.stack).toContain('Object.asyncOperation');
expect(error.stack).toContain('doIt1');
expect(error.stack).toContain('doIt2');
}

@@ -229,6 +240,56 @@ expect(fetched).toBe(true);

test('getObjectKeysSize', async () => {
expect(core_1.getObjectKeysSize({})).toBe(0);
expect(core_1.getObjectKeysSize({ a: true })).toBe(1);
expect(core_1.getObjectKeysSize({ a: 1, b: 1, c: 3, d: 4, e: {} })).toBe(5);
expect(getObjectKeysSize({})).toBe(0);
expect(getObjectKeysSize({ a: true })).toBe(1);
expect(getObjectKeysSize({ a: 1, b: 1, c: 3, d: 4, e: {} })).toBe(5);
});
test('isPrototypeOfBase', () => {
class Base {
}
class Child1 extends Base {
}
class Child2 extends Base {
}
class Child1_1 extends Child1 {
}
class Child1_1_1 extends Child1_1 {
}
expect(isPrototypeOfBase(Base, Base)).toBe(true);
expect(isPrototypeOfBase(Child1, Base)).toBe(true);
expect(isPrototypeOfBase(Child2, Base)).toBe(true);
expect(isPrototypeOfBase(Child1_1, Base)).toBe(true);
expect(isPrototypeOfBase(Child1_1, Child1)).toBe(true);
expect(isPrototypeOfBase(Child1_1_1, Base)).toBe(true);
expect(isPrototypeOfBase(Child1_1_1, Child1_1)).toBe(true);
});
test('isConstructable', () => {
expect(isConstructable(class {
})).toBe(true);
expect(isConstructable(class {
}.bind(undefined))).toBe(true);
expect(isConstructable(function () { })).toBe(true);
expect(isConstructable(function () { }.bind(undefined))).toBe(true);
expect(isConstructable(() => { })).toBe(false);
expect(isConstructable((() => { }).bind(undefined))).toBe(false);
expect(isConstructable(async () => { })).toBe(false);
expect(isConstructable(async function () { })).toBe(false);
expect(isConstructable(function* () { })).toBe(false);
expect(isConstructable({ foo() { } }.foo)).toBe(false);
expect(isConstructable(URL)).toBe(true);
});
test('collectForMicrotask', async () => {
let got = [];
const collected = (strings) => {
got.length = 0;
got.push(...strings);
};
const fn = collectForMicrotask(collected);
fn('a');
fn('b');
fn('c');
await sleep(0.1);
expect(got).toEqual(['a', 'b', 'c']);
fn('d');
await sleep(0.1);
expect(got).toEqual(['d']);
});
//# sourceMappingURL=core.spec.js.map

@@ -1,1 +0,1 @@

import 'jest-extended';
export {};

@@ -1,2 +0,1 @@

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -11,6 +10,5 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

};
Object.defineProperty(exports, "__esModule", { value: true });
require("jest-extended");
const decorators_1 = require("../src/decorators");
const core_1 = require("../src/core");
import { expect, test } from '@jest/globals';
import { log, stack } from '../src/decorators';
import { sleep } from '../src/core';
test('test decorators @sync', async () => {

@@ -41,4 +39,4 @@ class Test {

__decorate([
decorators_1.stack(),
decorators_1.log(),
stack(),
log(),
__metadata("design:type", Function),

@@ -72,9 +70,9 @@ __metadata("design:paramtypes", []),

expect(test.j).toBe(0);
await core_1.sleep(0.1);
await sleep(0.1);
expect(test.i).toBe(2);
expect(test.j).toBe(1);
await core_1.sleep(0.1);
await sleep(0.1);
expect(test.i).toBe(3);
expect(test.j).toBe(2);
await core_1.sleep(0.1);
await sleep(0.1);
expect(test.i).toBe(3);

@@ -81,0 +79,0 @@ expect(test.j).toBe(3);

@@ -1,1 +0,1 @@

import 'jest-extended';
export {};

@@ -1,5 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("jest-extended");
const enum_1 = require("../src/enum");
import { expect, test } from '@jest/globals';
import { getEnumLabels, getEnumValues } from '../src/enum';
test('getEnumLabels numbered index', () => {

@@ -12,4 +10,4 @@ let MyEnum;

})(MyEnum || (MyEnum = {}));
expect(enum_1.getEnumValues(MyEnum)).toEqual([0, 1, 2]);
expect(enum_1.getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
expect(getEnumValues(MyEnum)).toEqual([0, 1, 2]);
expect(getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
});

@@ -23,4 +21,4 @@ test('getEnumLabels custom numbered index', () => {

})(MyEnum || (MyEnum = {}));
expect(enum_1.getEnumValues(MyEnum)).toEqual([400, 500, 600]);
expect(enum_1.getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
expect(getEnumValues(MyEnum)).toEqual([400, 500, 600]);
expect(getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
});

@@ -34,4 +32,4 @@ test('getEnumLabels partial custom numbered index', () => {

})(MyEnum || (MyEnum = {}));
expect(enum_1.getEnumValues(MyEnum)).toEqual([0, 500, 501]);
expect(enum_1.getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
expect(getEnumValues(MyEnum)).toEqual([0, 500, 501]);
expect(getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
});

@@ -45,4 +43,4 @@ test('getEnumLabels string index', () => {

})(MyEnum || (MyEnum = {}));
expect(enum_1.getEnumValues(MyEnum)).toEqual(['my_first', 'my_second', 'my_third']);
expect(enum_1.getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
expect(getEnumValues(MyEnum)).toEqual(['my_first', 'my_second', 'my_third']);
expect(getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
});

@@ -56,4 +54,4 @@ test('getEnumLabels mixed string index', () => {

})(MyEnum || (MyEnum = {}));
expect(enum_1.getEnumValues(MyEnum)).toEqual([0, 'my_second', 'my_third']);
expect(enum_1.getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
expect(getEnumValues(MyEnum)).toEqual([0, 'my_second', 'my_third']);
expect(getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
});

@@ -67,5 +65,5 @@ test('getEnumLabels string index same name', () => {

})(MyEnum || (MyEnum = {}));
expect(enum_1.getEnumValues(MyEnum)).toEqual(['first', 'second', 'third']);
expect(enum_1.getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
expect(getEnumValues(MyEnum)).toEqual(['first', 'second', 'third']);
expect(getEnumLabels(MyEnum)).toEqual(['first', 'second', 'third']);
});
//# sourceMappingURL=enum.spec.js.map

@@ -1,2 +0,1 @@

import 'jest';
import 'jest-extended';
export {};

@@ -1,22 +0,19 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("jest");
const iterators_1 = require("../src/iterators");
require("jest-extended");
import { expect, test } from '@jest/globals';
import { each, eachKey, eachPair } from '../src/iterators';
test('test array', () => {
const array = ['a', 'b', 'c'];
for (const v of iterators_1.each(array)) {
expect(v).toBeString();
for (const v of each(array)) {
expect(typeof v).toBe('string');
}
for (let i in array) {
expect(i).toBeString();
expect(typeof i).toBe('string');
}
for (const i of iterators_1.eachKey(array)) {
expect(i).toBeNumber();
for (const i of eachKey(array)) {
expect(typeof i).toBe('number');
}
for (const [k, v] of iterators_1.eachPair(array)) {
expect(k).toBeNumber();
expect(v).toBeString();
for (const [k, v] of eachPair(array)) {
expect(typeof k).toBe('number');
expect(typeof v).toBe('string');
}
for (const [k, v] of iterators_1.eachPair(['y'])) {
for (const [k, v] of eachPair(['y'])) {
expect(k).toBe(0);

@@ -28,7 +25,7 @@ expect(v).toBe('y');

const object = { 'a': 1, 'b': 2, 'c': 3 };
for (const v of iterators_1.each(object)) {
expect(v).toBeNumber();
for (const v of each(object)) {
expect(typeof v).toBe('number');
}
for (const i of iterators_1.eachKey(object)) {
expect(i).toBeString();
for (const i of eachKey(object)) {
expect(typeof i).toBe('string');
}

@@ -43,10 +40,10 @@ });

const object2 = { 'a': new Mowla('hallo'), 'b': new Mowla('hallo'), 'c': new Mowla('hallo') };
for (const v of iterators_1.eachKey(object2)) {
expect(v).toBeString();
for (const v of eachKey(object2)) {
expect(typeof v).toBe('string');
}
for (const v of iterators_1.each(object2)) {
for (const v of each(object2)) {
expect(v).toBeInstanceOf(Mowla);
}
for (const [i, v] of iterators_1.eachPair(object2)) {
expect(i).toBeString();
for (const [i, v] of eachPair(object2)) {
expect(typeof i).toBe('string');
expect(v).toBeInstanceOf(Mowla);

@@ -60,13 +57,13 @@ }

};
for (const v of iterators_1.eachKey(object3)) {
expect(v).toBeString();
for (const v of eachKey(object3)) {
expect(typeof v).toBe('string');
}
for (const v of iterators_1.each(object3)) {
expect(v).toBeBoolean();
for (const v of each(object3)) {
expect(typeof v).toBe('boolean');
}
for (const [k, v] of iterators_1.eachPair(object3)) {
expect(k).toBeString();
expect(v).toBeBoolean();
for (const [k, v] of eachPair(object3)) {
expect(typeof k).toBe('string');
expect(typeof v).toBe('boolean');
}
});
//# sourceMappingURL=iterator.spec.js.map

@@ -1,1 +0,1 @@

import 'jest-extended';
export {};

@@ -1,9 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("jest-extended");
const process_locker_1 = require("../src/process-locker");
import { jest, expect, test, beforeAll } from '@jest/globals';
import { ProcessLock, ProcessLocker } from '../src/process-locker';
jest.setTimeout(20000);
let locker;
beforeAll(async () => {
locker = new process_locker_1.ProcessLocker();
locker = new ProcessLocker();
});

@@ -47,35 +45,38 @@ test('test lock competing', async () => {

});
test('test performance', async () => {
const start = performance.now();
const count = 2000;
for (let i = 0; i < count; i++) {
const lock1 = await locker.acquireLock('test-perf');
await lock1.unlock();
}
console.log(count, 'locks took', performance.now() - start, (performance.now() - start) / count);
// expect(performance.now() - start).toBeLessThan(100);
});
// test('test performance', async () => {
// const start = performance.now();
//
// const count = 2000;
// for (let i = 0; i < count; i++) {
// const lock1 = await locker.acquireLock('test-perf');
// await lock1.unlock();
// }
//
// console.log(count, 'locks took', performance.now() - start, (performance.now() - start) / count);
//
// // expect(performance.now() - start).toBeLessThan(100);
// });
test('test tryLock', async () => {
const lock1 = await locker.acquireLock('trylock', 1);
expect(lock1).toBeInstanceOf(process_locker_1.ProcessLock);
expect(lock1).toBeInstanceOf(ProcessLock);
const lock2 = await locker.tryLock('trylock', 1);
expect(lock2).toBeUndefined();
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
await new Promise((resolve) => {
setTimeout(async () => {
expect(await locker.isLocked('trylock')).toBeFalse();
expect(await locker.isLocked('trylock')).toBe(false);
const lock3 = await locker.tryLock('trylock', 1);
expect(lock3).toBeInstanceOf(process_locker_1.ProcessLock);
expect(await locker.isLocked('trylock')).toBeTrue();
expect(lock3).toBeInstanceOf(ProcessLock);
expect(await locker.isLocked('trylock')).toBe(true);
setTimeout(async () => {
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
const lock4 = await locker.tryLock('trylock', 1);
expect(lock4).toBeUndefined();
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
}, 200);
setTimeout(async () => {
expect(await locker.isLocked('trylock')).toBeFalse();
expect(await locker.isLocked('trylock')).toBe(false);
const lock5 = await locker.acquireLock('trylock', 1);
expect(lock5).toBeInstanceOf(process_locker_1.ProcessLock);
expect(await locker.isLocked('trylock')).toBeTrue();
expect(lock5).toBeInstanceOf(ProcessLock);
expect(await locker.isLocked('trylock')).toBe(true);
await lock5.unlock();

@@ -82,0 +83,0 @@ resolve(undefined);

@@ -1,1 +0,1 @@

import 'jest-extended';
export {};

@@ -1,8 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("jest-extended");
const network_1 = require("../src/network");
import { expect, test } from '@jest/globals';
import { parseHost } from '../src/network';
test('parseHost', () => {
{
const parsed = network_1.parseHost('aosdad');
const parsed = parseHost('aosdad');
expect(parsed.isUnixSocket).toBe(false);

@@ -14,3 +12,3 @@ expect(parsed.isHostname).toBe(true);

{
const parsed = network_1.parseHost('aosdad:80');
const parsed = parseHost('aosdad:80');
expect(parsed.isUnixSocket).toBe(false);

@@ -27,3 +25,3 @@ expect(parsed.isHostname).toBe(true);

{
const parsed = network_1.parseHost(':80');
const parsed = parseHost(':80');
expect(parsed.isUnixSocket).toBe(false);

@@ -36,3 +34,3 @@ expect(parsed.isHostname).toBe(true);

{
const parsed = network_1.parseHost(':');
const parsed = parseHost(':');
expect(parsed.isUnixSocket).toBe(false);

@@ -45,3 +43,3 @@ expect(parsed.isHostname).toBe(true);

{
const parsed = network_1.parseHost('');
const parsed = parseHost('');
expect(parsed.isUnixSocket).toBe(false);

@@ -54,3 +52,3 @@ expect(parsed.isHostname).toBe(true);

{
const parsed = network_1.parseHost('localhost:');
const parsed = parseHost('localhost:');
expect(parsed.isUnixSocket).toBe(false);

@@ -63,3 +61,3 @@ expect(parsed.isHostname).toBe(true);

{
const parsed = network_1.parseHost('./unix-path');
const parsed = parseHost('./unix-path');
expect(parsed.isUnixSocket).toBe(true);

@@ -70,3 +68,3 @@ expect(parsed.isHostname).toBe(false);

{
const parsed = network_1.parseHost('unix-path.sock');
const parsed = parseHost('unix-path.sock');
expect(parsed.isUnixSocket).toBe(true);

@@ -81,3 +79,3 @@ expect(parsed.isHostname).toBe(false);

{
const parsed = network_1.parseHost('\\windoze\\unix-path.sock');
const parsed = parseHost('\\windoze\\unix-path.sock');
expect(parsed.isUnixSocket).toBe(true);

@@ -84,0 +82,0 @@ expect(parsed.isHostname).toBe(false);

@@ -6,3 +6,2 @@ export * from './src/core';

export * from './src/timer';
export * from './src/meta-data';
export * from './src/process-locker';

@@ -14,1 +13,3 @@ export * from './src/network';

export * from './src/emitter';
export * from './src/reactive';
export * from './src/reflection';
{
"name": "@deepkit/core",
"version": "1.0.1-alpha.1",
"description": "Super Hornet core library",
"version": "1.0.1-alpha.3",
"description": "Deepkit core library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"sideEffects": false,

@@ -21,7 +22,3 @@ "publishConfig": {

},
"scripts": {
"test": "jest --coverage",
"tsc": "rm -rf dist && tsc",
"tsc-watch": "rm -rf dist && tsc --watch"
},
"scripts": {},
"jest": {

@@ -31,2 +28,6 @@ "transform": {

},
"extensionsToTreatAsEsm": [
".ts",
".tsx"
],
"testMatch": [

@@ -36,3 +37,3 @@ "**/tests/**/*.spec.ts"

},
"gitHead": "b8107bb0fcdb090e54498e5c75b2abda3a82bef0"
"gitHead": "63df0602e66e513d5a6989bbe8990c97cef2632d"
}

@@ -16,2 +16,8 @@ /*

/**
* Code that is executed in the context, but before the actual function is generated.
* This helps for example to initialize dynamically some context variables.
*/
public preCode: string = '';
reserveVariable(name: string = 'var', value?: any): string {

@@ -29,9 +35,18 @@ for (let i = 0; i < this.maxReservedVariable; i++) {

build(functionCode: string, ...args: string[]): Function {
raw(functionCode: string): Function {
return new Function(...this.context.keys(), functionCode)(...this.context.values());
}
build(functionCode: string, ...args: string[]): any {
functionCode = `
return function(${args.join(', ')}){
${this.preCode}
return function self(${args.join(', ')}){
${functionCode}
};
`;
return new Function(...this.context.keys(), functionCode)(...this.context.values());
try {
return new Function(...this.context.keys(), functionCode)(...this.context.values());
} catch (error) {
throw new Error('Could not build function: ' + error + functionCode);
}
}

@@ -41,8 +56,13 @@

functionCode = `
return async function(${args.join(', ')}){
${this.preCode}
return async function self(${args.join(', ')}){
${functionCode}
};
`;
return new Function(...this.context.keys(), functionCode)(...this.context.values());
try {
return new Function(...this.context.keys(), functionCode)(...this.context.values());
} catch (error) {
throw new Error('Could not build function: ' + error + functionCode);
}
}
}

@@ -11,4 +11,4 @@ /*

import {eachPair} from './iterators';
import * as dotProp from 'dot-prop';
import dotProp from 'dot-prop';
import { eachPair } from './iterators';

@@ -28,3 +28,5 @@ /**

export class CustomError extends Error {
constructor(message: string) {
public name: string;
public stack?: string;
constructor(public message: string = '') {
super(message);

@@ -42,3 +44,11 @@ this.name = this.constructor.name;

export type ExtractClassType<T> = T extends ClassType<infer K> ? K : never;
/**
* This type maintains the actual type, but erases the decoratorMetadata, which is requires in a circular reference for ECMAScript modules.
* Basically fixes like "ReferenceError: Cannot access 'MyClass' before initialization"
*/
export type Forward<T> = T & { __forward?: true };
/**
* Returns the class name either of the class definition or of the class of an instance.

@@ -60,2 +70,3 @@ *

export function getClassName<T>(classTypeOrInstance: ClassType<T> | Object): string {
if (!classTypeOrInstance) return 'undefined';
const proto = (classTypeOrInstance as any)['prototype'] ? (classTypeOrInstance as any)['prototype'] : classTypeOrInstance;

@@ -128,3 +139,3 @@ return proto.constructor.name;

*/
export function isPromise(obj: any): obj is Promise<any> {
export function isPromise<T>(obj: any | Promise<T>): obj is Promise<T> {
return obj !== null && typeof obj === "object" && typeof obj.then === "function"

@@ -152,3 +163,3 @@ && typeof obj.catch === "function" && typeof obj.finally === "function";

*/
export function isObject(obj: any): obj is {[key: string]: any} {
export function isObject(obj: any): obj is { [key: string]: any } {
if (obj === null) {

@@ -395,3 +406,3 @@ return false;

/**
* A better alternative to "new Promise()" that supports error handling and maintains the stack trace.
* A better alternative to "new Promise()" that supports error handling and maintains the stack trace for Error.stack.
*

@@ -416,10 +427,20 @@ * When you use `new Promise()` you need to wrap your code inside a try-catch to call `reject` on error.

*/
export function asyncOperation<T>(executor: (resolve: (value: T) => void, reject: (error: any) => void) => void | Promise<void>): Promise<T> {
return mergePromiseStack(new Promise<T>(async (resolve, reject) => {
try {
await executor(resolve, reject);
} catch (e) {
reject(e);
}
}));
export async function asyncOperation<T>(executor: (resolve: (value: T) => void, reject: (error: any) => void) => void | Promise<void>): Promise<T> {
let error: any, async: any;
try {
async = await new Promise<T>(async (resolve, reject) => {
try {
await executor(resolve, reject);
} catch (e) {
reject(e);
}
})
} catch (e) {
error = e;
}
if (error) {
mergeStack(error, createStack());
throw error;
}
return async;
}

@@ -475,2 +496,19 @@

export function collectForMicrotask<T>(callback: (args: T[]) => void): (arg: T) => void {
let items: T[] = [];
let taskScheduled = false;
return (arg: T) => {
items.push(arg);
if (!taskScheduled) {
taskScheduled = true;
queueMicrotask(() => {
taskScheduled = false;
callback(items);
items.length = 0;
});
}
};
}
/**

@@ -506,2 +544,9 @@ * Returns the current time as seconds.

/**
* @public
*/
export function deletePathValue(bag: object, parameterPath: string) {
dotProp.delete(bag, parameterPath);
}
/**
* Returns the human readable byte representation.

@@ -536,1 +581,21 @@ *

}
export function isConstructable(fn: any): boolean {
try {
new new Proxy(fn, { construct: () => ({}) });
return true;
} catch (err) {
return false;
}
};
export function isPrototypeOfBase(prototype: ClassType | undefined, base: ClassType): boolean {
if (!prototype) return false;
if (prototype === base) return true;
let currentProto = Object.getPrototypeOf(prototype);
while (currentProto && currentProto !== Object.prototype) {
if (currentProto === base) return true;
currentProto = Object.getPrototypeOf(currentProto);
}
return false;
}

@@ -11,4 +11,4 @@ /*

import {getClassName} from './core';
import {toFastProperties} from './perf';
import { getClassName } from './core';
import { toFastProperties } from './perf';

@@ -15,0 +15,0 @@ /**

@@ -11,3 +11,3 @@ /*

import {arrayRemoveItem} from './core';
import { arrayRemoveItem } from './core';

@@ -23,4 +23,16 @@ type AsyncSubscriber<T> = (event: T) => Promise<void> | void;

public stopped = false;
public propagationStopped = false;
/**
* Stop propagating the event to subsequent event listeners.
*/
stopPropagation() {
this.propagationStopped = true;
}
/**
* Signal the emitter that you want to abort.
* Subsequent event listeners will still be called.
*/
stop() {
this.stopped = true;

@@ -48,7 +60,7 @@ }

if (this.parent) await this.parent.emit(event);
if (event.stopped) return;
if (event.propagationStopped) return;
for (const subscriber of this.subscribers) {
await subscriber(event);
if (event.stopped) return;
if (event.propagationStopped) return;
}

@@ -55,0 +67,0 @@ }

@@ -11,3 +11,3 @@ /*

import {eachKey} from './iterators';
import { eachKey } from './iterators';

@@ -14,0 +14,0 @@ const cacheEnumLabels = new Map<Object, string[]>();

@@ -11,3 +11,3 @@ /*

import {arrayRemoveItem} from './core';
import { arrayRemoveItem } from './core';

@@ -26,2 +26,3 @@ const LOCKS: { [id: string]: { time: number, queue: Function[] } } = {};

private holding = false;
protected ttlTimeout: any;

@@ -37,2 +38,3 @@ constructor(

}
return new Promise<void>((resolve, reject) => {

@@ -46,3 +48,3 @@ const ourTake = () => {

if (ttl) {
setTimeout(() => {
this.ttlTimeout = setTimeout(() => {
this.unlock();

@@ -73,3 +75,3 @@ }, ttl * 1000);

if (ttl) {
setTimeout(() => {
this.ttlTimeout = setTimeout(() => {
this.unlock();

@@ -86,3 +88,3 @@ }, ttl * 1000);

public tryLock(timeout?: number) {
public tryLock(ttl: number = 0) {
this.holding = false;

@@ -97,6 +99,6 @@

if (timeout) {
setTimeout(() => {
if (ttl) {
this.ttlTimeout = setTimeout(() => {
this.unlock();
}, timeout * 1000);
}, ttl * 1000);
}

@@ -109,2 +111,4 @@ }

public unlock() {
clearTimeout(this.ttlTimeout);
if (!this.holding) {

@@ -142,6 +146,6 @@ return;

public async tryLock(id: string, timeout?: number): Promise<ProcessLock | undefined> {
public async tryLock(id: string, ttl: number = 0): Promise<ProcessLock | undefined> {
const lock = new ProcessLock(id);
if (lock.tryLock(timeout)) {
if (lock.tryLock(ttl)) {
return lock;

@@ -153,5 +157,5 @@ }

public async isLocked(id: string): Promise<boolean> {
public isLocked(id: string): boolean {
return !!LOCKS[id];
}
}

@@ -16,1 +16,5 @@ /*

}
export function capitalize(string: string): string {
return string.charAt(0).toUpperCase() + string.slice(1)
}

@@ -1,3 +0,3 @@

import 'jest';
import {CompilerContext} from '../src/compiler';
import { expect, test } from '@jest/globals';
import { CompilerContext } from '../src/compiler';

@@ -33,2 +33,2 @@ test('compiler', () => {

expect(compiler.build(`return ${a}`)()).toBe(1337);
});
});

@@ -1,4 +0,6 @@

import 'jest-extended';
import { expect, test } from '@jest/globals';
import { domainToASCII } from 'url';
import {
asyncOperation,
collectForMicrotask,
getClassName,

@@ -9,2 +11,3 @@ getObjectKeysSize,

isClass,
isConstructable,
isFunction,

@@ -14,2 +17,3 @@ isObject,

isPromise,
isPrototypeOfBase,
isUndefined,

@@ -21,3 +25,3 @@ setPathValue,

class SimpleClass {
constructor(public name: string){}
constructor(public name: string) { }
}

@@ -27,6 +31,6 @@

class User {
constructor(public readonly name: string) {}
constructor(public readonly name: string) { }
}
class MyError extends Error {}
class MyError extends Error { }

@@ -41,27 +45,27 @@ expect(getClassName(new User('peter'))).toBe('User');

test('helper isObject', () => {
expect(isObject([])).toBeFalse();
expect(isObject(false)).toBeFalse();
expect(isObject(true)).toBeFalse();
expect(isObject(null)).toBeFalse();
expect(isObject(undefined)).toBeFalse();
expect(isObject(() => {})).toBeFalse();
expect(isObject(function() {})).toBeFalse();
expect(isObject(1)).toBeFalse();
expect(isObject('1')).toBeFalse();
expect(isObject([])).toBe(false);
expect(isObject(false)).toBe(false);
expect(isObject(true)).toBe(false);
expect(isObject(null)).toBe(false);
expect(isObject(undefined)).toBe(false);
expect(isObject(() => { })).toBe(false);
expect(isObject(function () { })).toBe(false);
expect(isObject(1)).toBe(false);
expect(isObject('1')).toBe(false);
expect(isObject({})).toBeTrue();
expect(isObject(new Date())).toBeTrue();
expect(isObject(new SimpleClass('asd'))).toBeTrue();
expect(isObject({})).toBe(true);
expect(isObject(new Date())).toBe(true);
expect(isObject(new SimpleClass('asd'))).toBe(true);
});
test('helper isPromise', async () => {
expect(isPromise([])).toBeFalse();
expect(isPromise(false)).toBeFalse();
expect(isPromise(true)).toBeFalse();
expect(isPromise(null)).toBeFalse();
expect(isPromise(undefined)).toBeFalse();
expect(isPromise(() => {})).toBeFalse();
expect(isPromise(function() {})).toBeFalse();
expect(isPromise(1)).toBeFalse();
expect(isPromise('1')).toBeFalse();
expect(isPromise([])).toBe(false);
expect(isPromise(false)).toBe(false);
expect(isPromise(true)).toBe(false);
expect(isPromise(null)).toBe(false);
expect(isPromise(undefined)).toBe(false);
expect(isPromise(() => { })).toBe(false);
expect(isPromise(function () { })).toBe(false);
expect(isPromise(1)).toBe(false);
expect(isPromise('1')).toBe(false);

@@ -71,5 +75,5 @@ function foo1() {

const foo2 = () => {};
expect(isPromise(foo1())).toBeFalse();
expect(isPromise(foo2())).toBeFalse();
const foo2 = () => { };
expect(isPromise(foo1())).toBe(false);
expect(isPromise(foo2())).toBe(false);

@@ -84,95 +88,95 @@ async function foo3() {

expect(isObject(foo3())).toBeTrue();
expect(isObject(foo4())).toBeTrue();
expect(isObject(await foo4())).toBeFalse();
expect(isObject((async () => {})())).toBeTrue();
expect(isObject(foo3())).toBe(true);
expect(isObject(foo4())).toBe(true);
expect(isObject(await foo4())).toBe(false);
expect(isObject((async () => { })())).toBe(true);
});
test('helper isFunction', () => {
expect(isFunction([])).toBeFalse();
expect(isFunction(false)).toBeFalse();
expect(isFunction(true)).toBeFalse();
expect(isFunction(null)).toBeFalse();
expect(isFunction(undefined)).toBeFalse();
expect(isFunction(1)).toBeFalse();
expect(isFunction('1')).toBeFalse();
expect(isFunction({})).toBeFalse();
expect(isFunction(new Date())).toBeFalse();
expect(isFunction(new SimpleClass('asd'))).toBeFalse();
expect(isFunction([])).toBe(false);
expect(isFunction(false)).toBe(false);
expect(isFunction(true)).toBe(false);
expect(isFunction(null)).toBe(false);
expect(isFunction(undefined)).toBe(false);
expect(isFunction(1)).toBe(false);
expect(isFunction('1')).toBe(false);
expect(isFunction({})).toBe(false);
expect(isFunction(new Date())).toBe(false);
expect(isFunction(new SimpleClass('asd'))).toBe(false);
expect(isFunction(isFunction)).toBeTrue();
expect(isFunction(() => {})).toBeTrue();
expect(isFunction(async () => {})).toBeTrue();
expect(isFunction(function() {})).toBeTrue();
expect(isFunction(async function() {})).toBeTrue();
expect(isFunction(isFunction)).toBe(true);
expect(isFunction(() => { })).toBe(true);
expect(isFunction(async () => { })).toBe(true);
expect(isFunction(function () { })).toBe(true);
expect(isFunction(async function () { })).toBe(true);
});
test('helper isClass', () => {
expect(isClass([])).toBeFalse();
expect(isClass(false)).toBeFalse();
expect(isClass(true)).toBeFalse();
expect(isClass(null)).toBeFalse();
expect(isClass(undefined)).toBeFalse();
expect(isClass(1)).toBeFalse();
expect(isClass('1')).toBeFalse();
expect(isClass({})).toBeFalse();
expect(isClass(new Date())).toBeFalse();
expect(isClass(new SimpleClass('asd'))).toBeFalse();
expect(isClass(isFunction)).toBeFalse();
expect(isClass(() => {})).toBeFalse();
expect(isClass(async () => {})).toBeFalse();
expect(isClass(function() {})).toBeFalse();
expect(isClass(async function() {})).toBeFalse();
expect(isClass([])).toBe(false);
expect(isClass(false)).toBe(false);
expect(isClass(true)).toBe(false);
expect(isClass(null)).toBe(false);
expect(isClass(undefined)).toBe(false);
expect(isClass(1)).toBe(false);
expect(isClass('1')).toBe(false);
expect(isClass({})).toBe(false);
expect(isClass(new Date())).toBe(false);
expect(isClass(new SimpleClass('asd'))).toBe(false);
expect(isClass(isFunction)).toBe(false);
expect(isClass(() => { })).toBe(false);
expect(isClass(async () => { })).toBe(false);
expect(isClass(function () { })).toBe(false);
expect(isClass(async function () { })).toBe(false);
expect(isClass(SimpleClass)).toBeTrue();
expect(isClass(SimpleClass)).toBe(true);
});
test('helper isPlainObject', () => {
expect(isPlainObject([])).toBeFalse();
expect(isPlainObject(false)).toBeFalse();
expect(isPlainObject(true)).toBeFalse();
expect(isPlainObject(null)).toBeFalse();
expect(isPlainObject(undefined)).toBeFalse();
expect(isPlainObject(1)).toBeFalse();
expect(isPlainObject('1')).toBeFalse();
expect(isPlainObject(() => {})).toBeFalse();
expect(isPlainObject(function() {})).toBeFalse();
expect(isPlainObject([])).toBe(false);
expect(isPlainObject(false)).toBe(false);
expect(isPlainObject(true)).toBe(false);
expect(isPlainObject(null)).toBe(false);
expect(isPlainObject(undefined)).toBe(false);
expect(isPlainObject(1)).toBe(false);
expect(isPlainObject('1')).toBe(false);
expect(isPlainObject(() => { })).toBe(false);
expect(isPlainObject(function () { })).toBe(false);
expect(isPlainObject(new Date())).toBeFalse();
expect(isPlainObject(new SimpleClass('asd'))).toBeFalse();
expect(isPlainObject(new Date())).toBe(false);
expect(isPlainObject(new SimpleClass('asd'))).toBe(false);
class O extends Object {
}
expect(isPlainObject(new O)).toBeFalse();
expect(isPlainObject(new O)).toBe(false);
expect(isPlainObject({})).toBeTrue();
expect(isPlainObject(new Object)).toBeTrue();
expect(isPlainObject({})).toBe(true);
expect(isPlainObject(new Object)).toBe(true);
});
test('helper is array', () => {
expect(isArray({})).toBeFalse();
expect(isArray(new Date())).toBeFalse();
expect(isArray(new SimpleClass('asd'))).toBeFalse();
expect(isArray(false)).toBeFalse();
expect(isArray(true)).toBeFalse();
expect(isArray(null)).toBeFalse();
expect(isArray(undefined)).toBeFalse();
expect(isArray(1)).toBeFalse();
expect(isArray('1')).toBeFalse();
expect(isArray({})).toBe(false);
expect(isArray(new Date())).toBe(false);
expect(isArray(new SimpleClass('asd'))).toBe(false);
expect(isArray(false)).toBe(false);
expect(isArray(true)).toBe(false);
expect(isArray(null)).toBe(false);
expect(isArray(undefined)).toBe(false);
expect(isArray(1)).toBe(false);
expect(isArray('1')).toBe(false);
expect(isArray([])).toBeTrue();
expect(isArray([])).toBe(true);
});
test('helper is isUndefined', () => {
expect(isUndefined({})).toBeFalse();
expect(isUndefined(new Date())).toBeFalse();
expect(isUndefined(new SimpleClass('asd'))).toBeFalse();
expect(isUndefined(false)).toBeFalse();
expect(isUndefined(true)).toBeFalse();
expect(isUndefined(null)).toBeFalse();
expect(isUndefined(1)).toBeFalse();
expect(isUndefined('1')).toBeFalse();
expect(isUndefined([])).toBeFalse();
expect(isUndefined({})).toBe(false);
expect(isUndefined(new Date())).toBe(false);
expect(isUndefined(new SimpleClass('asd'))).toBe(false);
expect(isUndefined(false)).toBe(false);
expect(isUndefined(true)).toBe(false);
expect(isUndefined(null)).toBe(false);
expect(isUndefined(1)).toBe(false);
expect(isUndefined('1')).toBe(false);
expect(isUndefined([])).toBe(false);
expect(isUndefined(undefined)).toBeTrue();
expect(isUndefined(undefined)).toBe(true);
});

@@ -238,12 +242,18 @@

test('asyncOperation', async () => {
class MyError extends Error { }
let fetched = false;
try {
await asyncOperation(async (resolve) => {
await sleep(0.2);
throw new Error('MyError1');
});
async function doIt() {
await asyncOperation(async (resolve) => {
await sleep(0.2);
throw new MyError('MyError1');
});
}
await doIt();
} catch (error) {
fetched = true;
expect(error).toBeInstanceOf(MyError);
expect(error.stack).toContain('MyError1');
expect(error.stack).toContain('Object.asyncOperation');
expect(error.stack).toContain('doIt');
}

@@ -256,14 +266,20 @@ expect(fetched).toBe(true);

try {
await asyncOperation(async (resolve) => {
await sleep(0.2);
async function doIt1() {
await asyncOperation(async (resolve) => {
await sleep(0.2);
throw new Error('MyError2');
})
});
async function doIt2() {
await asyncOperation(async (resolve) => {
await sleep(0.2);
throw new Error('MyError2');
})
};
await doIt2();
});
}
await doIt1();
} catch (error) {
fetched = true;
console.log(error);
expect(error.stack).toContain('MyError2');
expect(error.stack).toContain('Object.asyncOperation');
expect(error.stack).toContain('doIt1');
expect(error.stack).toContain('doIt2');
}

@@ -276,4 +292,57 @@ expect(fetched).toBe(true);

expect(getObjectKeysSize({})).toBe(0);
expect(getObjectKeysSize({a: true})).toBe(1);
expect(getObjectKeysSize({a: 1, b: 1, c: 3, d: 4, e: {}})).toBe(5);
expect(getObjectKeysSize({ a: true })).toBe(1);
expect(getObjectKeysSize({ a: 1, b: 1, c: 3, d: 4, e: {} })).toBe(5);
});
test('isPrototypeOfBase', () => {
class Base { }
class Child1 extends Base { }
class Child2 extends Base { }
class Child1_1 extends Child1 { }
class Child1_1_1 extends Child1_1 { }
expect(isPrototypeOfBase(Base, Base)).toBe(true);
expect(isPrototypeOfBase(Child1, Base)).toBe(true);
expect(isPrototypeOfBase(Child2, Base)).toBe(true);
expect(isPrototypeOfBase(Child1_1, Base)).toBe(true);
expect(isPrototypeOfBase(Child1_1, Child1)).toBe(true);
expect(isPrototypeOfBase(Child1_1_1, Base)).toBe(true);
expect(isPrototypeOfBase(Child1_1_1, Child1_1)).toBe(true);
});
test('isConstructable', () => {
expect(isConstructable(class { })).toBe(true)
expect(isConstructable(class { }.bind(undefined))).toBe(true)
expect(isConstructable(function () { })).toBe(true)
expect(isConstructable(function () { }.bind(undefined))).toBe(true)
expect(isConstructable(() => { })).toBe(false)
expect(isConstructable((() => { }).bind(undefined))).toBe(false)
expect(isConstructable(async () => { })).toBe(false)
expect(isConstructable(async function () { })).toBe(false)
expect(isConstructable(function* () { })).toBe(false)
expect(isConstructable({ foo() { } }.foo)).toBe(false)
expect(isConstructable(URL)).toBe(true)
});
test('collectForMicrotask', async () => {
let got: string[] = [];
const collected = (strings: string[]) => {
got.length = 0;
got.push(...strings);
};
const fn = collectForMicrotask(collected);
fn('a');
fn('b');
fn('c');
await sleep(0.1);
expect(got).toEqual(['a', 'b', 'c']);
fn('d');
await sleep(0.1);
expect(got).toEqual(['d']);
});

@@ -1,4 +0,4 @@

import 'jest-extended';
import {log, stack} from '../src/decorators';
import {sleep} from '../src/core';
import { expect, test } from '@jest/globals';
import { log, stack } from '../src/decorators';
import { sleep } from '../src/core';

@@ -57,5 +57,5 @@ test('test decorators @sync', async () => {

expect(test.i).toBe(0);
test.increase().then((j) => {expect(j).toBe(1)});
test.increase().then((j) => {expect(j).toBe(2)});
test.increase().then((j) => {expect(j).toBe(3)});
test.increase().then((j) => { expect(j).toBe(1) });
test.increase().then((j) => { expect(j).toBe(2) });
test.increase().then((j) => { expect(j).toBe(3) });
expect(test.i).toBe(1);

@@ -62,0 +62,0 @@ expect(test.j).toBe(0);

@@ -1,3 +0,3 @@

import 'jest-extended';
import {getEnumLabels, getEnumValues} from '../src/enum';
import { expect, test } from '@jest/globals';
import { getEnumLabels, getEnumValues } from '../src/enum';

@@ -4,0 +4,0 @@ test('getEnumLabels numbered index', () => {

@@ -1,4 +0,3 @@

import 'jest';
import {each, eachKey, eachPair} from '../src/iterators';
import 'jest-extended';
import { expect, test } from '@jest/globals';
import { each, eachKey, eachPair } from '../src/iterators';

@@ -9,16 +8,16 @@ test('test array', () => {

for (const v of each(array)) {
expect(v).toBeString();
expect(typeof v).toBe('string');
}
for (let i in array) {
expect(i).toBeString();
expect(typeof i).toBe('string');
}
for (const i of eachKey(array)) {
expect(i).toBeNumber();
expect(typeof i).toBe('number');
}
for (const [k, v] of eachPair(array)) {
expect(k).toBeNumber();
expect(v).toBeString();
expect(typeof k).toBe('number');
expect(typeof v).toBe('string');
}

@@ -35,10 +34,10 @@

test('test object1', () => {
const object: {[index: string]: number} = {'a': 1, 'b': 2, 'c': 3};
const object: { [index: string]: number } = { 'a': 1, 'b': 2, 'c': 3 };
for (const v of each(object)) {
expect(v).toBeNumber();
expect(typeof v).toBe('number');
}
for (const i of eachKey(object)) {
expect(i).toBeString();
expect(typeof i).toBe('string');
}

@@ -57,6 +56,6 @@ });

const object2: {[index: string]: Mowla} = {'a': new Mowla('hallo'), 'b': new Mowla('hallo'), 'c': new Mowla('hallo')};
const object2: { [index: string]: Mowla } = { 'a': new Mowla('hallo'), 'b': new Mowla('hallo'), 'c': new Mowla('hallo') };
for (const v of eachKey(object2)) {
expect(v).toBeString();
expect(typeof v).toBe('string');
}

@@ -69,3 +68,3 @@

for (const [i, v] of eachPair(object2)) {
expect(i).toBeString();
expect(typeof i).toBe('string');
expect(v).toBeInstanceOf(Mowla);

@@ -82,13 +81,13 @@ }

for (const v of eachKey(object3)) {
expect(v).toBeString();
expect(typeof v).toBe('string');
}
for (const v of each(object3)) {
expect(v).toBeBoolean();
expect(typeof v).toBe('boolean');
}
for (const [k, v] of eachPair(object3)) {
expect(k).toBeString();
expect(v).toBeBoolean();
expect(typeof k).toBe('string');
expect(typeof v).toBe('boolean');
}
});

@@ -1,3 +0,3 @@

import 'jest-extended';
import {ProcessLock, ProcessLocker} from '../src/process-locker';
import { jest, expect, test, beforeAll } from '@jest/globals';
import { ProcessLock, ProcessLocker } from '../src/process-locker';

@@ -59,16 +59,16 @@ jest.setTimeout(20000);

test('test performance', async () => {
const start = performance.now();
// test('test performance', async () => {
// const start = performance.now();
//
// const count = 2000;
// for (let i = 0; i < count; i++) {
// const lock1 = await locker.acquireLock('test-perf');
// await lock1.unlock();
// }
//
// console.log(count, 'locks took', performance.now() - start, (performance.now() - start) / count);
//
// // expect(performance.now() - start).toBeLessThan(100);
// });
const count = 2000;
for (let i = 0; i < count; i++) {
const lock1 = await locker.acquireLock('test-perf');
await lock1.unlock();
}
console.log(count, 'locks took', performance.now() - start, (performance.now() - start) / count);
// expect(performance.now() - start).toBeLessThan(100);
});
test('test tryLock', async () => {

@@ -80,23 +80,23 @@ const lock1 = await locker.acquireLock('trylock', 1);

expect(lock2).toBeUndefined();
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
await new Promise((resolve) => {
setTimeout(async () => {
expect(await locker.isLocked('trylock')).toBeFalse();
expect(await locker.isLocked('trylock')).toBe(false);
const lock3 = await locker.tryLock('trylock', 1);
expect(lock3).toBeInstanceOf(ProcessLock);
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
setTimeout(async () => {
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
const lock4 = await locker.tryLock('trylock', 1);
expect(lock4).toBeUndefined();
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
}, 200);
setTimeout(async () => {
expect(await locker.isLocked('trylock')).toBeFalse();
expect(await locker.isLocked('trylock')).toBe(false);
const lock5 = await locker.acquireLock('trylock', 1);
expect(lock5).toBeInstanceOf(ProcessLock);
expect(await locker.isLocked('trylock')).toBeTrue();
expect(await locker.isLocked('trylock')).toBe(true);
await lock5.unlock();

@@ -103,0 +103,0 @@ resolve(undefined);

@@ -1,6 +0,5 @@

import 'jest-extended';
import {parseHost} from '../src/network';
import { expect, test } from '@jest/globals';
import { parseHost } from '../src/network';
test('parseHost', () => {
{

@@ -7,0 +6,0 @@ const parsed = parseHost('aosdad');

@@ -8,8 +8,7 @@ {

"sourceMap": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"target": "es2017",
"module": "CommonJS",
"target": "es2018",
"module": "es2020",
"esModuleInterop": true,

@@ -16,0 +15,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc