liminal 0.4.0 → 1.0.0-beta.2

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 (239) hide show
  1. package/LICENSE +201 -15
  2. package/README.md +96 -81
  3. package/esm/client/Client.d.ts +39 -0
  4. package/esm/client/Client.d.ts.map +1 -0
  5. package/esm/client/Client.js +9 -0
  6. package/esm/client/Client.js.map +1 -0
  7. package/esm/client/Store.d.ts +3 -0
  8. package/esm/client/Store.d.ts.map +1 -0
  9. package/esm/client/Store.js +3 -0
  10. package/esm/client/Store.js.map +1 -0
  11. package/esm/client/Tx.d.ts +40 -0
  12. package/esm/client/Tx.d.ts.map +1 -0
  13. package/esm/client/Tx.js +36 -0
  14. package/esm/client/Tx.js.map +1 -0
  15. package/esm/client/mod.d.ts +4 -0
  16. package/esm/client/mod.d.ts.map +1 -0
  17. package/esm/client/mod.js +5 -0
  18. package/esm/client/mod.js.map +1 -0
  19. package/esm/core/Bool.d.ts +104 -0
  20. package/esm/core/Bool.d.ts.map +1 -0
  21. package/esm/core/Bool.js +73 -0
  22. package/esm/core/Bool.js.map +1 -0
  23. package/esm/core/Bytes.d.ts +39 -0
  24. package/esm/core/Bytes.d.ts.map +1 -0
  25. package/esm/core/Bytes.js +7 -0
  26. package/esm/core/Bytes.js.map +1 -0
  27. package/esm/core/Call.d.ts +11 -0
  28. package/esm/core/Call.d.ts.map +1 -0
  29. package/esm/core/Call.js +23 -0
  30. package/esm/core/Call.js.map +1 -0
  31. package/esm/core/Effect.d.ts +20 -0
  32. package/esm/core/Effect.d.ts.map +1 -0
  33. package/esm/core/Effect.js +37 -0
  34. package/esm/core/Effect.js.map +1 -0
  35. package/esm/core/Hash.d.ts +41 -0
  36. package/esm/core/Hash.d.ts.map +1 -0
  37. package/esm/core/Hash.js +8 -0
  38. package/esm/core/Hash.js.map +1 -0
  39. package/esm/core/Id.d.ts +198 -0
  40. package/esm/core/Id.d.ts.map +1 -0
  41. package/esm/core/Id.js +69 -0
  42. package/esm/core/Id.js.map +1 -0
  43. package/esm/core/Int.d.ts +768 -0
  44. package/esm/core/Int.d.ts.map +1 -0
  45. package/esm/core/Int.js +201 -0
  46. package/esm/core/Int.js.map +1 -0
  47. package/esm/core/Key.d.ts +40 -0
  48. package/esm/core/Key.d.ts.map +1 -0
  49. package/esm/core/Key.js +7 -0
  50. package/esm/core/Key.js.map +1 -0
  51. package/esm/core/MerkleList.d.ts +105 -0
  52. package/esm/core/MerkleList.d.ts.map +1 -0
  53. package/esm/core/MerkleList.js +82 -0
  54. package/esm/core/MerkleList.js.map +1 -0
  55. package/esm/core/MerkleMap.d.ts +87 -0
  56. package/esm/core/MerkleMap.d.ts.map +1 -0
  57. package/esm/core/MerkleMap.js +67 -0
  58. package/esm/core/MerkleMap.js.map +1 -0
  59. package/esm/core/None.d.ts +52 -0
  60. package/esm/core/None.d.ts.map +1 -0
  61. package/esm/core/None.js +12 -0
  62. package/esm/core/None.js.map +1 -0
  63. package/esm/core/State.d.ts +16 -0
  64. package/esm/core/State.d.ts.map +1 -0
  65. package/esm/core/State.js +22 -0
  66. package/esm/core/State.js.map +1 -0
  67. package/esm/core/String.d.ts +41 -0
  68. package/esm/core/String.d.ts.map +1 -0
  69. package/esm/core/String.js +4 -0
  70. package/esm/core/String.js.map +1 -0
  71. package/esm/core/Struct.d.ts +58 -0
  72. package/esm/core/Struct.d.ts.map +1 -0
  73. package/esm/core/Struct.js +13 -0
  74. package/esm/core/Struct.js.map +1 -0
  75. package/esm/core/Type.d.ts +78 -0
  76. package/esm/core/Type.d.ts.map +1 -0
  77. package/esm/core/Type.js +71 -0
  78. package/esm/core/Type.js.map +1 -0
  79. package/esm/core/Union.d.ts +43 -0
  80. package/esm/core/Union.d.ts.map +1 -0
  81. package/esm/core/Union.js +7 -0
  82. package/esm/core/Union.js.map +1 -0
  83. package/esm/core/Use.d.ts +62 -0
  84. package/esm/core/Use.d.ts.map +1 -0
  85. package/esm/core/Use.js +16 -0
  86. package/esm/core/Use.js.map +1 -0
  87. package/esm/core/mod.d.ts +18 -0
  88. package/esm/core/mod.d.ts.map +1 -0
  89. package/esm/core/mod.js +19 -0
  90. package/esm/core/mod.js.map +1 -0
  91. package/esm/lib/MerkleList.d.ts +4 -0
  92. package/esm/lib/MerkleList.d.ts.map +1 -0
  93. package/esm/lib/MerkleList.js +4 -0
  94. package/esm/lib/MerkleList.js.map +1 -0
  95. package/esm/lib/MerkleMap.d.ts +4 -0
  96. package/esm/lib/MerkleMap.d.ts.map +1 -0
  97. package/esm/lib/MerkleMap.js +4 -0
  98. package/esm/lib/MerkleMap.js.map +1 -0
  99. package/esm/lib/mod.d.ts +3 -0
  100. package/esm/lib/mod.d.ts.map +1 -0
  101. package/esm/lib/mod.js +3 -0
  102. package/esm/lib/mod.js.map +1 -0
  103. package/esm/mod.d.ts +3 -0
  104. package/esm/mod.d.ts.map +1 -0
  105. package/esm/mod.js +4 -0
  106. package/esm/mod.js.map +1 -0
  107. package/esm/package.json +3 -0
  108. package/esm/test/Signer.d.ts +10 -0
  109. package/esm/test/Signer.d.ts.map +1 -0
  110. package/esm/test/Signer.js +13 -0
  111. package/esm/test/Signer.js.map +1 -0
  112. package/esm/test/mod.d.ts +2 -0
  113. package/esm/test/mod.d.ts.map +1 -0
  114. package/esm/test/mod.js +2 -0
  115. package/esm/test/mod.js.map +1 -0
  116. package/esm/util/AbortController.d.ts +4 -0
  117. package/esm/util/AbortController.d.ts.map +1 -0
  118. package/esm/util/AbortController.js +2 -0
  119. package/esm/util/AbortController.js.map +1 -0
  120. package/esm/util/ArrayOfLength.d.ts +2 -0
  121. package/esm/util/ArrayOfLength.d.ts.map +1 -0
  122. package/esm/util/ArrayOfLength.js +2 -0
  123. package/esm/util/ArrayOfLength.js.map +1 -0
  124. package/esm/util/Flatten.d.ts +4 -0
  125. package/esm/util/Flatten.d.ts.map +1 -0
  126. package/esm/util/Flatten.js +2 -0
  127. package/esm/util/Flatten.js.map +1 -0
  128. package/esm/util/Rest.d.ts +2 -0
  129. package/esm/util/Rest.d.ts.map +1 -0
  130. package/esm/util/Rest.js +2 -0
  131. package/esm/util/Rest.js.map +1 -0
  132. package/esm/util/Subscription.d.ts +5 -0
  133. package/esm/util/Subscription.d.ts.map +1 -0
  134. package/esm/util/Subscription.js +2 -0
  135. package/esm/util/Subscription.js.map +1 -0
  136. package/esm/util/Tagged.d.ts +6 -0
  137. package/esm/util/Tagged.d.ts.map +1 -0
  138. package/esm/util/Tagged.js +6 -0
  139. package/esm/util/Tagged.js.map +1 -0
  140. package/esm/util/U2I.d.ts +2 -0
  141. package/esm/util/U2I.d.ts.map +1 -0
  142. package/esm/util/U2I.js +2 -0
  143. package/esm/util/U2I.js.map +1 -0
  144. package/esm/util/generator/collect.d.ts +3 -0
  145. package/esm/util/generator/collect.d.ts.map +1 -0
  146. package/esm/util/generator/collect.js +16 -0
  147. package/esm/util/generator/collect.js.map +1 -0
  148. package/esm/util/isKey.d.ts +2 -0
  149. package/esm/util/isKey.d.ts.map +1 -0
  150. package/esm/util/isKey.js +8 -0
  151. package/esm/util/isKey.js.map +1 -0
  152. package/esm/util/unimplemented.d.ts +2 -0
  153. package/esm/util/unimplemented.d.ts.map +1 -0
  154. package/esm/util/unimplemented.js +6 -0
  155. package/esm/util/unimplemented.js.map +1 -0
  156. package/package.json +21 -21
  157. package/src/client/Client.ts +49 -0
  158. package/src/client/Store.ts +1 -0
  159. package/src/client/Tx.ts +62 -0
  160. package/src/client/mod.ts +5 -0
  161. package/src/core/Bool.ts +75 -0
  162. package/src/core/Bytes.ts +9 -0
  163. package/src/core/Call.ts +38 -0
  164. package/src/core/Effect.ts +87 -0
  165. package/src/core/Hash.ts +23 -0
  166. package/src/core/Id.ts +97 -0
  167. package/src/core/Int.ts +177 -0
  168. package/src/core/Key.ts +9 -0
  169. package/src/core/MerkleList.ts +92 -0
  170. package/src/core/MerkleMap.ts +86 -0
  171. package/src/core/None.ts +11 -0
  172. package/src/core/State.ts +31 -0
  173. package/src/core/String.ts +5 -0
  174. package/src/core/Struct.ts +49 -0
  175. package/src/core/Type.ts +120 -0
  176. package/src/core/Union.ts +17 -0
  177. package/src/core/Use.ts +33 -0
  178. package/src/core/mod.ts +19 -0
  179. package/src/lib/MerkleList.ts +4 -0
  180. package/src/lib/MerkleMap.ts +4 -0
  181. package/src/lib/mod.ts +2 -0
  182. package/src/mod.ts +4 -0
  183. package/src/test/Signer.ts +22 -0
  184. package/src/test/mod.ts +1 -0
  185. package/src/util/AbortController.ts +3 -0
  186. package/src/util/ArrayOfLength.ts +5 -0
  187. package/src/util/Flatten.ts +2 -0
  188. package/src/util/Rest.ts +1 -0
  189. package/src/util/Subscription.ts +5 -0
  190. package/src/util/Tagged.ts +5 -0
  191. package/src/util/U2I.ts +1 -0
  192. package/src/util/generator/collect.ts +16 -0
  193. package/src/util/isKey.ts +7 -0
  194. package/src/util/unimplemented.ts +4 -0
  195. package/jest.config.js +0 -4
  196. package/lib/array/array.d.ts +0 -6
  197. package/lib/array/array.js +0 -21
  198. package/lib/array/index.d.ts +0 -11
  199. package/lib/array/index.js +0 -17
  200. package/lib/composition/composition.d.ts +0 -6
  201. package/lib/composition/composition.js +0 -37
  202. package/lib/composition/index.d.ts +0 -9
  203. package/lib/composition/index.js +0 -13
  204. package/lib/composition/types.d.ts +0 -2
  205. package/lib/composition/types.js +0 -2
  206. package/lib/dispatch/getType.d.ts +0 -2
  207. package/lib/dispatch/getType.js +0 -15
  208. package/lib/dispatch/identity.d.ts +0 -2
  209. package/lib/dispatch/identity.js +0 -4
  210. package/lib/dispatch/index.d.ts +0 -22
  211. package/lib/dispatch/index.js +0 -13
  212. package/lib/dispatch/types.d.ts +0 -14
  213. package/lib/dispatch/types.js +0 -16
  214. package/lib/error/error.d.ts +0 -24
  215. package/lib/error/error.js +0 -25
  216. package/lib/error/index.d.ts +0 -2
  217. package/lib/error/index.js +0 -4
  218. package/lib/index.d.ts +0 -67
  219. package/lib/index.js +0 -19
  220. package/lib/multimethod/index.d.ts +0 -7
  221. package/lib/multimethod/index.js +0 -9
  222. package/lib/multimethod/multimethod.d.ts +0 -3
  223. package/lib/multimethod/multimethod.js +0 -101
  224. package/src/array/array.ts +0 -29
  225. package/src/array/index.ts +0 -12
  226. package/src/composition/composition.ts +0 -45
  227. package/src/composition/index.ts +0 -10
  228. package/src/composition/types.ts +0 -6
  229. package/src/dispatch/getType.ts +0 -17
  230. package/src/dispatch/identity.ts +0 -3
  231. package/src/dispatch/index.ts +0 -11
  232. package/src/dispatch/types.ts +0 -15
  233. package/src/error/error.ts +0 -26
  234. package/src/error/index.ts +0 -3
  235. package/src/index.ts +0 -15
  236. package/src/multimethod/index.ts +0 -8
  237. package/src/multimethod/multimethod.test.ts +0 -10
  238. package/src/multimethod/multimethod.ts +0 -148
  239. package/tsconfig.json +0 -12
