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,38 @@
1
+ import * as G from "../util/generator/collect.js"
2
+ import { Type } from "./Type.js"
3
+
4
+ export type Yield = Type
5
+ export type Result = Type | void
6
+
7
+ export type ValueCall<R, A extends unknown[]> = R | ((...args: A) => R)
8
+
9
+ export type GenCall<
10
+ Y extends Yield = any,
11
+ R extends Result = any,
12
+ A extends unknown[] = any,
13
+ > = Generator<Y, R> | ((...args: A) => Generator<Y, R>)
14
+
15
+ export type Call<
16
+ Y extends Yield = any,
17
+ R extends Result = any,
18
+ A extends unknown[] = any,
19
+ > = ValueCall<R, A> | GenCall<Y, R, A>
20
+
21
+ export namespace Call {
22
+ export function collect<Y extends Yield, R extends Result>(
23
+ call: Call<Y, R>,
24
+ ): G.Collected<Y, R> {
25
+ if (typeof call === "function") {
26
+ const maybeGen = call()
27
+ if (typeof maybeGen === "object" && Symbol.iterator in maybeGen) {
28
+ return G.collect(maybeGen)
29
+ } else {
30
+ return [[], maybeGen]
31
+ }
32
+ } else if (typeof call === "object" && Symbol.iterator in call) {
33
+ return G.collect(call)
34
+ } else {
35
+ return [[], call]
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,87 @@
1
+ import { Flatten } from "../util/Flatten.js"
2
+ import { unimplemented } from "../util/unimplemented.js"
3
+ import { GenCall, Result, ValueCall, Yield } from "./Call.js"
4
+ import { Factory, Type } from "./Type.js"
5
+ import { ExtractUse, Use } from "./Use.js"
6
+
7
+ export abstract class Effect<Y extends Yield, R extends Result> implements Generator<Y, R> {
8
+ declare yields?: Y[]
9
+ declare result?: R
10
+
11
+ map<R2 extends Result>(_f: (value: R) => R2): Effect<Y, R2> {
12
+ unimplemented()
13
+ }
14
+
15
+ next(): IteratorResult<Y, R> {
16
+ unimplemented()
17
+ }
18
+
19
+ return(): IteratorResult<Y, R> {
20
+ unimplemented()
21
+ }
22
+
23
+ throw(): IteratorResult<Y, R> {
24
+ unimplemented()
25
+ }
26
+
27
+ *[Symbol.iterator](): Generator<Y, R> {
28
+ while (this.yields?.length) {
29
+ yield this.yields.shift()!
30
+ }
31
+ delete this.yields
32
+ const result = this.result!
33
+ delete this.result
34
+ return result
35
+ }
36
+
37
+ "?"<M extends Factory<Exclude<R, void>>>(
38
+ match: M,
39
+ ): Effect<Y | InstanceType<M>, Exclude<R, InstanceType<M>>>
40
+ "?"<M extends Factory<Exclude<R, void>>, W extends Type>(
41
+ match: M,
42
+ with_: W,
43
+ ): Effect<Y | W, Exclude<R, InstanceType<M>>>
44
+ "?"(
45
+ _match: Factory<Exclude<R, void>>,
46
+ _maybeWith_?: Type,
47
+ ) {
48
+ return unimplemented()
49
+ }
50
+
51
+ handle<M extends Factory<Y>, R extends Result>(
52
+ match: M,
53
+ f: ValueCall<R, [value: InstanceType<M>]>,
54
+ ): [Exclude<Y, InstanceType<M>>] extends [never] ? R : Effect<Exclude<Y, InstanceType<M>>, R>
55
+ handle<M extends Factory<Y>, Y2 extends Yield, R extends Result>(
56
+ match: M,
57
+ f: GenCall<Y2, R, [value: InstanceType<M>]>,
58
+ ): [Exclude<Y, InstanceType<M>> | Y2] extends [never] ? R
59
+ : Effect<Exclude<Y, InstanceType<M>> | Y2, R>
60
+ handle(_match: any, _f: any): any {
61
+ unimplemented()
62
+ }
63
+
64
+ rehandle<M extends Factory[]>(
65
+ ..._match: M
66
+ ): [Exclude<Y, InstanceType<M[number]>>] extends [never] ? Extract<Y, InstanceType<M[number]>> | R
67
+ : Effect<Exclude<Y, InstanceType<M[number]>>, R>
68
+ {
69
+ unimplemented()
70
+ }
71
+ }
72
+
73
+ export function call<
74
+ Y extends Yield,
75
+ R extends Result,
76
+ D extends ExtractUse<Y>,
77
+ A extends Partial<D>,
78
+ N extends Omit<D, keyof A>,
79
+ >(
80
+ _call: Generator<Y, R> | (() => Generator<Y, R>),
81
+ _uses: A,
82
+ ): Effect<
83
+ Exclude<Y, Use> | [keyof N] extends [never] ? never : Use<Flatten<N>>,
84
+ R
85
+ > {
86
+ unimplemented()
87
+ }
@@ -0,0 +1,23 @@
1
+ import { Factory, Type } from "./Type.js"
2
+
3
+ export function Hash<T extends Type, A extends HashAlgorithm>(
4
+ targetType: Factory<T>,
5
+ algorithm: A,
6
+ ) {
7
+ return class extends Type.make("Hash")<HashSource, Uint8Array, never, never> {
8
+ targetType = targetType
9
+ algorithm = algorithm
10
+ }
11
+ }
12
+
13
+ export type HashAlgorithm =
14
+ | "Keccak256"
15
+ | "Keccak384"
16
+ | "Keccak512"
17
+ | "Poseidon"
18
+ | "SHA2_256"
19
+ | "SHA3_256"
20
+ | "SHA3_384"
21
+ | "SHA3_512"
22
+
23
+ export type HashSource = never
package/src/core/Id.ts ADDED
@@ -0,0 +1,97 @@
1
+ import { Store } from "../client/mod.js"
2
+ import { Tagged } from "../util/Tagged.js"
3
+ import { unimplemented } from "../util/unimplemented.js"
4
+ import { Effect } from "./Effect.js"
5
+ import { u64 } from "./Int.js"
6
+ import { State } from "./State.js"
7
+ import { Type } from "./Type.js"
8
+
9
+ export type IdSource = IdSource.Sender | IdSource.Self | IdSource.Caller | IdSource.Null
10
+ export namespace IdSource {
11
+ export class Hex extends Tagged("Hex") {}
12
+ export class Bytes extends Tagged("Bytes") {}
13
+ export class Sender extends Tagged("Sender") {}
14
+ export class Self extends Tagged("Self") {}
15
+ export class Caller extends Tagged("Caller") {}
16
+ export class Null extends Tagged("Null") {}
17
+ }
18
+
19
+ export class id extends Type.make("id")<IdSource, Uint8Array, Uint8Array> {
20
+ static fromHex(_hex: string): id {
21
+ unimplemented()
22
+ }
23
+
24
+ bind<N>(_namespace: N): Contract<N> {
25
+ unimplemented()
26
+ }
27
+
28
+ signer<K extends string>(_key: K): SignerEffect<K> {
29
+ unimplemented()
30
+ }
31
+ }
32
+
33
+ export class SignerEffect<K extends string> extends Effect<SignerRequirement<K>, signer<K>> {
34
+ constructor(readonly key: K) {
35
+ super()
36
+ }
37
+
38
+ deploy<N>(
39
+ _namespace: N,
40
+ _deployOptions: DeployOptions<N>,
41
+ ): Generator<SignerRequirement<K>, Contract<N>> {
42
+ unimplemented()
43
+ }
44
+ }
45
+
46
+ export class SignerRequirement<K extends string = any>
47
+ extends Type.make("SignerRequirement")<K, never>
48
+ {
49
+ constructor(readonly key: K) {
50
+ super(key)
51
+ }
52
+ }
53
+
54
+ export interface signer<K extends keyof any = any>
55
+ extends InstanceType<ReturnType<typeof signer<K>>>
56
+ {}
57
+
58
+ export function signer<K extends keyof any>(key: K) {
59
+ return class extends id {
60
+ readonly key = key
61
+
62
+ deploy<N>(
63
+ _namespace: N,
64
+ _deployOptions: DeployOptions<N>,
65
+ ): Generator<never, Contract<N>> {
66
+ unimplemented()
67
+ }
68
+
69
+ send(_props: SendProps): Effect<never, never> {
70
+ unimplemented()
71
+ }
72
+ }
73
+ }
74
+
75
+ export const nullId = new id(new IdSource.Null())
76
+ export const caller = new id(new IdSource.Caller())
77
+ export const self = new id(new IdSource.Self())
78
+ export const sender = new id(new IdSource.Sender())
79
+
80
+ export interface DeployOptions<N> {
81
+ deployer?: signer
82
+ state: DeployState<N>
83
+ }
84
+
85
+ export type DeployState<N> = {
86
+ [K in keyof N as N[K] extends State ? K : never]: N[K] extends State<infer T> ? T : never
87
+ }
88
+
89
+ export interface SendProps {
90
+ to: id
91
+ amount: u64
92
+ }
93
+
94
+ // TODO
95
+ export type Contract<T> = id & T & {
96
+ store(store: Store): Contract<T>
97
+ }
@@ -0,0 +1,177 @@
1
+ import { Tagged } from "../util/Tagged.js"
2
+ import type { bool } from "./Bool.js"
3
+ import type { MerkleList } from "./MerkleList.js"
4
+ import type { MerkleMap } from "./MerkleMap.js"
5
+ import { Factory, Type } from "./Type.js"
6
+
7
+ // TODO: bit manipulation, floats, floor/ceil, power ...
8
+
9
+ export type Int = SignedInt | UnsignedInt
10
+ export type SignedInt = i8 | i16 | i32 | i64 | i256
11
+ export type UnsignedInt = u8 | u16 | u32 | u64 | u256
12
+
13
+ // TODO: allow from/into from opposite-signed types (effectively enabling an `absolute` method)
14
+ export class u8 extends Int(false, 8)<never, u16 | u32 | u64 | u128 | u256> {}
15
+ export class u16 extends Int(false, 16)<u8, u32 | u64 | u128 | u256> {}
16
+ export class u32 extends Int(false, 32)<u8 | u16, u64 | u128 | u256> {}
17
+ export class u64 extends Int(false, 64)<u8 | u16 | u32, u128 | u256> {}
18
+ export class u128 extends Int(false, 128)<u8 | u16 | u32 | u64, u256> {}
19
+ export class u256 extends Int(false, 256)<u8 | u16 | u32 | u64 | u128, never, U256Source> {}
20
+
21
+ export class i8 extends Int(true, 8)<never, i16 | i32 | i64 | i128 | i256> {}
22
+ export class i16 extends Int(true, 16)<i8, i32 | i64 | i128 | i256> {}
23
+ export class i32 extends Int(true, 32)<i8 | i16, i64 | i128 | i256> {}
24
+ export class i64 extends Int(true, 64)<i8 | i16 | i32, i128 | i256> {}
25
+ export class i128 extends Int(true, 128)<i8 | i16 | i32 | i64, i256> {}
26
+ export class i256 extends Int(true, 256)<i8 | i16 | i32 | i64 | i256, never> {}
27
+
28
+ export type IntSize = 8 | 16 | 32 | 64 | 128 | 256
29
+
30
+ function Int<Signed extends boolean, Size extends IntSize>(signed: Signed, size: Size) {
31
+ return class<From extends Type, Into extends Type, ExtraSource = never>
32
+ extends Type.make(`${signed ? "i" : "u"}${size}`)<
33
+ IntSource | ExtraSource,
34
+ number,
35
+ number | From,
36
+ Into
37
+ >
38
+ {
39
+ signed = signed
40
+
41
+ static min<This extends Factory>(this: This) {
42
+ return new this(new IntSource.Min())
43
+ }
44
+
45
+ static max<This extends Factory>(this: This) {
46
+ return new this(new IntSource.Max())
47
+ }
48
+
49
+ static random<This extends Factory>(this: This) {
50
+ return new this(new IntSource.Random())
51
+ }
52
+
53
+ add(value: this): this {
54
+ return new this.ctor(new IntSource.Add(this, value))
55
+ }
56
+
57
+ subtract(value: this): this {
58
+ return new this.ctor(new IntSource.Subtract(this, value))
59
+ }
60
+
61
+ multiply(value: this): this {
62
+ return new this.ctor(new IntSource.Multiply(this, value))
63
+ }
64
+
65
+ divide(value: this): this {
66
+ return new this.ctor(new IntSource.Divide(this, value))
67
+ }
68
+
69
+ square(this: this): this {
70
+ return new this.ctor(new IntSource.Square(this))
71
+ }
72
+
73
+ logarithm(value: this): this {
74
+ return new this.ctor(new IntSource.Logarithm(this, value))
75
+ }
76
+
77
+ gt(value: this): bool {
78
+ return new this.ctor(new IntSource.Gt(this, value)) as never
79
+ }
80
+
81
+ gte(value: this): bool {
82
+ return new this.ctor(new IntSource.Gte(this, value)) as never
83
+ }
84
+
85
+ lt(value: this): bool {
86
+ return new this.ctor(new IntSource.Lt(this, value)) as never
87
+ }
88
+
89
+ lte(value: this): bool {
90
+ return new this.ctor(new IntSource.Lte(this, value)) as never
91
+ }
92
+ }
93
+ }
94
+
95
+ export type IntSource =
96
+ | IntSource.Random
97
+ | IntSource.Min
98
+ | IntSource.Max
99
+ | IntSource.Add
100
+ | IntSource.Subtract
101
+ | IntSource.Multiply
102
+ | IntSource.Divide
103
+ | IntSource.Square
104
+ | IntSource.Logarithm
105
+ | IntSource.Gt
106
+ | IntSource.Gte
107
+ | IntSource.Lt
108
+ | IntSource.Lte
109
+ export namespace IntSource {
110
+ export class Random extends Tagged("Random") {}
111
+ export class Min extends Tagged("Min") {}
112
+ export class Max extends Tagged("Max") {}
113
+ export class Add extends Tagged("Add") {
114
+ constructor(readonly left: Type, readonly right: Type) {
115
+ super()
116
+ }
117
+ }
118
+ export class Subtract extends Tagged("Subtract") {
119
+ constructor(readonly left: Type, readonly right: Type) {
120
+ super()
121
+ }
122
+ }
123
+ export class Multiply extends Tagged("Multiply") {
124
+ constructor(readonly left: Type, readonly right: Type) {
125
+ super()
126
+ }
127
+ }
128
+ export class Divide extends Tagged("Divide") {
129
+ constructor(readonly left: Type, readonly right: Type) {
130
+ super()
131
+ }
132
+ }
133
+ export class Square extends Tagged("Square") {
134
+ constructor(readonly self: Type) {
135
+ super()
136
+ }
137
+ }
138
+ export class Logarithm extends Tagged("Logarithm") {
139
+ constructor(readonly left: Type, readonly right: Type) {
140
+ super()
141
+ }
142
+ }
143
+ export class Gt extends Tagged("Gt") {
144
+ constructor(readonly left: Type, readonly right: Type) {
145
+ super()
146
+ }
147
+ }
148
+ export class Gte extends Tagged("Gte") {
149
+ constructor(readonly left: Type, readonly right: Type) {
150
+ super()
151
+ }
152
+ }
153
+ export class Lt extends Tagged("Lt") {
154
+ constructor(readonly left: Type, readonly right: Type) {
155
+ super()
156
+ }
157
+ }
158
+ export class Lte extends Tagged("Lte") {
159
+ constructor(readonly left: Type, readonly right: Type) {
160
+ super()
161
+ }
162
+ }
163
+ }
164
+
165
+ export type U256Source = U256Source.MerkleMapSize | U256Source.MerkleListSize
166
+ export namespace U256Source {
167
+ export class MerkleMapSize extends Tagged("MerkleMapSize") {
168
+ constructor(readonly self: MerkleMap) {
169
+ super()
170
+ }
171
+ }
172
+ export class MerkleListSize extends Tagged("MerkleMapSize") {
173
+ constructor(readonly self: MerkleList) {
174
+ super()
175
+ }
176
+ }
177
+ }
@@ -0,0 +1,9 @@
1
+ import { Type } from "./Type.js"
2
+
3
+ export interface Key<T extends keyof any> extends InstanceType<ReturnType<typeof Key<T>>> {}
4
+
5
+ export function Key<T extends keyof any>(value: T) {
6
+ return class Key extends Type.make("Key")<never, T> {
7
+ value = value
8
+ }
9
+ }
@@ -0,0 +1,92 @@
1
+ import { MerkleList as MerkleListNative } from "../lib/mod.js"
2
+ import { Tagged } from "../util/Tagged.js"
3
+ import { unimplemented } from "../util/unimplemented.js"
4
+ import { Effect } from "./Effect.js"
5
+ import { u256, U256Source } from "./Int.js"
6
+ import { None } from "./None.js"
7
+ import { Factory, Type } from "./Type.js"
8
+ import { Union } from "./Union.js"
9
+
10
+ export interface MerkleList<T extends Type = Type>
11
+ extends InstanceType<ReturnType<typeof MerkleList<T>>>
12
+ {}
13
+
14
+ export function MerkleList<T extends Type>(elementType: Factory<T>) {
15
+ return class extends Type.make("MerkleList")<
16
+ MerkleListSource,
17
+ MerkleListNative<Type.Native<T>>,
18
+ undefined,
19
+ never
20
+ > {
21
+ elementType = elementType
22
+
23
+ length: u256 = new u256(new U256Source.MerkleListSize(this))
24
+
25
+ first = this.at(u256.new(1))
26
+
27
+ last = this.at(this.length.subtract(u256.new(1)))
28
+
29
+ prepend(value: T): MerkleList<T> {
30
+ return new this.ctor(new MerkleListSource.Prepend(this, value))
31
+ }
32
+
33
+ append(value: T): MerkleList<T> {
34
+ return new this.ctor(new MerkleListSource.Append(this, value))
35
+ }
36
+
37
+ shift(): MerkleList<T> {
38
+ return new this.ctor(new MerkleListSource.Shift(this))
39
+ }
40
+
41
+ pop(): MerkleList<T> {
42
+ return new this.ctor(new MerkleListSource.Pop(this))
43
+ }
44
+
45
+ at(index: u256): T | None {
46
+ return new (Union(None, this.elementType))(
47
+ new MerkleListSource.At(this, index),
48
+ ) as never as T | None
49
+ }
50
+
51
+ reduceKeys<R extends Type, Y extends Type>(
52
+ _initial: R,
53
+ _f: (acc: R, cur: T) => Generator<Y, R>,
54
+ ): Effect<R, Y> {
55
+ unimplemented()
56
+ }
57
+ }
58
+ }
59
+
60
+ export type MerkleListSource =
61
+ | MerkleListSource.Prepend
62
+ | MerkleListSource.Append
63
+ | MerkleListSource.Shift
64
+ | MerkleListSource.Pop
65
+ | MerkleListSource.At
66
+ export namespace MerkleListSource {
67
+ export class Prepend extends Tagged("Prepend") {
68
+ constructor(readonly self: MerkleList, readonly value: Type) {
69
+ super()
70
+ }
71
+ }
72
+ export class Append extends Tagged("Append") {
73
+ constructor(readonly self: MerkleList, readonly value: Type) {
74
+ super()
75
+ }
76
+ }
77
+ export class Shift extends Tagged("Shift") {
78
+ constructor(readonly self: MerkleList) {
79
+ super()
80
+ }
81
+ }
82
+ export class Pop extends Tagged("Pop") {
83
+ constructor(readonly self: MerkleList) {
84
+ super()
85
+ }
86
+ }
87
+ export class At extends Tagged("At") {
88
+ constructor(readonly list: MerkleList, readonly index: u256) {
89
+ super()
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,86 @@
1
+ import { MerkleMap as MerkleMapNative } from "../lib/mod.js"
2
+ import { Tagged } from "../util/Tagged.js"
3
+ import { unimplemented } from "../util/unimplemented.js"
4
+ import { Effect } from "./Effect.js"
5
+ import { u256, U256Source } from "./Int.js"
6
+ import { None } from "./None.js"
7
+ import { Factory, Type } from "./Type.js"
8
+ import { Union } from "./Union.js"
9
+
10
+ export interface MerkleMap<K extends Type = Type, V extends Type = Type>
11
+ extends InstanceType<ReturnType<typeof MerkleMap<K, V>>>
12
+ {}
13
+
14
+ export function MerkleMap<K extends Type, V extends Type>(
15
+ keyType: Factory<K>,
16
+ valueType: Factory<V>,
17
+ ) {
18
+ return class extends Type.make("MerkleMap")<
19
+ MerkleMapSource,
20
+ MerkleMapNative<Type.Native<K>, Type.Native<V>>,
21
+ undefined
22
+ > {
23
+ keyType = keyType
24
+ valueType = valueType
25
+
26
+ size: u256 = new u256(new U256Source.MerkleMapSize(this))
27
+
28
+ set(key: K, value: V): MerkleMap<K, V> {
29
+ return new this.ctor(new MerkleMapSource.Set(this, key, value))
30
+ }
31
+
32
+ delete(key: K): MerkleMap<K, V> {
33
+ return new this.ctor(new MerkleMapSource.Delete(this, key))
34
+ }
35
+
36
+ get(key: K): V | None {
37
+ return new (Union(None, this.valueType))(
38
+ new MerkleMapSource.Get(this, key),
39
+ ) as never as V | None
40
+ }
41
+
42
+ reduceKeys<R extends Type, Y extends Type>(
43
+ _initial: R,
44
+ _f: (acc: R, cur: K) => Generator<Y, R>,
45
+ ): Effect<R, Y> {
46
+ unimplemented()
47
+ }
48
+
49
+ reduceValues<R extends Type, Y extends Type>(
50
+ _initial: R,
51
+ _f: (acc: R, cur: V) => Generator<Y, R>,
52
+ ): Effect<R, Y> {
53
+ unimplemented()
54
+ }
55
+
56
+ reduceEntries<R extends Type, Y extends Type>(
57
+ _initial: R,
58
+ _f: (acc: R, cur: [K, V]) => Generator<Y, R>,
59
+ ): Effect<R, Y> {
60
+ unimplemented()
61
+ }
62
+ }
63
+ }
64
+
65
+ export type MerkleMapSource = MerkleMapSource.Get | MerkleMapSource.Set | MerkleMapSource.Delete
66
+ export namespace MerkleMapSource {
67
+ export class Get extends Tagged("Get") {
68
+ constructor(readonly map: MerkleMap, readonly key: Type) {
69
+ super()
70
+ }
71
+ }
72
+ export class Delete extends Tagged("Delete") {
73
+ constructor(readonly map: MerkleMap, readonly key: Type) {
74
+ super()
75
+ }
76
+ }
77
+ export class Set extends Tagged("Set") {
78
+ constructor(
79
+ readonly map: MerkleMap,
80
+ readonly key: Type,
81
+ readonly value: Type,
82
+ ) {
83
+ super()
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,11 @@
1
+ import { Tagged } from "../util/Tagged.js"
2
+ import { Type } from "./Type.js"
3
+
4
+ export class None extends Type.make("None")<NoneSource, undefined> {}
5
+
6
+ export type NoneSource = NoneSource.Intrinsic
7
+ export namespace NoneSource {
8
+ export class Intrinsic extends Tagged("Default") {}
9
+ }
10
+
11
+ export const none = new None(new NoneSource.Intrinsic())
@@ -0,0 +1,31 @@
1
+ import { Effect } from "./Effect.js"
2
+ import { Factory, Type } from "./Type.js"
3
+
4
+ export type State<T extends Type = any> = {
5
+ (): Effect<never, T>
6
+ (setter: StateSetter<T>): Effect<never, T>
7
+ tag: "State"
8
+ type: Factory<T>
9
+ }
10
+
11
+ export function State<T extends Type>(type: Factory<T>): State<T> {
12
+ const state = Object.assign((setter?: StateSetter<T>) => {
13
+ return new StateEffect<T>(state, setter)
14
+ }, {
15
+ tag: "State" as const,
16
+ type,
17
+ })
18
+ return state
19
+ }
20
+
21
+ export class StateEffect<T extends Type> extends Effect<never, T> {
22
+ declare setter?: StateSetter<T>
23
+ constructor(readonly state: State<T>, setter?: StateSetter<T>) {
24
+ super()
25
+ this.yields = [this as never]
26
+ this.result = new state.type(this)
27
+ if (setter) this.setter = setter
28
+ }
29
+ }
30
+
31
+ export type StateSetter<T> = T | ((value: T) => T)
@@ -0,0 +1,5 @@
1
+ import { Type } from "./Type.js"
2
+
3
+ export class String extends Type.make("String")<StringSource, string, string> {}
4
+
5
+ export type StringSource = never