Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelcoxon committed Feb 8, 2024
1 parent 2a3f6c1 commit f2137ca
Show file tree
Hide file tree
Showing 93 changed files with 2,886 additions and 673 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
};
2,756 changes: 2,458 additions & 298 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@
"@types/prop-types": "^15.7.9",
"@types/shelljs": "^0.8.14",
"@types/webpack-env": "^1.18.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"ajv": "^8.12.0",
"browserslist": "^4.22.1",
"copyfiles": "^2.4.1",
"dts-bundle": "^0.7.3",
"eslint": "^8.56.0",
"file-loader": "^6.2.0",
"jest": "^29.7.0",
"json-loader": "^0.5.7",
Expand Down
4 changes: 0 additions & 4 deletions src/Arrays/utils/_Array.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import all from './all';
import any from './any';
import average from './average';
import contains from './contains';
import count from "./count";
import distinct from './distinct';
import first from './first';
import firstOrDefault from './firstOrDefault';
import forEach from './forEach';
import groupBy from './groupBy';
import item from './item';
import last from './last';
Expand All @@ -16,8 +14,6 @@ import min from './min';
import ofType from './ofType';
import select from './select';
import selectMany from './selectMany';
import single from './single';
import singleOrDefault from './singleOrDefault';
import take from './take';
import where from './where';
import orderBy from './orderBy';
Expand Down
5 changes: 0 additions & 5 deletions src/Arrays/utils/groupBy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Selector } from '../../Types';
import distinct from './distinct';
import select from './select';
import where from './where';



