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.
- package/LICENSE +201 -15
- package/README.md +96 -81
- 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 +21 -21
- 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/jest.config.js +0 -4
- package/lib/array/array.d.ts +0 -6
- package/lib/array/array.js +0 -21
- package/lib/array/index.d.ts +0 -11
- package/lib/array/index.js +0 -17
- package/lib/composition/composition.d.ts +0 -6
- package/lib/composition/composition.js +0 -37
- package/lib/composition/index.d.ts +0 -9
- package/lib/composition/index.js +0 -13
- package/lib/composition/types.d.ts +0 -2
- package/lib/composition/types.js +0 -2
- package/lib/dispatch/getType.d.ts +0 -2
- package/lib/dispatch/getType.js +0 -15
- package/lib/dispatch/identity.d.ts +0 -2
- package/lib/dispatch/identity.js +0 -4
- package/lib/dispatch/index.d.ts +0 -22
- package/lib/dispatch/index.js +0 -13
- package/lib/dispatch/types.d.ts +0 -14
- package/lib/dispatch/types.js +0 -16
- package/lib/error/error.d.ts +0 -24
- package/lib/error/error.js +0 -25
- package/lib/error/index.d.ts +0 -2
- package/lib/error/index.js +0 -4
- package/lib/index.d.ts +0 -67
- package/lib/index.js +0 -19
- package/lib/multimethod/index.d.ts +0 -7
- package/lib/multimethod/index.js +0 -9
- package/lib/multimethod/multimethod.d.ts +0 -3
- package/lib/multimethod/multimethod.js +0 -101
- package/src/array/array.ts +0 -29
- package/src/array/index.ts +0 -12
- package/src/composition/composition.ts +0 -45
- package/src/composition/index.ts +0 -10
- package/src/composition/types.ts +0 -6
- package/src/dispatch/getType.ts +0 -17
- package/src/dispatch/identity.ts +0 -3
- package/src/dispatch/index.ts +0 -11
- package/src/dispatch/types.ts +0 -15
- package/src/error/error.ts +0 -26
- package/src/error/index.ts +0 -3
- package/src/index.ts +0 -15
- package/src/multimethod/index.ts +0 -8
- package/src/multimethod/multimethod.test.ts +0 -10
- package/src/multimethod/multimethod.ts +0 -148
- 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
|
package/src/core/Type.ts
ADDED
|
@@ -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
|
package/src/core/Use.ts
ADDED
|
@@ -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
|
package/src/core/mod.ts
ADDED
|
@@ -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"
|
package/src/lib/mod.ts
ADDED
package/src/mod.ts
ADDED
|
@@ -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
|
+
}
|
package/src/test/mod.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Signer.js"
|
package/src/util/Rest.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Rest<T> = undefined extends T ? [value?: T] : [value: T]
|
package/src/util/U2I.ts
ADDED
|
@@ -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
|
+
}
|
package/jest.config.js
DELETED
package/lib/array/array.d.ts
DELETED
|
@@ -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[];
|
package/lib/array/array.js
DELETED
|
@@ -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
|
-
};
|
package/lib/array/index.d.ts
DELETED
|
@@ -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;
|
package/lib/array/index.js
DELETED
|
@@ -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,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;
|
package/lib/composition/index.js
DELETED
|
@@ -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
|
-
};
|
package/lib/composition/types.js
DELETED
package/lib/dispatch/getType.js
DELETED
|
@@ -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;
|
package/lib/dispatch/identity.js
DELETED
package/lib/dispatch/index.d.ts
DELETED
|
@@ -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;
|
package/lib/dispatch/index.js
DELETED
|
@@ -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
|
-
};
|
package/lib/dispatch/types.d.ts
DELETED
|
@@ -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;
|
package/lib/dispatch/types.js
DELETED
|
@@ -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;
|
package/lib/error/error.d.ts
DELETED
|
@@ -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;
|
package/lib/error/error.js
DELETED
|
@@ -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
|
-
};
|