patron-oop 1.39.1 → 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 +19 -0
- package/dist/patron.cjs +186 -96
- package/dist/patron.cjs.map +1 -1
- package/dist/patron.d.ts +21 -24
- package/dist/patron.js +185 -95
- 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 +185 -95
- 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 +13 -15
- package/src/Guest/GuestAwareMap.fn.test.ts +6 -9
- package/src/Guest/GuestAwareMap.test.ts +8 -11
- package/src/Guest/GuestAwareMap.ts +24 -13
- package/src/Guest/GuestAwareRace.test.ts +8 -8
- package/src/Guest/GuestAwareRace.ts +12 -5
- package/src/Guest/GuestAwareSequence.defered.test.ts +20 -17
- package/src/Guest/GuestAwareSequence.test.ts +7 -10
- package/src/Guest/GuestAwareSequence.ts +31 -19
- package/src/Guest/GuestCast.test.ts +3 -3
- 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 +12 -0
- package/src/Private/Private.ts +20 -0
- package/src/Private/PrivateClass.modules.test.ts +33 -0
- package/src/Private/PrivateClass.test.ts +12 -0
- package/src/Private/PrivateClass.ts +29 -0
- 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
- package/src/index.ts +2 -2
- package/src/Factory/Factory.test.ts +0 -42
- package/src/Factory/Factory.ts +0 -30
- package/src/Factory/Module.test.ts +0 -12
- package/src/Factory/Module.ts +0 -12
@@ -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
|
}
|
package/src/index.ts
CHANGED
@@ -16,5 +16,5 @@ export * from "./Patron/PatronPool";
|
|
16
16
|
export * from "./Source/Source";
|
17
17
|
export * from "./Source/SourceDynamic";
|
18
18
|
export * from "./Source/SourceEmpty";
|
19
|
-
export * from "./
|
20
|
-
export * from "./
|
19
|
+
export * from "./Private/PrivateClass";
|
20
|
+
export * from "./Private/Private";
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { Factory, FactoryType } from "./Factory";
|
2
|
-
import { GuestType } from "../Guest/Guest";
|
3
|
-
import { Source, SourceType } from "../Source/Source";
|
4
|
-
import { expect, test } from "vitest";
|
5
|
-
|
6
|
-
test("factory", () => {
|
7
|
-
const sourceFactory = new Factory(Source);
|
8
|
-
const source = sourceFactory.create(42);
|
9
|
-
|
10
|
-
source.value((value) => {
|
11
|
-
expect(value).toBe(42);
|
12
|
-
});
|
13
|
-
});
|
14
|
-
|
15
|
-
class TestFactory {
|
16
|
-
private source: SourceType;
|
17
|
-
|
18
|
-
public constructor(
|
19
|
-
baseNum: number,
|
20
|
-
private factories: { mainFactory: FactoryType<SourceType> },
|
21
|
-
) {
|
22
|
-
this.source = factories.mainFactory.create(baseNum + 55);
|
23
|
-
}
|
24
|
-
|
25
|
-
public value(guest: GuestType) {
|
26
|
-
this.source.value(guest);
|
27
|
-
return this;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
test("factory with factories", () => {
|
32
|
-
const mainFactory = new Factory(Source);
|
33
|
-
const sourceFactory = new Factory(TestFactory, {
|
34
|
-
mainFactory,
|
35
|
-
});
|
36
|
-
|
37
|
-
const source = sourceFactory.create(42);
|
38
|
-
|
39
|
-
source.value((value) => {
|
40
|
-
expect(value).toBe(97);
|
41
|
-
});
|
42
|
-
});
|
package/src/Factory/Factory.ts
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
interface Constructable<T> {
|
2
|
-
new(...args: unknown[]): T;
|
3
|
-
}
|
4
|
-
|
5
|
-
interface Prototyped<T> {
|
6
|
-
prototype: T;
|
7
|
-
}
|
8
|
-
|
9
|
-
export interface FactoryType<T> {
|
10
|
-
create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;
|
11
|
-
}
|
12
|
-
|
13
|
-
/**
|
14
|
-
* @url https://kosukhin.github.io/patron.site/#/utils/factory
|
15
|
-
*/
|
16
|
-
export class Factory<T> implements FactoryType<T> {
|
17
|
-
public constructor(
|
18
|
-
private constructorFn: Prototyped<T>,
|
19
|
-
private factories: Record<string, unknown> = {},
|
20
|
-
) { }
|
21
|
-
|
22
|
-
public create<R extends unknown[], CT = null>(
|
23
|
-
...args: R
|
24
|
-
): CT extends null ? T : CT {
|
25
|
-
return new (this.constructorFn as Constructable<T>)(
|
26
|
-
...args,
|
27
|
-
this.factories,
|
28
|
-
) as CT extends null ? T : CT;
|
29
|
-
}
|
30
|
-
}
|
package/src/Factory/Module.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { FactoryType } from "./Factory";
|
2
|
-
|
3
|
-
/**
|
4
|
-
* @url https://kosukhin.github.io/patron.site/#/utils/module
|
5
|
-
*/
|
6
|
-
export class Module<T> implements FactoryType<T> {
|
7
|
-
public constructor(private buildingFn: (...args: any[]) => T) { }
|
8
|
-
|
9
|
-
public create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT {
|
10
|
-
return this.buildingFn(...args) as CT extends null ? T : CT;
|
11
|
-
}
|
12
|
-
}
|