patron-oop 1.40.0 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-push +2 -0
- package/CHANGELOG.md +12 -0
- package/dist/patron.cjs +98 -8
- package/dist/patron.cjs.map +1 -1
- package/dist/patron.js +98 -8
- package/dist/patron.js.map +1 -1
- package/dist/patron.min.js +1 -1
- package/dist/patron.min.mjs +1 -1
- package/dist/patron.min.mjs.map +1 -1
- package/dist/patron.mjs +98 -8
- package/dist/patron.mjs.map +1 -1
- package/eslint.config.mjs +6 -7
- package/package.json +7 -4
- package/src/Guest/Guest.ts +15 -2
- package/src/Guest/GuestAware.ts +26 -6
- package/src/Guest/GuestAwareActive.test.ts +5 -7
- package/src/Guest/GuestAwareActive.ts +12 -3
- package/src/Guest/GuestAwareMap.defered.test.ts +10 -12
- package/src/Guest/GuestAwareMap.fn.test.ts +5 -8
- package/src/Guest/GuestAwareMap.test.ts +7 -10
- package/src/Guest/GuestAwareMap.ts +21 -8
- package/src/Guest/GuestAwareRace.test.ts +8 -8
- package/src/Guest/GuestAwareRace.ts +12 -5
- package/src/Guest/GuestAwareSequence.defered.test.ts +18 -15
- package/src/Guest/GuestAwareSequence.test.ts +6 -9
- package/src/Guest/GuestAwareSequence.ts +26 -13
- package/src/Guest/GuestCast.ts +10 -6
- package/src/Guest/GuestDisposable.ts +8 -1
- package/src/Guest/GuestObject.ts +6 -5
- package/src/Guest/GuestPool.test.ts +15 -2
- package/src/Guest/GuestSync.ts +5 -1
- package/src/Patron/Patron.ts +5 -1
- package/src/Patron/PatronOnce.sourceEmpty.test.ts +7 -4
- package/src/Patron/PatronOnce.test.ts +2 -2
- package/src/Patron/PatronOnce.ts +5 -1
- package/src/Patron/PatronPool.ts +6 -0
- package/src/Private/Private.test.ts +2 -2
- package/src/Private/Private.ts +9 -3
- package/src/Private/PrivateClass.modules.test.ts +1 -1
- package/src/Private/PrivateClass.test.ts +2 -4
- package/src/Private/PrivateClass.ts +6 -2
- package/src/Source/Source.ts +5 -1
- package/src/Source/SourceDynamic.ofSource.test.ts +4 -4
- package/src/Source/SourceDynamic.test.ts +2 -2
- package/src/Source/SourceDynamic.ts +9 -2
@@ -6,19 +6,26 @@ import { GuestCast } from "./GuestCast";
|
|
6
6
|
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware-race
|
7
7
|
*/
|
8
8
|
export class GuestAwareRace<T> implements GuestAwareObjectType<T> {
|
9
|
-
public constructor(private guestAwares: GuestAwareType<T>[]) {
|
9
|
+
public constructor(private guestAwares: GuestAwareType<T>[]) {
|
10
|
+
if (guestAwares === undefined) {
|
11
|
+
throw new Error("GuestAwareRace didnt receive guestAwares argument");
|
12
|
+
}
|
13
|
+
}
|
10
14
|
|
11
15
|
public value(guest: GuestType<T>): this {
|
12
16
|
let connectedWithGuestAware: GuestAwareType | null = null;
|
13
|
-
this.guestAwares.forEach(guestAware => {
|
17
|
+
this.guestAwares.forEach((guestAware) => {
|
14
18
|
value(
|
15
19
|
guestAware,
|
16
20
|
new GuestCast(<GuestType>guest, (value) => {
|
17
|
-
if (
|
21
|
+
if (
|
22
|
+
!connectedWithGuestAware ||
|
23
|
+
connectedWithGuestAware === guestAware
|
24
|
+
) {
|
18
25
|
give(value as T, guest);
|
19
|
-
connectedWithGuestAware = guestAware
|
26
|
+
connectedWithGuestAware = guestAware;
|
20
27
|
}
|
21
|
-
})
|
28
|
+
}),
|
22
29
|
);
|
23
30
|
});
|
24
31
|
return this;
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import { GuestAwareSequence } from "./GuestAwareSequence";
|
2
2
|
import { give } from "./Guest";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
GuestAware,
|
5
|
+
GuestAwareObjectType,
|
6
|
+
GuestAwareType,
|
7
|
+
value,
|
8
|
+
} from "./GuestAware";
|
4
9
|
import { GuestCast } from "./GuestCast";
|
5
10
|
import { GuestType } from "./Guest";
|
6
11
|
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
@@ -18,38 +23,36 @@ afterEach(() => {
|
|
18
23
|
});
|
19
24
|
|
20
25
|
class X2 implements GuestAwareObjectType<number> {
|
21
|
-
public constructor(private baseNumber: GuestAwareType<number>) {
|
26
|
+
public constructor(private baseNumber: GuestAwareType<number>) {}
|
22
27
|
|
23
28
|
public value(guest: GuestType<number>) {
|
24
29
|
value(
|
25
30
|
this.baseNumber,
|
26
31
|
new GuestCast(<GuestType>guest, (v) => {
|
27
32
|
give(v * 2, guest);
|
28
|
-
})
|
33
|
+
}),
|
29
34
|
);
|
30
35
|
return this;
|
31
36
|
}
|
32
37
|
}
|
33
38
|
|
34
|
-
test(
|
35
|
-
const guestAwareOf = (val: number) =>
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
test("GuestAwareSequence.defered.test", async () => {
|
40
|
+
const guestAwareOf = (val: number) =>
|
41
|
+
new GuestAware((guest) => {
|
42
|
+
setTimeout(() => {
|
43
|
+
give(val, guest);
|
44
|
+
}, 10);
|
45
|
+
});
|
40
46
|
const source = new Source([1, 2, 3, 9].map(guestAwareOf));
|
41
47
|
|
42
|
-
const sequence = new GuestAwareSequence(
|
43
|
-
source,
|
44
|
-
new PrivateClass(X2)
|
45
|
-
);
|
48
|
+
const sequence = new GuestAwareSequence(source, new PrivateClass(X2));
|
46
49
|
|
47
50
|
const callFn = vi.fn();
|
48
51
|
sequence.value((v) => {
|
49
|
-
expect(v.join()).toBe(
|
52
|
+
expect(v.join()).toBe("2,4,6,18");
|
50
53
|
callFn();
|
51
54
|
});
|
52
55
|
|
53
56
|
await wait(51);
|
54
57
|
expect(callFn).toBeCalled();
|
55
|
-
})
|
58
|
+
});
|
@@ -8,26 +8,23 @@ import { Source } from "../Source/Source";
|
|
8
8
|
import { PrivateClass } from "../Private/PrivateClass";
|
9
9
|
|
10
10
|
class X2 implements GuestAwareObjectType<number> {
|
11
|
-
public constructor(private baseNumber: GuestAwareType<number>) {
|
11
|
+
public constructor(private baseNumber: GuestAwareType<number>) {}
|
12
12
|
|
13
13
|
public value(guest: GuestType<number>) {
|
14
14
|
value(
|
15
15
|
this.baseNumber,
|
16
16
|
new GuestCast(<GuestType>guest, (v) => {
|
17
17
|
give(v * 2, guest);
|
18
|
-
})
|
18
|
+
}),
|
19
19
|
);
|
20
20
|
return this;
|
21
21
|
}
|
22
22
|
}
|
23
23
|
|
24
|
-
test(
|
24
|
+
test("GuestAwareSequence.test", () => {
|
25
25
|
const source = new Source([1, 2, 3, 9]);
|
26
|
-
const guestMapped = new GuestAwareSequence(
|
27
|
-
source,
|
28
|
-
new PrivateClass(X2)
|
29
|
-
);
|
26
|
+
const guestMapped = new GuestAwareSequence(source, new PrivateClass(X2));
|
30
27
|
guestMapped.value((v) => {
|
31
|
-
expect(v.join()).toBe(
|
28
|
+
expect(v.join()).toBe("2,4,6,18");
|
32
29
|
});
|
33
|
-
})
|
30
|
+
});
|
@@ -2,7 +2,12 @@ import { PatronOnce } from "../Patron/PatronOnce";
|
|
2
2
|
import { PrivateType } from "../Private/Private";
|
3
3
|
import { SourceEmpty } from "../Source/SourceEmpty";
|
4
4
|
import { give, GuestType } from "./Guest";
|
5
|
-
import {
|
5
|
+
import {
|
6
|
+
GuestAwareObjectType,
|
7
|
+
GuestAwareType,
|
8
|
+
isGuestAware,
|
9
|
+
value,
|
10
|
+
} from "./GuestAware";
|
6
11
|
import { GuestAwareAll } from "./GuestAwareAll";
|
7
12
|
import { GuestCast } from "./GuestCast";
|
8
13
|
|
@@ -12,15 +17,20 @@ import { GuestCast } from "./GuestCast";
|
|
12
17
|
export class GuestAwareSequence<T, TG> implements GuestAwareObjectType<TG[]> {
|
13
18
|
public constructor(
|
14
19
|
private baseSource: GuestAwareType<T[]>,
|
15
|
-
private targetSource: PrivateType<GuestAwareType<TG
|
16
|
-
) {
|
20
|
+
private targetSource: PrivateType<GuestAwareType<TG>>,
|
21
|
+
) {
|
22
|
+
if (baseSource === undefined) {
|
23
|
+
throw new Error("GuestAwareSequence didnt receive baseSource argument");
|
24
|
+
}
|
25
|
+
if (targetSource === undefined) {
|
26
|
+
throw new Error("GuestAwareSequence didnt receive targetSource argument");
|
27
|
+
}
|
28
|
+
}
|
17
29
|
|
18
30
|
public value(guest: GuestType<TG[]>) {
|
19
31
|
const all = new GuestAwareAll<TG[]>();
|
20
32
|
const sequenceSource = new SourceEmpty();
|
21
|
-
const targetSource = this.targetSource.get(
|
22
|
-
sequenceSource
|
23
|
-
)
|
33
|
+
const targetSource = this.targetSource.get(sequenceSource);
|
24
34
|
|
25
35
|
value(
|
26
36
|
this.baseSource,
|
@@ -34,17 +44,20 @@ export class GuestAwareSequence<T, TG> implements GuestAwareObjectType<TG[]> {
|
|
34
44
|
} else {
|
35
45
|
all.valueArray(guest);
|
36
46
|
}
|
37
|
-
}
|
47
|
+
};
|
38
48
|
|
39
49
|
function handle() {
|
40
50
|
sequenceSource.give(null);
|
41
51
|
const nextValue = theValue[index];
|
42
52
|
if (isGuestAware(nextValue)) {
|
43
|
-
value(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
value(
|
54
|
+
nextValue,
|
55
|
+
new PatronOnce((theNextValue) => {
|
56
|
+
sequenceSource.give(theNextValue);
|
57
|
+
value(targetSource, all.guestKey(index.toString()));
|
58
|
+
nextItemHandle();
|
59
|
+
}),
|
60
|
+
);
|
48
61
|
} else {
|
49
62
|
sequenceSource.give(nextValue);
|
50
63
|
value(targetSource, all.guestKey(index.toString()));
|
@@ -57,7 +70,7 @@ export class GuestAwareSequence<T, TG> implements GuestAwareObjectType<TG[]> {
|
|
57
70
|
} else {
|
58
71
|
give([], guest);
|
59
72
|
}
|
60
|
-
})
|
73
|
+
}),
|
61
74
|
);
|
62
75
|
return this;
|
63
76
|
}
|
package/src/Guest/GuestCast.ts
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
GuestDisposableType,
|
3
|
-
MaybeDisposableType,
|
4
|
-
} from "./GuestDisposable";
|
1
|
+
import { GuestDisposableType, MaybeDisposableType } from "./GuestDisposable";
|
5
2
|
import { give, GiveOptions, GuestType } from "./Guest";
|
6
3
|
import { PoolAwareOptions } from "../Patron/PatronOnce";
|
7
4
|
|
@@ -12,7 +9,14 @@ export class GuestCast<T> implements GuestDisposableType<T> {
|
|
12
9
|
public constructor(
|
13
10
|
private sourceGuest: GuestType<any>,
|
14
11
|
private targetGuest: GuestType<T>,
|
15
|
-
) {
|
12
|
+
) {
|
13
|
+
if (sourceGuest === undefined) {
|
14
|
+
throw new Error("GuestCast didnt receive sourceGuest argument");
|
15
|
+
}
|
16
|
+
if (targetGuest === undefined) {
|
17
|
+
throw new Error("GuestCast didnt receive targetGuest argument");
|
18
|
+
}
|
19
|
+
}
|
16
20
|
|
17
21
|
public introduction() {
|
18
22
|
if (typeof this.sourceGuest === "function") {
|
@@ -30,7 +34,7 @@ export class GuestCast<T> implements GuestDisposableType<T> {
|
|
30
34
|
data: {
|
31
35
|
...(options?.data ?? {}),
|
32
36
|
castedGuest: (options?.data as PoolAwareOptions)?.castedGuest ?? this,
|
33
|
-
}
|
37
|
+
},
|
34
38
|
});
|
35
39
|
return this;
|
36
40
|
}
|
@@ -13,7 +13,14 @@ export class GuestDisposable<T> implements GuestDisposableType<T> {
|
|
13
13
|
public constructor(
|
14
14
|
private guest: GuestType,
|
15
15
|
private disposeCheck: (value: T | null) => boolean,
|
16
|
-
) {
|
16
|
+
) {
|
17
|
+
if (guest === undefined) {
|
18
|
+
throw new Error("GuestDisposable didnt receive guest argument");
|
19
|
+
}
|
20
|
+
if (disposeCheck === undefined) {
|
21
|
+
throw new Error("GuestDisposable didnt receive disposeCheck argument");
|
22
|
+
}
|
23
|
+
}
|
17
24
|
|
18
25
|
public disposed(value: T | null): boolean {
|
19
26
|
return this.disposeCheck(value);
|
package/src/Guest/GuestObject.ts
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
GuestDisposableType,
|
3
|
-
MaybeDisposableType,
|
4
|
-
} from "./GuestDisposable";
|
1
|
+
import { GuestDisposableType, MaybeDisposableType } from "./GuestDisposable";
|
5
2
|
import { GiveOptions, Guest, GuestType } from "./Guest";
|
6
3
|
|
7
4
|
/**
|
8
5
|
* @url https://kosukhin.github.io/patron.site/#/guest/guest-object
|
9
6
|
*/
|
10
7
|
export class GuestObject<T> implements GuestDisposableType<T> {
|
11
|
-
public constructor(private baseGuest: GuestType<T>) {
|
8
|
+
public constructor(private baseGuest: GuestType<T>) {
|
9
|
+
if (baseGuest === undefined) {
|
10
|
+
throw new Error("GuestObject didnt receive baseGuest argument");
|
11
|
+
}
|
12
|
+
}
|
12
13
|
|
13
14
|
public give(value: T, options?: GiveOptions): this {
|
14
15
|
let guest = this.baseGuest;
|
@@ -1,8 +1,18 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
1
|
+
import { expect, test, vi, beforeEach, afterEach } from "vitest";
|
2
2
|
import { GuestPool } from "./GuestPool";
|
3
3
|
import { Patron } from "../Patron/Patron";
|
4
|
+
import { wait } from "test-utils/wait";
|
4
5
|
|
5
|
-
|
6
|
+
beforeEach(() => {
|
7
|
+
vi.useFakeTimers({ shouldAdvanceTime: true });
|
8
|
+
});
|
9
|
+
|
10
|
+
afterEach(() => {
|
11
|
+
vi.runOnlyPendingTimers();
|
12
|
+
vi.useRealTimers();
|
13
|
+
});
|
14
|
+
|
15
|
+
test("GuestPool.test", async () => {
|
6
16
|
const pool = new GuestPool<number>(null);
|
7
17
|
let receivedCount = 0;
|
8
18
|
|
@@ -28,7 +38,10 @@ test("GuestPool.test", () => {
|
|
28
38
|
pool.give(2);
|
29
39
|
});
|
30
40
|
|
41
|
+
await wait(50);
|
42
|
+
|
31
43
|
setTimeout(() => {
|
44
|
+
pool.give(2);
|
32
45
|
expect(receivedCount).toBe(10);
|
33
46
|
}, 10);
|
34
47
|
});
|
package/src/Guest/GuestSync.ts
CHANGED
@@ -8,7 +8,11 @@ export interface GuestValueType<T = any> extends GuestObjectType<T> {
|
|
8
8
|
* @url https://kosukhin.github.io/patron.site/#/guest/guest-sync
|
9
9
|
*/
|
10
10
|
export class GuestSync<T> implements GuestValueType<T> {
|
11
|
-
public constructor(private theValue: T) {
|
11
|
+
public constructor(private theValue: T) {
|
12
|
+
if (theValue === undefined) {
|
13
|
+
throw new Error("GuestSync didnt receive theValue argument");
|
14
|
+
}
|
15
|
+
}
|
12
16
|
|
13
17
|
public give(value: T): this {
|
14
18
|
this.theValue = value;
|
package/src/Patron/Patron.ts
CHANGED
@@ -5,7 +5,11 @@ import { give, GiveOptions, GuestType } from "../Guest/Guest";
|
|
5
5
|
* @url https://kosukhin.github.io/patron.site/#/patron
|
6
6
|
*/
|
7
7
|
export class Patron<T> implements GuestDisposableType<T> {
|
8
|
-
public constructor(private willBePatron: GuestType<T>) {
|
8
|
+
public constructor(private willBePatron: GuestType<T>) {
|
9
|
+
if (willBePatron === undefined) {
|
10
|
+
throw new Error("Patron didnt receive willBePatron argument");
|
11
|
+
}
|
12
|
+
}
|
9
13
|
|
10
14
|
public introduction() {
|
11
15
|
return "patron" as const;
|
@@ -11,14 +11,17 @@ afterEach(() => {
|
|
11
11
|
vi.useRealTimers();
|
12
12
|
});
|
13
13
|
|
14
|
-
const wait = (ms: number) =>
|
15
|
-
|
16
|
-
|
14
|
+
const wait = (ms: number) =>
|
15
|
+
new Promise((resolve) => {
|
16
|
+
setTimeout(() => {
|
17
|
+
resolve(1);
|
18
|
+
}, ms);
|
19
|
+
});
|
17
20
|
|
18
21
|
test("PatronOnce.sourceEmpty.test", async () => {
|
19
22
|
const source = new SourceEmpty();
|
20
23
|
let calls = 0;
|
21
|
-
const patron = new PatronOnce((
|
24
|
+
const patron = new PatronOnce(() => {
|
22
25
|
calls += 1;
|
23
26
|
});
|
24
27
|
source.value(patron);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { wait } from
|
1
|
+
import { wait } from "./../../test-utils/wait";
|
2
2
|
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
3
3
|
import { Source } from "../Source/Source";
|
4
4
|
import { PatronOnce } from "./PatronOnce";
|
@@ -15,7 +15,7 @@ afterEach(() => {
|
|
15
15
|
test("PatronOnce.test", async () => {
|
16
16
|
const source = new Source(12);
|
17
17
|
let calls = 0;
|
18
|
-
const patron = new PatronOnce((
|
18
|
+
const patron = new PatronOnce(() => {
|
19
19
|
calls += 1;
|
20
20
|
});
|
21
21
|
source.value(patron);
|
package/src/Patron/PatronOnce.ts
CHANGED
@@ -16,7 +16,11 @@ export type PoolAwareOptions = {
|
|
16
16
|
export class PatronOnce<T> implements GuestDisposableType<T> {
|
17
17
|
private received = false;
|
18
18
|
|
19
|
-
public constructor(private baseGuest: GuestType<T>) {
|
19
|
+
public constructor(private baseGuest: GuestType<T>) {
|
20
|
+
if (baseGuest === undefined) {
|
21
|
+
throw new Error("PatronOnce didnt receive baseGuest argument");
|
22
|
+
}
|
23
|
+
}
|
20
24
|
|
21
25
|
public introduction() {
|
22
26
|
return "patron" as const;
|
package/src/Patron/PatronPool.ts
CHANGED
@@ -7,6 +7,9 @@ const poolSets = new Map<PoolType, Set<GuestObjectType>>();
|
|
7
7
|
* @url https://kosukhin.github.io/patron.site/#/utils/remove-patron-from-pools
|
8
8
|
*/
|
9
9
|
export const removePatronFromPools = (patron: GuestObjectType) => {
|
10
|
+
if (patron === undefined) {
|
11
|
+
throw new Error("removePatronFromPools didnt receive patron argument");
|
12
|
+
}
|
10
13
|
poolSets.forEach((pool) => {
|
11
14
|
pool.delete(patron);
|
12
15
|
});
|
@@ -16,6 +19,9 @@ export const removePatronFromPools = (patron: GuestObjectType) => {
|
|
16
19
|
* @url https://kosukhin.github.io/patron.site/#/utils/is-patron-in-pools
|
17
20
|
*/
|
18
21
|
export const isPatronInPools = (patron: GuestObjectType) => {
|
22
|
+
if (patron === undefined) {
|
23
|
+
throw new Error("isPatronInPools didnt receive patron argument");
|
24
|
+
}
|
19
25
|
let inPool = false;
|
20
26
|
poolSets.forEach((pool) => {
|
21
27
|
if (!inPool) {
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { Private } from "./Private";
|
2
2
|
import { expect, test } from "vitest";
|
3
3
|
|
4
|
-
test(
|
4
|
+
test("Private.test", () => {
|
5
5
|
const privateNum = new Private((val) => {
|
6
6
|
return {
|
7
7
|
num: val,
|
8
|
-
}
|
8
|
+
};
|
9
9
|
});
|
10
10
|
|
11
11
|
expect(JSON.stringify(privateNum.get(11))).toBe('{"num":11}');
|
package/src/Private/Private.ts
CHANGED
@@ -2,13 +2,19 @@
|
|
2
2
|
* @url https://kosukhin.github.io/patron.site/#/utils/private
|
3
3
|
*/
|
4
4
|
export interface PrivateType<T> {
|
5
|
-
|
5
|
+
get<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;
|
6
6
|
}
|
7
7
|
|
8
8
|
export class Private<T> implements PrivateType<T> {
|
9
|
-
public constructor(private buildingFn: (...args: any[]) => T) {
|
9
|
+
public constructor(private buildingFn: (...args: any[]) => T) {
|
10
|
+
if (buildingFn === undefined) {
|
11
|
+
throw new Error("Private didnt receive buildingFn argument");
|
12
|
+
}
|
13
|
+
}
|
10
14
|
|
11
|
-
public get<R extends unknown[], CT = null>(
|
15
|
+
public get<R extends unknown[], CT = null>(
|
16
|
+
...args: R
|
17
|
+
): CT extends null ? T : CT {
|
12
18
|
return this.buildingFn(...args) as CT extends null ? T : CT;
|
13
19
|
}
|
14
20
|
}
|
@@ -1,8 +1,6 @@
|
|
1
|
-
import { PrivateClass } from "./PrivateClass";
|
2
|
-
import { GuestType } from "../Guest/Guest";
|
3
|
-
import { Source, SourceType } from "../Source/Source";
|
4
1
|
import { expect, test } from "vitest";
|
5
|
-
import {
|
2
|
+
import { Source } from "../Source/Source";
|
3
|
+
import { PrivateClass } from "./PrivateClass";
|
6
4
|
|
7
5
|
test("PrivateClass.test", () => {
|
8
6
|
const sourcePrivate = new PrivateClass(Source);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { PrivateType } from "./Private";
|
2
2
|
|
3
3
|
interface Constructable<T> {
|
4
|
-
new(...args: unknown[]): T;
|
4
|
+
new (...args: unknown[]): T;
|
5
5
|
}
|
6
6
|
|
7
7
|
interface Prototyped<T> {
|
@@ -12,7 +12,11 @@ export class PrivateClass<T> implements PrivateType<T> {
|
|
12
12
|
public constructor(
|
13
13
|
private constructorFn: Prototyped<T>,
|
14
14
|
private modules: Record<string, unknown> = {},
|
15
|
-
) {
|
15
|
+
) {
|
16
|
+
if (constructorFn === undefined) {
|
17
|
+
throw new Error("PrivateClass didnt receive constructorFn argument");
|
18
|
+
}
|
19
|
+
}
|
16
20
|
|
17
21
|
public get<R extends unknown[], CT = null>(
|
18
22
|
...args: R
|
package/src/Source/Source.ts
CHANGED
@@ -16,7 +16,11 @@ export type SourceType<T = any> = GuestAwareObjectType<T> &
|
|
16
16
|
export class Source<T> implements SourceType<T> {
|
17
17
|
private thePool = new PatronPool(this);
|
18
18
|
|
19
|
-
public constructor(private sourceDocument: T) {
|
19
|
+
public constructor(private sourceDocument: T) {
|
20
|
+
if (sourceDocument === undefined) {
|
21
|
+
throw new Error("Source didnt receive sourceDocument argument");
|
22
|
+
}
|
23
|
+
}
|
20
24
|
|
21
25
|
public pool() {
|
22
26
|
return this.thePool;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { SourceDynamic } from
|
2
|
-
import { Source } from
|
3
|
-
import { expect, test } from
|
1
|
+
import { SourceDynamic } from "./SourceDynamic";
|
2
|
+
import { Source } from "./Source";
|
3
|
+
import { expect, test } from "vitest";
|
4
4
|
|
5
|
-
test(
|
5
|
+
test("SourceDynamic.ofSource.test", () => {
|
6
6
|
const source = new Source(1);
|
7
7
|
const sourceDynamic = new SourceDynamic(source, source);
|
8
8
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { SourceDynamic } from "./SourceDynamic";
|
2
|
-
import { expect, test } from
|
2
|
+
import { expect, test } from "vitest";
|
3
3
|
import { give, Guest } from "../Guest/Guest";
|
4
4
|
import { GuestAware } from "../Guest/GuestAware";
|
5
5
|
|
6
|
-
test(
|
6
|
+
test("SourceDynamic", () => {
|
7
7
|
let theValue = 1;
|
8
8
|
const sourceDynamic = new SourceDynamic(
|
9
9
|
new Guest((value: number) => {
|
@@ -10,7 +10,14 @@ export class SourceDynamic<T = unknown> implements SourceType<T> {
|
|
10
10
|
public constructor(
|
11
11
|
private baseGuest: GuestType<T>,
|
12
12
|
private baseGuestAware: GuestAwareType<T>,
|
13
|
-
) {
|
13
|
+
) {
|
14
|
+
if (baseGuest === undefined) {
|
15
|
+
throw new Error("SourceDynamic didnt receive baseGuest argument");
|
16
|
+
}
|
17
|
+
if (baseGuestAware === undefined) {
|
18
|
+
throw new Error("SourceDynamic didnt receive baseGuestAware argument");
|
19
|
+
}
|
20
|
+
}
|
14
21
|
|
15
22
|
public value(guest: GuestType<T>) {
|
16
23
|
value(this.baseGuestAware, guest);
|
@@ -23,6 +30,6 @@ export class SourceDynamic<T = unknown> implements SourceType<T> {
|
|
23
30
|
}
|
24
31
|
|
25
32
|
public pool(): PatronPool<T> {
|
26
|
-
throw Error(
|
33
|
+
throw Error("No pool in SourceDynamic");
|
27
34
|
}
|
28
35
|
}
|