@solana/codecs-data-structures 2.0.0-canary-20240731173615
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +728 -0
- package/dist/index.browser.cjs +709 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +653 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.native.mjs +653 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/index.node.cjs +709 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +653 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/types/array.d.ts +62 -0
- package/dist/types/array.d.ts.map +1 -0
- package/dist/types/assertions.d.ts +3 -0
- package/dist/types/assertions.d.ts.map +1 -0
- package/dist/types/bit-array.d.ts +31 -0
- package/dist/types/bit-array.d.ts.map +1 -0
- package/dist/types/boolean.d.ts +41 -0
- package/dist/types/boolean.d.ts.map +1 -0
- package/dist/types/bytes.d.ts +23 -0
- package/dist/types/bytes.d.ts.map +1 -0
- package/dist/types/constant.d.ts +16 -0
- package/dist/types/constant.d.ts.map +1 -0
- package/dist/types/discriminated-union.d.ts +97 -0
- package/dist/types/discriminated-union.d.ts.map +1 -0
- package/dist/types/enum-helpers.d.ts +51 -0
- package/dist/types/enum-helpers.d.ts.map +1 -0
- package/dist/types/enum.d.ts +57 -0
- package/dist/types/enum.d.ts.map +1 -0
- package/dist/types/hidden-prefix.d.ts +20 -0
- package/dist/types/hidden-prefix.d.ts.map +1 -0
- package/dist/types/hidden-suffix.d.ts +20 -0
- package/dist/types/hidden-suffix.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/map.d.ts +54 -0
- package/dist/types/map.d.ts.map +1 -0
- package/dist/types/nullable.d.ts +95 -0
- package/dist/types/nullable.d.ts.map +1 -0
- package/dist/types/set.d.ts +51 -0
- package/dist/types/set.d.ts.map +1 -0
- package/dist/types/struct.d.ts +33 -0
- package/dist/types/struct.d.ts.map +1 -0
- package/dist/types/tuple.d.ts +31 -0
- package/dist/types/tuple.d.ts.map +1 -0
- package/dist/types/union.d.ts +32 -0
- package/dist/types/union.d.ts.map +1 -0
- package/dist/types/unit.d.ts +14 -0
- package/dist/types/unit.d.ts.map +1 -0
- package/dist/types/utils.d.ts +24 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the "lookup object" of an enum.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* enum Direction { Left, Right };
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export type EnumLookupObject = {
|
|
10
|
+
[key: string]: number | string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Returns the allowed input for an enum.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* enum Direction { Left, Right };
|
|
18
|
+
* type DirectionInput = GetEnumFrom<Direction>; // "Left" | "Right" | 0 | 1
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type GetEnumFrom<TEnum extends EnumLookupObject> = TEnum[keyof TEnum] | keyof TEnum;
|
|
22
|
+
/**
|
|
23
|
+
* Returns all the available variants of an enum.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* enum Direction { Left, Right };
|
|
28
|
+
* type DirectionOutput = GetEnumTo<Direction>; // 0 | 1
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export type GetEnumTo<TEnum extends EnumLookupObject> = TEnum[keyof TEnum];
|
|
32
|
+
export declare function getEnumStats(constructor: EnumLookupObject): {
|
|
33
|
+
enumKeys: string[];
|
|
34
|
+
enumRecord: Record<string, string | number>;
|
|
35
|
+
enumValues: (string | number)[];
|
|
36
|
+
numericalValues: number[];
|
|
37
|
+
stringValues: string[];
|
|
38
|
+
};
|
|
39
|
+
export declare function getEnumIndexFromVariant({ enumKeys, enumValues, variant, }: {
|
|
40
|
+
enumKeys: string[];
|
|
41
|
+
enumValues: (number | string)[];
|
|
42
|
+
variant: number | string | symbol;
|
|
43
|
+
}): number;
|
|
44
|
+
export declare function getEnumIndexFromDiscriminator({ discriminator, enumKeys, enumValues, useValuesAsDiscriminators, }: {
|
|
45
|
+
discriminator: number;
|
|
46
|
+
enumKeys: string[];
|
|
47
|
+
enumValues: (number | string)[];
|
|
48
|
+
useValuesAsDiscriminators: boolean;
|
|
49
|
+
}): number;
|
|
50
|
+
export declare function formatNumericalValues(values: number[]): string;
|
|
51
|
+
//# sourceMappingURL=enum-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-helpers.d.ts","sourceRoot":"","sources":["../../src/enum-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CAAC,KAAK,SAAS,gBAAgB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,MAAM,KAAK,CAAC;AAE3F;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,gBAAgB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;AAE3E,wBAAgB,YAAY,CAAC,WAAW,EAAE,gBAAgB;;;;;;EAezD;AAED,wBAAgB,uBAAuB,CAAC,EACpC,QAAQ,EACR,UAAU,EACV,OAAO,GACV,EAAE;IACC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CACrC,GAAG,MAAM,CAIT;AAED,wBAAgB,6BAA6B,CAAC,EAC1C,aAAa,EACb,QAAQ,EACR,UAAU,EACV,yBAAyB,GAC5B,EAAE;IACC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChC,yBAAyB,EAAE,OAAO,CAAC;CACtC,GAAG,MAAM,CAKT;AAUD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAe9D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
import { FixedSizeNumberCodec, FixedSizeNumberDecoder, FixedSizeNumberEncoder, NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
|
|
3
|
+
import { EnumLookupObject, GetEnumFrom, GetEnumTo } from './enum-helpers';
|
|
4
|
+
/** Defines the config for enum codecs. */
|
|
5
|
+
export type EnumCodecConfig<TDiscriminator extends NumberCodec | NumberDecoder | NumberEncoder> = {
|
|
6
|
+
/**
|
|
7
|
+
* The codec to use for the enum discriminator.
|
|
8
|
+
* @defaultValue u8 discriminator.
|
|
9
|
+
*/
|
|
10
|
+
size?: TDiscriminator;
|
|
11
|
+
/**
|
|
12
|
+
* When set to `true`, numeric values will be used as discriminantors and
|
|
13
|
+
* an error will be thrown if a string value is found on the enum.
|
|
14
|
+
* @defaultValue `false`
|
|
15
|
+
*/
|
|
16
|
+
useValuesAsDiscriminators?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Creates an enum encoder.
|
|
20
|
+
*
|
|
21
|
+
* @param constructor - The constructor of the enum.
|
|
22
|
+
* @param config - A set of config for the encoder.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEnumEncoder<TEnum extends EnumLookupObject>(constructor: TEnum, config?: Omit<EnumCodecConfig<NumberEncoder>, 'size'>): FixedSizeEncoder<GetEnumFrom<TEnum>, 1>;
|
|
25
|
+
export declare function getEnumEncoder<TEnum extends EnumLookupObject, TSize extends number>(constructor: TEnum, config: EnumCodecConfig<NumberEncoder> & {
|
|
26
|
+
size: FixedSizeNumberEncoder<TSize>;
|
|
27
|
+
}): FixedSizeEncoder<GetEnumFrom<TEnum>, TSize>;
|
|
28
|
+
export declare function getEnumEncoder<TEnum extends EnumLookupObject>(constructor: TEnum, config?: EnumCodecConfig<NumberEncoder>): VariableSizeEncoder<GetEnumFrom<TEnum>>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an enum decoder.
|
|
31
|
+
*
|
|
32
|
+
* @param constructor - The constructor of the enum.
|
|
33
|
+
* @param config - A set of config for the decoder.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getEnumDecoder<TEnum extends EnumLookupObject>(constructor: TEnum, config?: Omit<EnumCodecConfig<NumberDecoder>, 'size'>): FixedSizeDecoder<GetEnumTo<TEnum>, 1>;
|
|
36
|
+
export declare function getEnumDecoder<TEnum extends EnumLookupObject, TSize extends number>(constructor: TEnum, config: EnumCodecConfig<NumberDecoder> & {
|
|
37
|
+
size: FixedSizeNumberDecoder<TSize>;
|
|
38
|
+
}): FixedSizeDecoder<GetEnumTo<TEnum>, TSize>;
|
|
39
|
+
export declare function getEnumDecoder<TEnum extends EnumLookupObject>(constructor: TEnum, config?: EnumCodecConfig<NumberDecoder>): VariableSizeDecoder<GetEnumTo<TEnum>>;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an enum codec.
|
|
42
|
+
*
|
|
43
|
+
* @param constructor - The constructor of the enum.
|
|
44
|
+
* @param config - A set of config for the codec.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getEnumCodec<TEnum extends EnumLookupObject>(constructor: TEnum, config?: Omit<EnumCodecConfig<NumberCodec>, 'size'>): FixedSizeCodec<GetEnumFrom<TEnum>, GetEnumTo<TEnum>, 1>;
|
|
47
|
+
export declare function getEnumCodec<TEnum extends EnumLookupObject, TSize extends number>(constructor: TEnum, config: EnumCodecConfig<NumberCodec> & {
|
|
48
|
+
size: FixedSizeNumberCodec<TSize>;
|
|
49
|
+
}): FixedSizeCodec<GetEnumFrom<TEnum>, GetEnumTo<TEnum>, TSize>;
|
|
50
|
+
export declare function getEnumCodec<TEnum extends EnumLookupObject>(constructor: TEnum, config?: EnumCodecConfig<NumberCodec>): VariableSizeCodec<GetEnumFrom<TEnum>, GetEnumTo<TEnum>>;
|
|
51
|
+
/** @deprecated Use `getEnumEncoder` instead. */
|
|
52
|
+
export declare const getScalarEnumEncoder: typeof getEnumEncoder;
|
|
53
|
+
/** @deprecated Use `getEnumDecoder` instead. */
|
|
54
|
+
export declare const getScalarEnumDecoder: typeof getEnumDecoder;
|
|
55
|
+
/** @deprecated Use `getEnumCodec` instead. */
|
|
56
|
+
export declare const getScalarEnumCodec: typeof getEnumCodec;
|
|
57
|
+
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACH,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EAGtB,WAAW,EACX,aAAa,EACb,aAAa,EAChB,MAAM,wBAAwB,CAAC;AAQhC,OAAO,EACH,gBAAgB,EAEhB,WAAW,EAIX,SAAS,EACZ,MAAM,gBAAgB,CAAC;AAExB,0CAA0C;AAC1C,MAAM,MAAM,eAAe,CAAC,cAAc,SAAS,WAAW,GAAG,aAAa,GAAG,aAAa,IAAI;IAC9F;;;OAGG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;I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oder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
/**
|
|
3
|
+
* Prefixes a given encoder with a list of void encoders.
|
|
4
|
+
* All void encoders are hidden from the returned encoder.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getHiddenPrefixEncoder<TFrom>(encoder: FixedSizeEncoder<TFrom>, prefixedEncoders: readonly FixedSizeEncoder<void>[]): FixedSizeEncoder<TFrom>;
|
|
7
|
+
export declare function getHiddenPrefixEncoder<TFrom>(encoder: Encoder<TFrom>, prefixedEncoders: readonly Encoder<void>[]): VariableSizeEncoder<TFrom>;
|
|
8
|
+
/**
|
|
9
|
+
* Prefixes a given decoder with a list of void decoder.
|
|
10
|
+
* All void decoder are hidden from the returned decoder.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getHiddenPrefixDecoder<TTo>(decoder: FixedSizeDecoder<TTo>, prefixedDecoders: readonly FixedSizeDecoder<void>[]): FixedSizeDecoder<TTo>;
|
|
13
|
+
export declare function getHiddenPrefixDecoder<TTo>(decoder: Decoder<TTo>, prefixedDecoders: readonly Decoder<void>[]): VariableSizeDecoder<TTo>;
|
|
14
|
+
/**
|
|
15
|
+
* Prefixes a given codec with a list of void codec.
|
|
16
|
+
* All void codec are hidden from the returned codec.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getHiddenPrefixCodec<TFrom, TTo extends TFrom>(codec: FixedSizeCodec<TFrom, TTo>, prefixedCodecs: readonly FixedSizeCodec<void>[]): FixedSizeCodec<TFrom, TTo>;
|
|
19
|
+
export declare function getHiddenPrefixCodec<TFrom, TTo extends TFrom>(codec: Codec<TFrom, TTo>, prefixedCodecs: readonly Codec<void>[]): VariableSizeCodec<TFrom, TTo>;
|
|
20
|
+
//# sourceMappingURL=hidden-prefix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hidden-prefix.d.ts","sourceRoot":"","sources":["../../src/hidden-prefix.ts"],"names":[],"mappings":"AAA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,cAAc,EAAE,SAAS,KAAK,CAAC,IAAI,CAAC,EAAE,GACvC,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
/**
|
|
3
|
+
* Suffixes a given encoder with a list of void encoders.
|
|
4
|
+
* All void encoders are hidden from the returned encoder.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getHiddenSuffixEncoder<TFrom>(encoder: FixedSizeEncoder<TFrom>, suffixedEncoders: readonly FixedSizeEncoder<void>[]): FixedSizeEncoder<TFrom>;
|
|
7
|
+
export declare function getHiddenSuffixEncoder<TFrom>(encoder: Encoder<TFrom>, suffixedEncoders: readonly Encoder<void>[]): VariableSizeEncoder<TFrom>;
|
|
8
|
+
/**
|
|
9
|
+
* Suffixes a given decoder with a list of void decoder.
|
|
10
|
+
* All void decoder are hidden from the returned decoder.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getHiddenSuffixDecoder<TTo>(decoder: FixedSizeDecoder<TTo>, suffixedDecoders: readonly FixedSizeDecoder<void>[]): FixedSizeDecoder<TTo>;
|
|
13
|
+
export declare function getHiddenSuffixDecoder<TTo>(decoder: Decoder<TTo>, suffixedDecoders: readonly Decoder<void>[]): VariableSizeDecoder<TTo>;
|
|
14
|
+
/**
|
|
15
|
+
* Suffixes a given codec with a list of void codec.
|
|
16
|
+
* All void codec are hidden from the returned codec.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getHiddenSuffixCodec<TFrom, TTo extends TFrom>(codec: FixedSizeCodec<TFrom, TTo>, suffixedCodecs: readonly FixedSizeCodec<void>[]): FixedSizeCodec<TFrom, TTo>;
|
|
19
|
+
export declare function getHiddenSuffixCodec<TFrom, TTo extends TFrom>(codec: Codec<TFrom, TTo>, suffixedCodecs: readonly Codec<void>[]): VariableSizeCodec<TFrom, TTo>;
|
|
20
|
+
//# sourceMappingURL=hidden-suffix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hidden-suffix.d.ts","sourceRoot":"","sources":["../../src/hidden-suffix.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAEL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,qBAAqB,CAAC;AAI7B;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EACxC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAChC,gBAAgB,EAAE,SAAS,gBAAgB,CAAC,IAAI,CAAC,EAAE,GACpD,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC3B,wBAAgB,sBAAsB,CAAC,KAAK,EACxC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,gBAAgB,EAAE,SAAS,OAAO,CAAC,IAAI,CAAC,EAAE,GAC3C,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAW9B;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EACtC,OAAO,EAAE,gBAAgB,CAAC,GAAG,CAAC,EAC9B,gBAAgB,EAAE,SAAS,gBAAgB,CAAC,IAAI,CAAC,EAAE,GACpD,gBAAgB,CAAC,GAAG,CAAC,CAAC;AACzB,wBAAgB,sBAAsB,CAAC,GAAG,EACtC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,gBAAgB,EAAE,SAAS,OAAO,CAAC,IAAI,CAAC,EAAE,GAC3C,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAW5B;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EACzD,KAAK,EAAE,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,EACjC,cAAc,EAAE,SAAS,cAAc,CAAC,IAAI,CAAC,EAAE,GAChD,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC9B,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EACzD,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EACxB,cAAc,EAAE,SAAS,KAAK,CAAC,IAAI,CAAC,EAAE,GACvC,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './array';
|
|
2
|
+
export * from './assertions';
|
|
3
|
+
export * from './bit-array';
|
|
4
|
+
export * from './boolean';
|
|
5
|
+
export * from './bytes';
|
|
6
|
+
export * from './constant';
|
|
7
|
+
export * from './discriminated-union';
|
|
8
|
+
export * from './enum';
|
|
9
|
+
export * from './hidden-prefix';
|
|
10
|
+
export * from './hidden-suffix';
|
|
11
|
+
export * from './map';
|
|
12
|
+
export * from './nullable';
|
|
13
|
+
export * from './set';
|
|
14
|
+
export * from './struct';
|
|
15
|
+
export * from './tuple';
|
|
16
|
+
export * from './union';
|
|
17
|
+
export * from './unit';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
import { NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
|
|
3
|
+
import { ArrayLikeCodecSize } from './array';
|
|
4
|
+
/** Defines the config for Map codecs. */
|
|
5
|
+
export type MapCodecConfig<TPrefix extends NumberCodec | NumberDecoder | NumberEncoder> = {
|
|
6
|
+
/**
|
|
7
|
+
* The size of the array.
|
|
8
|
+
* @defaultValue u32 prefix.
|
|
9
|
+
*/
|
|
10
|
+
size?: ArrayLikeCodecSize<TPrefix>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates a encoder for a map.
|
|
14
|
+
*
|
|
15
|
+
* @param key - The encoder to use for the map's keys.
|
|
16
|
+
* @param value - The encoder to use for the map's values.
|
|
17
|
+
* @param config - A set of config for the encoder.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getMapEncoder<TFromKey, TFromValue>(key: Encoder<TFromKey>, value: Encoder<TFromValue>, config: MapCodecConfig<NumberEncoder> & {
|
|
20
|
+
size: 0;
|
|
21
|
+
}): FixedSizeEncoder<Map<TFromKey, TFromValue>, 0>;
|
|
22
|
+
export declare function getMapEncoder<TFromKey, TFromValue>(key: FixedSizeEncoder<TFromKey>, value: FixedSizeEncoder<TFromValue>, config: MapCodecConfig<NumberEncoder> & {
|
|
23
|
+
size: number;
|
|
24
|
+
}): FixedSizeEncoder<Map<TFromKey, TFromValue>>;
|
|
25
|
+
export declare function getMapEncoder<TFromKey, TFromValue>(key: Encoder<TFromKey>, value: Encoder<TFromValue>, config?: MapCodecConfig<NumberEncoder>): VariableSizeEncoder<Map<TFromKey, TFromValue>>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a decoder for a map.
|
|
28
|
+
*
|
|
29
|
+
* @param key - The decoder to use for the map's keys.
|
|
30
|
+
* @param value - The decoder to use for the map's values.
|
|
31
|
+
* @param config - A set of config for the decoder.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getMapDecoder<TToKey, TToValue>(key: Decoder<TToKey>, value: Decoder<TToValue>, config: MapCodecConfig<NumberDecoder> & {
|
|
34
|
+
size: 0;
|
|
35
|
+
}): FixedSizeDecoder<Map<TToKey, TToValue>, 0>;
|
|
36
|
+
export declare function getMapDecoder<TToKey, TToValue>(key: FixedSizeDecoder<TToKey>, value: FixedSizeDecoder<TToValue>, config: MapCodecConfig<NumberDecoder> & {
|
|
37
|
+
size: number;
|
|
38
|
+
}): FixedSizeDecoder<Map<TToKey, TToValue>>;
|
|
39
|
+
export declare function getMapDecoder<TToKey, TToValue>(key: Decoder<TToKey>, value: Decoder<TToValue>, config?: MapCodecConfig<NumberDecoder>): VariableSizeDecoder<Map<TToKey, TToValue>>;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a codec for a map.
|
|
42
|
+
*
|
|
43
|
+
* @param key - The codec to use for the map's keys.
|
|
44
|
+
* @param value - The codec to use for the map's values.
|
|
45
|
+
* @param config - A set of config for the codec.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getMapCodec<TFromKey, TFromValue, TToKey extends TFromKey = TFromKey, TToValue extends TFromValue = TFromValue>(key: Codec<TFromKey, TToKey>, value: Codec<TFromValue, TToValue>, config: MapCodecConfig<NumberCodec> & {
|
|
48
|
+
size: 0;
|
|
49
|
+
}): FixedSizeCodec<Map<TFromKey, TFromValue>, Map<TToKey, TToValue>, 0>;
|
|
50
|
+
export declare function getMapCodec<TFromKey, TFromValue, TToKey extends TFromKey = TFromKey, TToValue extends TFromValue = TFromValue>(key: FixedSizeCodec<TFromKey, TToKey>, value: FixedSizeCodec<TFromValue, TToValue>, config: MapCodecConfig<NumberCodec> & {
|
|
51
|
+
size: number;
|
|
52
|
+
}): FixedSizeCodec<Map<TFromKey, TFromValue>, Map<TToKey, TToValue>>;
|
|
53
|
+
export declare function getMapCodec<TFromKey, TFromValue, TToKey extends TFromKey = TFromKey, TToValue extends TFromValue = TFromValue>(key: Codec<TFromKey, TToKey>, value: Codec<TFromValue, TToValue>, config?: MapCodecConfig<NumberCodec>): VariableSizeCodec<Map<TFromKey, TFromValue>, Map<TToKey, TToValue>>;
|
|
54
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAEL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAoC,MAAM,SAAS,CAAC;AAG/E,yCAAyC;AACzC,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,WAAW,GAAG,aAAa,GAAG,aAAa,IAAI;IACtF;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,UAAU,EAC9C,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,EACtB,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GACpD,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AAClD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,UAAU,EAC9C,GAAG,EAAE,gBAAgB,CAAC,QAAQ,CA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C,WAAW,CAAC,GACrC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, ReadonlyUint8Array, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
import { FixedSizeNumberCodec, FixedSizeNumberDecoder, FixedSizeNumberEncoder, NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
|
|
3
|
+
/** Defines the config for nullable codecs. */
|
|
4
|
+
export type NullableCodecConfig<TPrefix extends NumberCodec | NumberDecoder | NumberEncoder> = {
|
|
5
|
+
/**
|
|
6
|
+
* Defines how the `None` (or `null`) value should be represented.
|
|
7
|
+
*
|
|
8
|
+
* By default, no none value is used. This means a `null` value will be
|
|
9
|
+
* represented by the absence of the item.
|
|
10
|
+
*
|
|
11
|
+
* When `'zeroes'` is provided, a `null` value will skip the bytes that would
|
|
12
|
+
* have been used for the item. Note that this returns a fixed-size codec
|
|
13
|
+
* and thus will only work if the item codec is of fixed size.
|
|
14
|
+
*
|
|
15
|
+
* When a custom byte array is provided, a `null` value will be represented
|
|
16
|
+
* by the provided byte array. Note that this returns a variable-size codec
|
|
17
|
+
* since the byte array representing `null` does not need to match the size
|
|
18
|
+
* of the item codec.
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue No none value is used.
|
|
21
|
+
*/
|
|
22
|
+
noneValue?: ReadonlyUint8Array | 'zeroes';
|
|
23
|
+
/**
|
|
24
|
+
* The codec to use for the boolean prefix, if any.
|
|
25
|
+
*
|
|
26
|
+
* By default a `u8` number is used as a prefix to determine if the value is `null`.
|
|
27
|
+
* The value `0` is encoded for `null` and `1` if the value is present.
|
|
28
|
+
* This can be set to any number codec to customize the prefix.
|
|
29
|
+
*
|
|
30
|
+
* When `null` is provided, no prefix is used and the `noneValue` is used to
|
|
31
|
+
* determine if the value is `null`. If no `noneValue` is provided, then the
|
|
32
|
+
* absence of any bytes is used to determine if the value is `null`.
|
|
33
|
+
*
|
|
34
|
+
* @defaultValue `u8` prefix.
|
|
35
|
+
*/
|
|
36
|
+
prefix?: TPrefix | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Creates a encoder for an optional value using `null` as the `None` value.
|
|
40
|
+
*
|
|
41
|
+
* @param item - The encoder to use for the value that may be present.
|
|
42
|
+
* @param config - A set of config for the encoder.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getNullableEncoder<TFrom, TSize extends number>(item: FixedSizeEncoder<TFrom, TSize>, config: NullableCodecConfig<NumberEncoder> & {
|
|
45
|
+
noneValue: 'zeroes';
|
|
46
|
+
prefix: null;
|
|
47
|
+
}): FixedSizeEncoder<TFrom | null, TSize>;
|
|
48
|
+
export declare function getNullableEncoder<TFrom>(item: FixedSizeEncoder<TFrom>, config: NullableCodecConfig<FixedSizeNumberEncoder> & {
|
|
49
|
+
noneValue: 'zeroes';
|
|
50
|
+
}): FixedSizeEncoder<TFrom | null>;
|
|
51
|
+
export declare function getNullableEncoder<TFrom>(item: FixedSizeEncoder<TFrom>, config: NullableCodecConfig<NumberEncoder> & {
|
|
52
|
+
noneValue: 'zeroes';
|
|
53
|
+
}): VariableSizeEncoder<TFrom | null>;
|
|
54
|
+
export declare function getNullableEncoder<TFrom>(item: Encoder<TFrom>, config?: NullableCodecConfig<NumberEncoder> & {
|
|
55
|
+
noneValue?: ReadonlyUint8Array;
|
|
56
|
+
}): VariableSizeEncoder<TFrom | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a decoder for an optional value using `null` as the `None` value.
|
|
59
|
+
*
|
|
60
|
+
* @param item - The decoder to use for the value that may be present.
|
|
61
|
+
* @param config - A set of config for the decoder.
|
|
62
|
+
*/
|
|
63
|
+
export declare function getNullableDecoder<TTo, TSize extends number>(item: FixedSizeDecoder<TTo, TSize>, config: NullableCodecConfig<NumberDecoder> & {
|
|
64
|
+
noneValue: 'zeroes';
|
|
65
|
+
prefix: null;
|
|
66
|
+
}): FixedSizeDecoder<TTo | null, TSize>;
|
|
67
|
+
export declare function getNullableDecoder<TTo>(item: FixedSizeDecoder<TTo>, config: NullableCodecConfig<FixedSizeNumberDecoder> & {
|
|
68
|
+
noneValue: 'zeroes';
|
|
69
|
+
}): FixedSizeDecoder<TTo | null>;
|
|
70
|
+
export declare function getNullableDecoder<TTo>(item: FixedSizeDecoder<TTo>, config: NullableCodecConfig<NumberDecoder> & {
|
|
71
|
+
noneValue: 'zeroes';
|
|
72
|
+
}): VariableSizeDecoder<TTo | null>;
|
|
73
|
+
export declare function getNullableDecoder<TTo>(item: Decoder<TTo>, config?: NullableCodecConfig<NumberDecoder> & {
|
|
74
|
+
noneValue?: ReadonlyUint8Array;
|
|
75
|
+
}): VariableSizeDecoder<TTo | null>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a codec for an optional value using `null` as the `None` value.
|
|
78
|
+
*
|
|
79
|
+
* @param item - The codec to use for the value that may be present.
|
|
80
|
+
* @param config - A set of config for the codec.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getNullableCodec<TFrom, TTo extends TFrom, TSize extends number>(item: FixedSizeCodec<TFrom, TTo, TSize>, config: NullableCodecConfig<NumberCodec> & {
|
|
83
|
+
noneValue: 'zeroes';
|
|
84
|
+
prefix: null;
|
|
85
|
+
}): FixedSizeCodec<TFrom | null, TTo | null, TSize>;
|
|
86
|
+
export declare function getNullableCodec<TFrom, TTo extends TFrom = TFrom>(item: FixedSizeCodec<TFrom, TTo>, config: NullableCodecConfig<FixedSizeNumberCodec> & {
|
|
87
|
+
noneValue: 'zeroes';
|
|
88
|
+
}): FixedSizeCodec<TFrom | null, TTo | null>;
|
|
89
|
+
export declare function getNullableCodec<TFrom, TTo extends TFrom = TFrom>(item: FixedSizeCodec<TFrom, TTo>, config: NullableCodecConfig<NumberCodec> & {
|
|
90
|
+
noneValue: 'zeroes';
|
|
91
|
+
}): VariableSizeCodec<TFrom | null, TTo | null>;
|
|
92
|
+
export declare function getNullableCodec<TFrom, TTo extends TFrom = TFrom>(item: Codec<TFrom, TTo>, config?: NullableCodecConfig<NumberCodec> & {
|
|
93
|
+
noneValue?: ReadonlyUint8Array;
|
|
94
|
+
}): VariableSizeCodec<TFrom | null, TTo | null>;
|
|
95
|
+
//# sourceMappingURL=nullable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nullable.d.ts","sourceRoot":"","sources":["../../src/nullable.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,EAGL,OAAO,EACP,OAAO,EAEP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAEhB,kBAAkB,EAGlB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACH,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EAGtB,WAAW,EACX,aAAa,EACb,aAAa,EAChB,MAAM,wBAAwB,CAAC;AAQhC,8CAA8C;AAC9C,MAAM,MAAM,mBAAmB,CAAC,OAAO,SAAS,WAAW,GAAG,aAAa,GAAG,aAAa,IAAI;IAC3F;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAAC;IAE1C;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,EAC1D,IAAI,EAAE,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,EACpC,MAAM,EAAE,mBAAmB,CAAC,aAAa,CAAC,GAAG;IAAE,SAAS,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,IAAI,CAAA;CAAE,GACnF,gBAAgB,CAAC,K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,EAAE,GAAG,CAAC,EAChC,MAAM,EAAE,mBAAmB,CAAC,WAAW,CAAC,GAAG;IAAE,SAAS,EAAE,QAAQ,CAAA;CAAE,GACnE,iBAAiB,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC,CAAC;AAC/C,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,GAAG,KAAK,EAC7D,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EACvB,MAAM,CAAC,EAAE,mBAAmB,CAAC,WAAW,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,kBAAkB,CAAA;CAAE,GAC/E,iBAAiB,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
import { NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
|
|
3
|
+
import { ArrayLikeCodecSize } from './array';
|
|
4
|
+
/** Defines the config for set codecs. */
|
|
5
|
+
export type SetCodecConfig<TPrefix extends NumberCodec | NumberDecoder | NumberEncoder> = {
|
|
6
|
+
/**
|
|
7
|
+
* The size of the set.
|
|
8
|
+
* @defaultValue u32 prefix.
|
|
9
|
+
*/
|
|
10
|
+
size?: ArrayLikeCodecSize<TPrefix>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Encodes an set of items.
|
|
14
|
+
*
|
|
15
|
+
* @param item - The encoder to use for the set's items.
|
|
16
|
+
* @param config - A set of config for the encoder.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSetEncoder<TFrom>(item: Encoder<TFrom>, config: SetCodecConfig<NumberEncoder> & {
|
|
19
|
+
size: 0;
|
|
20
|
+
}): FixedSizeEncoder<Set<TFrom>, 0>;
|
|
21
|
+
export declare function getSetEncoder<TFrom>(item: FixedSizeEncoder<TFrom>, config: SetCodecConfig<NumberEncoder> & {
|
|
22
|
+
size: number;
|
|
23
|
+
}): FixedSizeEncoder<Set<TFrom>>;
|
|
24
|
+
export declare function getSetEncoder<TFrom>(item: Encoder<TFrom>, config?: SetCodecConfig<NumberEncoder>): VariableSizeEncoder<Set<TFrom>>;
|
|
25
|
+
/**
|
|
26
|
+
* Decodes an set of items.
|
|
27
|
+
*
|
|
28
|
+
* @param item - The encoder to use for the set's items.
|
|
29
|
+
* @param config - A set of config for the encoder.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSetDecoder<TTo>(item: Decoder<TTo>, config: SetCodecConfig<NumberDecoder> & {
|
|
32
|
+
size: 0;
|
|
33
|
+
}): FixedSizeDecoder<Set<TTo>, 0>;
|
|
34
|
+
export declare function getSetDecoder<TTo>(item: FixedSizeDecoder<TTo>, config: SetCodecConfig<NumberDecoder> & {
|
|
35
|
+
size: number;
|
|
36
|
+
}): FixedSizeDecoder<Set<TTo>>;
|
|
37
|
+
export declare function getSetDecoder<TTo>(item: Decoder<TTo>, config?: SetCodecConfig<NumberDecoder>): VariableSizeDecoder<Set<TTo>>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a codec for an set of items.
|
|
40
|
+
*
|
|
41
|
+
* @param item - The codec to use for the set's items.
|
|
42
|
+
* @param config - A set of config for the codec.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getSetCodec<TFrom, TTo extends TFrom = TFrom>(item: Codec<TFrom, TTo>, config: SetCodecConfig<NumberCodec> & {
|
|
45
|
+
size: 0;
|
|
46
|
+
}): FixedSizeCodec<Set<TFrom>, Set<TTo>, 0>;
|
|
47
|
+
export declare function getSetCodec<TFrom, TTo extends TFrom = TFrom>(item: FixedSizeCodec<TFrom, TTo>, config: SetCodecConfig<NumberCodec> & {
|
|
48
|
+
size: number;
|
|
49
|
+
}): FixedSizeCodec<Set<TFrom>, Set<TTo>>;
|
|
50
|
+
export declare function getSetCodec<TFrom, TTo extends TFrom = TFrom>(item: Codec<TFrom, TTo>, config?: SetCodecConfig<NumberCodec>): VariableSizeCodec<Set<TFrom>, Set<TTo>>;
|
|
51
|
+
//# sourceMappingURL=set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../src/set.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAEL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAoC,MAAM,SAAS,CAAC;AAE/E,yCAAyC;AACzC,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,WAAW,GAAG,aAAa,GAAG,aAAa,IAAI;IACtF;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAC/B,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EACpB,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GACpD,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,wBAAgB,aAAa,CAAC,KAAK,EAC/B,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC7B,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GACzD,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAChC,wBAAgB,aAAa,CAAC,KAAK,EAC/B,I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AChC,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GACvD,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACxC,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,GAAG,KAAK,EACxD,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EACvB,MAAM,CAAC,EAAE,cAAc,CAAC,WAAW,CAAC,GACrC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
import { DrainOuterGeneric } from './utils';
|
|
3
|
+
type Fields<T> = readonly (readonly [string, T])[];
|
|
4
|
+
type ArrayIndices<T extends readonly unknown[]> = Exclude<Partial<T>['length'], T['length']> & number;
|
|
5
|
+
type GetEncoderTypeFromFields<TFields extends Fields<Encoder<any>>> = DrainOuterGeneric<{
|
|
6
|
+
[I in ArrayIndices<TFields> as TFields[I][0]]: TFields[I][1] extends Encoder<infer TFrom> ? TFrom : never;
|
|
7
|
+
}>;
|
|
8
|
+
type GetDecoderTypeFromFields<TFields extends Fields<Decoder<any>>> = DrainOuterGeneric<{
|
|
9
|
+
[I in ArrayIndices<TFields> as TFields[I][0]]: TFields[I][1] extends Decoder<infer TTo> ? TTo : never;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a encoder for a custom object.
|
|
13
|
+
*
|
|
14
|
+
* @param fields - The name and encoder of each field.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getStructEncoder<const TFields extends Fields<FixedSizeEncoder<any>>>(fields: TFields): FixedSizeEncoder<GetEncoderTypeFromFields<TFields>>;
|
|
17
|
+
export declare function getStructEncoder<const TFields extends Fields<Encoder<any>>>(fields: TFields): VariableSizeEncoder<GetEncoderTypeFromFields<TFields>>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a decoder for a custom object.
|
|
20
|
+
*
|
|
21
|
+
* @param fields - The name and decoder of each field.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getStructDecoder<const TFields extends Fields<FixedSizeDecoder<any>>>(fields: TFields): FixedSizeDecoder<GetDecoderTypeFromFields<TFields>>;
|
|
24
|
+
export declare function getStructDecoder<const TFields extends Fields<Decoder<any>>>(fields: TFields): VariableSizeDecoder<GetDecoderTypeFromFields<TFields>>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a codec for a custom object.
|
|
27
|
+
*
|
|
28
|
+
* @param fields - The name and codec of each field.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getStructCodec<const TFields extends Fields<FixedSizeCodec<any>>>(fields: TFields): FixedSizeCodec<GetEncoderTypeFromFields<TFields>, GetDecoderTypeFromFields<TFields> & GetEncoderTypeFromFields<TFields>>;
|
|
31
|
+
export declare function getStructCodec<const TFields extends Fields<Codec<any>>>(fields: TFields): VariableSizeCodec<GetEncoderTypeFromFields<TFields>, GetDecoderTypeFromFields<TFields> & GetEncoderTypeFromFields<TFields>>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=struct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../../src/struct.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,EAIL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAA2C,MAAM,SAAS,CAAC;AAErF,KAAK,MAAM,CAAC,CAAC,IAAI,SA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,CAAC,CAAC;AA4B1D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAChF,MAAM,EAAE,OAAO,GAChB,gBAAgB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;AACvD,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EACvE,MAAM,EAAE,OAAO,GAChB,mBAAmB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;AAuB1D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EAC5E,MAAM,EAAE,OAAO,GAChB,cAAc,CACb,wBAAwB,CAAC,OAAO,CAAC,EACjC,wBAAwB,CAAC,OAAO,CAAC,GAAG,wBAAwB,CAAC,OAAO,CAAC,CACxE,CAAC;AACF,wBAAgB,cAAc,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EACnE,MAAM,EAAE,OAAO,GAChB,iBAAiB,CAChB,wBAAwB,CAAC,OAAO,CAAC,EACjC,wBAAwB,CAAC,OAAO,CAAC,GAAG,wBAAwB,CAAC,OAAO,CAAC,CACxE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
import { DrainOuterGeneric } from './utils';
|
|
3
|
+
type GetEncoderTypeFromItems<TItems extends readonly Encoder<any>[]> = DrainOuterGeneric<{
|
|
4
|
+
[I in keyof TItems]: TItems[I] extends Encoder<infer TFrom> ? TFrom : never;
|
|
5
|
+
}>;
|
|
6
|
+
type GetDecoderTypeFromItems<TItems extends readonly Decoder<any>[]> = DrainOuterGeneric<{
|
|
7
|
+
[I in keyof TItems]: TItems[I] extends Decoder<infer TTo> ? TTo : never;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a encoder for a tuple-like array.
|
|
11
|
+
*
|
|
12
|
+
* @param items - The encoders to use for each item in the tuple.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTupleEncoder<const TItems extends readonly FixedSizeEncoder<any>[]>(items: TItems): FixedSizeEncoder<GetEncoderTypeFromItems<TItems>>;
|
|
15
|
+
export declare function getTupleEncoder<const TItems extends readonly Encoder<any>[]>(items: TItems): VariableSizeEncoder<GetEncoderTypeFromItems<TItems>>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a decoder for a tuple-like array.
|
|
18
|
+
*
|
|
19
|
+
* @param items - The decoders to use for each item in the tuple.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getTupleDecoder<const TItems extends readonly FixedSizeDecoder<any>[]>(items: TItems): FixedSizeDecoder<GetDecoderTypeFromItems<TItems>>;
|
|
22
|
+
export declare function getTupleDecoder<const TItems extends readonly Decoder<any>[]>(items: TItems): VariableSizeDecoder<GetDecoderTypeFromItems<TItems>>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a codec for a tuple-like array.
|
|
25
|
+
*
|
|
26
|
+
* @param items - The codecs to use for each item in the tuple.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getTupleCodec<const TItems extends readonly FixedSizeCodec<any>[]>(items: TItems): FixedSizeCodec<GetEncoderTypeFromItems<TItems>, GetDecoderTypeFromItems<TItems> & GetEncoderTypeFromItems<TItems>>;
|
|
29
|
+
export declare function getTupleCodec<const TItems extends readonly Codec<any>[]>(items: TItems): VariableSizeCodec<GetEncoderTypeFromItems<TItems>, GetDecoderTypeFromItems<TItems> & GetEncoderTypeFromItems<TItems>>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=tuple.d.ts.map
|
|
@@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EACjF,KAAK,EAAE,MAAM,GACd,gBAAgB,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;AACrD,wBAAgB,eAAe,CAAC,KAAK,CAAC,MAAM,SAAS,SAAS,OAAO,CAAC,GAAG,CAAC,EAAE,EACxE,KAAK,EAAE,MAAM,GACd,mBAAmB,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;AAsBxD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,CAAC,MAAM,SAAS,SAAS,cAAc,CAAC,GAAG,CAAC,EAAE,EAC7E,KAAK,EAAE,MAAM,GACd,cAAc,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,MAAM,CAAC,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;AACtH,wBAAgB,aAAa,CAAC,KAAK,CAAC,MAAM,SAAS,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,EACpE,KAAK,EAAE,MAAM,GACd,iBAAiB,CAChB,uBAAuB,CAAC,MAAM,CAAC,EAC/B,uBAAuB,CAAC,MAAM,CAAC,GAAG,uBAAuB,CAAC,MAAM,CAAC,CACpE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder, Offset, ReadonlyUint8Array } from '@solana/codecs-core';
|
|
2
|
+
import { DrainOuterGeneric } from './utils';
|
|
3
|
+
type GetEncoderTypeFromVariants<TVariants extends readonly Encoder<any>[]> = DrainOuterGeneric<{
|
|
4
|
+
[I in keyof TVariants]: TVariants[I] extends Encoder<infer TFrom> ? TFrom : never;
|
|
5
|
+
}>[number];
|
|
6
|
+
type GetDecoderTypeFromVariants<TVariants extends readonly Decoder<any>[]> = DrainOuterGeneric<{
|
|
7
|
+
[I in keyof TVariants]: TVariants[I] extends Decoder<infer TFrom> ? TFrom : never;
|
|
8
|
+
}>[number];
|
|
9
|
+
/**
|
|
10
|
+
* Creates a union encoder from the provided array of encoder.
|
|
11
|
+
*
|
|
12
|
+
* @param variants - The variant encoders of the union.
|
|
13
|
+
* @param getIndexFromValue - A function that returns the index of the variant from the provided value.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getUnionEncoder<const TVariants extends readonly Encoder<any>[]>(variants: TVariants, getIndexFromValue: (value: GetEncoderTypeFromVariants<TVariants>) => number): Encoder<GetEncoderTypeFromVariants<TVariants>>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a union decoder from the provided array of decoder.
|
|
18
|
+
*
|
|
19
|
+
* @param variants - The variant decoders of the union.
|
|
20
|
+
* @param getIndexFromBytes - A function that returns the index of the variant from the byte array.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getUnionDecoder<const TVariants extends readonly Decoder<any>[]>(variants: TVariants, getIndexFromBytes: (bytes: ReadonlyUint8Array, offset: Offset) => number): Decoder<GetDecoderTypeFromVariants<TVariants>>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a union codec from the provided array of codec.
|
|
25
|
+
*
|
|
26
|
+
* @param variants - The variant codecs of the union.
|
|
27
|
+
* @param getIndexFromValue - A function that returns the index of the variant from the provided value.
|
|
28
|
+
* @param getIndexFromBytes - A function that returns the index of the variant from the byte array.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getUnionCodec<const TVariants extends readonly Codec<any>[]>(variants: TVariants, getIndexFromValue: (value: GetEncoderTypeFromVariants<TVariants>) => number, getIndexFromBytes: (bytes: ReadonlyUint8Array, offset: Offset) => number): Codec<GetEncoderTypeFromVariants<TVariants>, GetDecoderTypeFromVariants<TVariants> & GetEncoderTypeFromVariants<TVariants>>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=union.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/union.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,EAIL,OAAO,EACP,OAAO,EAGP,MAAM,EACN,kBAAkB,EACrB,MAAM,qBAAqB,CAAC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iB,EAAE,CAAC,KAAK,EAAE,0BAA0B,CAAC,SAAS,CAAC,KAAK,MAAM,EAC3E,iBAAiB,EAAE,CAAC,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GACzE,KAAK,CACJ,0BAA0B,CAAC,SAAS,CAAC,EACrC,0BAA0B,CAAC,SAAS,CAAC,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAChF,CAOA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a void encoder.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getUnitEncoder(): FixedSizeEncoder<void, 0>;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a void decoder.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getUnitDecoder(): FixedSizeDecoder<void, 0>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a void codec.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getUnitCodec(): FixedSizeCodec<void, void, 0>;
|
|
14
|
+
//# sourceMappingURL=unit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../../src/unit.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAEnB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,CAK1D;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,CAK1D;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAE5D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functionally, this type helper is equivalent to the identity type — i.e. `type Identity<T> = T`.
|
|
3
|
+
* However, wrapping generic object mappings in this type significantly reduces the number
|
|
4
|
+
* of instantiation expressions processed, which increases TypeScript performance and
|
|
5
|
+
* prevents "Type instantiation is excessively deep and possibly infinite" errors.
|
|
6
|
+
*
|
|
7
|
+
* This works because TypeScript doesn't create a new level of nesting when encountering conditional generic types.
|
|
8
|
+
* @see https://github.com/microsoft/TypeScript/issues/34933
|
|
9
|
+
* @see https://github.com/kysely-org/kysely/pull/483
|
|
10
|
+
*/
|
|
11
|
+
export type DrainOuterGeneric<T> = [T] extends [unknown] ? T : never;
|
|
12
|
+
export declare function maxCodecSizes(sizes: (number | null)[]): number | null;
|
|
13
|
+
export declare function sumCodecSizes(sizes: (number | null)[]): number | null;
|
|
14
|
+
export declare function getFixedSize(codec: {
|
|
15
|
+
fixedSize: number;
|
|
16
|
+
} | {
|
|
17
|
+
maxSize?: number;
|
|
18
|
+
}): number | null;
|
|
19
|
+
export declare function getMaxSize(codec: {
|
|
20
|
+
fixedSize: number;
|
|
21
|
+
} | {
|
|
22
|
+
maxSize?: number;
|
|
23
|
+
}): number | null;
|
|
24
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAErE,wBAAgB,aAAa,CAAC,KAAK,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,MAAM,GAAG,IAAI,CAKrE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,MAAM,GAAG,IAAI,CAErE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAE/F;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAE7F"}
|