ballerina-core 1.0.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.
Files changed (118) hide show
  1. package/main.ts +149 -0
  2. package/package.json +20 -0
  3. package/src/apiResultStatus/state.ts +7 -0
  4. package/src/async/domains/mirroring/domains/collection/coroutines/synchronizers.ts +334 -0
  5. package/src/async/domains/mirroring/domains/collection/state.ts +137 -0
  6. package/src/async/domains/mirroring/domains/entity/domains/loaded-collection/state.ts +24 -0
  7. package/src/async/domains/mirroring/domains/entity/domains/loaded-collection-entity/state.ts +27 -0
  8. package/src/async/domains/mirroring/domains/entity/domains/loaded-entities/state.ts +12 -0
  9. package/src/async/domains/mirroring/domains/entity/domains/loaded-entity/state.ts +29 -0
  10. package/src/async/domains/mirroring/domains/entity/state.ts +22 -0
  11. package/src/async/domains/mirroring/domains/singleton/coroutines/synchronizers.ts +216 -0
  12. package/src/async/domains/mirroring/domains/singleton/state.ts +57 -0
  13. package/src/async/domains/mirroring/domains/synchronization-result/state.ts +2 -0
  14. package/src/async/domains/mirroring/domains/synchronized-entities/state.ts +23 -0
  15. package/src/async/domains/promise/state.ts +13 -0
  16. package/src/async/domains/synchronized/coroutines/synchronize.ts +62 -0
  17. package/src/async/domains/synchronized/state.ts +20 -0
  18. package/src/async/state.ts +144 -0
  19. package/src/baseEntity/domains/identifiable/state.ts +29 -0
  20. package/src/collections/domains/array/state.ts +16 -0
  21. package/src/collections/domains/immutable/domains/list/state.ts +20 -0
  22. package/src/collections/domains/immutable/domains/map/state.ts +33 -0
  23. package/src/collections/domains/immutable/domains/orderedMap/state.ts +117 -0
  24. package/src/collections/domains/immutable/domains/ordereredSet/state.ts +19 -0
  25. package/src/collections/domains/immutable/domains/set/state.ts +15 -0
  26. package/src/collections/domains/maybe/state.ts +20 -0
  27. package/src/collections/domains/product/state.ts +47 -0
  28. package/src/collections/domains/sum/state.ts +82 -0
  29. package/src/coroutines/builder.tsx +66 -0
  30. package/src/coroutines/state.ts +574 -0
  31. package/src/coroutines/template.tsx +119 -0
  32. package/src/debounced/coroutines/debounce.ts +118 -0
  33. package/src/debounced/state.ts +61 -0
  34. package/src/diagnostics/domains/message-box/state.ts +4 -0
  35. package/src/foreignMutations/state.ts +4 -0
  36. package/src/forms/domains/attachments/views/attachments-view.tsx +22 -0
  37. package/src/forms/domains/collection/domains/reference/state.ts +18 -0
  38. package/src/forms/domains/collection/domains/selection/state.ts +5 -0
  39. package/src/forms/domains/launcher/domains/create/coroutines/runner.ts +60 -0
  40. package/src/forms/domains/launcher/domains/create/state.ts +71 -0
  41. package/src/forms/domains/launcher/domains/create/template.tsx +66 -0
  42. package/src/forms/domains/launcher/domains/edit/coroutines/runner.ts +47 -0
  43. package/src/forms/domains/launcher/domains/edit/state.ts +55 -0
  44. package/src/forms/domains/launcher/domains/edit/template.tsx +39 -0
  45. package/src/forms/domains/parser/domains/validator/state.ts +423 -0
  46. package/src/forms/domains/parser/state.tsx +311 -0
  47. package/src/forms/domains/primitives/domains/boolean/state.ts +13 -0
  48. package/src/forms/domains/primitives/domains/boolean/template.tsx +24 -0
  49. package/src/forms/domains/primitives/domains/date/state.ts +23 -0
  50. package/src/forms/domains/primitives/domains/date/template.tsx +31 -0
  51. package/src/forms/domains/primitives/domains/enum/state.ts +27 -0
  52. package/src/forms/domains/primitives/domains/enum/template.tsx +52 -0
  53. package/src/forms/domains/primitives/domains/enum-multiselect/state.ts +18 -0
  54. package/src/forms/domains/primitives/domains/enum-multiselect/template.tsx +56 -0
  55. package/src/forms/domains/primitives/domains/number/state.ts +8 -0
  56. package/src/forms/domains/primitives/domains/number/template.tsx +26 -0
  57. package/src/forms/domains/primitives/domains/searchable-infinite-stream/state.ts +55 -0
  58. package/src/forms/domains/primitives/domains/searchable-infinite-stream/template.tsx +114 -0
  59. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/state.ts +27 -0
  60. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/template.tsx +119 -0
  61. package/src/forms/domains/primitives/domains/string/state.ts +12 -0
  62. package/src/forms/domains/primitives/domains/string/template.tsx +24 -0
  63. package/src/forms/domains/singleton/domains/descriptors/entity/state.ts +9 -0
  64. package/src/forms/domains/singleton/domains/descriptors/field/domains/base/state.ts +5 -0
  65. package/src/forms/domains/singleton/domains/descriptors/field/domains/boolean/state.ts +6 -0
  66. package/src/forms/domains/singleton/domains/descriptors/field/domains/custom/state.ts +21 -0
  67. package/src/forms/domains/singleton/domains/descriptors/field/domains/date/state.ts +6 -0
  68. package/src/forms/domains/singleton/domains/descriptors/field/domains/enum/state.ts +7 -0
  69. package/src/forms/domains/singleton/domains/descriptors/field/domains/infinite-enum/state.ts +8 -0
  70. package/src/forms/domains/singleton/domains/descriptors/field/domains/number/state.ts +7 -0
  71. package/src/forms/domains/singleton/domains/descriptors/field/domains/string/state.ts +7 -0
  72. package/src/forms/domains/singleton/domains/descriptors/field/state.ts +16 -0
  73. package/src/forms/domains/singleton/domains/descriptors/form/state.ts +13 -0
  74. package/src/forms/domains/singleton/domains/form-label/state.ts +2 -0
  75. package/src/forms/domains/singleton/state.ts +87 -0
  76. package/src/forms/domains/singleton/template.tsx +92 -0
  77. package/src/forms/domains/singleton/views/field-views.ts +23 -0
  78. package/src/forms/domains/singleton/views/simple-inputs/base.ts +5 -0
  79. package/src/forms/domains/singleton/views/simple-inputs/boolean.tsx +4 -0
  80. package/src/forms/domains/singleton/views/simple-inputs/date.tsx +4 -0
  81. package/src/forms/domains/singleton/views/simple-inputs/number.tsx +4 -0
  82. package/src/forms/domains/singleton/views/simple-inputs/string.tsx +4 -0
  83. package/src/fun/domains/curry/state.ts +6 -0
  84. package/src/fun/domains/id/state.ts +2 -0
  85. package/src/fun/domains/predicate/domains/bool-expr.ts +98 -0
  86. package/src/fun/domains/predicate/state.ts +29 -0
  87. package/src/fun/domains/simpleCallback/state.ts +3 -0
  88. package/src/fun/domains/uncurry/state.ts +5 -0
  89. package/src/fun/domains/unit/state.ts +3 -0
  90. package/src/fun/domains/updater/domains/caseUpdater/state.ts +44 -0
  91. package/src/fun/domains/updater/domains/mapUpdater/state.ts +36 -0
  92. package/src/fun/domains/updater/domains/maybeUpdater/state.ts +45 -0
  93. package/src/fun/domains/updater/domains/orderedMapUpdater/state.ts +26 -0
  94. package/src/fun/domains/updater/domains/orderedSetUpdater/state.ts +23 -0
  95. package/src/fun/domains/updater/domains/replaceWith/state.ts +3 -0
  96. package/src/fun/domains/updater/domains/simpleUpdater/domains/baseSimpleUpdater/state.ts +18 -0
  97. package/src/fun/domains/updater/domains/simpleUpdater/state.ts +72 -0
  98. package/src/fun/domains/updater/state.ts +86 -0
  99. package/src/fun/state.ts +33 -0
  100. package/src/infinite-data-stream/coroutines/builder.ts +8 -0
  101. package/src/infinite-data-stream/coroutines/infiniteLoader.ts +51 -0
  102. package/src/infinite-data-stream/coroutines/runner.ts +12 -0
  103. package/src/infinite-data-stream/state.ts +175 -0
  104. package/src/infinite-data-stream/template.tsx +16 -0
  105. package/src/math/domains/DOMRect/state.ts +12 -0
  106. package/src/math/domains/number/state.ts +9 -0
  107. package/src/math/domains/rect/state.ts +22 -0
  108. package/src/math/domains/rgba/state.ts +87 -0
  109. package/src/math/domains/size2/state.ts +14 -0
  110. package/src/math/domains/vector2/state.ts +16 -0
  111. package/src/queue/state.ts +42 -0
  112. package/src/state/domains/repository/state.ts +14 -0
  113. package/src/template/state.tsx +198 -0
  114. package/src/validation/state.ts +2 -0
  115. package/src/value/domains/mutable-value/state.ts +13 -0
  116. package/src/value/state.ts +12 -0
  117. package/src/visibility/state.ts +3 -0
  118. package/tsconfig.json +22 -0
