@radixdlt/actions
Advanced tools
Comparing version 1.0.4-alpha.0 to 1.0.6-alpha.0
@@ -8,19 +8,16 @@ import { AddressT } from '@radixdlt/account'; | ||
} | ||
export declare type UserAction = Readonly<{ | ||
actionType: UserActionType; | ||
export declare type UserAction<T> = Readonly<{ | ||
actionType: T; | ||
sender: AddressT; | ||
uuid: string; | ||
}>; | ||
export declare type TokensActionBase = UserAction & Readonly<{ | ||
export declare type TokensActionBase<T> = UserAction<T> & Readonly<{ | ||
amount: AmountT; | ||
resourceIdentifier: ResourceIdentifierT; | ||
}>; | ||
export declare type TransferTokensAction = TokensActionBase & Readonly<{ | ||
actionType: UserActionType.TOKEN_TRANSFER; | ||
export declare type TransferTokensActionT = TokensActionBase<UserActionType.TOKEN_TRANSFER> & Readonly<{ | ||
recipient: AddressT; | ||
message?: string; | ||
}>; | ||
export declare type BurnTokensAction = TokensActionBase & Readonly<{ | ||
actionType: UserActionType.BURN_TOKENS; | ||
}>; | ||
export declare type BurnTokensActionT = TokensActionBase<UserActionType.BURN_TOKENS>; | ||
export declare type TokensActionBaseInput = Readonly<{ | ||
@@ -27,0 +24,0 @@ amount: AmountT; |
@@ -1,3 +0,9 @@ | ||
import { BurnTokensAction, BurnTokensActionInput } from './_types'; | ||
export declare const burnTokensAction: (input: BurnTokensActionInput) => BurnTokensAction; | ||
import { BurnTokensActionT, BurnTokensActionInput } from './_types'; | ||
import { Decoder } from '@radixdlt/data-formats'; | ||
export declare const BurnTokensAction: { | ||
JSONDecoder: Decoder; | ||
fromJSON: (json: unknown) => import("neverthrow").Result<unknown, Error[]>; | ||
JSONDecoders: Decoder[]; | ||
create: (input: BurnTokensActionInput) => BurnTokensActionT; | ||
}; | ||
//# sourceMappingURL=burnTokensAction.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.burnTokensAction = void 0; | ||
exports.BurnTokensAction = void 0; | ||
const _types_1 = require("./_types"); | ||
const uuid_1 = require("uuid"); | ||
const burnTokensAction = (input) => { | ||
const data_formats_1 = require("@radixdlt/data-formats"); | ||
const atom_1 = require("@radixdlt/atom"); | ||
const primitives_1 = require("@radixdlt/primitives"); | ||
const account_1 = require("@radixdlt/account"); | ||
const util_1 = require("@radixdlt/util"); | ||
const neverthrow_1 = require("neverthrow"); | ||
const JSONDecoder = (value) => util_1.isObject(value) && value['type'] === _types_1.UserActionType.BURN_TOKENS | ||
? neverthrow_1.ok(create(value)) | ||
: undefined; | ||
const decoding = data_formats_1.JSONDecoding.withDependencies(atom_1.ResourceIdentifier, primitives_1.Amount, account_1.Address) | ||
.withDecoders(JSONDecoder) | ||
.create(); | ||
const create = (input) => { | ||
var _a; | ||
@@ -17,3 +29,3 @@ const uuid = (_a = input.uuid) !== null && _a !== void 0 ? _a : uuid_1.v4(); | ||
}; | ||
exports.burnTokensAction = burnTokensAction; | ||
exports.BurnTokensAction = Object.assign(Object.assign({ create }, decoding), { JSONDecoder }); | ||
//# sourceMappingURL=burnTokensAction.js.map |
@@ -1,3 +0,9 @@ | ||
import { TransferTokensAction, TransferTokensActionInput } from './_types'; | ||
export declare const transferTokensAction: (input: TransferTokensActionInput) => TransferTokensAction; | ||
import { TransferTokensActionT, TransferTokensActionInput } from './_types'; | ||
import { Decoder } from '@radixdlt/data-formats'; | ||
export declare const TransferTokensAction: { | ||
JSONDecoder: Decoder; | ||
fromJSON: (json: unknown) => import("neverthrow").Result<unknown, Error[]>; | ||
JSONDecoders: Decoder[]; | ||
create: (input: TransferTokensActionInput) => TransferTokensActionT; | ||
}; | ||
//# sourceMappingURL=transferTokensAction.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transferTokensAction = void 0; | ||
exports.TransferTokensAction = void 0; | ||
const _types_1 = require("./_types"); | ||
const uuid_1 = require("uuid"); | ||
const transferTokensAction = (input) => { | ||
const data_formats_1 = require("@radixdlt/data-formats"); | ||
const util_1 = require("@radixdlt/util"); | ||
const neverthrow_1 = require("neverthrow"); | ||
const atom_1 = require("@radixdlt/atom"); | ||
const primitives_1 = require("@radixdlt/primitives"); | ||
const account_1 = require("@radixdlt/account"); | ||
const JSONDecoder = (value) => util_1.isObject(value) && value['type'] === _types_1.UserActionType.TOKEN_TRANSFER | ||
? neverthrow_1.ok(create(value)) | ||
: undefined; | ||
const decoding = data_formats_1.JSONDecoding.withDependencies(atom_1.ResourceIdentifier, primitives_1.Amount, account_1.Address) | ||
.withDecoders(JSONDecoder) | ||
.create(); | ||
const create = (input) => { | ||
var _a; | ||
@@ -19,3 +31,3 @@ const uuid = (_a = input.uuid) !== null && _a !== void 0 ? _a : uuid_1.v4(); | ||
}; | ||
exports.transferTokensAction = transferTokensAction; | ||
exports.TransferTokensAction = Object.assign(Object.assign({ create }, decoding), { JSONDecoder }); | ||
//# sourceMappingURL=transferTokensAction.js.map |
{ | ||
"name": "@radixdlt/actions", | ||
"version": "1.0.4-alpha.0", | ||
"version": "1.0.6-alpha.0", | ||
"description": "Declare actions you as a user would like to perform e.g. 'transfer tokens' (`TransferTokensAction`)", | ||
@@ -23,5 +23,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@radixdlt/account": "^1.0.4-alpha.0", | ||
"@radixdlt/atom": "^1.0.4-alpha.0", | ||
"@radixdlt/primitives": "^1.0.4-alpha.0", | ||
"@radixdlt/account": "^1.0.6-alpha.0", | ||
"@radixdlt/atom": "^1.0.6-alpha.0", | ||
"@radixdlt/primitives": "^1.0.6-alpha.0", | ||
"@types/uuid": "^8.3.0", | ||
@@ -37,3 +37,3 @@ "neverthrow": "^4.0.1", | ||
}, | ||
"gitHead": "0547412dfaa4c75e787140b0f9c543b34c2edb00" | ||
"gitHead": "ff82b95b52d86e5ca1738a436d402435d6a49ba6" | ||
} |
export * from './_types' | ||
export * from './transferTokensAction' | ||
export * from './burnTokensAction' |
@@ -10,4 +10,4 @@ import { AddressT } from '@radixdlt/account' | ||
export type UserAction = Readonly<{ | ||
actionType: UserActionType | ||
export type UserAction<T> = Readonly<{ | ||
actionType: T | ||
sender: AddressT | ||
@@ -17,3 +17,3 @@ uuid: string | ||
export type TokensActionBase = UserAction & | ||
export type TokensActionBase<T> = UserAction<T> & | ||
Readonly<{ | ||
@@ -24,5 +24,4 @@ amount: AmountT | ||
export type TransferTokensAction = TokensActionBase & | ||
export type TransferTokensActionT = TokensActionBase<UserActionType.TOKEN_TRANSFER> & | ||
Readonly<{ | ||
actionType: UserActionType.TOKEN_TRANSFER | ||
recipient: AddressT | ||
@@ -32,6 +31,3 @@ message?: string | ||
export type BurnTokensAction = TokensActionBase & | ||
Readonly<{ | ||
actionType: UserActionType.BURN_TOKENS | ||
}> | ||
export type BurnTokensActionT = TokensActionBase<UserActionType.BURN_TOKENS> | ||
@@ -38,0 +34,0 @@ export type TokensActionBaseInput = Readonly<{ |
import { | ||
BurnTokensAction, | ||
BurnTokensActionT, | ||
BurnTokensActionInput, | ||
@@ -7,6 +7,23 @@ UserActionType, | ||
import { v4 as uuidv4 } from 'uuid' | ||
import { Decoder, JSONDecoding } from '@radixdlt/data-formats' | ||
import { ResourceIdentifier } from '@radixdlt/atom' | ||
import { Amount } from '@radixdlt/primitives' | ||
import { Address } from '@radixdlt/account' | ||
import { isObject } from '@radixdlt/util' | ||
import { ok } from 'neverthrow' | ||
export const burnTokensAction = ( | ||
input: BurnTokensActionInput, | ||
): BurnTokensAction => { | ||
const JSONDecoder: Decoder = (value) => | ||
isObject(value) && value['type'] === UserActionType.BURN_TOKENS | ||
? ok(create(value as BurnTokensActionInput)) | ||
: undefined | ||
const decoding = JSONDecoding.withDependencies( | ||
ResourceIdentifier, | ||
Amount, | ||
Address, | ||
) | ||
.withDecoders(JSONDecoder) | ||
.create() | ||
const create = (input: BurnTokensActionInput): BurnTokensActionT => { | ||
const uuid = input.uuid ?? uuidv4() | ||
@@ -22,1 +39,7 @@ | ||
} | ||
export const BurnTokensAction = { | ||
create, | ||
...decoding, | ||
JSONDecoder, | ||
} |
import { | ||
TransferTokensAction, | ||
TransferTokensActionT, | ||
TransferTokensActionInput, | ||
@@ -7,6 +7,23 @@ UserActionType, | ||
import { v4 as uuidv4 } from 'uuid' | ||
import { Decoder, JSONDecoding } from '@radixdlt/data-formats' | ||
import { isObject } from '@radixdlt/util' | ||
import { ok } from 'neverthrow' | ||
import { ResourceIdentifier } from '@radixdlt/atom' | ||
import { Amount } from '@radixdlt/primitives' | ||
import { Address } from '@radixdlt/account' | ||
export const transferTokensAction = ( | ||
input: TransferTokensActionInput, | ||
): TransferTokensAction => { | ||
const JSONDecoder: Decoder = (value) => | ||
isObject(value) && value['type'] === UserActionType.TOKEN_TRANSFER | ||
? ok(create(value as TransferTokensActionInput)) | ||
: undefined | ||
const decoding = JSONDecoding.withDependencies( | ||
ResourceIdentifier, | ||
Amount, | ||
Address, | ||
) | ||
.withDecoders(JSONDecoder) | ||
.create() | ||
const create = (input: TransferTokensActionInput): TransferTokensActionT => { | ||
const uuid = input.uuid ?? uuidv4() | ||
@@ -24,1 +41,7 @@ | ||
} | ||
export const TransferTokensAction = { | ||
create, | ||
...decoding, | ||
JSONDecoder, | ||
} |
@@ -1,5 +0,5 @@ | ||
import { addressFromBase58String } from '@radixdlt/account' | ||
import { Address } from '@radixdlt/account' | ||
import { Denomination, zero } from '@radixdlt/primitives' | ||
import { BurnTokensActionInput } from '../src/_types' | ||
import { burnTokensAction } from '../src/burnTokensAction' | ||
import { BurnTokensAction } from '../src/burnTokensAction' | ||
import { Amount } from '@radixdlt/primitives/src/amount' | ||
@@ -9,3 +9,3 @@ import { ResourceIdentifier } from '@radixdlt/atom' | ||
describe('BurnTokensAction', () => { | ||
const alice = addressFromBase58String( | ||
const alice = Address.fromBase58String( | ||
'9S8khLHZa6FsyGo634xQo9QwLgSHGpXHHW764D5mPYBcrnfZV6RT', | ||
@@ -27,3 +27,3 @@ )._unsafeUnwrap() | ||
it('should be possible to burn 0 tokens', () => { | ||
const burnAction = burnTokensAction({ ...input, amount: zero }) | ||
const burnAction = BurnTokensAction.create({ ...input, amount: zero }) | ||
expect(burnAction.amount.equals(zero)).toBe(true) | ||
@@ -33,3 +33,3 @@ }) | ||
it(`should have a 'sender' equal to 'input.burner'.`, () => { | ||
const burnTokens = burnTokensAction({ | ||
const burnTokens = BurnTokensAction.create({ | ||
...input, | ||
@@ -42,3 +42,3 @@ burner: alice, | ||
it(`should have an 'amount' equal to 'input.amount'.`, () => { | ||
const burnTokens = burnTokensAction(input) | ||
const burnTokens = BurnTokensAction.create(input) | ||
expect(burnTokens.amount.equals(amount)).toBe(true) | ||
@@ -48,3 +48,3 @@ }) | ||
it('should generate a UUID if none is provided.', () => { | ||
const burnTokens = burnTokensAction(input) | ||
const burnTokens = BurnTokensAction.create(input) | ||
expect(burnTokens.uuid).toBeTruthy() | ||
@@ -55,5 +55,5 @@ }) | ||
const uuid = 'randomly generated string' | ||
const burnTokens = burnTokensAction({ ...input, uuid }) | ||
const burnTokens = BurnTokensAction.create({ ...input, uuid }) | ||
expect(burnTokens.uuid).toBe(uuid) | ||
}) | ||
}) |
@@ -1,4 +0,4 @@ | ||
import { addressFromBase58String } from '@radixdlt/account' | ||
import { Address } from '@radixdlt/account' | ||
import { Denomination } from '@radixdlt/primitives' | ||
import { transferTokensAction } from '../src/transferTokensAction' | ||
import { TransferTokensAction } from '../src/transferTokensAction' | ||
import { TransferTokensActionInput } from '../src/_types' | ||
@@ -9,7 +9,7 @@ import { Amount, zero } from '@radixdlt/primitives/src/amount' | ||
describe('TransferTokensActions', () => { | ||
const alice = addressFromBase58String( | ||
const alice = Address.fromBase58String( | ||
'9S8khLHZa6FsyGo634xQo9QwLgSHGpXHHW764D5mPYBcrnfZV6RT', | ||
)._unsafeUnwrap() | ||
const bob = addressFromBase58String( | ||
const bob = Address.fromBase58String( | ||
'9S9LHeQNFpNJYqLtTJeAbos1LCC5Q7HBiGwPf2oju3NRq5MBKAGt', | ||
@@ -34,3 +34,3 @@ )._unsafeUnwrap() | ||
it(`should have a 'recipient' equal to 'input.to'.`, () => { | ||
const tokenTransfer = transferTokensAction({ | ||
const tokenTransfer = TransferTokensAction.create({ | ||
...input, | ||
@@ -43,3 +43,3 @@ to: bob, | ||
it(`should have an 'amount' equal to 'input.amount'.`, () => { | ||
const tokenTransfer = transferTokensAction(input) | ||
const tokenTransfer = TransferTokensAction.create(input) | ||
expect(tokenTransfer.amount.equals(amount)).toBe(true) | ||
@@ -49,3 +49,3 @@ }) | ||
it(`should have a 'sender' equal to 'input.from'.`, () => { | ||
const tokenTransfer = transferTokensAction({ | ||
const tokenTransfer = TransferTokensAction.create({ | ||
...input, | ||
@@ -58,3 +58,3 @@ from: alice, | ||
it('should be able to skip message.', () => { | ||
const tokenTransfer = transferTokensAction(input) | ||
const tokenTransfer = TransferTokensAction.create(input) | ||
expect(tokenTransfer).toBeDefined() | ||
@@ -65,3 +65,3 @@ expect(tokenTransfer.message).toBeUndefined() | ||
it('should be able to include a message.', () => { | ||
const tokenTransfer = transferTokensAction({ | ||
const tokenTransfer = TransferTokensAction.create({ | ||
...input, | ||
@@ -74,3 +74,3 @@ message: message, | ||
it('should generate a UUID if none is provided.', () => { | ||
const tokenTransfer = transferTokensAction(input) | ||
const tokenTransfer = TransferTokensAction.create(input) | ||
expect(tokenTransfer.uuid).toBeTruthy() | ||
@@ -81,3 +81,3 @@ }) | ||
const uuid = 'randomly generated string' | ||
const tokenTransfer = transferTokensAction({ | ||
const tokenTransfer = TransferTokensAction.create({ | ||
...input, | ||
@@ -90,3 +90,3 @@ uuid, | ||
it('should be possible to transfer 0 tokens', () => { | ||
const tokenTransfer = transferTokensAction({ | ||
const tokenTransfer = TransferTokensAction.create({ | ||
...input, | ||
@@ -93,0 +93,0 @@ amount: zero, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
266202
393
1
+ Added@radixdlt/atom@1.0.6-alpha.0(transitive)
- Removed@radixdlt/atom@1.0.4-alpha.0(transitive)