@midnight-ntwrk/wallet-sdk-runtime 1.0.2-rc.0 → 1.0.3
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/dist/Runtime.d.ts +5 -7
- package/dist/WalletBuilder.d.ts +7 -11
- package/dist/WalletBuilder.js +3 -5
- package/dist/abstractions/StateChange.d.ts +9 -19
- package/dist/abstractions/StateChange.js +3 -9
- package/dist/abstractions/Variant.d.ts +7 -13
- package/dist/abstractions/VariantBuilder.d.ts +5 -12
- package/dist/abstractions/VersionChangeType.d.ts +7 -11
- package/dist/abstractions/VersionChangeType.js +2 -6
- package/dist/abstractions/WalletLike.d.ts +10 -18
- package/dist/abstractions/WalletRuntimeError.d.ts +1 -1
- package/dist/testing/utils.d.ts +3 -5
- package/dist/testing/utils.js +1 -3
- package/dist/testing/variants.d.ts +5 -4
- package/dist/testing/variants.js +6 -4
- package/package.json +3 -3
package/dist/Runtime.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Effect, Scope, Stream, SynchronizedRef } from 'effect';
|
|
2
|
-
import { ProtocolState, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
|
-
import { Variant, WalletRuntimeError } from './abstractions/index.js';
|
|
2
|
+
import { type ProtocolState, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
|
+
import { type Variant, WalletRuntimeError } from './abstractions/index.js';
|
|
4
4
|
import { HList, Poly } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
5
|
-
/**
|
|
6
|
-
* The {@link Runtime} service type.
|
|
7
|
-
*/
|
|
5
|
+
/** The {@link Runtime} service type. */
|
|
8
6
|
export interface Runtime<Variants extends Variant.AnyVersionedVariantArray> {
|
|
9
7
|
readonly stateChanges: Stream.Stream<ProtocolState.ProtocolState<Variant.StateOf<HList.Each<Variants>>>, WalletRuntimeError>;
|
|
10
8
|
readonly progress: Effect.Effect<Progress>;
|
|
@@ -27,8 +25,8 @@ type EachRunningVariant<TAll extends Variant.AnyVersionedVariantArray> = TAll ex
|
|
|
27
25
|
...infer TRest extends Variant.AnyVersionedVariantArray
|
|
28
26
|
] ? RunningVariant<THead, TRest> | EachRunningVariant<TRest> : never;
|
|
29
27
|
/**
|
|
30
|
-
* A type that represents the reported progress of a variant expressed in terms of gaps to reaching synced
|
|
31
|
-
*
|
|
28
|
+
* A type that represents the reported progress of a variant expressed in terms of gaps to reaching synced progress in
|
|
29
|
+
* application site and data source site
|
|
32
30
|
*/
|
|
33
31
|
type Progress = {
|
|
34
32
|
readonly sourceGap: bigint;
|
package/dist/WalletBuilder.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Types } from 'effect';
|
|
1
|
+
import { type Types } from 'effect';
|
|
2
2
|
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
|
-
import { VariantBuilder, WalletLike } from './abstractions/index.js';
|
|
3
|
+
import { type VariantBuilder, type WalletLike } from './abstractions/index.js';
|
|
4
4
|
import { HList } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
5
5
|
/**
|
|
6
|
-
* Builds a wallet-like implementation from a collection of wallet-like variants, each specific
|
|
7
|
-
*
|
|
6
|
+
* Builds a wallet-like implementation from a collection of wallet-like variants, each specific to a given version of
|
|
7
|
+
* the Midnight protocol.
|
|
8
8
|
*
|
|
9
9
|
* @typeParam TBuilders The sequence of variant builders that will manage the wallet state
|
|
10
10
|
*/
|
|
@@ -20,9 +20,7 @@ export declare class WalletBuilder<TBuilders extends VariantBuilder.AnyVersioned
|
|
|
20
20
|
* @returns A new {@link WalletBuilder} that uses the variant that will be built from `variantBuilder`.
|
|
21
21
|
*/
|
|
22
22
|
withVariant<TBuilder extends VariantBuilder.AnyVariantBuilder>(sinceVersion: ProtocolVersion.ProtocolVersion, variantBuilder: TBuilder): WalletBuilder<HList.Append<TBuilders, VariantBuilder.VersionedVariantBuilder<TBuilder>>>;
|
|
23
|
-
/**
|
|
24
|
-
* Builds a wallet like implementation.
|
|
25
|
-
*/
|
|
23
|
+
/** Builds a wallet like implementation. */
|
|
26
24
|
build(...[maybeConfiguration]: WalletBuilder.BuildArguments<TBuilders>): WalletLike.BaseWalletClass<VariantBuilder.VersionedVariantsOf<TBuilders>, WalletBuilder.FullConfiguration<TBuilders>>;
|
|
27
25
|
}
|
|
28
26
|
export declare namespace WalletBuilder {
|
|
@@ -30,14 +28,12 @@ export declare namespace WalletBuilder {
|
|
|
30
28
|
* The internal build state of {@link WalletBuilder}.
|
|
31
29
|
*
|
|
32
30
|
* @remarks
|
|
33
|
-
*
|
|
31
|
+
* Represents the collection of configured variants and their configuration.
|
|
34
32
|
*/
|
|
35
33
|
type BuildState<TBuilders extends VariantBuilder.AnyVersionedVariantBuilder[]> = {
|
|
36
34
|
readonly variants: TBuilders;
|
|
37
35
|
};
|
|
38
|
-
/**
|
|
39
|
-
* Allows properly expressing no need for configuration if an empty one needs to be provided
|
|
40
|
-
*/
|
|
36
|
+
/** Allows properly expressing no need for configuration if an empty one needs to be provided */
|
|
41
37
|
type BuildArguments<TBuilders extends VariantBuilder.AnyVersionedVariantBuilder[]> = VoidIfEmpty<FullConfiguration<TBuilders>> extends undefined ? [] : [FullConfiguration<TBuilders>];
|
|
42
38
|
type FullConfiguration<TBuilders extends VariantBuilder.AnyVersionedVariantBuilder[]> = Types.UnionToIntersection<Configurations<TBuilders>>;
|
|
43
39
|
type VoidIfEmpty<TObject> = keyof TObject extends never ? undefined : TObject;
|
package/dist/WalletBuilder.js
CHANGED
|
@@ -17,8 +17,8 @@ import { Variant, WalletRuntimeError } from './abstractions/index.js';
|
|
|
17
17
|
import { ObservableOps, HList } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
18
18
|
import * as Runtime from './Runtime.js';
|
|
19
19
|
/**
|
|
20
|
-
* Builds a wallet-like implementation from a collection of wallet-like variants, each specific
|
|
21
|
-
*
|
|
20
|
+
* Builds a wallet-like implementation from a collection of wallet-like variants, each specific to a given version of
|
|
21
|
+
* the Midnight protocol.
|
|
22
22
|
*
|
|
23
23
|
* @typeParam TBuilders The sequence of variant builders that will manage the wallet state
|
|
24
24
|
*/
|
|
@@ -51,9 +51,7 @@ export class WalletBuilder {
|
|
|
51
51
|
variants: HList.append(this.#buildState.variants, newBuilder),
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Builds a wallet like implementation.
|
|
56
|
-
*/
|
|
54
|
+
/** Builds a wallet like implementation. */
|
|
57
55
|
build(...[maybeConfiguration]) {
|
|
58
56
|
if (this.#buildState.variants.length == 0) {
|
|
59
57
|
throw new WalletRuntimeError({ message: 'Empty variants list' });
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Data } from 'effect';
|
|
2
|
-
import { VersionChangeType } from './VersionChangeType.js';
|
|
2
|
+
import { type VersionChangeType } from './VersionChangeType.js';
|
|
3
3
|
/**
|
|
4
4
|
* A tagged enum data type that represents the state changes across wallet implementation variants.
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* A variant can report changes in state using the {@link StateChange.State} enum variant. The
|
|
8
|
+
* {@link StateChange.ProgressUpdate} and {@link StateChange.VersionChange} enum variants should be used when a variant
|
|
9
|
+
* needs to report a sync progress update, or a detected change in protocol version respectively.
|
|
10
10
|
*/
|
|
11
11
|
export type StateChange<TState> = Data.TaggedEnum<{
|
|
12
12
|
/** A change in state. */
|
|
@@ -15,13 +15,9 @@ export type StateChange<TState> = Data.TaggedEnum<{
|
|
|
15
15
|
};
|
|
16
16
|
/** A change in reported progress. */
|
|
17
17
|
ProgressUpdate: {
|
|
18
|
-
/**
|
|
19
|
-
* The number of blocks that remain for the underlying datasource to process in order to be fully synchronized.
|
|
20
|
-
*/
|
|
18
|
+
/** The number of blocks that remain for the underlying datasource to process in order to be fully synchronized. */
|
|
21
19
|
readonly sourceGap: bigint;
|
|
22
|
-
/**
|
|
23
|
-
* The number of blocks that remain for the variant to apply in order to be fully synchronized.
|
|
24
|
-
*/
|
|
20
|
+
/** The number of blocks that remain for the variant to apply in order to be fully synchronized. */
|
|
25
21
|
readonly applyGap: bigint;
|
|
26
22
|
};
|
|
27
23
|
/** A change in Midnight protocol version. */
|
|
@@ -29,9 +25,7 @@ export type StateChange<TState> = Data.TaggedEnum<{
|
|
|
29
25
|
readonly change: VersionChangeType;
|
|
30
26
|
};
|
|
31
27
|
}>;
|
|
32
|
-
/**
|
|
33
|
-
* A type predicate that determines if a given value is a {@link StateChange.State} enum variant.
|
|
34
|
-
*/
|
|
28
|
+
/** A type predicate that determines if a given value is a {@link StateChange.State} enum variant. */
|
|
35
29
|
export declare const isState: {
|
|
36
30
|
<T extends {
|
|
37
31
|
readonly _tag: "State";
|
|
@@ -51,9 +45,7 @@ export declare const isState: {
|
|
|
51
45
|
readonly state: unknown;
|
|
52
46
|
};
|
|
53
47
|
};
|
|
54
|
-
/**
|
|
55
|
-
* A type predicate that determines if a given value is a {@link StateChange.ProgressUpdate} enum variant.
|
|
56
|
-
*/
|
|
48
|
+
/** A type predicate that determines if a given value is a {@link StateChange.ProgressUpdate} enum variant. */
|
|
57
49
|
export declare const isProgressUpdate: {
|
|
58
50
|
<T extends {
|
|
59
51
|
readonly _tag: "State";
|
|
@@ -74,9 +66,7 @@ export declare const isProgressUpdate: {
|
|
|
74
66
|
readonly applyGap: bigint;
|
|
75
67
|
};
|
|
76
68
|
};
|
|
77
|
-
/**
|
|
78
|
-
* A type predicate that determines if a given value is a {@link StateChange.VersionChange} enum variant.
|
|
79
|
-
*/
|
|
69
|
+
/** A type predicate that determines if a given value is a {@link StateChange.VersionChange} enum variant. */
|
|
80
70
|
export declare const isVersionChange: {
|
|
81
71
|
<T extends {
|
|
82
72
|
readonly _tag: "State";
|
|
@@ -12,16 +12,10 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { Data } from 'effect';
|
|
14
14
|
const StateChange = Data.taggedEnum();
|
|
15
|
-
/**
|
|
16
|
-
* A type predicate that determines if a given value is a {@link StateChange.State} enum variant.
|
|
17
|
-
*/
|
|
15
|
+
/** A type predicate that determines if a given value is a {@link StateChange.State} enum variant. */
|
|
18
16
|
export const isState = StateChange.$is('State');
|
|
19
|
-
/**
|
|
20
|
-
* A type predicate that determines if a given value is a {@link StateChange.ProgressUpdate} enum variant.
|
|
21
|
-
*/
|
|
17
|
+
/** A type predicate that determines if a given value is a {@link StateChange.ProgressUpdate} enum variant. */
|
|
22
18
|
export const isProgressUpdate = StateChange.$is('ProgressUpdate');
|
|
23
|
-
/**
|
|
24
|
-
* A type predicate that determines if a given value is a {@link StateChange.VersionChange} enum variant.
|
|
25
|
-
*/
|
|
19
|
+
/** A type predicate that determines if a given value is a {@link StateChange.VersionChange} enum variant. */
|
|
26
20
|
export const isVersionChange = StateChange.$is('VersionChange');
|
|
27
21
|
export const { $match: match, State, ProgressUpdate, VersionChange } = StateChange;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Scope, SubscriptionRef } from 'effect';
|
|
1
|
+
import { type Scope, type SubscriptionRef } from 'effect';
|
|
2
2
|
import type { Effect } from 'effect/Effect';
|
|
3
3
|
import type { Stream } from 'effect/Stream';
|
|
4
4
|
import { Poly } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
5
5
|
import type { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
6
|
-
import { WalletRuntimeError } from './WalletRuntimeError.js';
|
|
7
|
-
import * as StateChange from './StateChange.js';
|
|
6
|
+
import { type WalletRuntimeError } from './WalletRuntimeError.js';
|
|
7
|
+
import type * as StateChange from './StateChange.js';
|
|
8
8
|
export interface VariantContext<TState> {
|
|
9
9
|
stateRef: SubscriptionRef.SubscriptionRef<TState>;
|
|
10
10
|
}
|
|
@@ -22,21 +22,15 @@ export type Variant<TTag extends string | symbol, TState, TPreviousState, TRunni
|
|
|
22
22
|
export type RunningVariant<TTag extends symbol | string, TState> = Poly.WithTag<TTag> & {
|
|
23
23
|
state: Stream<StateChange.StateChange<TState>, WalletRuntimeError>;
|
|
24
24
|
};
|
|
25
|
-
/**
|
|
26
|
-
* A utility type that represents any {@link Variant}.
|
|
27
|
-
*/
|
|
25
|
+
/** A utility type that represents any {@link Variant}. */
|
|
28
26
|
export type AnyVariant = Variant<string | symbol, any, any, AnyRunningVariant>;
|
|
29
27
|
export type AnyRunningVariant = RunningVariant<string | symbol, any>;
|
|
30
28
|
export type RunningVariantOf<T> = T extends VersionedVariant<infer V> ? RunningVariantOf<V> : T extends Variant<string | symbol, any, any, infer Running> ? Running : never;
|
|
31
29
|
export type StateOf<T> = T extends Variant<any, infer S, any, AnyRunningVariant> ? S : T extends VersionedVariant<infer V> ? StateOf<V> : never;
|
|
32
30
|
export type PreviousStateOf<T> = T extends VersionedVariant<infer V> ? PreviousStateOf<V> : T extends Variant<string | symbol, unknown, infer S, any> ? S : never;
|
|
33
|
-
/**
|
|
34
|
-
* An array of {@link Variant} instances.
|
|
35
|
-
*/
|
|
31
|
+
/** An array of {@link Variant} instances. */
|
|
36
32
|
export type AnyVariantArray = AnyVariant[];
|
|
37
|
-
/**
|
|
38
|
-
* A type that associates a {@link Variant} with a given version of the Midnight protocol.
|
|
39
|
-
*/
|
|
33
|
+
/** A type that associates a {@link Variant} with a given version of the Midnight protocol. */
|
|
40
34
|
export type VersionedVariant<T extends AnyVariant> = Readonly<{
|
|
41
35
|
sinceVersion: ProtocolVersion.ProtocolVersion;
|
|
42
36
|
variant: T;
|
|
@@ -46,7 +40,7 @@ export type AnyVersionedVariant = VersionedVariant<AnyVariant>;
|
|
|
46
40
|
* An ordered array of types that associates a {@link Variant} with a given version of the Midnight protocol.
|
|
47
41
|
*
|
|
48
42
|
* @remarks
|
|
49
|
-
*
|
|
43
|
+
* The expected order of the variants will be ascending on `sinceVersion`.
|
|
50
44
|
*/
|
|
51
45
|
export type AnyVersionedVariantArray = AnyVersionedVariant[];
|
|
52
46
|
export type VariantTag<T> = T extends VersionedVariant<infer V> ? VariantTag<V> : T extends Poly.WithTag<infer Tag> ? Tag : never;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
-
import { AnyVariant, VersionedVariant } from './Variant.js';
|
|
1
|
+
import { type ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
+
import { type AnyVariant, type VersionedVariant } from './Variant.js';
|
|
3
3
|
/**
|
|
4
4
|
* Builds a target {@link Variant} object from internal build state.
|
|
5
5
|
*
|
|
@@ -12,18 +12,13 @@ export interface VariantBuilder<TVariant extends AnyVariant, TConfiguration exte
|
|
|
12
12
|
* Builds the target variant object from the internal build state.
|
|
13
13
|
*
|
|
14
14
|
* @param configuration The configuration to use when building the target variant.
|
|
15
|
-
*
|
|
16
15
|
* @returns An instance of {@link Variant} that operates over `TState`.
|
|
17
16
|
*/
|
|
18
17
|
build(configuration: TConfiguration): TVariant;
|
|
19
18
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Base type that represents variant configuration.
|
|
22
|
-
*/
|
|
19
|
+
/** Base type that represents variant configuration. */
|
|
23
20
|
export type AnyBuilderConfiguration = object;
|
|
24
|
-
/**
|
|
25
|
-
* A utility type that represents any {@link VariantBuilder}.
|
|
26
|
-
*/
|
|
21
|
+
/** A utility type that represents any {@link VariantBuilder}. */
|
|
27
22
|
export type AnyVariantBuilder = VariantBuilder<AnyVariant, AnyBuilderConfiguration>;
|
|
28
23
|
export type VariantOf<T> = T extends VersionedVariantBuilder<infer TBuilder> ? VariantOf<TBuilder> : T extends VariantBuilder<infer TVariant, object> ? TVariant : never;
|
|
29
24
|
export type VersionedVariantBuilder<TBuilder extends AnyVariantBuilder> = Readonly<{
|
|
@@ -33,7 +28,5 @@ export type VersionedVariantBuilder<TBuilder extends AnyVariantBuilder> = Readon
|
|
|
33
28
|
export type VariantsOf<T> = T extends [infer THead, ...infer TRest] ? [VariantOf<THead>, ...VariantsOf<TRest>] : T extends [] ? [] : never;
|
|
34
29
|
export type VersionedVariantsOf<T> = T extends [infer THead, ...infer Rest] ? [VersionedVariant<VariantOf<THead>>, ...VersionedVariantsOf<Rest>] : T extends [] ? [] : never;
|
|
35
30
|
export type ConfigurationOf<T> = T extends VariantBuilder<any, infer Config> ? Config : T extends VersionedVariantBuilder<infer Builder> ? ConfigurationOf<Builder> : never;
|
|
36
|
-
/**
|
|
37
|
-
* A type that associates a {@link VariantBuilder} with a given version of the Midnight protocol.
|
|
38
|
-
*/
|
|
31
|
+
/** A type that associates a {@link VariantBuilder} with a given version of the Midnight protocol. */
|
|
39
32
|
export type AnyVersionedVariantBuilder = VersionedVariantBuilder<AnyVariantBuilder>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Data } from 'effect';
|
|
2
|
-
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
+
import { type ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
3
|
/**
|
|
4
4
|
* A tagged enum data type that represents a change in Midnight protocol versions.
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* A specific protocol version can be specified using the {@link VersionChangeType.Version} enum variant. It has a
|
|
8
|
+
* `version` property that accepts a {@link ProtocolVersion} value for a known protocol version. For use cases where a
|
|
9
|
+
* specific protocol version cannot be given, the {@link VersionChangeType.Next} enum variant can be used. Its use is
|
|
10
|
+
* context specific.
|
|
11
11
|
*/
|
|
12
12
|
export type VersionChangeType = Data.TaggedEnum<{
|
|
13
13
|
/** A change to a particular protocol version. */
|
|
@@ -17,16 +17,12 @@ export type VersionChangeType = Data.TaggedEnum<{
|
|
|
17
17
|
/** A change to the 'next' protocol version. Particularly useful in testing */
|
|
18
18
|
Next: {};
|
|
19
19
|
}>;
|
|
20
|
-
/**
|
|
21
|
-
* A type predicate that determines if a given value is a {@link VersionChangeType.Version} enum variant.
|
|
22
|
-
*/
|
|
20
|
+
/** A type predicate that determines if a given value is a {@link VersionChangeType.Version} enum variant. */
|
|
23
21
|
export declare const isVersion: (u: unknown) => u is {
|
|
24
22
|
readonly _tag: "Version";
|
|
25
23
|
readonly version: ProtocolVersion.ProtocolVersion;
|
|
26
24
|
};
|
|
27
|
-
/**
|
|
28
|
-
* A type predicate that determines if a given value is a {@link VersionChangeType.Next} enum variant.
|
|
29
|
-
*/
|
|
25
|
+
/** A type predicate that determines if a given value is a {@link VersionChangeType.Next} enum variant. */
|
|
30
26
|
export declare const isNext: (u: unknown) => u is {
|
|
31
27
|
readonly _tag: "Next";
|
|
32
28
|
};
|
|
@@ -12,12 +12,8 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { Data } from 'effect';
|
|
14
14
|
const VersionChangeType = Data.taggedEnum();
|
|
15
|
-
/**
|
|
16
|
-
* A type predicate that determines if a given value is a {@link VersionChangeType.Version} enum variant.
|
|
17
|
-
*/
|
|
15
|
+
/** A type predicate that determines if a given value is a {@link VersionChangeType.Version} enum variant. */
|
|
18
16
|
export const isVersion = VersionChangeType.$is('Version');
|
|
19
|
-
/**
|
|
20
|
-
* A type predicate that determines if a given value is a {@link VersionChangeType.Next} enum variant.
|
|
21
|
-
*/
|
|
17
|
+
/** A type predicate that determines if a given value is a {@link VersionChangeType.Next} enum variant. */
|
|
22
18
|
export const isNext = VersionChangeType.$is('Next');
|
|
23
19
|
export const { $match: match, Version, Next } = VersionChangeType;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Scope } from 'effect';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { Runtime } from '../Runtime.js';
|
|
4
|
-
import { AnyVersionedVariantArray, StateOf, VariantRecord } from './Variant.js';
|
|
5
|
-
import { HList, Poly } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
6
|
-
import { ProtocolState } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
7
|
-
/**
|
|
8
|
-
* Defines the static portion of base wallet class definition
|
|
9
|
-
*/
|
|
1
|
+
import { type Scope } from 'effect';
|
|
2
|
+
import { type Observable } from 'rxjs';
|
|
3
|
+
import { type Runtime } from '../Runtime.js';
|
|
4
|
+
import { type AnyVersionedVariantArray, type StateOf, type VariantRecord } from './Variant.js';
|
|
5
|
+
import { type HList, type Poly } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
6
|
+
import { type ProtocolState } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
7
|
+
/** Defines the static portion of base wallet class definition */
|
|
10
8
|
export interface BaseWalletClass<TVariants extends AnyVersionedVariantArray, TConfiguration = object> {
|
|
11
9
|
readonly configuration: Readonly<TConfiguration>;
|
|
12
10
|
new (runtime: Runtime<TVariants>, scope: Scope.CloseableScope): WalletLike<TVariants>;
|
|
@@ -18,9 +16,7 @@ export interface BaseWalletClass<TVariants extends AnyVersionedVariantArray, TCo
|
|
|
18
16
|
variant: Poly.WithTag<Tag>;
|
|
19
17
|
}>>): WalletOf<T>;
|
|
20
18
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Defines the static portion of wallet-like definition
|
|
23
|
-
*/
|
|
19
|
+
/** Defines the static portion of wallet-like definition */
|
|
24
20
|
export interface WalletClassLike<TVariants extends AnyVersionedVariantArray, TWallet extends WalletLike<TVariants>> extends BaseWalletClass<TVariants> {
|
|
25
21
|
new (runtime: Runtime<TVariants>, scope: Scope.CloseableScope): TWallet;
|
|
26
22
|
}
|
|
@@ -34,12 +30,8 @@ export type WalletOf<T> = T extends WalletClassLike<any, infer TWallet> ? TWalle
|
|
|
34
30
|
export interface WalletLike<TVariants extends AnyVersionedVariantArray> {
|
|
35
31
|
readonly runtime: Runtime<TVariants>;
|
|
36
32
|
readonly runtimeScope: Scope.CloseableScope;
|
|
37
|
-
/**
|
|
38
|
-
* A stream of state changes over any amount of time that have been processed by the wallet.
|
|
39
|
-
*/
|
|
33
|
+
/** A stream of state changes over any amount of time that have been processed by the wallet. */
|
|
40
34
|
readonly rawState: Observable<ProtocolState.ProtocolState<StateOf<HList.Each<TVariants>>>>;
|
|
41
|
-
/**
|
|
42
|
-
* Stops the wallet
|
|
43
|
-
*/
|
|
35
|
+
/** Stops the wallet */
|
|
44
36
|
stop(): Promise<void>;
|
|
45
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const WalletRuntimeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
1
|
+
declare const WalletRuntimeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
2
2
|
readonly _tag: "WalletRuntimeError";
|
|
3
3
|
} & Readonly<A>;
|
|
4
4
|
export declare class WalletRuntimeError extends WalletRuntimeError_base<{
|
package/dist/testing/utils.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { ProtocolState } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
1
|
+
import { type ProtocolState } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
2
|
import { Chunk } from 'effect';
|
|
3
|
-
import { Observable, OperatorFunction } from 'rxjs';
|
|
3
|
+
import { type Observable, type OperatorFunction } from 'rxjs';
|
|
4
4
|
/**
|
|
5
5
|
* Utility function that takes state values from an RxJS observable until it completes or errors.
|
|
6
6
|
*
|
|
7
7
|
* @param observable The RxJS observable from which state values should be read.
|
|
8
8
|
* @param onErrCallback An optional callback to invoke if an error is encountered reading a state value.
|
|
9
|
-
* @returns A `Promise` that resolves with an array of state values that were received before encountering
|
|
10
|
-
* any error.
|
|
11
|
-
*
|
|
9
|
+
* @returns A `Promise` that resolves with an array of state values that were received before encountering any error.
|
|
12
10
|
* @internal
|
|
13
11
|
*/
|
|
14
12
|
export declare const toProtocolStateArray: <T>(observable: Observable<ProtocolState.ProtocolState<T>>, onErrCallback?: (err: unknown) => void) => Promise<ProtocolState.ProtocolState<T>[]>;
|
package/dist/testing/utils.js
CHANGED
|
@@ -5,9 +5,7 @@ import { reduce } from 'rxjs';
|
|
|
5
5
|
*
|
|
6
6
|
* @param observable The RxJS observable from which state values should be read.
|
|
7
7
|
* @param onErrCallback An optional callback to invoke if an error is encountered reading a state value.
|
|
8
|
-
* @returns A `Promise` that resolves with an array of state values that were received before encountering
|
|
9
|
-
* any error.
|
|
10
|
-
*
|
|
8
|
+
* @returns A `Promise` that resolves with an array of state values that were received before encountering any error.
|
|
11
9
|
* @internal
|
|
12
10
|
*/
|
|
13
11
|
export const toProtocolStateArray = (observable, onErrCallback) => new Promise((resolve) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Variant, VariantBuilder, VersionChangeType, WalletRuntimeError } from '../abstractions/index.js';
|
|
2
|
-
import { Effect, Scope } from 'effect';
|
|
1
|
+
import { StateChange, type Variant, type VariantBuilder, VersionChangeType, WalletRuntimeError } from '../abstractions/index.js';
|
|
2
|
+
import { Effect, type Scope } from 'effect';
|
|
3
3
|
export type RangeConfig = {
|
|
4
4
|
min: number;
|
|
5
5
|
max: number;
|
|
@@ -40,6 +40,7 @@ export declare class NumericRangeMultiplierBuilder implements VariantBuilder.Var
|
|
|
40
40
|
}
|
|
41
41
|
export type InterceptingRunningVariant<TTag extends string | symbol, TState> = Variant.RunningVariant<TTag, TState> & {
|
|
42
42
|
emitProtocolVersionChange: (change: VersionChangeType.VersionChangeType) => Effect.Effect<void>;
|
|
43
|
+
emit: (change: StateChange.StateChange<TState>) => Effect.Effect<void>;
|
|
43
44
|
};
|
|
44
45
|
export declare class InterceptingVariant<TTag extends string | symbol, TState> implements Variant.Variant<TTag, TState, TState, InterceptingRunningVariant<TTag, TState>> {
|
|
45
46
|
__polyTag__: TTag;
|
|
@@ -48,8 +49,8 @@ export declare class InterceptingVariant<TTag extends string | symbol, TState> i
|
|
|
48
49
|
start(context: Variant.VariantContext<TState>): Effect.Effect<InterceptingRunningVariant<TTag, TState>, WalletRuntimeError, Scope.Scope>;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
|
-
* Builder of an intercepting variant
|
|
52
|
-
*
|
|
52
|
+
* Builder of an intercepting variant It allows removing the possibility of race conditions by requiring an explicit
|
|
53
|
+
* gesture to migrate to a next/specific protocol version
|
|
53
54
|
*/
|
|
54
55
|
export declare class InterceptingVariantBuilder<TTag extends string | symbol, TState> implements VariantBuilder.VariantBuilder<InterceptingVariant<TTag, TState>, object> {
|
|
55
56
|
tag: TTag;
|
package/dist/testing/variants.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { StateChange, VersionChangeType, WalletRuntimeError } from '../abstractions/index.js';
|
|
13
|
+
import { StateChange, VersionChangeType, WalletRuntimeError, } from '../abstractions/index.js';
|
|
14
14
|
import { Effect, Option, PubSub, Stream } from 'effect';
|
|
15
15
|
export const Numeric = 'NumericRange';
|
|
16
16
|
export class NumericRange {
|
|
@@ -122,21 +122,23 @@ export class InterceptingVariant {
|
|
|
122
122
|
});
|
|
123
123
|
const state = yield* context.stateRef.get;
|
|
124
124
|
yield* PubSub.publish(pubsub, StateChange.State({ state }));
|
|
125
|
+
const emit = (change) => PubSub.publish(pubsub, change);
|
|
125
126
|
return {
|
|
126
127
|
__polyTag__: tag,
|
|
127
128
|
state: Stream.fromPubSub(pubsub, {
|
|
128
129
|
shutdown: true,
|
|
129
130
|
}),
|
|
130
131
|
emitProtocolVersionChange: (change) => {
|
|
131
|
-
return
|
|
132
|
+
return emit(StateChange.VersionChange({ change }));
|
|
132
133
|
},
|
|
134
|
+
emit,
|
|
133
135
|
};
|
|
134
136
|
});
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
|
-
* Builder of an intercepting variant
|
|
139
|
-
*
|
|
140
|
+
* Builder of an intercepting variant It allows removing the possibility of race conditions by requiring an explicit
|
|
141
|
+
* gesture to migrate to a next/specific protocol version
|
|
140
142
|
*/
|
|
141
143
|
export class InterceptingVariantBuilder {
|
|
142
144
|
tag;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-runtime",
|
|
3
3
|
"description": "Runtime for the wallet variants",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@midnight-ntwrk/wallet-sdk-abstractions": "2.
|
|
33
|
-
"@midnight-ntwrk/wallet-sdk-utilities": "1.1.
|
|
32
|
+
"@midnight-ntwrk/wallet-sdk-abstractions": "2.1.0",
|
|
33
|
+
"@midnight-ntwrk/wallet-sdk-utilities": "1.1.1",
|
|
34
34
|
"effect": "^3.19.19",
|
|
35
35
|
"rxjs": "^7.8.2"
|
|
36
36
|
},
|