export default function groupBy<T, TKey>(array: T[], keySelector: Selector<T, TKey>): Map<TKey, T[]>
{
Expand Down
4 changes: 0 additions & 4 deletions src/Assertions/ArrayLikeArgumentAssertionBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import ArgumentAssertionBuilder from './ArgumentAssertionBuilder';
import ArgumentException from '../Exceptions/ArgumentException';
import ArgumentNullException from '../Exceptions/ArgumentNullException';
import ArgumentUndefinedException from '../Exceptions/ArgumentUndefinedException';
import NotSupportedException from '../Exceptions/NotSupportedException';


export default class ArrayLikeArgumentAssertionBuilder<T> extends ArgumentAssertionBuilder<ArrayLike<T>>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Assertions/GuidArgumentAssertionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class GuidArgumentAssertionBuilder extends ArgumentAssertionBuild
{
let matched = false;

for (let option of options)
for (const option of options)
{
matched = option.toString() === this.argument.toString();

Expand Down
30 changes: 15 additions & 15 deletions src/Cache/AsyncCacheItem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Awaitable } from '../Types';
import { IAsyncCacheItem, IExpiryPolicyDelegate } from './_types';
import CacheExpiredException from './CacheExpiredException';
import isFunction from '../TypeHelpers/isFunction';
import { cat } from 'shelljs';
import { Promises } from '..';
import { error } from 'console';


export default class AsyncCacheItem<T> implements IAsyncCacheItem<T>
Expand All @@ -27,24 +24,27 @@ export default class AsyncCacheItem<T> implements IAsyncCacheItem<T>

public getValueAsync(): Promise<T>
{
return new Promise<T>(async (resolve, reject) =>
return new Promise<T>((resolve, reject) =>
{
try
(async () =>
{
const value = await Promises.ensurePromise(this.#promiseOrValue);
if (this.#expiryPolicy(value))
try
{
reject();
const value = await Promises.ensurePromise(this.#promiseOrValue);
if (this.#expiryPolicy(value))
{
reject();
}
else
{
resolve(value);
}
}
else
catch (error)
{
resolve(value);
reject(error);
}
}
catch (error)
{
reject(error);
}
})();
});
}
}
2 changes: 1 addition & 1 deletion src/Cache/MemoryCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("MemoryCache + expire", () =>
}
catch (err)
{
;
//
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/Cache/MemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { isUndefinedOrNull } from '../TypeHelpers';
*/
export default class MemoryCache<TKey = string> implements ICache<TKey>
{
readonly #internalCache: Map<TKey, IAsyncCacheItem<any>>;
readonly #internalCache: Map<TKey, IAsyncCacheItem<unknown>>;

constructor()
{
this.#internalCache = new Map<TKey, IAsyncCacheItem<any>>();
this.#internalCache = new Map<TKey, IAsyncCacheItem<unknown>>();
}

add<T>(key: TKey, value: Awaitable<T>, expiryPolicy: IExpiryPolicyDelegate<T>): void
Expand All @@ -30,7 +30,7 @@ export default class MemoryCache<TKey = string> implements ICache<TKey>
async addOrGetAsync<T>(key: TKey, factory: (key: TKey) => Awaitable<T>, expiryPolicy: IExpiryPolicyDelegate<T>): Promise<T>
{
const cacheItem = this.#internalCache.get(key) as IAsyncCacheItem<T> | undefined;
let value = await cacheItem?.getValueAsync();
const value = await cacheItem?.getValueAsync();

if (!isUndefinedOrNull(value))
{
Expand All @@ -51,7 +51,7 @@ export default class MemoryCache<TKey = string> implements ICache<TKey>

async cleanAsync(): Promise<void>
{
for (var item of this.#internalCache)
for (const item of this.#internalCache)
{
const value = item[1];
const key = item[0];
Expand Down
21 changes: 10 additions & 11 deletions src/Cache/expire.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { any } from '../Arrays';
import { ArgumentNullException, NullReferenceException } from '../Exceptions';
import { ArgumentNullException } from '../Exceptions';
import { IExpiryPolicyDelegate } from './_types';


Expand Down Expand Up @@ -37,58 +36,58 @@ expire.inYears = expireInYears;
function expireAt(date: Date)
{
return expire(() => date <= new Date());
};
}

function expireIn(time: number)
{
const expires = new Date();
expires.setTime(expires.getTime() + time);
return expireAt(expires);
};
}

function expireTomorrow()
{
return expireInDays(1);
};
}

function expireInSeconds(seconds: number)
{
const expires = new Date();
expires.setSeconds(expires.getSeconds() + seconds);
return expireAt(expires);
};
}

function expireInMinutes(minutes: number)
{
const expires = new Date();
expires.setMinutes(expires.getMinutes() + minutes);
return expireAt(expires);
};
}

function expireInHours(hours: number)
{
const expires = new Date();
expires.setHours(expires.getHours() + hours);
return expireAt(expires);
};
}

function expireInDays(days: number)
{
const expires = new Date();
expires.setDate(expires.getDate() + days);
return expireAt(expires);
};
}

function expireInMonths(months: number)
{
const expires = new Date();
expires.setMonth(expires.getMonth() + months);
return expireAt(expires);
};
}

function expireInYears(years: number)
{
const expires = new Date();
expires.setFullYear(expires.getFullYear() + years);
return expireAt(expires);
};
}
4 changes: 2 additions & 2 deletions src/Comparers/CustomComparer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class CustomComparer<T> implements IComparer<T>, IEqualityCompare
}
else
{
throw new ArgumentUndefinedException("The comparer");
throw new ArgumentUndefinedException("you must specify the comparer in the constructor to use compare.");
}
}

Expand All @@ -38,7 +38,7 @@ export default class CustomComparer<T> implements IComparer<T>, IEqualityCompare
}
else
{
throw new ArgumentUndefinedException("The equality comparer");
throw new ArgumentUndefinedException("you must specify The equality comparer in the constructor to use equals.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Comparers/DefaultComparers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class DefaultComparer<T> implements IComparer<T>, IEqualityComparer<T> {


const DefaultComparers = {
DefaultComparer: new DefaultComparer<any>(),
DefaultComparer: new DefaultComparer<unknown>(),
StringComparer: new DefaultStringComparer(),
NumberComparer: new DefaultNumberComparer(),
ObjectComparer: new DefaultObjectComparer(),
Expand Down
2 changes: 1 addition & 1 deletion src/Comparers/DefaultObjectComparer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IComparer, IEqualityComparer } from './_types';
/**
* Default implementation
*/
export default class DefaultObjectComparer<T extends any = any> implements IComparer<T>, IEqualityComparer<T> {
export default class DefaultObjectComparer<T = unknown> implements IComparer<T>, IEqualityComparer<T> {
public compare(x: T, y: T): number
{
const toStringMethodName = 'toString';
Expand Down
2 changes: 1 addition & 1 deletion src/Comparers/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

export interface IComparable
{
valueOf(): any;
valueOf(): unknown;
}

export interface IComparer<T>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IEvent, Event } from '../Events';
import { INotifyPropertyChanged, INotifyComponentPropertyChangedEventArgs, INotifyPropertyChangedEventArgs } from '../INotifyPropertyChanged';
import { Collection, Enumerable } from '../Enumerables';

type Props = Undefinable<{}>;
type Props = Undefinable<unknown>;

export interface IComponent<TProps extends Props = undefined> extends INotifyPropertyChanged, IDisposable
{
Expand Down Expand Up @@ -57,7 +57,7 @@ export default abstract class Component<TProps extends Props> implements ICompon
{
component.propertyChanged.addHandler((s, e) =>
{
this.#propertyChanged.invoke(this, {...e, instance: s });
this.#propertyChanged.invoke(this, {...e, instance: s as INotifyPropertyChanged });
});
component.init();
}
Expand Down
1 change: 0 additions & 1 deletion src/Components/ListComponent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import Component from './Component';
import { List } from '../Enumerables';

interface IListComponentProps
{
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Json/Json.types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

export type ConfigValue<T = {}> = T[] | T | string | number | boolean;
export type ConfigValue<T = NonNullable<unknown>> = ConfigValue<T>[] | T | string | number | boolean;
32 changes: 21 additions & 11 deletions src/Configuration/Json/JsonConfigurationBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NotImplementedException } from '../../Exceptions';
import isString from '../../TypeHelpers/isString';
import isUndefinedOrNull from '../../TypeHelpers/isUndefinedOrNull';
//import merge from '../../Utilities/merge';
Expand All @@ -16,25 +17,32 @@ export default class JsonConfigurationBuilder implements IConfigurationBuilder
if (reload || this.#reload || isUndefinedOrNull(this.#configuration))
{
let mergedConfig = {};
for(const config of this.#configs)
for (const config of this.#configs)
{
mergedConfig = mergeWith(mergedConfig, config,customizer);
mergedConfig = mergeWith(mergedConfig, config, customizer);
}
this.#configuration = new JsonConfiguration(mergedConfig);
this.#reload = false;
}
return this.#configuration;
}
public append(json: string): this;
public append(array: any[]): this;
public append(object: Record<string, any>): this;
public append(value: any): this
public append(array: unknown[]): this;
public append(object: Record<string, unknown>): this;
public append(value: Record<string, unknown> | unknown[] | string): this
{
if (isString(value))
{
value = JSON.parse(value);
this.#configs.push(JSON.parse(value));
}
else if (Array.isArray(value))
{
throw new NotImplementedException();
}
else
{
this.#configs.push(value as Record<string, ConfigValue>);
}
this.#configs.push(value);
if (!this.#reload)
{
this.#reload = true;
Expand All @@ -43,8 +51,10 @@ export default class JsonConfigurationBuilder implements IConfigurationBuilder
}
}

function customizer(objValue, srcValue) {
if (Array.isArray(objValue)) {
return objValue.concat(srcValue);
function customizer(objValue, srcValue)
{
if (Array.isArray(objValue))
{
return objValue.concat(srcValue);
}
}
}
Loading

0 comments on commit f2137ca

Please sign in to comment.