Compare commits

..

12 Commits

Author SHA1 Message Date
f84822dd5d 4.0.21 2021-09-12 15:39:47 +02:00
21d6e19a22 fix(core): update 2021-09-12 15:39:47 +02:00
8947738dc1 4.0.20 2020-11-24 19:11:43 +00:00
14bc5dcd25 fix(core): update 2020-11-24 19:11:42 +00:00
c2f366de7f 4.0.19 2020-11-24 18:53:28 +00:00
ae47276569 fix(core): update 2020-11-24 18:53:28 +00:00
42b59c109d 4.0.18 2020-11-24 18:47:46 +00:00
8f18faaf1c fix(core): update 2020-11-24 18:47:45 +00:00
ccd5b80d67 4.0.17 2020-07-14 10:55:49 +00:00
298904e17e fix(core): update 2020-07-14 10:55:48 +00:00
fa91e67aef 4.0.16 2020-07-14 08:58:30 +00:00
5e99066bee fix(core): update 2020-07-14 08:58:30 +00:00
17 changed files with 1851 additions and 1546 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
audit:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
- npmci command npm audit --audit-level=high --only=dev
tags:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -85,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

3216
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/lik",
"version": "4.0.15",
"version": "4.0.21",
"private": false,
"description": "light little helpers for node",
"main": "dist_ts/index.js",
@ -20,21 +20,21 @@
},
"homepage": "https://gitlab.com/pushrocks/lik#README",
"devDependencies": {
"@gitzone/tsbuild": "^2.1.24",
"@gitzone/tsbundle": "^1.0.72",
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.78",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.41",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.22",
"tslint": "^6.1.2",
"@types/node": "^14.14.9",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartmatch": "^1.0.7",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrx": "^2.0.17",
"@pushrocks/smarttime": "^3.0.24",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrx": "^2.0.19",
"@pushrocks/smarttime": "^3.0.37",
"@types/minimatch": "^3.0.3",
"symbol-tree": "^3.2.4"
},

View File

@ -1,78 +0,0 @@
// import test framework
import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events';
import * as smartpromise from '@pushrocks/smartpromise';
// import the module
import * as lik from '../ts/index';
// Objectmap
interface ITestObject {
propOne: string;
propTwo: string;
}
let testObjectmap: lik.ObjectMap<ITestObject>;
let testObject1: ITestObject = {
propOne: 'hello',
propTwo: 'hello2',
};
let testObject2: ITestObject = {
propOne: 'hello',
propTwo: 'hello2',
};
tap.test('new lik.Objectmap() -> should correctly instantiate an Objectmap', async () => {
testObjectmap = new lik.ObjectMap<ITestObject>();
expect(testObjectmap).be.instanceof(lik.ObjectMap);
});
tap.test('lik.Objectmap.add() -> should correctly add an object to Objectmap', async () => {
testObjectmap.add(testObject1);
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject1)).be.true;
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject2)).be.false;
});
tap.test('lik.Objectmap.remove() -> should correctly remove an object to Objectmap', async () => {
testObjectmap.add(testObject2);
testObjectmap.remove(testObject1);
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject1)).be.false;
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject2)).be.true;
});
tap.test('Objectmap.forEach -> should correctly run a function forEach map object', async () => {
testObjectmap.forEach((itemArg) => {
expect(itemArg).to.have.property('propOne');
});
});
tap.test('lik.Objectmap.find() -> should correctly find an object', async () => {
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' };
testObjectmap.add(myObject);
let referenceObject = testObjectmap.find((itemArg) => {
return itemArg.propOne === 'helloThere';
});
// tslint:disable-next-line:no-unused-expression
expect(myObject === referenceObject).be.true;
});
tap.test('lik.Objectmap.getArray() -> should return a cloned array', async () => {
let myObject = { propOne: 'test1', propTwo: 'wow, how awesome' };
testObjectmap.add(myObject);
let clonedArray = testObjectmap.getArray();
expect(clonedArray[clonedArray.length - 1]).to.eql(myObject);
});
tap.test('should get one object and then remove it', async () => {
let originalLength = testObjectmap.getArray().length;
let oneObject = testObjectmap.getOneAndRemove();
// tslint:disable-next-line:no-unused-expression
expect(oneObject).not.be.null;
expect(testObjectmap.getArray().length).equal(originalLength - 1);
expect(testObjectmap.getArray()).to.not.contain(oneObject);
});
tap.start();

View File

@ -1,5 +1,6 @@
export * from './lik.fastmap';
export * from './lik.interestmap';
export * from './lik.interestmap.interest';
export * from './lik.limitedarray';
export * from './lik.looptracker';
export * from './lik.objectmap';

View File

