New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mysten/bcs

Package Overview
Dependencies
Maintainers
4
Versions
539
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mysten/bcs - npm Package Compare versions

Comparing version

to
0.0.0-experimental-20231204220336

8

CHANGELOG.md
# Change Log
## 0.0.0-experimental-20231012213307
## 0.0.0-experimental-20231204220336
### Minor Changes
- fce0a08d0f: Deprecate the bcs.generic helper. This helper causes typescript performance issues, and the generated generics can't be exported
## 0.8.1
### Patch Changes

@@ -6,0 +12,0 @@

20

dist/bcs.d.ts

@@ -146,10 +146,14 @@ import { BcsType, BcsTypeOptions } from './bcs-type.js';

/**
* Creates a helper function representing a generic type. This method returns
* a function that can be used to create concrete version of the generic type.
* @param names The names of the generic parameters
* @param cb A callback that returns the generic type
* @example
* const MyStruct = bcs.generic(['T'], (T) => bcs.struct('MyStruct', { inner: T }))
* MyStruct(bcs.u8()).serialize({ inner: 1 }).toBytes() // Uint8Array [ 1 ]
* MyStruct(bcs.string()).serialize({ inner: 'a' }).toBytes() // Uint8Array [ 1, 97 ]
* @deprecated
*
* Generics should be implemented as generic typescript functions instead:
*
* ```ts
* function VecMap<K, V>, (K: BcsType<K>, V: BcsType<V>) {
* return bcs.struct('VecMap<K, V>', {
* keys: bcs.vector(K),
* values: bcs.vector(V),
* })
* }
* ```
*/

@@ -156,0 +160,0 @@ generic<const Names extends readonly string[], const Type extends BcsType<any, any>>(names: Names, cb: (...types: { [K_13 in keyof Names]: BcsType<GenericPlaceholder<Names[K_13]>, GenericPlaceholder<Names[K_13]>>; }) => Type): <T_10 extends { [K_14 in keyof Names]: BcsType<any, any>; }>(...types: T_10) => ReplaceBcsGenerics<Type, Names, T_10>;

@@ -440,10 +440,14 @@ // Copyright (c) Mysten Labs, Inc.

/**
* Creates a helper function representing a generic type. This method returns
* a function that can be used to create concrete version of the generic type.
* @param names The names of the generic parameters
* @param cb A callback that returns the generic type
* @example
* const MyStruct = bcs.generic(['T'], (T) => bcs.struct('MyStruct', { inner: T }))
* MyStruct(bcs.u8()).serialize({ inner: 1 }).toBytes() // Uint8Array [ 1 ]
* MyStruct(bcs.string()).serialize({ inner: 'a' }).toBytes() // Uint8Array [ 1, 97 ]
* @deprecated
*
* Generics should be implemented as generic typescript functions instead:
*
* ```ts
* function VecMap<K, V>, (K: BcsType<K>, V: BcsType<V>) {
* return bcs.struct('VecMap<K, V>', {
* keys: bcs.vector(K),
* values: bcs.vector(V),
* })
* }
* ```
*/

@@ -450,0 +454,0 @@ generic(names, cb) {

@@ -1109,10 +1109,14 @@ "use strict";

/**
* Creates a helper function representing a generic type. This method returns
* a function that can be used to create concrete version of the generic type.
* @param names The names of the generic parameters
* @param cb A callback that returns the generic type
* @example
* const MyStruct = bcs.generic(['T'], (T) => bcs.struct('MyStruct', { inner: T }))
* MyStruct(bcs.u8()).serialize({ inner: 1 }).toBytes() // Uint8Array [ 1 ]
* MyStruct(bcs.string()).serialize({ inner: 'a' }).toBytes() // Uint8Array [ 1, 97 ]
* @deprecated
*
* Generics should be implemented as generic typescript functions instead:
*
* ```ts
* function VecMap<K, V>, (K: BcsType<K>, V: BcsType<V>) {
* return bcs.struct('VecMap<K, V>', {
* keys: bcs.vector(K),
* values: bcs.vector(V),
* })
* }
* ```
*/

@@ -1119,0 +1123,0 @@ generic(names, cb) {

{
"name": "@mysten/bcs",
"version": "0.0.0-experimental-20231012213307",
"version": "0.0.0-experimental-20231204220336",
"description": "BCS - Canonical Binary Serialization implementation for JavaScript",

@@ -10,6 +10,6 @@ "license": "Apache-2.0",

"types": "./dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"source": "./src/index.ts",
"import": "./dist/index.mjs",

@@ -19,3 +19,2 @@ "require": "./dist/index.js"

},
"sideEffects": false,
"files": [

@@ -22,0 +21,0 @@ "dist",

@@ -186,16 +186,15 @@ # BCS - Binary Canonical Serialization

To define a generic struct or an enum, you can use `bcs.generic` to create a generic type helper
To define a generic struct or an enum, you can define a generic typescript function helper
```ts
// Example: Generics
import { bcs } from '@mysten/bcs';
import { bcs, BcsType } from '@mysten/bcs';
// Container -> the name of the type
// [T] -> A list of names for the generic types
// The second argument is a function that takes the generic types as arguments and returns a bcs type
const Container = bcs.generic(['T'], (T) =>
bcs.struct('Container<T>', {
// The T typescript generic is a placeholder for the typescript type of the generic value
// The T argument will be the bcs type passed in when creating a concrete instance of the Container type
function Container<T>(T: BcsType<T>) {
return bcs.struct('Container<T>', {
contents: T,
}),
);
}

@@ -210,10 +209,14 @@ // When serializing, we have to pass the type to use for `T`

// Using multiple generics
function VecMap<K, V>, (K: BcsType<K>, V: BcsType<V>) {
// You can use the names of the generic params in the type name to
return bcs.struct(
// You can use the names of the generic params to give your type a more useful name
`VecMap<${K.name}, ${V.name}>`,
{
keys: bcs.vector(K),
values: bcs.vector(V),
}
)
}
const VecMap = bcs.generic(['K', 'V'], (K, V) =>
bcs.struct('VecMap<K, V>', {
keys: bcs.vector(K),
values: bcs.vector(V),
}),
);
// To serialize VecMap, we can use:

@@ -220,0 +223,0 @@ VecMap(bcs.string(), bcs.string())

@@ -552,10 +552,14 @@ // Copyright (c) Mysten Labs, Inc.

/**
* Creates a helper function representing a generic type. This method returns
* a function that can be used to create concrete version of the generic type.
* @param names The names of the generic parameters
* @param cb A callback that returns the generic type
* @example
* const MyStruct = bcs.generic(['T'], (T) => bcs.struct('MyStruct', { inner: T }))
* MyStruct(bcs.u8()).serialize({ inner: 1 }).toBytes() // Uint8Array [ 1 ]
* MyStruct(bcs.string()).serialize({ inner: 'a' }).toBytes() // Uint8Array [ 1, 97 ]
* @deprecated
*
* Generics should be implemented as generic typescript functions instead:
*
* ```ts
* function VecMap<K, V>, (K: BcsType<K>, V: BcsType<V>) {
* return bcs.struct('VecMap<K, V>', {
* keys: bcs.vector(K),
* values: bcs.vector(V),
* })
* }
* ```
*/

@@ -562,0 +566,0 @@ generic<const Names extends readonly string[], const Type extends BcsType<any>>(

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