@@ -4,10 +4,10 @@ import "substrate/nodejs/polyfill";
44import { expect , describe , test } from "vitest" ;
55import {
66 Future ,
7- FutureString ,
8- FutureNumber ,
97 Trace ,
108 StringConcat ,
9+ concat ,
10+ interpolate ,
1111} from "substrate/Future" ;
1212import { Node } from "substrate/Node" ;
1313import { SubstrateResponse } from "substrate/SubstrateResponse" ;
@@ -43,9 +43,9 @@ describe("Future", () => {
4343 } ) ;
4444
4545 test ( ".referencedFutures" , ( ) => {
46- const a = new FutureString ( new Trace ( [ ] , node ( ) ) ) ;
47- const b = new FutureString ( new Trace ( [ ] , node ( ) ) ) ;
48- const c = new FutureString ( new StringConcat ( [ a , b ] ) ) ;
46+ const a = new Future < string > ( new Trace ( [ ] , node ( ) ) ) ;
47+ const b = new Future < string > ( new Trace ( [ ] , node ( ) ) ) ;
48+ const c = new Future < string > ( new StringConcat ( [ a , b ] ) ) ;
4949 const f = new FooFuture ( new StringConcat ( [ c , "d" ] ) ) ;
5050
5151 // @ts -expect-error (accessing protected property)
@@ -54,8 +54,8 @@ describe("Future", () => {
5454
5555 describe ( "Trace (Directive)" , ( ) => {
5656 test ( ".next" , ( ) => {
57- const s = new FutureString ( new Trace ( [ ] , node ( "123" ) ) ) ;
58- const n = new FutureNumber ( new Trace ( [ ] , node ( "456" ) ) ) ;
57+ const s = new Future < string > ( new Trace ( [ ] , node ( "123" ) ) ) ;
58+ const n = new Future < number > ( new Trace ( [ ] , node ( "456" ) ) ) ;
5959 const d = new Trace ( [ "a" , 1 , s , n ] , node ( "NodeId" ) ) ;
6060 const d2 = d . next ( "b" , 2 ) ;
6161
@@ -75,16 +75,16 @@ describe("Future", () => {
7575 expect ( t1 . result ( ) ) . resolves . toEqual ( "result1" ) ;
7676
7777 // when the trace contains futures, they get resolved
78- const fs = new FutureString ( new Trace ( [ ] , staticNode ( "b" ) ) ) ;
79- const fn = new FutureNumber ( new Trace ( [ ] , staticNode ( 1 ) ) ) ;
78+ const fs = new Future < string > ( new Trace ( [ ] , staticNode ( "b" ) ) ) ;
79+ const fn = new Future < number > ( new Trace ( [ ] , staticNode ( 1 ) ) ) ;
8080 const n2 = staticNode ( { a : [ { b : [ undefined , "result2" ] } ] } ) ;
8181 const t2 = new Trace ( [ "a" , 0 , fs , fn ] , n2 ) ;
8282 expect ( t2 . result ( ) ) . resolves . toEqual ( "result2" ) ;
8383 } ) ;
8484
8585 test ( ".toJSON" , ( ) => {
86- const s = new FutureString ( new Trace ( [ ] , node ( ) ) , "123" ) ;
87- const n = new FutureNumber ( new Trace ( [ ] , node ( ) ) , "456" ) ;
86+ const s = new Future < string > ( new Trace ( [ ] , node ( ) ) , "123" ) ;
87+ const n = new Future < number > ( new Trace ( [ ] , node ( ) ) , "456" ) ;
8888 const d = new Trace ( [ "a" , 1 , s , n ] , node ( "NodeId" ) ) ;
8989
9090 expect ( d . toJSON ( ) ) . toEqual ( {
@@ -94,14 +94,15 @@ describe("Future", () => {
9494 Trace . Operation . key ( "attr" , "a" ) ,
9595 Trace . Operation . key ( "item" , 1 ) ,
9696 Trace . Operation . future ( "attr" , "123" ) ,
97- Trace . Operation . future ( "item" , "456" ) ,
97+ Trace . Operation . future ( "attr" , "456" ) , // LIAM_TODO: there isn't a way to distinguish at runtime using static types
98+ // Trace.Operation.future("item", "456"),
9899 ] ,
99100 } ) ;
100101 } ) ;
101102
102103 test ( ".referencedFutures" , ( ) => {
103- const s = new FutureString ( new Trace ( [ ] , node ( ) ) ) ;
104- const n = new FutureNumber ( new Trace ( [ ] , node ( ) ) ) ;
104+ const s = new Future < string > ( new Trace ( [ ] , node ( ) ) ) ;
105+ const n = new Future < number > ( new Trace ( [ ] , node ( ) ) ) ;
105106 const d = new Trace ( [ "a" , 1 , s , n ] , node ( "NodeId" ) ) ;
106107
107108 expect ( d . referencedFutures ( ) ) . toEqual ( [ s , n ] ) ;
@@ -110,8 +111,8 @@ describe("Future", () => {
110111
111112 describe ( "StringConcat (Directive)" , ( ) => {
112113 test ( ".next" , ( ) => {
113- const s = new FutureString ( new Trace ( [ ] , node ( ) ) ) ;
114- const s2 = new FutureString ( new Trace ( [ ] , node ( ) ) ) ;
114+ const s = new Future < string > ( new Trace ( [ ] , node ( ) ) ) ;
115+ const s2 = new Future < string > ( new Trace ( [ ] , node ( ) ) ) ;
115116 const d = new StringConcat ( [ "a" , s ] ) ;
116117 const d2 = d . next ( "b" , s2 ) ;
117118
@@ -128,13 +129,13 @@ describe("Future", () => {
128129 expect ( s1 . result ( ) ) . resolves . toEqual ( "ab" ) ;
129130
130131 // when the items includes primitive values and futures
131- const fs = new FutureString ( new Trace ( [ ] , staticNode ( "b" ) ) ) ;
132+ const fs = new Future < string > ( new Trace ( [ ] , staticNode ( "b" ) ) ) ;
132133 const s2 = new StringConcat ( [ "a" , fs ] ) ;
133134 expect ( s2 . result ( ) ) . resolves . toEqual ( "ab" ) ;
134135 } ) ;
135136
136137 test ( ".toJSON" , ( ) => {
137- const s = new FutureString ( new Trace ( [ ] , node ( ) ) , "123" ) ;
138+ const s = new Future < string > ( new Trace ( [ ] , node ( ) ) , "123" ) ;
138139 const d = new StringConcat ( [ "a" , s ] ) ;
139140
140141 expect ( d . toJSON ( ) ) . toEqual ( {
@@ -147,44 +148,37 @@ describe("Future", () => {
147148 } ) ;
148149
149150 test ( ".referencedFutures" , ( ) => {
150- const a = new FutureString ( new Trace ( [ ] , node ( ) ) ) ;
151- const b = new FutureString ( new Trace ( [ ] , node ( ) ) ) ;
152- const c = new FutureString ( new StringConcat ( [ a , b ] ) ) ;
151+ const a = new Future < string > ( new Trace ( [ ] , node ( ) ) ) ;
152+ const b = new Future < string > ( new Trace ( [ ] , node ( ) ) ) ;
153+ const c = new Future < string > ( new StringConcat ( [ a , b ] ) ) ;
153154 const d = new StringConcat ( [ c , "d" ] ) ;
154155
155156 expect ( d . referencedFutures ( ) ) . toEqual ( [ c , a , b ] ) ;
156157 } ) ;
157158 } ) ;
158159
159- describe ( "FutureString" , ( ) => {
160- test ( ".concat (static)" , ( ) => {
161- const s = FutureString . concat ( "a" ) ;
162- expect ( s ) . toBeInstanceOf ( FutureString ) ;
163- // @ts -expect-error (protected access)
164- expect ( s . _directive ) . toEqual ( new StringConcat ( [ "a" ] ) ) ;
165- } ) ;
166-
167- test ( ".concat" , ( ) => {
168- const s1 = FutureString . concat ( "a" ) ;
169- const s2 = s1 . concat ( "b" , "c" ) ;
170- expect ( s2 ) . toBeInstanceOf ( FutureString ) ;
160+ describe ( "Strings" , ( ) => {
161+ test ( "concat" , ( ) => {
162+ const s1 = concat ( "a" ) ;
163+ const s2 = concat ( s1 , "b" , "c" ) ;
164+ expect ( s2 ) . toBeInstanceOf ( Future ) ;
171165 // @ts -expect-error (protected access)
172166 expect ( s2 . _directive ) . toEqual ( new StringConcat ( [ s1 , "b" , "c" ] ) ) ;
173167 } ) ;
174168
175- test ( ". interpolate" , async ( ) => {
169+ test ( "interpolate" , async ( ) => {
176170 const world = "world" ;
177171 const nice = "nice" ;
178- const i1 = FutureString . interpolate `hello ${ world } , you look ${ nice } today.` ;
172+ const i1 = interpolate `hello ${ world } , you look ${ nice } today.` ;
179173
180174 // @ts -expect-error
181175 expect ( i1 . _result ( ) ) . resolves . toEqual (
182176 "hello world, you look nice today." ,
183177 ) ;
184178
185- const f1 = FutureString . concat ( "texas" , " " , "sun" ) ;
186- const f2 = FutureString . concat ( "texas" , " " , "moon" ) ;
187- const i2 = FutureString . interpolate `~~ ${ f1 } x ${ f2 } ~~` ;
179+ const f1 = concat ( "texas" , " " , "sun" ) ;
180+ const f2 = concat ( "texas" , " " , "moon" ) ;
181+ const i2 = interpolate `~~ ${ f1 } x ${ f2 } ~~` ;
188182
189183 // @ts -expect-error
190184 expect ( i2 . _result ( ) ) . resolves . toEqual ( "~~ texas sun x texas moon ~~" ) ;
0 commit comments