@ -29,7 +29,7 @@ export class FastMap<T> {
return this.mapObject[keyArg];
}
public removeFromMap(keyArg): T {
public removeFromMap(keyArg: string): T {
const removedItem = this.getByKey(keyArg);
delete this.mapObject[keyArg];
return removedItem;
@ -50,7 +50,7 @@ export class FastMap<T> {
}
/**
* returns a new Objectmap that includes
* returns a new Fastmap that includes all values from this and all from the fastmap in the argument
*/
public concat(fastMapArg: FastMap<T>) {
const concatedFastmap = new FastMap<T>();
@ -68,9 +68,9 @@ export class FastMap<T> {
}
/**
* tries to merge another Objectmap
* tries to merge another Fastmap
* Note: uniqueKeyCollisions will cause overwrite
* @param objectMapArg
* @param fastMapArg
*/
public addAllFromOther(fastMapArg: FastMap<T>) {
for (const key of fastMapArg.getKeys()) {
@ -79,4 +79,10 @@ export class FastMap<T> {
});
}
}
public async find(findFunction: (mapItemArg: T) => Promise<boolean>) {
for (const key of this.getKeys()) {
}
}
}

View File

@ -2,12 +2,13 @@ import * as plugins from './lik.plugins';
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
export interface IInterestOptions {
export interface IInterestOptions<DTInterestFullfillment> {
markLostAfterDefault: number;
defaultFullfillment?: DTInterestFullfillment;
}
export class Interest<DTInterestId, DTInterestFullfillment> {
public options: IInterestOptions;
public options: IInterestOptions<DTInterestFullfillment>;
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
public originalInterest: DTInterestId;
@ -48,7 +49,7 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
interestArg: DTInterestId,
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>,
optionsArg?: IInterestOptions
optionsArg?: IInterestOptions<DTInterestFullfillment>
) {
this.interestMapRef = interestMapArg;
this.originalInterest = interestArg;
@ -72,6 +73,9 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
*/
public destroy() {
this.interestMapRef.removeInterest(this);
if (!this.isFullfilled && this.options.defaultFullfillment) {
this.fullfillInterest(this.options.defaultFullfillment);
}
}
/**

View File

@ -24,7 +24,10 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
*/
private comparisonFunc: IInterestComparisonFunc<DTInterestId>;
constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>, optionsArg: IInterestMapOptions = {}) {
constructor(
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>,
optionsArg: IInterestMapOptions = {}
) {
this.comparisonFunc = comparisonFuncArg;
this.options = optionsArg;
}
@ -34,7 +37,8 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
* @param objectArg
*/
public async addInterest(
objectArg: DTInterestId
objectArg: DTInterestId,
defaultFullfillmentArg?: DTInterestFullfillment
): Promise<Interest<DTInterestId, DTInterestFullfillment>> {
const comparisonString = this.comparisonFunc(objectArg);
let returnInterest: Interest<DTInterestId, DTInterestFullfillment>;
@ -43,7 +47,8 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
objectArg,
this.comparisonFunc,
{
markLostAfterDefault: this.options.markLostAfterDefault
markLostAfterDefault: this.options.markLostAfterDefault,
defaultFullfillment: defaultFullfillmentArg,
}
);
let interestExists = false;

View File

@ -17,6 +17,11 @@ export interface IObjectmapFindFunction<T> {
(itemArg: T): boolean;
}
export interface IObjectMapEventData<T> {
operation: 'add' | 'remove';
payload: T;
}
/**
* allows keeping track of objects
*/
@ -24,7 +29,7 @@ export class ObjectMap<T> {
private fastMap = new FastMap<T>();
// events
public eventSubject = new plugins.smartrx.rxjs.Subject<any>();
public eventSubject = new plugins.smartrx.rxjs.Subject<IObjectMapEventData<T>>();
/**
* returns a new instance
@ -74,6 +79,10 @@ export class ObjectMap<T> {
// otherwise lets create it
const uniqueKey = uni('key');
this.addMappedUnique(uniqueKey, objectArg);
this.eventSubject.next({
operation: 'add',
payload: objectArg
});
return uniqueKey;
}
@ -150,7 +159,10 @@ export class ObjectMap<T> {
} else {
const keyToUse = keys[0];
const removedItem = this.fastMap.removeFromMap(keyToUse);
this.eventSubject.next('remove');
this.eventSubject.next({
operation: 'remove',
payload: removedItem
});
return removedItem;
}
}
@ -180,7 +192,10 @@ export class ObjectMap<T> {
if (this.checkForObject(objectArg)) {
const keyArg = this.getKeyForObject(objectArg);
const removedObject = this.fastMap.removeFromMap(keyArg);
this.eventSubject.next('remove');
this.eventSubject.next({
operation: 'remove',
payload: removedObject
});
return removedObject;
}
return null;