liminal 0.4.1 → 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.
- package/LICENSE +201 -0
- package/README.md +109 -0
- package/esm/client/Client.d.ts +39 -0
- package/esm/client/Client.d.ts.map +1 -0
- package/esm/client/Client.js +9 -0
- package/esm/client/Client.js.map +1 -0
- package/esm/client/Store.d.ts +3 -0
- package/esm/client/Store.d.ts.map +1 -0
- package/esm/client/Store.js +3 -0
- package/esm/client/Store.js.map +1 -0
- package/esm/client/Tx.d.ts +40 -0
- package/esm/client/Tx.d.ts.map +1 -0
- package/esm/client/Tx.js +36 -0
- package/esm/client/Tx.js.map +1 -0
- package/esm/client/mod.d.ts +4 -0
- package/esm/client/mod.d.ts.map +1 -0
- package/esm/client/mod.js +5 -0
- package/esm/client/mod.js.map +1 -0
- package/esm/core/Bool.d.ts +104 -0
- package/esm/core/Bool.d.ts.map +1 -0
- package/esm/core/Bool.js +73 -0
- package/esm/core/Bool.js.map +1 -0
- package/esm/core/Bytes.d.ts +39 -0
- package/esm/core/Bytes.d.ts.map +1 -0
- package/esm/core/Bytes.js +7 -0
- package/esm/core/Bytes.js.map +1 -0
- package/esm/core/Call.d.ts +11 -0
- package/esm/core/Call.d.ts.map +1 -0
- package/esm/core/Call.js +23 -0
- package/esm/core/Call.js.map +1 -0
- package/esm/core/Effect.d.ts +20 -0
- package/esm/core/Effect.d.ts.map +1 -0
- package/esm/core/Effect.js +37 -0
- package/esm/core/Effect.js.map +1 -0
- package/esm/core/Hash.d.ts +41 -0
- package/esm/core/Hash.d.ts.map +1 -0
- package/esm/core/Hash.js +8 -0
- package/esm/core/Hash.js.map +1 -0
- package/esm/core/Id.d.ts +198 -0
- package/esm/core/Id.d.ts.map +1 -0
- package/esm/core/Id.js +69 -0
- package/esm/core/Id.js.map +1 -0
- package/esm/core/Int.d.ts +768 -0
- package/esm/core/Int.d.ts.map +1 -0
- package/esm/core/Int.js +201 -0
- package/esm/core/Int.js.map +1 -0
- package/esm/core/Key.d.ts +40 -0
- package/esm/core/Key.d.ts.map +1 -0
- package/esm/core/Key.js +7 -0
- package/esm/core/Key.js.map +1 -0
- package/esm/core/MerkleList.d.ts +105 -0
- package/esm/core/MerkleList.d.ts.map +1 -0
- package/esm/core/MerkleList.js +82 -0
- package/esm/core/MerkleList.js.map +1 -0
- package/esm/core/MerkleMap.d.ts +87 -0
- package/esm/core/MerkleMap.d.ts.map +1 -0
- package/esm/core/MerkleMap.js +67 -0
- package/esm/core/MerkleMap.js.map +1 -0
- package/esm/core/None.d.ts +52 -0
- package/esm/core/None.d.ts.map +1 -0
- package/esm/core/None.js +12 -0
- package/esm/core/None.js.map +1 -0
- package/esm/core/State.d.ts +16 -0
- package/esm/core/State.d.ts.map +1 -0
- package/esm/core/State.js +22 -0
- package/esm/core/State.js.map +1 -0
- package/esm/core/String.d.ts +41 -0
- package/esm/core/String.d.ts.map +1 -0
- package/esm/core/String.js +4 -0
- package/esm/core/String.js.map +1 -0
- package/esm/core/Struct.d.ts +58 -0
- package/esm/core/Struct.d.ts.map +1 -0
- package/esm/core/Struct.js +13 -0
- package/esm/core/Struct.js.map +1 -0
- package/esm/core/Type.d.ts +78 -0
- package/esm/core/Type.d.ts.map +1 -0
- package/esm/core/Type.js +71 -0
- package/esm/core/Type.js.map +1 -0
- package/esm/core/Union.d.ts +43 -0
- package/esm/core/Union.d.ts.map +1 -0
- package/esm/core/Union.js +7 -0
- package/esm/core/Union.js.map +1 -0
- package/esm/core/Use.d.ts +62 -0
- package/esm/core/Use.d.ts.map +1 -0
- package/esm/core/Use.js +16 -0
- package/esm/core/Use.js.map +1 -0
- package/esm/core/mod.d.ts +18 -0
- package/esm/core/mod.d.ts.map +1 -0
- package/esm/core/mod.js +19 -0
- package/esm/core/mod.js.map +1 -0
- package/esm/lib/MerkleList.d.ts +4 -0
- package/esm/lib/MerkleList.d.ts.map +1 -0
- package/esm/lib/MerkleList.js +4 -0
- package/esm/lib/MerkleList.js.map +1 -0
- package/esm/lib/MerkleMap.d.ts +4 -0
- package/esm/lib/MerkleMap.d.ts.map +1 -0
- package/esm/lib/MerkleMap.js +4 -0
- package/esm/lib/MerkleMap.js.map +1 -0
- package/esm/lib/mod.d.ts +3 -0
- package/esm/lib/mod.d.ts.map +1 -0
- package/esm/lib/mod.js +3 -0
- package/esm/lib/mod.js.map +1 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +4 -0
- package/esm/mod.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/test/Signer.d.ts +10 -0
- package/esm/test/Signer.d.ts.map +1 -0
- package/esm/test/Signer.js +13 -0
- package/esm/test/Signer.js.map +1 -0
- package/esm/test/mod.d.ts +2 -0
- package/esm/test/mod.d.ts.map +1 -0
- package/esm/test/mod.js +2 -0
- package/esm/test/mod.js.map +1 -0
- package/esm/util/AbortController.d.ts +4 -0
- package/esm/util/AbortController.d.ts.map +1 -0
- package/esm/util/AbortController.js +2 -0
- package/esm/util/AbortController.js.map +1 -0
- package/esm/util/ArrayOfLength.d.ts +2 -0
- package/esm/util/ArrayOfLength.d.ts.map +1 -0
- package/esm/util/ArrayOfLength.js +2 -0
- package/esm/util/ArrayOfLength.js.map +1 -0
- package/esm/util/Flatten.d.ts +4 -0
- package/esm/util/Flatten.d.ts.map +1 -0
- package/esm/util/Flatten.js +2 -0
- package/esm/util/Flatten.js.map +1 -0
- package/esm/util/Rest.d.ts +2 -0
- package/esm/util/Rest.d.ts.map +1 -0
- package/esm/util/Rest.js +2 -0
- package/esm/util/Rest.js.map +1 -0
- package/esm/util/Subscription.d.ts +5 -0
- package/esm/util/Subscription.d.ts.map +1 -0
- package/esm/util/Subscription.js +2 -0
- package/esm/util/Subscription.js.map +1 -0
- package/esm/util/Tagged.d.ts +6 -0
- package/esm/util/Tagged.d.ts.map +1 -0
- package/esm/util/Tagged.js +6 -0
- package/esm/util/Tagged.js.map +1 -0
- package/esm/util/U2I.d.ts +2 -0
- package/esm/util/U2I.d.ts.map +1 -0
- package/esm/util/U2I.js +2 -0
- package/esm/util/U2I.js.map +1 -0
- package/esm/util/generator/collect.d.ts +3 -0
- package/esm/util/generator/collect.d.ts.map +1 -0
- package/esm/util/generator/collect.js +16 -0
- package/esm/util/generator/collect.js.map +1 -0
- package/esm/util/isKey.d.ts +2 -0
- package/esm/util/isKey.d.ts.map +1 -0
- package/esm/util/isKey.js +8 -0
- package/esm/util/isKey.js.map +1 -0
- package/esm/util/unimplemented.d.ts +2 -0
- package/esm/util/unimplemented.d.ts.map +1 -0
- package/esm/util/unimplemented.js +6 -0
- package/esm/util/unimplemented.js.map +1 -0
- package/package.json +24 -10
- package/src/client/Client.ts +49 -0
- package/src/client/Store.ts +1 -0
- package/src/client/Tx.ts +62 -0
- package/src/client/mod.ts +5 -0
- package/src/core/Bool.ts +75 -0
- package/src/core/Bytes.ts +9 -0
- package/src/core/Call.ts +38 -0
- package/src/core/Effect.ts +87 -0
- package/src/core/Hash.ts +23 -0
- package/src/core/Id.ts +97 -0
- package/src/core/Int.ts +177 -0
- package/src/core/Key.ts +9 -0
- package/src/core/MerkleList.ts +92 -0
- package/src/core/MerkleMap.ts +86 -0
- package/src/core/None.ts +11 -0
- package/src/core/State.ts +31 -0
- package/src/core/String.ts +5 -0
- package/src/core/Struct.ts +49 -0
- package/src/core/Type.ts +120 -0
- package/src/core/Union.ts +17 -0
- package/src/core/Use.ts +33 -0
- package/src/core/mod.ts +19 -0
- package/src/lib/MerkleList.ts +4 -0
- package/src/lib/MerkleMap.ts +4 -0
- package/src/lib/mod.ts +2 -0
- package/src/mod.ts +4 -0
- package/src/test/Signer.ts +22 -0
- package/src/test/mod.ts +1 -0
- package/src/util/AbortController.ts +3 -0
- package/src/util/ArrayOfLength.ts +5 -0
- package/src/util/Flatten.ts +2 -0
- package/src/util/Rest.ts +1 -0
- package/src/util/Subscription.ts +5 -0
- package/src/util/Tagged.ts +5 -0
- package/src/util/U2I.ts +1 -0
- package/src/util/generator/collect.ts +16 -0
- package/src/util/isKey.ts +7 -0
- package/src/util/unimplemented.ts +4 -0
- package/lib/index.js +0 -1
package/src/core/Call.ts
ADDED
|
@@ -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
|
+
}
|
package/src/core/Hash.ts
ADDED
|
@@ -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
|
+
}
|
package/src/core/Int.ts
ADDED
|
@@ -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
|
+
}
|
package/src/core/Key.ts
ADDED
|
@@ -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
|
+
}
|
package/src/core/None.ts
ADDED
|
@@ -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)
|