@@ -0,0 +1,144 @@
1
+ import { Updater } from "../fun/domains/updater/state";
2
+ import { BasicFun, Fun } from "../fun/state";
3
+
4
+ export type LoadedAsyncState<a> = { kind: "loaded"; value: a }
5
+ export type ReloadingAsyncState<a> = { kind: "reloading"; value: a }
6
+ export type FailedReloadAsyncState<a> = { kind: "failed-reload"; value: a; error: any }
7
+
8
+ export type AsyncState<a> = (
9
+ | ((
10
+ | { kind: "unloaded" }
11
+ | { kind: "loading" }
12
+ | ReloadingAsyncState<a>
13
+ | { kind: "error"; error: any }
14
+ ) & { failedLoadingAttempts: number })
15
+ | LoadedAsyncState<a>
16
+ | FailedReloadAsyncState<a>
17
+ ) & {
18
+ map: <b>(f: BasicFun<a, b>) => AsyncState<b>;
19
+ getLoadingAttempts: <a>(this: AsyncState<a>) => number;
20
+ };
21
+
22
+ export type HasValueAsyncState<a> = AsyncState<a> & { kind:"loaded" | "reloading" | "failed-reload"}
23
+ export type IsLoadingAsyncState<a> = AsyncState<a> & { kind:"loading" | "reloading" }
24
+
25
+ function map<a, b>(this: AsyncState<a>, f: BasicFun<a, b>): AsyncState<b> {
26
+ return this.kind == "loaded"
27
+ ? AsyncState.Default.loaded(f(this.value))
28
+ : this.kind == "unloaded"
29
+ ? AsyncState.Default.unloaded()
30
+ : this.kind == "error"
31
+ ? AsyncState.Default.error()
32
+ : this.kind == "loading"
33
+ ? AsyncState.Default.loading()
34
+ : AsyncState.Default.reloading(f(this.value));
35
+ }
36
+
37
+ function getLoadingAttempts<a>(this: AsyncState<a>): number {
38
+ return this.kind == "loaded" || this.kind == "failed-reload" ? 0 : this.failedLoadingAttempts;
39
+ }
40
+
41
+ export const AsyncState = {
42
+ Default: {
43
+ unloaded: <a>(): AsyncState<a> => ({
44
+ kind: "unloaded",
45
+ map,
46
+ getLoadingAttempts,
47
+ failedLoadingAttempts: 0,
48
+ }),
49
+ loading: <a>(): AsyncState<a> => ({
50
+ kind: "loading",
51
+ map,
52
+ getLoadingAttempts,
53
+ failedLoadingAttempts: 0,
54
+ }),
55
+ reloading: <a>(value: a): AsyncState<a> => ({
56
+ kind: "reloading",
57
+ value,
58
+ map,
59
+ getLoadingAttempts,
60
+ failedLoadingAttempts: 0,
61
+ }),
62
+ failedReload: <a>(value: a, error?: any): AsyncState<a> => ({
63
+ kind: "failed-reload",
64
+ value,
65
+ error,
66
+ map,
67
+ getLoadingAttempts,
68
+ }),
69
+ error: <a>(value?: any): AsyncState<a> => ({
70
+ kind: "error",
71
+ map,
72
+ error: value,
73
+ getLoadingAttempts,
74
+ failedLoadingAttempts: 0,
75
+ }),
76
+ loaded: <a>(value: a): AsyncState<a> => ({
77
+ kind: "loaded",
78
+ value,
79
+ map,
80
+ getLoadingAttempts,
81
+ }),
82
+ },
83
+ Updaters: {
84
+ failedLoadingAttempts: <a>(updateAttempts: Updater<number>): Updater<AsyncState<a>> =>
85
+ Updater((current) =>
86
+ current.kind == "loaded" || current.kind == "failed-reload"
87
+ ? current
88
+ : {
89
+ ...current,
90
+ failedLoadingAttempts: updateAttempts(current.failedLoadingAttempts),
91
+ }
92
+ ),
93
+ toUnloaded: <a>(): Updater<AsyncState<a>> =>
94
+ Updater((_) => ({
95
+ kind: "unloaded",
96
+ map,
97
+ getLoadingAttempts,
98
+ failedLoadingAttempts: 0,
99
+ })),
100
+ toLoading: <a>(): Updater<AsyncState<a>> =>
101
+ Updater((current) => ({
102
+ kind: "loading",
103
+ map,
104
+ getLoadingAttempts,
105
+ failedLoadingAttempts: current.getLoadingAttempts(),
106
+ })),
107
+ toReloading: <a>(): Updater<AsyncState<a>> =>
108
+ Updater((current) =>
109
+ current.kind == "loaded" ?
110
+ AsyncState.Default.reloading(current.value)
111
+ : AsyncState.Updaters.toLoading<a>()(current)),
112
+ toError: <a>(error?: any): Updater<AsyncState<a>> =>
113
+ Updater((current) =>
114
+ AsyncState.Operations.hasValue(current) ?
115
+ ({
116
+ kind: "failed-reload",
117
+ value:current.value,
118
+ map,
119
+ error,
120
+ getLoadingAttempts,
121
+ failedLoadingAttempts: current.getLoadingAttempts() + 1,
122
+ }) : ({
123
+ kind: "error",
124
+ map,
125
+ error,
126
+ getLoadingAttempts,
127
+ failedLoadingAttempts: current.getLoadingAttempts() + 1,
128
+ })),
129
+ toLoaded: <a>(value: a): Updater<AsyncState<a>> =>
130
+ Updater((_) => ({ kind: "loaded", value, map, getLoadingAttempts })),
131
+ },
132
+ Operations: {
133
+ map: <a, b>(f: BasicFun<a, b>): Fun<AsyncState<a>, AsyncState<b>> =>
134
+ Fun((_) => _.map(f)),
135
+ status:<a>(_:AsyncState<a>) : a | AsyncState<a>["kind"] =>
136
+ _.kind == "loaded" || _.kind == "reloading" ? _.value : _.kind,
137
+ hasValue:<a>(_:AsyncState<a>) : _ is HasValueAsyncState<a> =>
138
+ _.kind == "loaded" || _.kind == "reloading" || _.kind == "failed-reload",
139
+ isLoading:<a>(_:AsyncState<a>) : _ is IsLoadingAsyncState<a> =>
140
+ _.kind == "loading" || _.kind == "reloading",
141
+ errors:<a>(_:AsyncState<a>) : Array<any> =>
142
+ _.kind == "error" ? [_.error] : [],
143
+ },
144
+ };
@@ -0,0 +1,29 @@
1
+ import { Map, OrderedMap } from "immutable"
2
+
3
+ export type Guid = string;
4
+
5
+ export type Identifiable = { Id: Guid };
6
+ export type SmallIdentifiable = { id: string };
7
+
8
+ export const Identifiable = {
9
+ Operations:{
10
+ toMap:<T extends Identifiable>(
11
+ values: Array<T>
12
+ ): Map<Guid, T> => Map(values.map((_) => [_.Id, _])),
13
+ toOrderedMap:<T extends Identifiable>(
14
+ values: Array<T>
15
+ ): OrderedMap<Guid, T> => OrderedMap(values.map((_) => [_.Id, _]))
16
+
17
+ }
18
+ }
19
+
20
+ export const SmallIdentifiable = {
21
+ Operations:{
22
+ toMap:<T extends SmallIdentifiable>(
23
+ values: Array<T>
24
+ ): Map<Guid, T> => Map(values.map((_) => [_.id, _])),
25
+ toOrderedMap:<T extends SmallIdentifiable>(
26
+ values: Array<T>
27
+ ): OrderedMap<Guid, T> => OrderedMap(values.map((_) => [_.id, _]))
28
+ }
29
+ }
@@ -0,0 +1,16 @@
1
+ import { BasicFun, Fun } from "../../../fun/state";
2
+
3
+ export const ArrayRepo = {
4
+ Operations: {
5
+ map: <a, b>(f: BasicFun<a, b>): Fun<Array<a>, Array<b>> => Fun(_ => _.map(f))
6
+ }
7
+ };
8
+
9
+ declare global {
10
+ interface Array<T> {
11
+ random(): T;
12
+ }
13
+ }
14
+ Array.prototype.random = function <a>(this:Array<a>) : a {
15
+ return this[Math.floor((Math.random() * this.length))];
16
+ };
@@ -0,0 +1,20 @@
1
+ import { List } from "immutable";
2
+ import { Updater } from "../../../../../fun/domains/updater/state";
3
+ import { BasicFun } from "../../../../../fun/state";
4
+
5
+ export const ListRepo = {
6
+ Default: {
7
+
8
+ },
9
+ Updaters: {
10
+ push<V>(v:V): Updater<List<V>> {
11
+ return Updater((_) => _.push(v));
12
+ },
13
+ filter<V>(predicate: BasicFun<V, boolean>): Updater<List<V>> {
14
+ return Updater((_) => _.filter(predicate));
15
+ },
16
+ },
17
+ Operations: {
18
+ },
19
+ };
20
+
@@ -0,0 +1,33 @@
1
+ import { Map } from "immutable";
2
+ import { Identifiable } from "../../../../../baseEntity/domains/identifiable/state";
3
+ import { Unit } from "../../../../../fun/domains/unit/state";
4
+ import { BasicUpdater, Updater } from "../../../../../fun/domains/updater/state";
5
+ import { BasicFun } from "../../../../../fun/state";
6
+
7
+ export const MapRepo = {
8
+ Default: {
9
+ fromIdentifiables: <T extends Identifiable>(array: T[]): Map<T["Id"], T> =>
10
+ Map(
11
+ array.reduce<Record<string, T>>((acc, item) => {
12
+ acc[item.Id] = item;
13
+ return acc;
14
+ }, {})
15
+ ),
16
+ },
17
+ Updaters:{
18
+ set<K, V>(key: K, value: V): Updater<Map<K, V>> {
19
+ return Updater((_) => _.set(key, value));
20
+ },
21
+ remove<K, V>(key: K): Updater<Map<K, V>> {
22
+ return Updater((_) => _.remove(key));
23
+ },
24
+ update: <k, v>(k: k, _: BasicUpdater<v>): Updater<Map<k, v>> =>
25
+ Updater((current) =>
26
+ current.has(k) ? current.set(k, _(current.get(k)!)) : current
27
+ ),
28
+ upsert: <k, v>(k: k, defaultValue:BasicFun<Unit,v>, _: BasicUpdater<v>): Updater<Map<k, v>> =>
29
+ Updater((current) =>
30
+ current.has(k) ? current.set(k, _(current.get(k)!)) : current.set(k, _(defaultValue({})))
31
+ ),
32
+ }
33
+ };
@@ -0,0 +1,117 @@
1
+ import { OrderedMap } from "immutable";
2
+ import { Identifiable, SmallIdentifiable } from "../../../../../baseEntity/domains/identifiable/state";
3
+ import { BasicUpdater, Updater } from "../../../../../fun/domains/updater/state";
4
+ import { BasicFun } from "../../../../../fun/state";
5
+ import { Unit } from "../../../../../../main";
6
+
7
+ export const OrderedMapRepo = {
8
+ Default: {
9
+ fromSmallIdentifiables: <T extends SmallIdentifiable>(
10
+ array: T[]
11
+ ): OrderedMap<T["id"], T> =>
12
+ OrderedMap(
13
+ array.reduce(
14
+ (acc, item) => {
15
+ acc[item.id] = item;
16
+ return acc;
17
+ },
18
+ {} as Record<string, T>
19
+ )
20
+ ),
21
+ fromIdentifiables: <T extends Identifiable>(
22
+ array: T[]
23
+ ): OrderedMap<T["Id"], T> =>
24
+ OrderedMap(
25
+ array.reduce(
26
+ (acc, item) => {
27
+ acc[item.Id] = item;
28
+ return acc;
29
+ },
30
+ {} as Record<string, T>
31
+ )
32
+ ),
33
+ },
34
+ Updaters: {
35
+ replaceAndMerge<K, V>(
36
+ key: K,
37
+ originalMap: OrderedMap<K, V>,
38
+ mergeMap: OrderedMap<K, V>
39
+ ) {
40
+ const index = originalMap.keySeq().findIndex((k) => k === key);
41
+
42
+ let newMap = originalMap.remove(key);
43
+
44
+ mergeMap.entrySeq().forEach((entry, idx) => {
45
+ newMap = newMap
46
+ .slice(0, index + idx)
47
+ .concat([[entry[0], entry[1]]], newMap.slice(index + idx));
48
+ });
49
+
50
+ return newMap;
51
+ },
52
+ filter<K, V>(predicate: BasicFun<[K, V], boolean>): Updater<OrderedMap<K, V>> {
53
+ return Updater((_) => _.filter((v: V, k: K) => predicate([k, v])))
54
+ },
55
+ set<K, V>(key: K, value: V): Updater<OrderedMap<K, V>> {
56
+ return Updater((_) => _.set(key, value));
57
+ },
58
+ insertAtBeginning<K, V>(key: K, value: V): Updater<OrderedMap<K,V>> {
59
+ return Updater((_) => OrderedMap<K, V>(_.toArray().toSpliced(0, 0, [key, value])))
60
+ },
61
+ insertAtEnd<K, V>(key: K, value: V): Updater<OrderedMap<K,V>> {
62
+ return Updater((_) => OrderedMap<K, V>(_.toArray().toSpliced(_.size, 0, [key, value])))
63
+ },
64
+ insertAt<K, V>([key, value] : [K, V], insertionPosition: K, order: "before" | "after"): Updater<OrderedMap<K,V>> {
65
+ return Updater((_) => { const __ = _.toArray();
66
+ const insertionIndex = __.findIndex((value) => value[0] == insertionPosition) + (order == "after" ? 1 : 0)
67
+ return OrderedMap(__.toSpliced(insertionIndex, 0, [key, value]))})
68
+ },
69
+ remove<K, V>(key: K): Updater<OrderedMap<K, V>> {
70
+ return Updater((_) => _.remove(key));
71
+ },
72
+ clear<K, V>(): Updater<OrderedMap<K, V>> {
73
+ return Updater((_) => OrderedMap<K,V>());
74
+ },
75
+ merge<K, V>(
76
+ key: K,
77
+ originalMap: OrderedMap<K, V>,
78
+ mergeMap: OrderedMap<K, V>
79
+ ) {
80
+ const index = originalMap.keySeq().findIndex((k) => k === key);
81
+
82
+ mergeMap.entrySeq().forEach((entry, idx) => {
83
+ originalMap = originalMap
84
+ .slice(0, index + idx)
85
+ .concat([[entry[0], entry[1]]], originalMap.slice(index + idx));
86
+ });
87
+
88
+ return originalMap;
89
+ },
90
+ update: <k, v>(k: k, _: BasicUpdater<v>): Updater<OrderedMap<k, v>> =>
91
+ Updater((current) =>
92
+ current.has(k) ? current.set(k, _(current.get(k)!)) : current
93
+ ),
94
+ upsert: <k, v>(k: k, defaultValue: BasicFun<Unit, v>, _: BasicUpdater<v>): Updater<OrderedMap<k, v>> =>
95
+ Updater((current) =>
96
+ current.has(k) ? current.set(k, _(current.get(k)!)) : current.set(k, _(defaultValue({})))
97
+ ),
98
+ append: <k, v>(
99
+ newEntries:Array<[k, v]>
100
+ ) : Updater<OrderedMap<k, v>> =>
101
+ Updater(current =>
102
+ OrderedMap([...current.toArray(), ...newEntries])
103
+ ),
104
+ prepend: <k, v>(
105
+ newEntries:Array<[k, v]>
106
+ ) : Updater<OrderedMap<k, v>> =>
107
+ Updater(current =>
108
+ OrderedMap([...newEntries, ...current.toArray()])
109
+ ),
110
+
111
+ },
112
+ Operations: {
113
+ toArray: <T extends Identifiable>(map: OrderedMap<T["Id"], T>) =>
114
+ map.valueSeq().toArray(),
115
+ },
116
+ };
117
+
@@ -0,0 +1,19 @@
1
+ import { Set } from "immutable";
2
+ import { Updater } from "../../../../../fun/domains/updater/state";
3
+
4
+ export const SetRepo = {
5
+ Updaters: {
6
+ add: <e>(e: e): Updater<Set<e>> =>
7
+ Updater(current =>
8
+ current.add(e)
9
+ ),
10
+ remove: <e>(e: e): Updater<Set<e>> =>
11
+ Updater(current =>
12
+ current.remove(e)
13
+ ),
14
+ subtract: <e>(elements: Iterable<e>): Updater<Set<e>> =>
15
+ Updater(current =>
16
+ current.subtract(elements)
17
+ )
18
+ }
19
+ }
@@ -0,0 +1,15 @@
1
+ import { OrderedSet } from "immutable";
2
+ import { Updater } from "../../../../../fun/domains/updater/state";
3
+
4
+ export const OrderedSetRepo = {
5
+ Updaters:{
6
+ add:<e>(e:e) : Updater<OrderedSet<e>> =>
7
+ Updater(current =>
8
+ current.add(e)
9
+ ),
10
+ subtract:<e>(elements:Iterable<e>) : Updater<OrderedSet<e>> =>
11
+ Updater(current =>
12
+ current.subtract(elements)
13
+ )
14
+ }
15
+ }
@@ -0,0 +1,20 @@
1
+ import { unit, Unit } from "../../../fun/domains/unit/state";
2
+ import { BasicUpdater, Updater } from "../../../fun/domains/updater/state";
3
+ import { BasicFun, Fun } from "../../../fun/state";
4
+
5
+ export type Maybe<e> = e | undefined;
6
+ export const Maybe = {
7
+ Default: <e>(_: e | undefined) => _,
8
+ Updaters: {
9
+ value: <e>(_: BasicUpdater<e>): Updater<Maybe<e>> =>
10
+ Updater(Maybe.Operations.map(_)),
11
+ ensureValue: <e>(_: BasicFun<Unit, e>): Updater<Maybe<e>> =>
12
+ Updater((__) => (__ != undefined ? __ : _(unit))),
13
+ },
14
+ Operations: {
15
+ map: <a, b>(f: BasicFun<a, b>): Fun<Maybe<a>, Maybe<b>> =>
16
+ Fun<Maybe<a>, Maybe<b>>((_) =>
17
+ _ != undefined ? Maybe.Default(f(_)) : Maybe.Default(undefined)
18
+ ),
19
+ },
20
+ };
@@ -0,0 +1,47 @@
1
+ import { id } from "../../../fun/domains/id/state";
2
+ import { Unit } from "../../../fun/domains/unit/state";
3
+ import { BasicUpdater, Updater } from "../../../fun/domains/updater/state";
4
+ import { BasicFun, Fun } from "../../../fun/state";
5
+
6
+ export type Product<a, b> = { left:a, right:b };
7
+ export type Pair<a, b> = Product<a, b>;
8
+ export const Product = Object.assign(
9
+ <a, b>() => ({
10
+ Default: (left:a, right:b) : Product<a,b> => ({ left, right }),
11
+ Updaters: {
12
+ left: Fun(
13
+ (_: BasicUpdater<a>): Updater<Product<a, b>> =>
14
+ Updater(Product<a, b>().Operations.map2(_, id))
15
+ ),
16
+ right: Fun(
17
+ (_: BasicUpdater<b>): Updater<Product<a, b>> =>
18
+ Updater(Product<a, b>().Operations.map2(id, _))
19
+ ),
20
+ },
21
+ Operations: {
22
+ map2: <a1, b1>(
23
+ l: BasicFun<a, a1>,
24
+ r: BasicFun<b, b1>
25
+ ): Fun<Product<a, b>, Product<a1, b1>> =>
26
+ Fun(_ => Product.Default(l(_.left), r(_.right))),
27
+ },
28
+ }),
29
+ {
30
+ Default: <a,b>(left:a, right:b) : Product<a,b> => ({ left, right }),
31
+ Updaters: {
32
+ left:
33
+ <a,b>(_: BasicUpdater<a>): Updater<Product<a, b>> =>
34
+ Updater(Product<a, b>().Operations.map2(_, id)),
35
+ right:
36
+ <a,b>(_: BasicUpdater<b>): Updater<Product<a, b>> =>
37
+ Updater(Product<a, b>().Operations.map2(id, _)),
38
+ },
39
+ Operations: {
40
+ map2: <a, b, a1, b1>(
41
+ l: BasicFun<a, a1>,
42
+ r: BasicFun<b, b1>
43
+ ): Fun<Product<a, b>, Product<a1, b1>> =>
44
+ Fun(_ => Product.Default(l(_.left), r(_.right))),
45
+ },
46
+ }
47
+ );
@@ -0,0 +1,82 @@
1
+ import { id } from "../../../fun/domains/id/state";
2
+ import { Unit } from "../../../fun/domains/unit/state";
3
+ import { BasicUpdater, Updater } from "../../../fun/domains/updater/state";
4
+ import { BasicFun, Fun } from "../../../fun/state";
5
+ export type LeftValue<a> = { value: a; kind: "l" };
6
+ export const LeftValue = {
7
+ Updaters: {
8
+ value: <a>(_: BasicUpdater<a>): Updater<LeftValue<a>> =>
9
+ Updater((v) => ({ ...v, value: _(v.value) })),
10
+ },
11
+ };
12
+ export type RightValue<b> = { value: b; kind: "r" };
13
+ export const RightValue = {
14
+ Updaters: {
15
+ value: <b>(_: BasicUpdater<b>): Updater<RightValue<b>> =>
16
+ Updater((v) => ({ ...v, value: _(v.value) })),
17
+ },
18
+ };
19
+ export type Sum<a, b> = { value: a; kind: "l" } | { value: b; kind: "r" };
20
+ export type Either<a, b> = Sum<a, b>;
21
+ export const Sum = Object.assign(
22
+ <a, b>() => ({
23
+ Default: {
24
+ left: Fun((_: a): Sum<a, b> => ({ value: _, kind: "l" })),
25
+ right: Fun((_: b): Sum<a, b> => ({ value: _, kind: "r" })),
26
+ },
27
+ Updaters: {
28
+ left: Fun(
29
+ (_: BasicUpdater<a>): Updater<Sum<a, b>> =>
30
+ Updater(Sum<a, b>().Updaters.map2(_, id))
31
+ ),
32
+ right: Fun(
33
+ (_: BasicUpdater<b>): Updater<Sum<a, b>> =>
34
+ Updater(Sum<a, b>().Updaters.map2(id, _))
35
+ ),
36
+ map2: <a, b, a1, b1>(
37
+ l: BasicFun<a, a1>,
38
+ r: BasicFun<b, b1>
39
+ ): Fun<Sum<a, b>, Sum<a1, b1>> =>
40
+ Sum<a, b>().Operations.fold<a, b, Sum<a1, b1>>(
41
+ Fun(l).then(Sum<a1, b1>().Default.left),
42
+ Fun(r).then(Sum<a1, b1>().Default.right)
43
+ ),
44
+ },
45
+ Operations: {
46
+ fold: <a, b, c>(
47
+ l: BasicFun<a, c>,
48
+ r: BasicFun<b, c>
49
+ ): Fun<Sum<a, b>, c> =>
50
+ Fun((_) => (_.kind == "l" ? l(_.value) : r(_.value))),
51
+ },
52
+ }),
53
+ {
54
+ Default: {
55
+ left: <a, b>(_: a): Sum<a, b> => ({ value: _, kind: "l" }),
56
+ right: <a, b>(_: b): Sum<a, b> => ({ value: _, kind: "r" }),
57
+ },
58
+ Updaters: {
59
+ left: <a, b>(_: BasicUpdater<a>): Updater<Sum<a, b>> =>
60
+ Updater(Sum.Updaters.map2(_, id)),
61
+ right: <a, b>(_: BasicUpdater<b>): Updater<Sum<a, b>> =>
62
+ Updater(Sum.Updaters.map2(id, _)),
63
+ map2: <a, b, a1, b1>(
64
+ l: BasicFun<a, a1>,
65
+ r: BasicFun<b, b1>
66
+ ): Fun<Sum<a, b>, Sum<a1, b1>> =>
67
+ Sum.Operations.fold<a, b, Sum<a1, b1>>(
68
+ Fun(l).then(Sum.Default.left<a1, b1>),
69
+ Fun(r).then(Sum.Default.right<a1, b1>)
70
+ ),
71
+ },
72
+ Operations: {
73
+ fold: <a, b, c>(
74
+ l: BasicFun<a, c>,
75
+ r: BasicFun<b, c>
76
+ ): Fun<Sum<a, b>, c> =>
77
+ Fun((_) => (_.kind == "l" ? l(_.value) : r(_.value))),
78
+ },
79
+ }
80
+ );
81
+ export const Either = Sum;
82
+ export type Option<a> = Sum<Unit, a>;
@@ -0,0 +1,66 @@
1
+ import { Map, Collection, OrderedMap } from "immutable";
2
+ import { Unit } from "../fun/domains/unit/state";
3
+ import { BasicUpdater } from "../fun/domains/updater/state";
4
+ import { BasicFun } from "../fun/state";
5
+ import { Template, createTemplate } from "../template/state";
6
+ import { Coroutine, InboundEventFromContext, InboundKindFromContext } from "./state";
7
+ import { CoroutineComponentOptions, CoroutineTemplate } from "./template";
8
+ import { Guid } from "../baseEntity/domains/identifiable/state";
9
+ import { SimpleCallback } from "../fun/domains/simpleCallback/state";
10
+
11
+ export const CoTypedFactory = Object.assign(<c, s>() => ({
12
+ Seq: Coroutine.Seq<c & s, s>,
13
+ GetState: Coroutine.GetState<c & s, s>,
14
+ SetState: Coroutine.SetState<c & s, s>,
15
+ UpdateState: Coroutine.UpdateState<c & s, s>,
16
+ Any: Coroutine.Any<c & s, s, Unit>,
17
+ All:<result,>(ps: Array<Coroutine<c & s, s, result>>) => Coroutine.All<c & s, s, result>(ps),
18
+ Yield: Coroutine.Yield<c & s, s, Unit>,
19
+ Wait: Coroutine.Wait<c & s, s>,
20
+ Await: <r, err>(
21
+ p: BasicFun<Unit, Promise<r>>,
22
+ onErr: BasicFun<any, err>,
23
+ debugName?: string
24
+ ) => Coroutine.Await<c & s, s, r, err>(p, onErr, debugName),
25
+ Repeat: Coroutine.Repeat<c & s, s>,
26
+ Return: <r,>(res: r) => Coroutine.Return<c & s, s, r>(res),
27
+ While: Coroutine.While<c & s, s>,
28
+ For: <element,>(collection:Collection<number, element>) => (p:BasicFun<element, Coroutine<c & s, s, Unit>>) =>
29
+ Coroutine.For<c & s, s, element>(collection, p),
30
+ Embed: <parentContext, parentState, result>(
31
+ p: Coroutine<c &s, s, result>,
32
+ narrow:BasicFun<parentContext & parentState, c &s>,
33
+ widen:BasicFun<BasicUpdater<s>,BasicUpdater<parentState>>
34
+ ): Coroutine<parentContext & parentState, parentState, result> =>
35
+ Coroutine.Embed(p, narrow, widen),
36
+ Template:<fm,>(
37
+ initialCoroutine: Coroutine<c & s, s, Unit>,
38
+ options?: CoroutineComponentOptions<c & s, s>
39
+ ) : Template<c & s , s, fm> => createTemplate(
40
+ props => (options?.runFilter || (_ => true))({...props, foreignMutations:{}}) ? CoroutineTemplate<c & s, s, fm>()({
41
+ ...props,
42
+ context:{
43
+ ...props.context,
44
+ initialCoroutine,
45
+ options,
46
+ },
47
+ }) : <></>
48
+ ),
49
+ Trigger:<event extends { id:Guid, kind:kind }, kind extends string>(event:event)
50
+ : Coroutine<c & s & { outboundEvents:Map<kind, OrderedMap<Guid, event>> }, s & { outboundEvents:Map<kind, OrderedMap<Guid, event>> }, Unit> =>
51
+ Coroutine.Trigger<c & s & { outboundEvents:Map<kind, OrderedMap<Guid, event>> }, s & { outboundEvents:Map<kind, OrderedMap<Guid, event>> }, event, kind>(event),
52
+ Do:(action:SimpleCallback<void>)
53
+ : Coroutine<c & s, s, Unit> =>
54
+ Coroutine.Do(action),
55
+ }),
56
+ {
57
+ withOn:<eventKind, event, c, s extends { inboundEvents: Map<eventKind, OrderedMap<Guid, event>> }>() => ({
58
+ ...CoTypedFactory<c,s>(),
59
+ On:<matchedEvent extends InboundKindFromContext<c & s>>(
60
+ kind:matchedEvent,
61
+ filter?:BasicFun<[InboundEventFromContext<c & s> & { kind:matchedEvent }, c & s], boolean>)
62
+ : Coroutine<c & s, s, InboundEventFromContext<c & s> & { kind:matchedEvent }> => {
63
+ return Coroutine.On<eventKind, event, c & s, s, matchedEvent>(kind, filter)
64
+ },
65
+ })
66
+ });