@fncts/io 0.0.19 → 0.0.20

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.
Files changed (46) hide show
  1. package/Differ/api.d.ts +24 -0
  2. package/Differ/definition.d.ts +15 -0
  3. package/FiberRef/unsafe.d.ts +12 -6
  4. package/IOEnv/services.d.ts +2 -2
  5. package/Supervisor/api.d.ts +11 -5
  6. package/Supervisor/definition.d.ts +28 -0
  7. package/SupervisorPatch.d.ts +61 -0
  8. package/_cjs/Differ/api.cjs +108 -0
  9. package/_cjs/Differ/api.cjs.map +1 -0
  10. package/_cjs/Differ/definition.cjs +23 -0
  11. package/_cjs/Differ/definition.cjs.map +1 -0
  12. package/_cjs/FiberRef/unsafe.cjs +35 -21
  13. package/_cjs/FiberRef/unsafe.cjs.map +1 -1
  14. package/_cjs/IOEnv/definition.cjs.map +1 -1
  15. package/_cjs/IOEnv/services.cjs.map +1 -1
  16. package/_cjs/Supervisor/api.cjs +44 -33
  17. package/_cjs/Supervisor/api.cjs.map +1 -1
  18. package/_cjs/Supervisor/definition.cjs +66 -1
  19. package/_cjs/Supervisor/definition.cjs.map +1 -1
  20. package/_cjs/SupervisorPatch.cjs +172 -0
  21. package/_cjs/SupervisorPatch.cjs.map +1 -0
  22. package/_mjs/Differ/api.mjs +90 -0
  23. package/_mjs/Differ/api.mjs.map +1 -0
  24. package/_mjs/Differ/definition.mjs +13 -0
  25. package/_mjs/Differ/definition.mjs.map +1 -0
  26. package/_mjs/FiberRef/unsafe.mjs +31 -20
  27. package/_mjs/FiberRef/unsafe.mjs.map +1 -1
  28. package/_mjs/IOEnv/definition.mjs.map +1 -1
  29. package/_mjs/IOEnv/services.mjs.map +1 -1
  30. package/_mjs/Supervisor/api.mjs +39 -32
  31. package/_mjs/Supervisor/api.mjs.map +1 -1
  32. package/_mjs/Supervisor/definition.mjs +55 -0
  33. package/_mjs/Supervisor/definition.mjs.map +1 -1
  34. package/_mjs/SupervisorPatch.mjs +131 -0
  35. package/_mjs/SupervisorPatch.mjs.map +1 -0
  36. package/_src/Differ/api.ts +72 -0
  37. package/_src/Differ/definition.ts +16 -0
  38. package/_src/FiberRef/unsafe.ts +24 -22
  39. package/_src/IOEnv/definition.ts +0 -2
  40. package/_src/IOEnv/services.ts +5 -4
  41. package/_src/Supervisor/api.ts +33 -29
  42. package/_src/Supervisor/definition.ts +59 -0
  43. package/_src/SupervisorPatch.ts +107 -0
  44. package/_src/global.ts +4 -0
  45. package/global.d.ts +4 -0
  46. package/package.json +2 -2
