Skip to content

Commit 3cfccbf

Browse files
committed
move toExternalValue function to util since impl types are not exported
anymore
1 parent 15809dc commit 3cfccbf

File tree

4 files changed

+43
-43
lines changed

4 files changed

+43
-43
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"build:1-lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --max-warnings 0",
1616
"build:2-check-types": "tsc -p tsconfig.json",
1717
"build:3-build": "rollup -c --configPlugin typescript",
18-
"build:4-remove-internal-types": "rimraf dist/impl/**/*.d.ts dist/internal/*.d.ts -g",
18+
"build:4-remove-internal-types": "rimraf -g dist/impl/*.d.ts dist/impl/**/*.d.ts dist/internal/*.d.ts",
1919
"build:5-copy-pkg-json": "tstk copy-package-json -c",
2020
"build:6-copy-readme": "copyfiles ./README.md ./dist",
2121
"watch": "rollup -c -w --configPlugin typescript",

src/impl/primitives.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,6 @@ export type StubBigUintCompat = BigUintCompat | BigUintCls | Uint64Cls
1212
export type StubBytesCompat = BytesCompat | BytesCls
1313
export type StubUint64Compat = Uint64Compat | Uint64Cls
1414

15-
/**
16-
* Converts internal Algorand type representations to their external primitive values.
17-
*
18-
* @overload
19-
* @param {uint64} val - A uint64 value to convert
20-
* @returns {bigint} The uint64 value as a bigint
21-
*
22-
* @overload
23-
* @param {biguint} val - A biguint value to convert
24-
* @returns {bigint} The biguint value as a bigint
25-
*
26-
* @overload
27-
* @param {bytes} val - A bytes value to convert
28-
* @returns {Uint8Array} The bytes value as a Uint8Array
29-
*
30-
* @overload
31-
* @param {string} val - A string value to pass through
32-
* @returns {string} The original string value unchanged
33-
*
34-
* @example
35-
* ```ts
36-
* const uint64Val = Uint64(123n)
37-
* toExternalValue(uint64Val) // returns 123n
38-
*
39-
* const bytesVal = Bytes.fromBase64("SGVsbG8=");
40-
* toExternalValue(bytesVal) // returns Uint8Array([72, 101, 108, 108, 111])
41-
* ```
42-
*/
43-
export function toExternalValue(val: uint64): bigint
44-
export function toExternalValue(val: biguint): bigint
45-
export function toExternalValue(val: bytes): Uint8Array
46-
export function toExternalValue(val: string): string
47-
export function toExternalValue(val: uint64 | biguint | bytes | string) {
48-
const instance = val as unknown
49-
if (instance instanceof BytesCls) return instance.asUint8Array()
50-
if (instance instanceof Uint64Cls) return instance.asBigInt()
51-
if (instance instanceof BigUintCls) return instance.asBigInt()
52-
if (typeof val === 'string') return val
53-
}
54-
5515
/**
5616
* Create a uint64 with the default value of 0
5717
*/

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { ApplicationSpy } from './application-spy'
22
export { AssertError, AvmError, CodeError, InternalError, NotImplementedError } from './errors'
3-
export { toExternalValue } from './impl/primitives'
43
export { addEqualityTesters } from './set-up'
54
export { TestExecutionContext } from './test-execution-context'
5+
export { toExternalValue } from './util'

src/util.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
1-
import type { bytes } from '@algorandfoundation/algorand-typescript'
1+
import type { biguint, bytes, uint64 } from '@algorandfoundation/algorand-typescript'
22
import { randomBytes } from 'crypto'
33
import { BITS_IN_BYTE, MAX_BYTES_SIZE, MAX_UINT512, MAX_UINT8, UINT512_SIZE } from './constants'
44
import { AssertError, AvmError, InternalError } from './errors'
55
import type { StubBigUintCompat, StubBytesCompat, StubUint64Compat } from './impl/primitives'
66
import { BigUintCls, Bytes, BytesCls, Uint64Cls } from './impl/primitives'
77
import type { DeliberateAny } from './typescript-helpers'
88

9+
/**
10+
* Converts internal Algorand type representations to their external primitive values.
11+
*
12+
* @overload
13+
* @param {uint64} val - A uint64 value to convert
14+
* @returns {bigint} The uint64 value as a bigint
15+
*
16+
* @overload
17+
* @param {biguint} val - A biguint value to convert
18+
* @returns {bigint} The biguint value as a bigint
19+
*
20+
* @overload
21+
* @param {bytes} val - A bytes value to convert
22+
* @returns {Uint8Array} The bytes value as a Uint8Array
23+
*
24+
* @overload
25+
* @param {string} val - A string value to pass through
26+
* @returns {string} The original string value unchanged
27+
*
28+
* @example
29+
* ```ts
30+
* const uint64Val = Uint64(123n)
31+
* toExternalValue(uint64Val) // returns 123n
32+
*
33+
* const bytesVal = Bytes.fromBase64("SGVsbG8=");
34+
* toExternalValue(bytesVal) // returns Uint8Array([72, 101, 108, 108, 111])
35+
* ```
36+
*/
37+
export function toExternalValue(val: uint64): bigint
38+
export function toExternalValue(val: biguint): bigint
39+
export function toExternalValue(val: bytes): Uint8Array
40+
export function toExternalValue(val: string): string
41+
export function toExternalValue(val: uint64 | biguint | bytes | string) {
42+
const instance = val as unknown
43+
if (instance instanceof BytesCls) return instance.asUint8Array()
44+
if (instance instanceof Uint64Cls) return instance.asBigInt()
45+
if (instance instanceof BigUintCls) return instance.asBigInt()
46+
if (typeof val === 'string') return val
47+
}
48+
949
export function* iterBigInt(start: bigint, end: bigint): Generator<bigint> {
1050
for (let i = start; i < end; i++) {
1151
yield BigInt(i)

0 commit comments

Comments
 (0)