silentium-components 0.0.83 → 0.0.85
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/CHANGELOG.md +14 -0
- package/dist/silentium-components.cjs +326 -411
- package/dist/silentium-components.cjs.map +1 -1
- package/dist/silentium-components.d.ts +80 -87
- package/dist/silentium-components.js +328 -412
- package/dist/silentium-components.js.map +1 -1
- package/dist/silentium-components.min.js +1 -1
- package/dist/silentium-components.min.mjs +1 -1
- package/dist/silentium-components.min.mjs.map +1 -1
- package/dist/silentium-components.mjs +328 -412
- package/dist/silentium-components.mjs.map +1 -1
- package/eslint.config.mjs +26 -12
- package/package.json +4 -2
- package/rollup.config.js +2 -1
- package/src/behaviors/Branch._main.test.ts +4 -3
- package/src/behaviors/Branch._values.test.ts +3 -2
- package/src/behaviors/Branch.branchesDontAffectResult.test.ts +4 -3
- package/src/behaviors/Branch.ts +13 -21
- package/src/behaviors/BranchLazy._main.test.ts +5 -4
- package/src/behaviors/BranchLazy.ts +17 -20
- package/src/behaviors/Const.test.ts +6 -7
- package/src/behaviors/Const.ts +5 -7
- package/src/behaviors/Deadline._main.test.ts +5 -4
- package/src/behaviors/Deadline._value.test.ts +4 -3
- package/src/behaviors/Deadline.ts +20 -27
- package/src/behaviors/Deferred.test.ts +5 -4
- package/src/behaviors/Deferred.ts +8 -10
- package/src/behaviors/Detached.test.ts +4 -3
- package/src/behaviors/Detached.ts +2 -2
- package/src/behaviors/Dirty.test.ts +4 -3
- package/src/behaviors/Dirty.ts +18 -45
- package/src/behaviors/Loading.test.ts +4 -3
- package/src/behaviors/Loading.ts +4 -4
- package/src/behaviors/Lock.test.ts +4 -3
- package/src/behaviors/Lock.ts +6 -8
- package/src/behaviors/Memo.test.ts +7 -8
- package/src/behaviors/Memo.ts +8 -10
- package/src/behaviors/OnlyChanged.test.ts +5 -4
- package/src/behaviors/OnlyChanged.ts +9 -11
- package/src/behaviors/Part.test.ts +12 -15
- package/src/behaviors/Part.ts +23 -40
- package/src/behaviors/Path._keyRaw.test.ts +3 -2
- package/src/behaviors/Path._main.test.ts +3 -2
- package/src/behaviors/Path.index.test.ts +3 -2
- package/src/behaviors/Path.nested.test.ts +4 -3
- package/src/behaviors/Path.ts +11 -14
- package/src/behaviors/Polling.test.ts +3 -2
- package/src/behaviors/Polling.ts +5 -7
- package/src/behaviors/Shot._main.test.ts +5 -4
- package/src/behaviors/Shot._onlyChanged.test.ts +9 -10
- package/src/behaviors/Shot.ts +8 -10
- package/src/behaviors/Task.test.ts +9 -12
- package/src/behaviors/Task.ts +11 -5
- package/src/behaviors/Tick.test.ts +5 -4
- package/src/behaviors/Tick.ts +9 -11
- package/src/behaviors/index.ts +0 -1
- package/src/boolean/And.test.ts +3 -2
- package/src/boolean/And.ts +5 -7
- package/src/boolean/Bool.test.ts +4 -3
- package/src/boolean/Bool.ts +2 -2
- package/src/boolean/Not.test.ts +4 -3
- package/src/boolean/Not.ts +5 -7
- package/src/boolean/Or.test.ts +4 -3
- package/src/boolean/Or.ts +5 -7
- package/src/boolean/index.ts +2 -2
- package/src/formats/FromJson.test.ts +2 -1
- package/src/formats/FromJson.ts +9 -12
- package/src/formats/ToJson.test.ts +1 -0
- package/src/formats/ToJson.ts +10 -12
- package/src/index.ts +4 -4
- package/src/lists/First.test.ts +3 -2
- package/src/lists/First.ts +2 -2
- package/src/navigation/Router._destroy.test.ts +14 -24
- package/src/navigation/Router._firstMatch.test.ts +7 -13
- package/src/navigation/Router._main.test.ts +7 -13
- package/src/navigation/Router._nested.test.ts +19 -30
- package/src/navigation/Router.ts +30 -34
- package/src/strings/Concatenated.test.ts +4 -3
- package/src/strings/Concatenated.ts +5 -7
- package/src/strings/Template._main.test.ts +5 -4
- package/src/strings/Template._place.test.ts +4 -3
- package/src/strings/Template.ts +21 -9
- package/src/structures/HashTable.test.ts +4 -3
- package/src/structures/HashTable.ts +6 -8
- package/src/structures/Record._main.test.ts +3 -2
- package/src/structures/Record._mixed.test.ts +3 -2
- package/src/structures/Record.concatenated.test.ts +7 -8
- package/src/structures/Record.nested.test.ts +3 -2
- package/src/structures/Record.ts +10 -14
- package/src/system/RegexpMatch._group.test.ts +3 -2
- package/src/system/RegexpMatch._main.test.ts +3 -2
- package/src/system/RegexpMatch.ts +12 -11
- package/src/system/RegexpMatched.test.ts +4 -3
- package/src/system/RegexpMatched.ts +11 -10
- package/src/system/RegexpReplaced.test.ts +4 -3
- package/src/system/RegexpReplaced.ts +6 -8
- package/src/system/Set.test.ts +4 -3
- package/src/system/Set.ts +9 -8
- package/src/system/index.ts +1 -1
- package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +0 -35
- package/src/behaviors/Transaction.test.ts +0 -44
- package/src/behaviors/Transaction.ts +0 -42
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { All,
|
|
1
|
+
import { ActualMessage, All, MaybeMessage, Message, Of } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* First match Of regexp
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/system/regexp-matched
|
|
6
6
|
*/
|
|
7
7
|
export function RegexpMatch(
|
|
8
|
-
patternSrc:
|
|
9
|
-
valueSrc:
|
|
10
|
-
flagsSrc:
|
|
8
|
+
patternSrc: MaybeMessage<string>,
|
|
9
|
+
valueSrc: MaybeMessage<string>,
|
|
10
|
+
flagsSrc: MaybeMessage<string> = Of(""),
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const $pattern = ActualMessage(patternSrc);
|
|
13
|
+
const $value = ActualMessage(valueSrc);
|
|
14
|
+
const $flags = ActualMessage(flagsSrc);
|
|
15
|
+
return Message<string[]>(function RegexpMatchImpl(r) {
|
|
16
|
+
All($pattern, $value, $flags).then(([pattern, value, flags]) => {
|
|
17
|
+
const result = new RegExp(pattern, flags).exec(value);
|
|
18
|
+
r(result ?? []);
|
|
19
|
+
});
|
|
19
20
|
});
|
|
20
21
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Late, Of
|
|
2
|
-
import { RegexpMatched } from "../system/RegexpMatched";
|
|
1
|
+
import { Late, Of } from "silentium";
|
|
3
2
|
import { expect, test, vi } from "vitest";
|
|
4
3
|
|
|
4
|
+
import { RegexpMatched } from "../system/RegexpMatched";
|
|
5
|
+
|
|
5
6
|
test("RegexpMatched.test", () => {
|
|
6
7
|
const $url = Late<string>("http://domain.com/some/url/");
|
|
7
8
|
const $matched = RegexpMatched(Of("/some/url"), $url);
|
|
8
9
|
const g = vi.fn();
|
|
9
|
-
$matched.
|
|
10
|
+
$matched.then(g);
|
|
10
11
|
|
|
11
12
|
expect(g).toHaveBeenLastCalledWith(true);
|
|
12
13
|
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { All,
|
|
1
|
+
import { ActualMessage, All, MaybeMessage, Message, Of } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Boolean source what checks what string matches pattern
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/system/regexp-matched
|
|
6
6
|
*/
|
|
7
7
|
export function RegexpMatched(
|
|
8
|
-
patternSrc:
|
|
9
|
-
valueSrc:
|
|
10
|
-
flagsSrc:
|
|
8
|
+
patternSrc: MaybeMessage<string>,
|
|
9
|
+
valueSrc: MaybeMessage<string>,
|
|
10
|
+
flagsSrc: MaybeMessage<string> = Of(""),
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const $pattern = ActualMessage(patternSrc);
|
|
13
|
+
const $value = ActualMessage(valueSrc);
|
|
14
|
+
const $flags = ActualMessage(flagsSrc);
|
|
15
|
+
return Message<boolean>(function RegexpMatchedImpl(r) {
|
|
16
|
+
All($pattern, $value, $flags).then(([pattern, value, flags]) => {
|
|
17
|
+
r(new RegExp(pattern, flags).test(value));
|
|
18
|
+
});
|
|
18
19
|
});
|
|
19
20
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Late, Of
|
|
2
|
-
import { RegexpReplaced } from "../system/RegexpReplaced";
|
|
1
|
+
import { Late, Of } from "silentium";
|
|
3
2
|
import { expect, test, vi } from "vitest";
|
|
4
3
|
|
|
4
|
+
import { RegexpReplaced } from "../system/RegexpReplaced";
|
|
5
|
+
|
|
5
6
|
test("RegexpReplaced.test", () => {
|
|
6
7
|
const $url = Late<string>("http://domain.com/some/url/");
|
|
7
8
|
const $matched = RegexpReplaced($url, Of("some/url/"), Of(""));
|
|
8
9
|
const g = vi.fn();
|
|
9
|
-
$matched.
|
|
10
|
+
$matched.then(g);
|
|
10
11
|
|
|
11
12
|
expect(g).toHaveBeenLastCalledWith("http://domain.com/");
|
|
12
13
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { All, Message, MessageType, Of
|
|
1
|
+
import { All, Message, MessageType, Of } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns string replaced by regular expression pattern
|
|
@@ -10,13 +10,11 @@ export function RegexpReplaced(
|
|
|
10
10
|
replaceValueSrc: MessageType<string>,
|
|
11
11
|
flagsSrc: MessageType<string> = Of(""),
|
|
12
12
|
) {
|
|
13
|
-
return Message<string>(function () {
|
|
14
|
-
All(patternSrc, valueSrc, replaceValueSrc, flagsSrc).
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
19
|
-
}),
|
|
13
|
+
return Message<string>(function RegexpReplacedImpl(r) {
|
|
14
|
+
All(patternSrc, valueSrc, replaceValueSrc, flagsSrc).then(
|
|
15
|
+
([pattern, value, replaceValue, flags]) => {
|
|
16
|
+
r(String(value).replace(new RegExp(pattern, flags), replaceValue));
|
|
17
|
+
},
|
|
20
18
|
);
|
|
21
19
|
});
|
|
22
20
|
}
|
package/src/system/Set.test.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Late, Of
|
|
2
|
-
import { Set } from "../system/Set";
|
|
1
|
+
import { Late, Of } from "silentium";
|
|
3
2
|
import { expect, test, vi } from "vitest";
|
|
4
3
|
|
|
4
|
+
import { Set } from "../system/Set";
|
|
5
|
+
|
|
5
6
|
test("Set.test", () => {
|
|
6
7
|
const $value = Late<string>();
|
|
7
8
|
const object = {
|
|
@@ -9,7 +10,7 @@ test("Set.test", () => {
|
|
|
9
10
|
};
|
|
10
11
|
const obj = Set(Of(object), Of("value"), $value);
|
|
11
12
|
const g = vi.fn();
|
|
12
|
-
obj.
|
|
13
|
+
obj.then(g);
|
|
13
14
|
|
|
14
15
|
expect(object.value).toBe("hello");
|
|
15
16
|
|
package/src/system/Set.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { All, Message, MessageType
|
|
1
|
+
import { ActualMessage, All, Message, MessageType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Ability to mutate some object, helpful when integrate to procedure systems
|
|
@@ -9,12 +9,13 @@ export function Set<T extends Record<string, unknown>>(
|
|
|
9
9
|
keySrc: MessageType<string>,
|
|
10
10
|
valueSrc: MessageType<unknown>,
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const $base = ActualMessage(baseSrc);
|
|
13
|
+
const $key = ActualMessage(keySrc);
|
|
14
|
+
const $value = ActualMessage(valueSrc);
|
|
15
|
+
return Message<T>(function SetImpl(r) {
|
|
16
|
+
All($base, $key, $value).then(([base, key, value]) => {
|
|
17
|
+
(base as Record<string, unknown>)[key] = value;
|
|
18
|
+
r(base);
|
|
19
|
+
});
|
|
19
20
|
});
|
|
20
21
|
}
|
package/src/system/index.ts
CHANGED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Applied, Late, Of, Shared, Tap } from "silentium";
|
|
2
|
-
import { expect, test, vi } from "vitest";
|
|
3
|
-
import { Branch } from "../behaviors/Branch";
|
|
4
|
-
|
|
5
|
-
test("Branch.dontRespondAfterRespond.test", () => {
|
|
6
|
-
const l = Late<number>(1);
|
|
7
|
-
const ti = Of<any>("then");
|
|
8
|
-
const branchI = Shared(
|
|
9
|
-
Branch(
|
|
10
|
-
Applied(l, (t) => t === 2),
|
|
11
|
-
ti,
|
|
12
|
-
),
|
|
13
|
-
true,
|
|
14
|
-
);
|
|
15
|
-
const g = vi.fn();
|
|
16
|
-
branchI.pipe(Tap(g));
|
|
17
|
-
|
|
18
|
-
l.use(2);
|
|
19
|
-
expect(g).toHaveBeenLastCalledWith("then");
|
|
20
|
-
|
|
21
|
-
const g2 = vi.fn();
|
|
22
|
-
branchI.pipe(Tap(g2));
|
|
23
|
-
l.use(1);
|
|
24
|
-
expect(g2).not.toHaveBeenCalled();
|
|
25
|
-
|
|
26
|
-
const g3 = vi.fn();
|
|
27
|
-
branchI.pipe(Tap(g3));
|
|
28
|
-
l.use(2);
|
|
29
|
-
expect(g3).toHaveBeenLastCalledWith("then");
|
|
30
|
-
|
|
31
|
-
const g4 = vi.fn();
|
|
32
|
-
branchI.pipe(Tap(g4));
|
|
33
|
-
l.use(3);
|
|
34
|
-
expect(g4).not.toHaveBeenCalled();
|
|
35
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { All, Applied, LateShared, Primitive } from "silentium";
|
|
2
|
-
import { Transaction } from "../behaviors/Transaction";
|
|
3
|
-
import { describe, expect, test } from "vitest";
|
|
4
|
-
|
|
5
|
-
describe("Transaction.test", () => {
|
|
6
|
-
test("value inside transaction", () => {
|
|
7
|
-
const $base = LateShared(1);
|
|
8
|
-
|
|
9
|
-
const t = Transaction($base, ($b) => {
|
|
10
|
-
return Applied($b, (x) => x * 2);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
expect(Primitive(t).primitiveWithException()).toBe(2);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("value inside transaction", () => {
|
|
17
|
-
const $base = LateShared(1);
|
|
18
|
-
const $mult = LateShared(2);
|
|
19
|
-
|
|
20
|
-
const t = Transaction(
|
|
21
|
-
$base,
|
|
22
|
-
($b, $m) => {
|
|
23
|
-
return Applied(All($b, $m), ([x, m]) => x * m);
|
|
24
|
-
},
|
|
25
|
-
$mult,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
expect(Primitive(t).primitiveWithException()).toBe(2);
|
|
29
|
-
|
|
30
|
-
$base.use(2);
|
|
31
|
-
|
|
32
|
-
expect(Primitive(t).primitiveWithException()).toBe(4);
|
|
33
|
-
|
|
34
|
-
$base.use(3);
|
|
35
|
-
$mult.use(3);
|
|
36
|
-
|
|
37
|
-
expect(Primitive(t).primitiveWithException()).toBe(9);
|
|
38
|
-
|
|
39
|
-
// $mult is of value 3, hence result will be 12
|
|
40
|
-
$base.use(4);
|
|
41
|
-
|
|
42
|
-
expect(Primitive(t).primitiveWithException()).toBe(12);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConstructorType,
|
|
3
|
-
DestroyableType,
|
|
4
|
-
LateShared,
|
|
5
|
-
Message,
|
|
6
|
-
MessageType,
|
|
7
|
-
Of,
|
|
8
|
-
Tap,
|
|
9
|
-
} from "silentium";
|
|
10
|
-
import { Detached } from "../behaviors/Detached";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Do something on message value.
|
|
14
|
-
* Each message value will create new builder instance
|
|
15
|
-
*/
|
|
16
|
-
export function Transaction<T, R = unknown>(
|
|
17
|
-
$base: MessageType<T>,
|
|
18
|
-
builder: ConstructorType<
|
|
19
|
-
[MessageType<T>, ...MessageType<any>[]],
|
|
20
|
-
MessageType<R>
|
|
21
|
-
>,
|
|
22
|
-
...args: MessageType[]
|
|
23
|
-
) {
|
|
24
|
-
return Message<R>(function () {
|
|
25
|
-
const $res = LateShared<R>();
|
|
26
|
-
const destructors: DestroyableType[] = [];
|
|
27
|
-
|
|
28
|
-
$base.pipe(
|
|
29
|
-
Tap((v) => {
|
|
30
|
-
const $msg = builder(Of(v), ...args.map((a) => Detached(a)));
|
|
31
|
-
destructors.push($msg as unknown as DestroyableType);
|
|
32
|
-
$msg.pipe($res);
|
|
33
|
-
}),
|
|
34
|
-
);
|
|
35
|
-
$res.pipe(this);
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
destructors.forEach((d) => d?.destroy());
|
|
39
|
-
destructors.length = 0;
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
}
|