@@ -1,3 +1,11 @@
1
+ import type { SupervisorPatch } from "@fncts/io/SupervisorPatch";
2
+
3
+ export const enum SupervisorTag {
4
+ Const,
5
+ Proxy,
6
+ Zip,
7
+ }
8
+
1
9
  /**
2
10
  * @tsplus type fncts.io.Supervisor
3
11
  * @tsplus companion fncts.io.SupervisorOps
@@ -22,7 +30,12 @@ export abstract class Supervisor<A> {
22
30
  }
23
31
  }
24
32
 
33
+ export declare namespace Supervisor {
34
+ type Patch = SupervisorPatch;
35
+ }
36
+
25
37
  export class ConstSupervisor<A> extends Supervisor<A> {
38
+ readonly _tag = SupervisorTag.Const;
26
39
  constructor(readonly value: UIO<A>) {
27
40
  super();
28
41
  }
@@ -44,6 +57,7 @@ export class ConstSupervisor<A> extends Supervisor<A> {
44
57
  }
45
58
 
46
59
  export class ProxySupervisor<A> extends Supervisor<A> {
60
+ readonly _tag = SupervisorTag.Proxy;
47
61
  constructor(readonly value: UIO<A>, readonly underlying: Supervisor<any>) {
48
62
  super();
49
63
  }
@@ -68,3 +82,48 @@ export class ProxySupervisor<A> extends Supervisor<A> {
68
82
  this.underlying.unsafeOnResume(fiber);
69
83
  }
70
84
  }
85
+
86
+ export class Zip<A, B> extends Supervisor<readonly [A, B]> {
87
+ readonly _tag = SupervisorTag.Zip;
88
+ constructor(readonly first: Supervisor<A>, readonly second: Supervisor<B>) {
89
+ super();
90
+ }
91
+ value = this.first.value.zip(this.second.value);
92
+ unsafeOnStart<R, E, A>(
93
+ environment: Environment<R>,
94
+ effect: IO<R, E, A>,
95
+ parent: Maybe<Fiber.Runtime<any, any>>,
96
+ fiber: Fiber.Runtime<E, A>,
97
+ ) {
98
+ try {
99
+ this.first.unsafeOnStart(environment, effect, parent, fiber);
100
+ } finally {
101
+ this.second.unsafeOnStart(environment, effect, parent, fiber);
102
+ }
103
+ }
104
+ unsafeOnEnd<E, A>(value: Exit<E, A>, fiber: Fiber.Runtime<E, A>) {
105
+ this.first.unsafeOnEnd(value, fiber);
106
+ this.second.unsafeOnEnd(value, fiber);
107
+ }
108
+ unsafeOnEffect<E, A>(fiber: Fiber.Runtime<E, A>, effect: IO<any, any, any>) {
109
+ this.first.unsafeOnEffect(fiber, effect);
110
+ this.second.unsafeOnEffect(fiber, effect);
111
+ }
112
+ unsafeOnSuspend<E, A>(fiber: Fiber.Runtime<E, A>) {
113
+ this.first.unsafeOnSuspend(fiber);
114
+ this.second.unsafeOnSuspend(fiber);
115
+ }
116
+ unsafeOnResume<E, A>(fiber: Fiber.Runtime<E, A>) {
117
+ this.first.unsafeOnResume(fiber);
118
+ this.second.unsafeOnResume(fiber);
119
+ }
120
+ }
121
+
122
+ export type Concrete = ConstSupervisor<any> | ProxySupervisor<any> | Zip<any, any>;
123
+
124
+ /**
125
+ * @tsplus macro remove
126
+ */
127
+ export function concrete(_: Supervisor<any>): asserts _ is Concrete {
128
+ //
129
+ }
@@ -0,0 +1,107 @@
1
+ export const SupervisorPatchTypeId = Symbol.for("fncts.io.Supervisor.Patch");
2
+ export type SupervisorPatchTypeId = typeof SupervisorPatchTypeId;
3
+
4
+ export const enum SupervisorPatchTag {
5
+ AddSupervisor,
6
+ Combine,
7
+ Empty,
8
+ RemoveSupervisor,
9
+ }
10
+
11
+ /**
12
+ * @tsplus type fncts.io.SupervisorPatch
13
+ * @tsplus companion fncts.io.SupervisorPatchOps
14
+ */
15
+ export abstract class SupervisorPatch {
16
+ readonly _typeId: SupervisorPatchTypeId = SupervisorPatchTypeId;
17
+ }
18
+
19
+ export class AddSupervisor extends SupervisorPatch {
20
+ readonly _tag = SupervisorPatchTag.AddSupervisor;
21
+ constructor(readonly supervisor: Supervisor<any>) {
22
+ super();
23
+ }
24
+ }
25
+
26
+ export class Combine extends SupervisorPatch {
27
+ readonly _tag = SupervisorPatchTag.Combine;
28
+ constructor(readonly first: SupervisorPatch, readonly second: SupervisorPatch) {
29
+ super();
30
+ }
31
+ }
32
+
33
+ export class Empty extends SupervisorPatch {
34
+ readonly _tag = SupervisorPatchTag.Empty;
35
+ }
36
+
37
+ export class RemoveSupervisor extends SupervisorPatch {
38
+ readonly _tag = SupervisorPatchTag.RemoveSupervisor;
39
+ constructor(readonly supervisor: Supervisor<any>) {
40
+ super();
41
+ }
42
+ }
43
+
44
+ export type Concrete = AddSupervisor | Combine | Empty | RemoveSupervisor;
45
+
46
+ /**
47
+ * @tsplus macro remove
48
+ */
49
+ export function concrete(_: SupervisorPatch): asserts _ is Concrete {
50
+ //
51
+ }
52
+
53
+ /**
54
+ * @tsplus static fncts.io.SupervisorPatchOps empty
55
+ */
56
+ export const empty: SupervisorPatch = new Empty();
57
+
58
+ /**
59
+ * @tsplus fluent fncts.io.SupervisorPatch combine
60
+ */
61
+ export function combine(first: SupervisorPatch, second: SupervisorPatch): SupervisorPatch {
62
+ return new Combine(first, second);
63
+ }
64
+
65
+ /**
66
+ * @tsplus static fncts.io.SupervisorPatchOps diff
67
+ */
68
+ export function diff(oldValue: Supervisor<any>, newValue: Supervisor<any>): SupervisorPatch {
69
+ if (oldValue === newValue) return new Empty();
70
+ else {
71
+ const oldSupervisors = oldValue.toSet;
72
+ const newSupervisors = newValue.toSet;
73
+ const added = newSupervisors
74
+ .difference(oldSupervisors)
75
+ .foldLeft(SupervisorPatch.empty, (patch, supervisor) => patch.combine(new AddSupervisor(supervisor)));
76
+ const removed = oldSupervisors
77
+ .difference(newSupervisors)
78
+ .foldLeft(SupervisorPatch.empty, (patch, supervisor) => patch.combine(new RemoveSupervisor(supervisor)));
79
+ return added.combine(removed);
80
+ }
81
+ }
82
+
83
+ function applyLoop(supervisor: Supervisor<any>, patches: List<SupervisorPatch>): Supervisor<any> {
84
+ if (patches.isEmpty()) {
85
+ return supervisor;
86
+ }
87
+ const head = patches.head;
88
+ const tail = patches.tail;
89
+ concrete(head);
90
+ switch (head._tag) {
91
+ case SupervisorPatchTag.AddSupervisor:
92
+ return applyLoop(supervisor.zip(head.supervisor), tail);
93
+ case SupervisorPatchTag.Combine:
94
+ return applyLoop(supervisor, Cons(head.first, Cons(head.second, patches)));
95
+ case SupervisorPatchTag.Empty:
96
+ return applyLoop(supervisor, tail);
97
+ case SupervisorPatchTag.RemoveSupervisor:
98
+ return applyLoop(supervisor.removeSupervisor(head.supervisor), tail);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * @tsplus fluent fncts.io.SupervisorPatch __call
104
+ */
105
+ export function apply(self: SupervisorPatch, supervisor: Supervisor<any>): Supervisor<any> {
106
+ return applyLoop(supervisor, Cons(self));
107
+ }
package/_src/global.ts CHANGED
@@ -127,6 +127,10 @@ import { Stream } from "@fncts/io/Stream/definition";
127
127
  * @tsplus global
128
128
  */
129
129
  import { Supervisor } from "@fncts/io/Supervisor/definition";
130
+ /**
131
+ * @tsplus global
132
+ */
133
+ import { SupervisorPatch } from "@fncts/io/SupervisorPatch";
130
134
  /**
131
135
  * @tsplus global
132
136
  */
package/global.d.ts CHANGED
@@ -126,6 +126,10 @@ import { Stream } from "@fncts/io/Stream/definition";
126
126
  * @tsplus global
127
127
  */
128
128
  import { Supervisor } from "@fncts/io/Supervisor/definition";
129
+ /**
130
+ * @tsplus global
131
+ */
132
+ import { SupervisorPatch } from "@fncts/io/SupervisorPatch";
129
133
  /**
130
134
  * @tsplus global
131
135
  */
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@fncts/io",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "dependencies": {
5
- "@fncts/base": "0.0.19",
5
+ "@fncts/base": "0.0.20",
6
6
  "@fncts/transformers": "0.0.2",
7
7
  "@fncts/typelevel": "0.0.14"
8
8
  },