Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
f84822dd5d | |||
21d6e19a22 | |||
8947738dc1 | |||
14bc5dcd25 | |||
c2f366de7f | |||
ae47276569 | |||
42b59c109d | |||
8f18faaf1c | |||
ccd5b80d67 | |||
298904e17e | |||
fa91e67aef | |||
5e99066bee | |||
a838f7eb80 | |||
979e93be27 |
@ -19,23 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- 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
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- 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:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -50,9 +62,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -63,9 +73,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -85,6 +93,8 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3216
package-lock.json
generated
3216
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/lik",
|
"name": "@pushrocks/lik",
|
||||||
"version": "4.0.14",
|
"version": "4.0.21",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "light little helpers for node",
|
"description": "light little helpers for node",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -20,21 +20,21 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsbundle": "^1.0.72",
|
"@gitzone/tsbundle": "^1.0.78",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.41",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^14.0.22",
|
"@types/node": "^14.14.9",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
"@pushrocks/smartmatch": "^1.0.7",
|
"@pushrocks/smartmatch": "^1.0.7",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartrx": "^2.0.17",
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"@pushrocks/smarttime": "^3.0.24",
|
"@pushrocks/smarttime": "^3.0.37",
|
||||||
"@types/minimatch": "^3.0.3",
|
"@types/minimatch": "^3.0.3",
|
||||||
"symbol-tree": "^3.2.4"
|
"symbol-tree": "^3.2.4"
|
||||||
},
|
},
|
||||||
|
@ -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();
|
|
@ -1,5 +1,6 @@
|
|||||||
export * from './lik.fastmap';
|
export * from './lik.fastmap';
|
||||||
export * from './lik.interestmap';
|
export * from './lik.interestmap';
|
||||||
|
export * from './lik.interestmap.interest';
|
||||||
export * from './lik.limitedarray';
|
export * from './lik.limitedarray';
|
||||||
export * from './lik.looptracker';
|
export * from './lik.looptracker';
|
||||||
export * from './lik.objectmap';
|
export * from './lik.objectmap';
|
||||||
|
@ -29,7 +29,7 @@ export class FastMap<T> {
|
|||||||
return this.mapObject[keyArg];
|
return this.mapObject[keyArg];
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeFromMap(keyArg): T {
|
public removeFromMap(keyArg: string): T {
|
||||||
const removedItem = this.getByKey(keyArg);
|
const removedItem = this.getByKey(keyArg);
|
||||||
delete this.mapObject[keyArg];
|
delete this.mapObject[keyArg];
|
||||||
return removedItem;
|
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>) {
|
public concat(fastMapArg: FastMap<T>) {
|
||||||
const concatedFastmap = new 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
|
* Note: uniqueKeyCollisions will cause overwrite
|
||||||
* @param objectMapArg
|
* @param fastMapArg
|
||||||
*/
|
*/
|
||||||
public addAllFromOther(fastMapArg: FastMap<T>) {
|
public addAllFromOther(fastMapArg: FastMap<T>) {
|
||||||
for (const key of fastMapArg.getKeys()) {
|
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()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,14 @@ import * as plugins from './lik.plugins';
|
|||||||
|
|
||||||
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
|
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
|
||||||
|
|
||||||
|
export interface IInterestOptions<DTInterestFullfillment> {
|
||||||
|
markLostAfterDefault: number;
|
||||||
|
defaultFullfillment?: DTInterestFullfillment;
|
||||||
|
}
|
||||||
|
|
||||||
export class Interest<DTInterestId, DTInterestFullfillment> {
|
export class Interest<DTInterestId, DTInterestFullfillment> {
|
||||||
|
public options: IInterestOptions<DTInterestFullfillment>;
|
||||||
|
|
||||||
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
|
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
|
||||||
public originalInterest: DTInterestId;
|
public originalInterest: DTInterestId;
|
||||||
public comparisonFunc: IInterestComparisonFunc<DTInterestId>;
|
public comparisonFunc: IInterestComparisonFunc<DTInterestId>;
|
||||||
@ -41,14 +48,20 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
|
|||||||
constructor(
|
constructor(
|
||||||
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
|
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
|
||||||
interestArg: DTInterestId,
|
interestArg: DTInterestId,
|
||||||
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>
|
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>,
|
||||||
|
optionsArg?: IInterestOptions<DTInterestFullfillment>
|
||||||
) {
|
) {
|
||||||
|
this.interestMapRef = interestMapArg;
|
||||||
this.originalInterest = interestArg;
|
this.originalInterest = interestArg;
|
||||||
this.comparisonFunc = comparisonFuncArg;
|
this.comparisonFunc = comparisonFuncArg;
|
||||||
this.interestMapRef = interestMapArg;
|
this.options = optionsArg;
|
||||||
|
|
||||||
this.destructionTimer.completed.then(() => {
|
this.destructionTimer.completed.then(() => {
|
||||||
this.destroy();
|
this.destroy();
|
||||||
});
|
});
|
||||||
|
if (this.options?.markLostAfterDefault) {
|
||||||
|
plugins.smartdelay.delayFor(this.options.markLostAfterDefault).then(this.markLost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
@ -60,6 +73,9 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
|
|||||||
*/
|
*/
|
||||||
public destroy() {
|
public destroy() {
|
||||||
this.interestMapRef.removeInterest(this);
|
this.interestMapRef.removeInterest(this);
|
||||||
|
if (!this.isFullfilled && this.options.defaultFullfillment) {
|
||||||
|
this.fullfillInterest(this.options.defaultFullfillment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,13 @@ import { Interest } from './lik.interestmap.interest';
|
|||||||
|
|
||||||
export type IInterestComparisonFunc<T> = (objectArg: T) => string;
|
export type IInterestComparisonFunc<T> = (objectArg: T) => string;
|
||||||
|
|
||||||
|
export interface IInterestMapOptions {
|
||||||
|
markLostAfterDefault?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
||||||
|
public options: IInterestMapOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stores interests that are currently fullfilled by the cache
|
* stores interests that are currently fullfilled by the cache
|
||||||
*/
|
*/
|
||||||
@ -18,8 +24,12 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
|||||||
*/
|
*/
|
||||||
private comparisonFunc: IInterestComparisonFunc<DTInterestId>;
|
private comparisonFunc: IInterestComparisonFunc<DTInterestId>;
|
||||||
|
|
||||||
constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>) {
|
constructor(
|
||||||
|
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>,
|
||||||
|
optionsArg: IInterestMapOptions = {}
|
||||||
|
) {
|
||||||
this.comparisonFunc = comparisonFuncArg;
|
this.comparisonFunc = comparisonFuncArg;
|
||||||
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,14 +37,19 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
|||||||
* @param objectArg
|
* @param objectArg
|
||||||
*/
|
*/
|
||||||
public async addInterest(
|
public async addInterest(
|
||||||
objectArg: DTInterestId
|
objectArg: DTInterestId,
|
||||||
|
defaultFullfillmentArg?: DTInterestFullfillment
|
||||||
): Promise<Interest<DTInterestId, DTInterestFullfillment>> {
|
): Promise<Interest<DTInterestId, DTInterestFullfillment>> {
|
||||||
const comparisonString = this.comparisonFunc(objectArg);
|
const comparisonString = this.comparisonFunc(objectArg);
|
||||||
let returnInterest: Interest<DTInterestId, DTInterestFullfillment>;
|
let returnInterest: Interest<DTInterestId, DTInterestFullfillment>;
|
||||||
const newInterest = new Interest<DTInterestId, DTInterestFullfillment>(
|
const newInterest = new Interest<DTInterestId, DTInterestFullfillment>(
|
||||||
this,
|
this,
|
||||||
objectArg,
|
objectArg,
|
||||||
this.comparisonFunc
|
this.comparisonFunc,
|
||||||
|
{
|
||||||
|
markLostAfterDefault: this.options.markLostAfterDefault,
|
||||||
|
defaultFullfillment: defaultFullfillmentArg,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
let interestExists = false;
|
let interestExists = false;
|
||||||
await this.interestObjectMap.forEach((interestArg) => {
|
await this.interestObjectMap.forEach((interestArg) => {
|
||||||
|
@ -17,6 +17,11 @@ export interface IObjectmapFindFunction<T> {
|
|||||||
(itemArg: T): boolean;
|
(itemArg: T): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IObjectMapEventData<T> {
|
||||||
|
operation: 'add' | 'remove';
|
||||||
|
payload: T;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* allows keeping track of objects
|
* allows keeping track of objects
|
||||||
*/
|
*/
|
||||||
@ -24,7 +29,7 @@ export class ObjectMap<T> {
|
|||||||
private fastMap = new FastMap<T>();
|
private fastMap = new FastMap<T>();
|
||||||
|
|
||||||
// events
|
// events
|
||||||
public eventSubject = new plugins.smartrx.rxjs.Subject<any>();
|
public eventSubject = new plugins.smartrx.rxjs.Subject<IObjectMapEventData<T>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a new instance
|
* returns a new instance
|
||||||
@ -74,6 +79,10 @@ export class ObjectMap<T> {
|
|||||||
// otherwise lets create it
|
// otherwise lets create it
|
||||||
const uniqueKey = uni('key');
|
const uniqueKey = uni('key');
|
||||||
this.addMappedUnique(uniqueKey, objectArg);
|
this.addMappedUnique(uniqueKey, objectArg);
|
||||||
|
this.eventSubject.next({
|
||||||
|
operation: 'add',
|
||||||
|
payload: objectArg
|
||||||
|
});
|
||||||
return uniqueKey;
|
return uniqueKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +159,10 @@ export class ObjectMap<T> {
|
|||||||
} else {
|
} else {
|
||||||
const keyToUse = keys[0];
|
const keyToUse = keys[0];
|
||||||
const removedItem = this.fastMap.removeFromMap(keyToUse);
|
const removedItem = this.fastMap.removeFromMap(keyToUse);
|
||||||
this.eventSubject.next('remove');
|
this.eventSubject.next({
|
||||||
|
operation: 'remove',
|
||||||
|
payload: removedItem
|
||||||
|
});
|
||||||
return removedItem;
|
return removedItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,7 +192,10 @@ export class ObjectMap<T> {
|
|||||||
if (this.checkForObject(objectArg)) {
|
if (this.checkForObject(objectArg)) {
|
||||||
const keyArg = this.getKeyForObject(objectArg);
|
const keyArg = this.getKeyForObject(objectArg);
|
||||||
const removedObject = this.fastMap.removeFromMap(keyArg);
|
const removedObject = this.fastMap.removeFromMap(keyArg);
|
||||||
this.eventSubject.next('remove');
|
this.eventSubject.next({
|
||||||
|
operation: 'remove',
|
||||||
|
payload: removedObject
|
||||||
|
});
|
||||||
return removedObject;
|
return removedObject;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user