Skip to content

Commit 535393b

Browse files
committed
refactor: explicitly mark the items which should not be visible externally as internal
1 parent 49550e0 commit 535393b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+723
-254
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
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 -g dist/impl/*.d.ts dist/impl/**/*.d.ts dist/internal/*.d.ts",
19-
"build:5-copy-pkg-json": "tstk copy-package-json -c",
20-
"build:6-copy-readme": "copyfiles ./README.md ./dist",
18+
"build:4-copy-pkg-json": "tstk copy-package-json -c",
19+
"build:5-copy-readme": "copyfiles ./README.md ./dist",
2120
"watch": "rollup -c -w --configPlugin typescript",
2221
"test": "vitest run",
2322
"test:coverage": "vitest run --coverage",

src/abi-metadata.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { TypeInfo } from './impl/encoded-types'
66
import { getArc4TypeName } from './impl/encoded-types'
77
import type { DeliberateAny } from './typescript-helpers'
88

9+
/** @internal */
910
export interface AbiMetadata {
1011
methodName: string
1112
name?: string
@@ -18,6 +19,7 @@ export interface AbiMetadata {
1819
}
1920

2021
const metadataStore: WeakMap<{ new (): Contract }, Record<string, AbiMetadata>> = new WeakMap()
22+
/** @internal */
2123
export const attachAbiMetadata = (contract: { new (): Contract }, methodName: string, metadata: AbiMetadata): void => {
2224
if (!metadataStore.has(contract)) {
2325
metadataStore.set(contract, {})
@@ -31,6 +33,7 @@ export const attachAbiMetadata = (contract: { new (): Contract }, methodName: st
3133
}
3234
}
3335

36+
/** @internal */
3437
export const getContractAbiMetadata = <T extends Contract>(contract: T | { new (): T }): Record<string, AbiMetadata> => {
3538
// Initialize result object to store merged metadata
3639
const result: Record<string, AbiMetadata> = {}
@@ -63,11 +66,13 @@ export const getContractAbiMetadata = <T extends Contract>(contract: T | { new (
6366
return result
6467
}
6568

69+
/** @internal */
6670
export const getContractMethodAbiMetadata = <T extends Contract>(contract: T | { new (): T }, methodName: string): AbiMetadata => {
6771
const metadatas = getContractAbiMetadata(contract)
6872
return metadatas[methodName]
6973
}
7074

75+
/** @internal */
7176
export const getArc4Signature = (metadata: AbiMetadata): string => {
7277
if (metadata.methodSignature === undefined) {
7378
const argTypes = metadata.argTypes.map((t) => JSON.parse(t) as TypeInfo).map((t) => getArc4TypeName(t, metadata.resourceEncoding, 'in'))
@@ -77,6 +82,7 @@ export const getArc4Signature = (metadata: AbiMetadata): string => {
7782
return metadata.methodSignature
7883
}
7984

85+
/** @internal */
8086
export const getArc4Selector = (metadata: AbiMetadata): Uint8Array => {
8187
const hash = js_sha512.sha512_256.array(getArc4Signature(metadata))
8288
return new Uint8Array(hash.slice(0, 4))

src/collections/custom-key-map.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { Account } from '@algorandfoundation/algorand-typescript'
1+
import type { Account, BytesCompat, Uint64Compat } from '@algorandfoundation/algorand-typescript'
22
import { InternalError } from '../errors'
3-
import type { StubBytesCompat, StubUint64Compat } from '../impl/primitives'
43
import type { DeliberateAny } from '../typescript-helpers'
54
import { asBytesCls, asUint64Cls } from '../util'
65

@@ -75,13 +74,13 @@ export class AccountMap<TValue> extends CustomKeyMap<Account, TValue> {
7574
}
7675
}
7776

78-
export class BytesMap<TValue> extends CustomKeyMap<StubBytesCompat, TValue> {
77+
export class BytesMap<TValue> extends CustomKeyMap<BytesCompat, TValue> {
7978
constructor() {
8079
super((bytes) => asBytesCls(bytes).valueOf())
8180
}
8281
}
8382

84-
export class Uint64Map<TValue> extends CustomKeyMap<StubUint64Compat, TValue> {
83+
export class Uint64Map<TValue> extends CustomKeyMap<Uint64Compat, TValue> {
8584
constructor() {
8685
super((uint64) => asUint64Cls(uint64).valueOf())
8786
}

src/constants.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
import { Bytes, FixedBytes } from './impl/primitives'
22

3+
/** @internal */
34
export const UINT64_SIZE = 64
5+
/** @internal */
46
export const UINT512_SIZE = 512
7+
/** @internal */
58
export const MAX_UINT8 = 2 ** 8 - 1
9+
/** @internal */
610
export const MAX_UINT16 = 2 ** 16 - 1
11+
/** @internal */
712
export const MAX_UINT32 = 2 ** 32 - 1
13+
/** @internal */
814
export const MAX_UINT64 = 2n ** 64n - 1n
15+
/** @internal */
916
export const MAX_UINT128 = 2n ** 128n - 1n
17+
/** @internal */
1018
export const MAX_UINT256 = 2n ** 256n - 1n
19+
/** @internal */
1120
export const MAX_UINT512 = 2n ** 512n - 1n
21+
/** @internal */
1222
export const MAX_BYTES_SIZE = 4096
23+
/** @internal */
1324
export const MAX_LOG_SIZE = 1024
25+
/** @internal */
1426
export const MAX_ITEMS_IN_LOG = 32
27+
/** @internal */
1528
export const MAX_BOX_SIZE = 32768
29+
/** @internal */
1630
export const BITS_IN_BYTE = 8
31+
/** @internal */
1732
export const DEFAULT_ACCOUNT_MIN_BALANCE = 100_000
33+
/** @internal */
1834
export const DEFAULT_MAX_TXN_LIFE = 1_000
35+
/** @internal */
1936
export const DEFAULT_ASSET_CREATE_MIN_BALANCE = 1000_000
37+
/** @internal */
2038
export const DEFAULT_ASSET_OPT_IN_MIN_BALANCE = 10_000
2139

22-
// from python code: list(b"\x85Y\xb5\x14x\xfd\x89\xc1vC\xd0]\x15\xa8\xaek\x10\xabG\xbbm\x8a1\x88\x11V\xe6\xbd;\xae\x95\xd1")
40+
/** @internal
41+
* from python code: list(b"\x85Y\xb5\x14x\xfd\x89\xc1vC\xd0]\x15\xa8\xaek\x10\xabG\xbbm\x8a1\x88\x11V\xe6\xbd;\xae\x95\xd1")
42+
*/
2343
export const DEFAULT_GLOBAL_GENESIS_HASH = FixedBytes(
2444
32,
2545
new Uint8Array([
@@ -28,37 +48,55 @@ export const DEFAULT_GLOBAL_GENESIS_HASH = FixedBytes(
2848
]),
2949
)
3050

31-
// algorand encoded address of 32 zero bytes
51+
/** @internal
52+
* algorand encoded address of 32 zero bytes
53+
*/
3254
export const ZERO_ADDRESS = Bytes.fromBase32('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
3355

34-
/**
56+
/** @internal
3557
"\x09" # pragma version 9
3658
"\x81\x01" # pushint 1
3759
*/
3860
export const ALWAYS_APPROVE_TEAL_PROGRAM = Bytes(new Uint8Array([0x09, 0x81, 0x01]))
3961

40-
// bytes: program (logic) data prefix when signing
62+
/** @internal
63+
* bytes: program (logic) data prefix when signing
64+
*/
4165
export const LOGIC_DATA_PREFIX = Bytes('ProgData')
4266

43-
//number: minimum transaction fee
67+
/** @internal
68+
* number: minimum transaction fee
69+
*/
4470
export const MIN_TXN_FEE = 1000
4571

72+
/** @internal */
4673
export const ABI_RETURN_VALUE_LOG_PREFIX = Bytes.fromHex('151F7C75')
4774

75+
/** @internal */
4876
export const UINT64_OVERFLOW_UNDERFLOW_MESSAGE = 'Uint64 overflow or underflow'
77+
/** @internal */
4978
export const BIGUINT_OVERFLOW_UNDERFLOW_MESSAGE = 'BigUint overflow or underflow'
79+
/** @internal */
5080
export const DEFAULT_TEMPLATE_VAR_PREFIX = 'TMPL_'
5181

82+
/** @internal */
5283
export const APP_ID_PREFIX = 'appID'
84+
/** @internal */
5385
export const HASH_BYTES_LENGTH = 32
86+
/** @internal */
5487
export const ALGORAND_ADDRESS_BYTE_LENGTH = 36
88+
/** @internal */
5589
export const ALGORAND_CHECKSUM_BYTE_LENGTH = 4
90+
/** @internal */
5691
export const ALGORAND_ADDRESS_LENGTH = 58
5792

93+
/** @internal */
5894
export const PROGRAM_TAG = 'Program'
5995

96+
/** @internal */
6097
export const TRANSACTION_GROUP_MAX_SIZE = 16
6198

99+
/** @internal */
62100
export enum OnApplicationComplete {
63101
NoOpOC = 0,
64102
OptInOC = 1,
@@ -68,6 +106,7 @@ export enum OnApplicationComplete {
68106
DeleteApplicationOC = 5,
69107
}
70108

109+
/** @internal */
71110
export const ConventionalRouting = {
72111
methodNames: {
73112
closeOutOfApplication: 'closeOutOfApplication',

src/context-helpers/context-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { TestExecutionContext } from '../test-execution-context'
22

3+
/** @internal */
34
export class ContextManager {
45
private static _instance: TestExecutionContext | undefined
56

src/context-helpers/context-util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AssertError } from '../errors'
55
import { ApplicationCallTransaction } from '../impl/transactions'
66
import { lazyContext } from './internal-context'
77

8+
/** @internal */
89
export const checkRoutingConditions = (appId: uint64, metadata: AbiMetadata) => {
910
const appData = lazyContext.getApplicationData(appId)
1011
const isCreating = appData.isCreating

src/context-helpers/internal-context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class InternalContext {
6565
}
6666

6767
getApplicationData(id: StubUint64Compat | BaseContract): ApplicationData {
68-
const uint64Id = id instanceof BaseContract ? this.ledger.getApplicationForContract(id).id : Uint64Cls.fromCompat(id)
68+
const uint64Id = id instanceof BaseContract ? this.ledger.getApplicationForContract(id).id : Uint64Cls.fromCompat(id).asAlgoTs()
6969
const data = this.ledger.applicationDataMap.get(uint64Id)
7070
if (!data) {
7171
throw new InternalError('Unknown application, check correct testing context is active')
@@ -82,4 +82,5 @@ class InternalContext {
8282
}
8383
}
8484

85+
/** @internal */
8586
export const lazyContext = new InternalContext()

src/decode-logs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { btoi } from './impl/pure'
44
import { asNumber } from './util'
55

66
export type LogDecoding = 'i' | 's' | 'b'
7-
87
export type DecodedLog<T extends LogDecoding> = T extends 'i' ? bigint : T extends 's' ? string : Uint8Array
98
export type DecodedLogs<T extends [...LogDecoding[]]> = {
109
[Index in keyof T]: DecodedLog<T[Index]>
1110
} & { length: T['length'] }
1211

1312
const ABI_RETURN_VALUE_LOG_PREFIX_LENGTH = asNumber(ABI_RETURN_VALUE_LOG_PREFIX.length)
13+
/** @internal */
1414
export function decodeLogs<const T extends [...LogDecoding[]]>(logs: bytes[], decoding: T): DecodedLogs<T> {
1515
return logs.map((log, i) => {
1616
const value = log.slice(0, ABI_RETURN_VALUE_LOG_PREFIX_LENGTH).equals(ABI_RETURN_VALUE_LOG_PREFIX)

src/impl/acct-params.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getApp } from './app-params'
55
import { Global } from './global'
66
import type { StubUint64Compat } from './primitives'
77

8+
/** @internal */
89
export const getAccount = (acct: Account | StubUint64Compat): Account => {
910
const acctId = asMaybeUint64Cls(acct)
1011
if (acctId !== undefined) {
@@ -14,16 +15,19 @@ export const getAccount = (acct: Account | StubUint64Compat): Account => {
1415
return acct as Account
1516
}
1617

18+
/** @internal */
1719
export const balance = (a: Account | StubUint64Compat): uint64 => {
1820
const acct = getAccount(a)
1921
return acct.balance
2022
}
2123

24+
/** @internal */
2225
export const minBalance = (a: Account | StubUint64Compat): uint64 => {
2326
const acct = getAccount(a)
2427
return acct.minBalance
2528
}
2629

30+
/** @internal */
2731
export const appOptedIn = (a: Account | StubUint64Compat, b: Application | StubUint64Compat): boolean => {
2832
const account = getAccount(a)
2933
const app = getApp(b)
@@ -34,6 +38,7 @@ export const appOptedIn = (a: Account | StubUint64Compat, b: Application | StubU
3438
return account.isOptedIn(app)
3539
}
3640

41+
/** @internal */
3742
export const AcctParams: typeof op.AcctParams = {
3843
acctBalance(a: Account | StubUint64Compat): readonly [uint64, boolean] {
3944
const acct = getAccount(a)

src/impl/app-global.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import type { Application, bytes, op, uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type { Application, bytes, BytesCompat, op, uint64, Uint64Compat } from '@algorandfoundation/algorand-typescript'
22
import { lazyContext } from '../context-helpers/internal-context'
33
import { asBytes } from '../util'
44
import { getApp } from './app-params'
55
import { toBytes } from './encoded-types'
66
import { Bytes, Uint64, type StubBytesCompat, type StubUint64Compat } from './primitives'
77

8+
/** @internal */
89
export const AppGlobal: typeof op.AppGlobal = {
910
delete(a: StubBytesCompat): void {
10-
lazyContext.ledger.setGlobalState(lazyContext.activeApplication, a, undefined)
11+
lazyContext.ledger.setGlobalState(lazyContext.activeApplication, asBytes(a), undefined)
1112
},
1213
getBytes(a: StubBytesCompat): bytes {
1314
return this.getExBytes(0, asBytes(a))[0]
@@ -20,7 +21,7 @@ export const AppGlobal: typeof op.AppGlobal = {
2021
if (app === undefined) {
2122
return [Bytes(), false]
2223
}
23-
const [state, exists] = lazyContext.ledger.getGlobalState(app, b)
24+
const [state, exists] = lazyContext.ledger.getGlobalState(app, asBytes(b))
2425
if (!exists) {
2526
return [Bytes(), false]
2627
}
@@ -31,13 +32,13 @@ export const AppGlobal: typeof op.AppGlobal = {
3132
if (app === undefined) {
3233
return [Uint64(0), false]
3334
}
34-
const [state, exists] = lazyContext.ledger.getGlobalState(app, b)
35+
const [state, exists] = lazyContext.ledger.getGlobalState(app, asBytes(b))
3536
if (!exists) {
3637
return [Uint64(0), false]
3738
}
3839
return [state!.value as uint64, exists]
3940
},
4041
put(a: StubBytesCompat, b: StubUint64Compat | StubBytesCompat): void {
41-
lazyContext.ledger.setGlobalState(lazyContext.activeApplication, a, b)
42+
lazyContext.ledger.setGlobalState(lazyContext.activeApplication, asBytes(a), b as unknown as Uint64Compat | BytesCompat)
4243
},
4344
}

0 commit comments

Comments
 (0)