Skip to content

Commit

Permalink
fix: Prevent webpack loading bindings when importing UTXOInput type (#…
Browse files Browse the repository at this point in the history
…990)

* fix: Prevent loading bindings when importing UtxoInput type. Constructs UtxoInput from outputId without callUtilsMethod.

* fix: Improve variable naming in UTXOInput.fromOutputId

* chore: Update changelog

* chore: Bump nodejs bindings version

* chore: Run prettier

* fix: Attach UTXOInput util method (fromOutputId) dynamically (prevent bindings loading when using type UTXOInput)
  • Loading branch information
msarcev authored Aug 8, 2023
1 parent 1225f4c commit ade9749
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
9 changes: 8 additions & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 1.0.4 - 2023-MM-DD
## 1.0.5 - YYYY-MM-DD


## 1.0.4 - 2023-08-03

### Changed

- Prevent loading of bindings when importing UTXOInput type (changed UTXOInput.fromOutputId implementation)

### Fixed

Expand Down
19 changes: 19 additions & 0 deletions bindings/nodejs/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// Needed for class-transformer json deserialisation
import 'reflect-metadata';
import { callUtilsMethod } from './bindings';
import { OutputId, UTXOInput } from './types';
import { bigIntToHex } from './utils';

// Allow bigint to be serialized as hex string.
Expand All @@ -14,6 +16,23 @@ import { bigIntToHex } from './utils';
return bigIntToHex(this);
};

// Assign the util method on UTXOInput here,
// to prevent loading bindings (callUtilsMethod) when importing UTXOInput just for typing.
Object.assign(UTXOInput, {
/**
* Creates a `UTXOInput` from an output id.
*/
fromOutputId(outputId: OutputId): UTXOInput {
const input = callUtilsMethod({
name: 'outputIdToUtxoInput',
data: {
outputId,
},
});
return new UTXOInput(input.transactionId, input.transactionOutputIndex);
},
});

export * from './client';
export * from './secret_manager';
export * from './types';
Expand Down
11 changes: 3 additions & 8 deletions bindings/nodejs/lib/types/block/input/input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { callUtilsMethod } from '../../../bindings';
import { HexEncodedString } from '../../utils';
import { OutputId } from '../output';

Expand Down Expand Up @@ -68,14 +67,10 @@ class UTXOInput extends Input {
/**
* Creates a `UTXOInput` from an output id.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
static fromOutputId(outputId: OutputId): UTXOInput {
const input = callUtilsMethod({
name: 'outputIdToUtxoInput',
data: {
outputId,
},
});
return new UTXOInput(input.transactionId, input.transactionOutputIndex);
// Implementation injected in lib/index.ts, as it uses bindings.
return null as unknown as UTXOInput;
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iota/sdk",
"version": "1.0.3",
"version": "1.0.4",
"description": "Node.js binding to the IOTA SDK library",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down

0 comments on commit ade9749

Please sign in to comment.