@@ -0,0 +1,49 @@
1
+ import { Flatten } from "../util/Flatten.js"
2
+ import { isKey } from "../util/isKey.js"
3
+ import { Key } from "./Key.js"
4
+ import { Factory, Type, TypeSource } from "./Type.js"
5
+
6
+ export interface Struct<F extends FieldTypes = any>
7
+ extends InstanceType<ReturnType<typeof Struct<F>>>
8
+ {}
9
+
10
+ export function Struct<const F extends FieldTypes>(fieldTypes: F) {
11
+ return class extends Type.make("Struct")<StructSource, StructNative<F>, StructFrom<F>> {
12
+ fieldTypes = fieldTypes
13
+ fields = Object.fromEntries(
14
+ Object.entries(fieldTypes).map(([key, type]) => [
15
+ key,
16
+ new (isKey(type) ? Key(type) : type)(
17
+ new TypeSource.StructField(this, key),
18
+ ),
19
+ ]),
20
+ ) as Fields<F>
21
+ }
22
+ }
23
+
24
+ export type FieldType = keyof any | Factory
25
+ export type FieldTypes = Record<string, FieldType>
26
+
27
+ export type Fields<F extends FieldTypes = any> = {
28
+ -readonly [K in keyof F]: F[K] extends keyof any ? Key<F[K]>
29
+ : F[K] extends Factory ? InstanceType<F[K]>
30
+ : never
31
+ }
32
+
33
+ export type StructFrom<F extends FieldTypes = any> = F extends Record<string, keyof any> ? undefined
34
+ : {
35
+ -readonly [K in keyof F as F[K] extends Factory ? K : never]: F[K] extends Factory<infer T>
36
+ ? T | Type.Native<T>
37
+ : never
38
+ }
39
+
40
+ type StructNativeField<T> = T extends Factory<infer U> ? Type.Native<U> : T
41
+ export type StructNative<F extends FieldTypes> = Flatten<
42
+ { -readonly [K in keyof F]: StructNativeField<F[K]> }
43
+ >
44
+
45
+ export type StructField<T> = T extends keyof any ? Key<T>
46
+ : T extends Factory ? InstanceType<T>
47
+ : never
48
+
49
+ export type StructSource = never
@@ -0,0 +1,120 @@
1
+ import { Rest } from "../util/Rest.js"
2
+ import { Tagged } from "../util/Tagged.js"
3
+ import { unimplemented } from "../util/unimplemented.js"
4
+ import { bool, BoolSource } from "./Bool.js"
5
+ import { GenCall, Result, ValueCall, Yield } from "./Call.js"
6
+ import { Effect } from "./Effect.js"
7
+ import { State } from "./State.js"
8
+
9
+ export type Factory<T extends Type = any> = new(source: any) => T
10
+
11
+ export class Type<
12
+ Name extends string = any,
13
+ Source = any,
14
+ Native = any,
15
+ From = any,
16
+ Into extends Type = any,
17
+ > {
18
+ declare ""?: [Native, From, Into]
19
+
20
+ static make<Name extends string>(name: Name) {
21
+ return class<Source, Native = never, From = Native, Into extends Type = never>
22
+ extends this<Name, Source, Native, From, Into>
23
+ {
24
+ constructor(source: Source | TypeSource) {
25
+ super(name, source)
26
+ }
27
+ }
28
+ }
29
+
30
+ static new<T extends Type>(this: Factory<T>, ...[value]: Rest<Type.From<T>>): T {
31
+ return new this(new TypeSource.New(value))
32
+ }
33
+
34
+ static state<T extends Type>(this: Factory<T>): State<T> {
35
+ return State(this)
36
+ }
37
+
38
+ constructor(readonly typeName: Name, readonly source: Source | TypeSource) {}
39
+
40
+ ctor = this.constructor as never as new(source: Source | TypeSource) => this
41
+
42
+ into<O extends Into>(into: Factory<O>): O {
43
+ return new into(new TypeSource.Into({ from: this }))
44
+ }
45
+
46
+ equals<T extends Type>(this: T, inQuestion: T): bool {
47
+ return new bool(new BoolSource.Equals(this, inQuestion))
48
+ }
49
+
50
+ is<T extends Type, M extends Factory<T>>(this: T, match: M): bool {
51
+ return new bool(new BoolSource.Is(this, match))
52
+ }
53
+
54
+ case<
55
+ T extends Type,
56
+ M extends Factory<T>,
57
+ R extends Result,
58
+ U extends Exclude<T, InstanceType<M>> | R,
59
+ >(
60
+ this: T,
61
+ match: M,
62
+ f: ValueCall<R, [InstanceType<M>]>,
63
+ ): U
64
+ case<
65
+ T extends Type,
66
+ M extends Factory<T>,
67
+ Y extends Yield,
68
+ R extends Result,
69
+ U extends Exclude<T, InstanceType<M>> | R,
70
+ >(
71
+ this: T,
72
+ match: M,
73
+ f: GenCall<Y, R, [InstanceType<M>]>,
74
+ ): Effect<Y, U>
75
+ case(_match: any, _f: any): any {
76
+ unimplemented()
77
+ }
78
+
79
+ "?"<T extends Type, M extends Factory<T>>(
80
+ this: T,
81
+ match: M,
82
+ ): Effect<InstanceType<M>, Exclude<T, InstanceType<M>>>
83
+ "?"<T extends Type, M extends Factory<T>, W extends Type>(
84
+ this: T,
85
+ match: M,
86
+ with_: W,
87
+ ): Effect<W, Exclude<T, InstanceType<M>>>
88
+ "?"<T extends Type>(
89
+ this: T,
90
+ _match: Factory<T>,
91
+ _maybeWith_?: Type,
92
+ ) {
93
+ return unimplemented()
94
+ }
95
+ }
96
+
97
+ export declare namespace Type {
98
+ export type From<T> = T extends Type<any, any, any, infer From> ? From : never
99
+ export type Native<T extends Type | void> = T extends Type<any, any, infer N> ? N : undefined
100
+ export type Source<T extends Type> = T extends Type<any, infer S> ? S : never
101
+ }
102
+
103
+ export type TypeSource = TypeSource.New | TypeSource.Into | TypeSource.StructField
104
+ export namespace TypeSource {
105
+ export class New extends Tagged("New") {
106
+ constructor(readonly from: unknown) {
107
+ super()
108
+ }
109
+ }
110
+ export class Into extends Tagged("Into") {
111
+ constructor(readonly from: unknown) {
112
+ super()
113
+ }
114
+ }
115
+ export class StructField extends Tagged("StructField") {
116
+ constructor(readonly self: Type, readonly key: keyof any) {
117
+ super()
118
+ }
119
+ }
120
+ }
@@ -0,0 +1,17 @@
1
+ import { MerkleListSource } from "./MerkleList.js"
2
+ import { MerkleMapSource } from "./MerkleMap.js"
3
+ import { Factory, Type } from "./Type.js"
4
+
5
+ export interface Union<T extends Factory[] = any> extends ReturnType<typeof Union<T>> {}
6
+
7
+ export function Union<T extends Factory[]>(...members: T) {
8
+ return class extends Type.make("Union")<
9
+ UnionSource,
10
+ Type.Native<InstanceType<T[number]>>,
11
+ Type.Native<InstanceType<T[number]>> | InstanceType<T[number]>
12
+ > {
13
+ members = members
14
+ }
15
+ }
16
+
17
+ export type UnionSource = MerkleMapSource.Get | MerkleListSource.At
@@ -0,0 +1,33 @@
1
+ import { Flatten } from "../util/Flatten.js"
2
+ import { Tagged } from "../util/Tagged.js"
3
+ import { U2I } from "../util/U2I.js"
4
+ import { unimplemented } from "../util/unimplemented.js"
5
+ import { Yield } from "./Call.js"
6
+ import { Factory, Type } from "./Type.js"
7
+ import { Union } from "./Union.js"
8
+
9
+ export type UseField = Factory
10
+ export type UseFieldTypes = Record<string, UseField>
11
+ export type UseFields<F extends UseFieldTypes = any> = { [K in keyof F]: InstanceType<F[K]> }
12
+
13
+ export function use<F extends UseFieldTypes>(
14
+ _fields: F,
15
+ ): Generator<
16
+ Use<Flatten<UseFields<F>>>,
17
+ Flatten<
18
+ { [K in keyof F]: F[K] extends Union<infer U> ? InstanceType<U[number]> : InstanceType<F[K]> }
19
+ >
20
+ > {
21
+ unimplemented()
22
+ }
23
+
24
+ export class Use<F extends UseFields = any> extends Type.make("Dependencies")<UseSource> {
25
+ constructor(readonly fields: F) {
26
+ super(new UseSource())
27
+ }
28
+ }
29
+
30
+ export class UseSource extends Tagged("UseSource") {}
31
+
32
+ export type ExtractUse<Y extends Yield> = Extract<Y, Use> extends Use<infer D> ? Flatten<U2I<D>>
33
+ : never
@@ -0,0 +1,19 @@
1
+ // moderate
2
+
3
+ export * from "./Bool.js"
4
+ export * from "./Bytes.js"
5
+ export * from "./Call.js"
6
+ export * from "./Effect.js"
7
+ export * from "./Hash.js"
8
+ export * from "./Id.js"
9
+ export * from "./Int.js"
10
+ export * from "./Key.js"
11
+ export * from "./MerkleList.js"
12
+ export * from "./MerkleMap.js"
13
+ export * from "./None.js"
14
+ export * from "./State.js"
15
+ export * from "./String.js"
16
+ export * from "./Struct.js"
17
+ export * from "./Type.js"
18
+ export * from "./Union.js"
19
+ export * from "./Use.js"
@@ -0,0 +1,4 @@
1
+ // TODO
2
+ export class MerkleList<T> {
3
+ declare ""?: [T]
4
+ }
@@ -0,0 +1,4 @@
1
+ // TODO
2
+ export class MerkleMap<K, V> {
3
+ declare ""?: [K, V]
4
+ }
package/src/lib/mod.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./MerkleList.js"
2
+ export * from "./MerkleMap.js"
package/src/mod.ts ADDED
@@ -0,0 +1,4 @@
1
+ // moderate --exclude lib test
2
+
3
+ export * from "./client/mod.js"
4
+ export * from "./core/mod.js"
@@ -0,0 +1,22 @@
1
+ import crypto from "node:crypto"
2
+ import { ArrayOfLength } from "../util/ArrayOfLength.js"
3
+
4
+ export function signer(): TestSigner
5
+ export function signer(count: 1): TestSigner
6
+ export function signer<C extends number>(count: C): ArrayOfLength<TestSigner, C>
7
+ export function signer(count?: number): TestSigner | TestSigner[] {
8
+ if (!count || count === 1) return TestSigner()
9
+ return Array.from({ length: count }, TestSigner)
10
+ }
11
+
12
+ export interface TestSigner {
13
+ publicKey: Uint8Array
14
+ (tx: Uint8Array): Uint8Array
15
+ }
16
+
17
+ // TODO: get signing actually working at some point
18
+ export function TestSigner(): TestSigner {
19
+ const pair = crypto.generateKeyPairSync("ec", { namedCurve: "secp256k1" })
20
+ const publicKey = new Uint8Array(pair.publicKey.export({ format: "der", type: "sec1" }))
21
+ return Object.assign((tx: Uint8Array) => crypto.sign(null, tx, pair.privateKey), { publicKey })
22
+ }
@@ -0,0 +1 @@
1
+ export * from "./Signer.js"
@@ -0,0 +1,3 @@
1
+ export interface SignalOptions {
2
+ signal?: AbortSignal
3
+ }
@@ -0,0 +1,5 @@
1
+ export type ArrayOfLength<
2
+ T,
3
+ L extends number,
4
+ A extends T[] = [],
5
+ > = number extends L ? T[] : L extends A["length"] ? A : ArrayOfLength<T, L, [...A, T]>
@@ -0,0 +1,2 @@
1
+ // TODO: adjust for misc. native datatypes
2
+ export type Flatten<T> = [{ [K in keyof T]: T[K] }][0]
@@ -0,0 +1 @@
1
+ export type Rest<T> = undefined extends T ? [value?: T] : [value: T]
@@ -0,0 +1,5 @@
1
+ import { SignalOptions } from "./AbortController.js"
2
+
3
+ export interface Subscription<T> {
4
+ subscribe(callback: (value: T) => void, options?: SignalOptions): Promise<void>
5
+ }
@@ -0,0 +1,5 @@
1
+ export function Tagged<K extends keyof any>(tag: K) {
2
+ return class {
3
+ readonly tag = tag
4
+ }
5
+ }
@@ -0,0 +1 @@
1
+ export type U2I<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never
@@ -0,0 +1,16 @@
1
+ export type Collected<Y, R> = [Y[], R]
2
+
3
+ export function collect<Y, R>(generator: Generator<Y, R>): Collected<Y, R> {
4
+ const statements: Y[] = []
5
+ let result: R
6
+ statements: while (true) {
7
+ const next = generator.next()
8
+ if (next.done) {
9
+ result = next.value
10
+ break statements
11
+ } else {
12
+ statements.push(next.value)
13
+ }
14
+ }
15
+ return [statements, result]
16
+ }
@@ -0,0 +1,7 @@
1
+ export function isKey(inQuestion: unknown): inQuestion is keyof any {
2
+ return !!({
3
+ number: true,
4
+ string: true,
5
+ symbol: true,
6
+ } as Record<string, boolean>)[typeof inQuestion]
7
+ }
@@ -0,0 +1,4 @@
1
+ export function unimplemented(message?: string): never {
2
+ if (message) console.error(message)
3
+ throw 0
4
+ }
package/jest.config.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- }
@@ -1,6 +0,0 @@
1
- export declare const filter: (fn: any) => (arr: any) => any;
2
- export declare const map: (fn: any) => (arr: any) => any;
3
- export declare const reduce: (fn: any, initialValue: any) => (arr: any) => any;
4
- export declare const reduceRight: (fn: any, initialValue: any) => (arr: any) => any;
5
- export declare const reverse: (arr: any) => any;
6
- export declare const sort: (fn: any) => (arr: any) => any[];
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filter = (fn) => (arr) => arr.filter(fn);
4
- exports.map = (fn) => (arr) => arr.map(fn);
5
- exports.reduce = (fn, initialValue) => (arr) => arr.reduce(fn, initialValue);
6
- exports.reduceRight = (fn, initialValue) => (arr) => arr.reduceRight(fn, initialValue);
7
- exports.reverse = (arr) => arr.reverse();
8
- exports.sort = (fn) => (arr) => {
9
- if (fn) {
10
- return [...arr].sort(fn);
11
- }
12
- if (typeof arr[0] === 'number') {
13
- return [...arr].sort((a, b) => a - b);
14
- }
15
- if (typeof arr[0] === 'bigint') {
16
- return [...arr].sort((a, b) => {
17
- return 1;
18
- });
19
- }
20
- return [...arr].sort();
21
- };
@@ -1,11 +0,0 @@
1
- import { filter, map, reduce, reduceRight, reverse, sort } from './array';
2
- export { filter, map, reduce, reduceRight, reverse, sort };
3
- declare const _default: {
4
- filter: (fn: any) => (arr: any) => any;
5
- map: (fn: any) => (arr: any) => any;
6
- reduce: (fn: any, initialValue: any) => (arr: any) => any;
7
- reduceRight: (fn: any, initialValue: any) => (arr: any) => any;
8
- reverse: (arr: any) => any;
9
- sort: (fn: any) => (arr: any) => any[];
10
- };
11
- export default _default;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const array_1 = require("./array");
4
- exports.filter = array_1.filter;
5
- exports.map = array_1.map;
6
- exports.reduce = array_1.reduce;
7
- exports.reduceRight = array_1.reduceRight;
8
- exports.reverse = array_1.reverse;
9
- exports.sort = array_1.sort;
10
- exports.default = {
11
- filter: array_1.filter,
12
- map: array_1.map,
13
- reduce: array_1.reduce,
14
- reduceRight: array_1.reduceRight,
15
- reverse: array_1.reverse,
16
- sort: array_1.sort,
17
- };
@@ -1,6 +0,0 @@
1
- import { ChainFunctions } from './types';
2
- declare const compose: ChainFunctions;
3
- declare const pipe: ChainFunctions;
4
- declare const rail: ChainFunctions;
5
- declare const railSync: ChainFunctions;
6
- export { compose, pipe, rail, railSync };
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const array_1 = require("../array");
4
- const wrapSync = (fn) => (input) => {
5
- if (input instanceof Error) {
6
- return input;
7
- }
8
- let result;
9
- try {
10
- result = fn(input);
11
- }
12
- catch (error) {
13
- result = error;
14
- }
15
- return typeof result === 'undefined' ? input : result;
16
- };
17
- const wrap = (fn) => (input) => {
18
- if (input instanceof Promise) {
19
- return input.then((rawInput) => {
20
- return wrapSync(fn)(rawInput);
21
- });
22
- }
23
- return wrapSync(fn)(input);
24
- };
25
- const chain = (reducingFn, wrappingFn = null) => (...fns) => (initialArg) => {
26
- return wrappingFn
27
- ? reducingFn((arg, fn) => wrappingFn(fn)(arg), initialArg)(fns)
28
- : reducingFn((arg, fn) => fn(arg), initialArg)(fns);
29
- };
30
- const compose = chain(array_1.reduceRight);
31
- exports.compose = compose;
32
- const pipe = chain(array_1.reduce);
33
- exports.pipe = pipe;
34
- const rail = chain(array_1.reduce, wrap);
35
- exports.rail = rail;
36
- const railSync = chain(array_1.reduce, wrapSync);
37
- exports.railSync = railSync;
@@ -1,9 +0,0 @@
1
- import { compose, pipe, rail, railSync } from './composition';
2
- export { compose, pipe, rail, railSync };
3
- declare const _default: {
4
- compose: import("./types").ChainFunctions;
5
- pipe: import("./types").ChainFunctions;
6
- rail: import("./types").ChainFunctions;
7
- railSync: import("./types").ChainFunctions;
8
- };
9
- export default _default;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const composition_1 = require("./composition");
4
- exports.compose = composition_1.compose;
5
- exports.pipe = composition_1.pipe;
6
- exports.rail = composition_1.rail;
7
- exports.railSync = composition_1.railSync;
8
- exports.default = {
9
- compose: composition_1.compose,
10
- pipe: composition_1.pipe,
11
- rail: composition_1.rail,
12
- railSync: composition_1.railSync,
13
- };
@@ -1,2 +0,0 @@
1
- export declare type ChainFunctions = (...fns: Function[]) => (initialArg: any) => any;
2
- export declare type ChainFactory = (reduceFn: Function, wrappingFn?: Function) => ChainFunctions;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- declare const getType: (val: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "null" | "regexp";
2
- export default getType;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getType = (val) => {
4
- if (Array.isArray(val)) {
5
- return 'array';
6
- }
7
- if (val === null) {
8
- return 'null';
9
- }
10
- if (val instanceof RegExp) {
11
- return 'regexp';
12
- }
13
- return typeof val;
14
- };
15
- exports.default = getType;
@@ -1,2 +0,0 @@
1
- declare const identity: (x: any) => any;
2
- export default identity;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const identity = (x) => x;
4
- exports.default = identity;
@@ -1,22 +0,0 @@
1
- import getType from './getType';
2
- import identity from './identity';
3
- import types from './types';
4
- export { getType, identity, types };
5
- declare const _default: {
6
- getType: (val: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "null" | "regexp";
7
- identity: (x: any) => any;
8
- types: {
9
- array: string;
10
- object: string;
11
- function: string;
12
- string: string;
13
- number: string;
14
- bigint: string;
15
- symbol: string;
16
- regexp: string;
17
- null: string;
18
- undefined: string;
19
- boolean: string;
20
- };
21
- };
22
- export default _default;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getType_1 = require("./getType");
4
- exports.getType = getType_1.default;
5
- const identity_1 = require("./identity");
6
- exports.identity = identity_1.default;
7
- const types_1 = require("./types");
8
- exports.types = types_1.default;
9
- exports.default = {
10
- getType: getType_1.default,
11
- identity: identity_1.default,
12
- types: types_1.default,
13
- };
@@ -1,14 +0,0 @@
1
- declare const types: {
2
- array: string;
3
- object: string;
4
- function: string;
5
- string: string;
6
- number: string;
7
- bigint: string;
8
- symbol: string;
9
- regexp: string;
10
- null: string;
11
- undefined: string;
12
- boolean: string;
13
- };
14
- export default types;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const types = {
4
- array: 'array',
5
- object: 'object',
6
- function: 'function',
7
- string: 'string',
8
- number: 'number',
9
- bigint: 'bigint',
10
- symbol: 'symbol',
11
- regexp: 'regexp',
12
- null: 'null',
13
- undefined: 'undefined',
14
- boolean: 'boolean',
15
- };
16
- exports.default = types;
@@ -1,24 +0,0 @@
1
- /// <reference types="node" />
2
- declare const _default: {
3
- create: ({ name, defaultMessage }: {
4
- name: any;
5
- defaultMessage?: string;
6
- }) => {
7
- new (message?: string): {
8
- name: string;
9
- message: string;
10
- stack?: string;
11
- };
12
- captureStackTrace(targetObject: Object, constructorOpt?: Function): void;
13
- prepareStackTrace?: (err: Error, stackTraces: NodeJS.CallSite[]) => any;
14
- stackTraceLimit: number;
15
- };
16
- toJSON: (error: any) => {
17
- error: {
18
- name: any;
19
- message: any;
20
- stacktrace: any;
21
- };
22
- };
23
- };
24
- export default _default;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const create = ({ name, defaultMessage = '' }) => {
4
- const err = class extends Error {
5
- constructor(message = defaultMessage) {
6
- super(message);
7
- this.name = name;
8
- this.message = message;
9
- }
10
- };
11
- return err;
12
- };
13
- const toJSON = (error) => {
14
- return {
15
- error: {
16
- name: error.name,
17
- message: error.message,
18
- stacktrace: error.stack,
19
- },
20
- };
21
- };
22
- exports.default = {
23
- create,
24
- toJSON,
25
- };