Files
pezkuwi-api/packages/bizinikiwi-bindings/upstream-src/codecs/scale/shaped.ts
T
SatoshiQaziMuhammed e3c72817fb chore(papi): commit the sources behind the four polkadot-api packages (#15)
* chore(papi): commit the sources behind the four polkadot-api packages

papi-utils, bizinikiwi-bindings, metadata-builders and merkleize-metadata
held only dist/ builds, and no repository held their source. Every
source map in dist/ embeds the TypeScript it was compiled from; that is
now committed as src/ (59 files), and it matches upstream polkadot-api
(MIT) exactly once @polkadot-api/* imports are renamed:

  papi-utils           @polkadot-api/utils 0.2.0
  bizinikiwi-bindings  @polkadot-api/substrate-bindings 0.16.6
  metadata-builders    @polkadot-api/metadata-builders 0.13.0-0.13.2
  merkleize-metadata   @polkadot-api/merkleize-metadata 1.1.21-1.1.23

scripts/check-papi-sources.mjs, run in the lint job, fails unless the
source embedded in dist/ is exactly the committed src/. tsconfig.json
excludes these src/ trees; ESLint already skipped the packages. Each
README now states the upstream package and version.

* chore(papi): keep the upstream sources in upstream-src/

The pezkuwi-dev build treats any package with a src/ directory as its
own: it requires our license header on every file and builds it. These
are upstream files that must stay byte-identical to the source embedded
in dist/, so they live in upstream-src/ instead, which neither the build
nor the root tsconfig picks up.
2026-10-19 22:50:59 +04:00

101 lines
3.2 KiB
TypeScript

import {
Struct as OStruct,
Tuple as OTuple,
Vector as OVector,
Result as OResult,
Option as OOption,
Codec,
Encoder,
Decoder,
StringRecord,
CodecType,
EncoderType,
DecoderType,
ResultPayload,
} from "scale-ts"
import { withInner } from "./with-inner"
export const Struct: {
<A extends StringRecord<Codec<any>>>(
codecs: A,
): Codec<{ [K in keyof A]: CodecType<A[K]> }> & { inner: A }
enc: <A_1 extends StringRecord<Encoder<any>>>(
encoders: A_1,
) => Encoder<{ [K_1 in keyof A_1]: EncoderType<A_1[K_1]> }> & { inner: A_1 }
dec: <A_2 extends StringRecord<Decoder<any>>>(
decoders: A_2,
) => Decoder<{ [K_2 in keyof A_2]: DecoderType<A_2[K_2]> }> & { inner: A_2 }
} = (codecs) => withInner(OStruct(codecs), codecs)
Struct.enc = (x) => withInner(OStruct.enc(x), x)
Struct.dec = (x) => withInner(OStruct.dec(x), x)
export const Tuple: {
<A extends Codec<any>[]>(
...inner: A
): Codec<{ [K in keyof A]: A[K] extends Codec<infer D> ? D : unknown }> & {
inner: A
}
enc: <A_1 extends Encoder<any>[]>(
...encoders: A_1
) => Encoder<{
[K_1 in keyof A_1]: A_1[K_1] extends Encoder<infer D_1> ? D_1 : unknown
}> & { inner: A_1 }
dec: <A_2 extends Decoder<any>[]>(
...decoders: A_2
) => Decoder<{
[K_2 in keyof A_2]: A_2[K_2] extends Decoder<infer D_2> ? D_2 : unknown
}> & { inner: A_2 }
} = (...inner) => withInner(OTuple(...inner), inner)
Tuple.enc = (...inner) => withInner(OTuple.enc(...inner), inner)
Tuple.dec = (...inner) => withInner(OTuple.dec(...inner), inner)
export const Vector: {
<T>(
inner: Codec<T>,
size?: number | undefined,
): Codec<T[]> & { inner: Codec<T> }
enc: <T_1>(
inner: Encoder<T_1>,
size?: number | undefined,
) => Encoder<T_1[]> & { inner: Encoder<T_1> }
dec: <T_2>(
getter: Decoder<T_2>,
size?: number | undefined,
) => Decoder<T_2[]> & { inner: Decoder<T_2> }
} = (inner, ...rest) => withInner(OVector(inner, ...rest), inner)
Vector.enc = (inner, ...rest) => withInner(OVector.enc(inner, ...rest), inner)
Vector.dec = (inner, ...rest) => withInner(OVector.dec(inner, ...rest), inner)
export const Result: {
<OK, KO>(
okCodec: Codec<OK>,
koCodec: Codec<KO>,
): Codec<ResultPayload<OK, KO>> & { inner: { ok: Codec<OK>; ko: Codec<KO> } }
dec: <OK_1, KO_1>(
okDecoder: Decoder<OK_1>,
koDecoder: Decoder<KO_1>,
) => Decoder<ResultPayload<OK_1, KO_1>> & {
inner: { ok: Decoder<OK_1>; ko: Decoder<KO_1> }
}
enc: <OK_2, KO_2>(
okEncoder: Encoder<OK_2>,
koEncoder: Encoder<KO_2>,
) => Encoder<ResultPayload<OK_2, KO_2>> & {
inner: { ok: Encoder<OK_2>; ko: Encoder<KO_2> }
}
} = (ok, ko) => withInner(OResult(ok, ko), { ok, ko })
Result.enc = (ok, ko) => withInner(OResult.enc(ok, ko), { ok, ko })
Result.dec = (ok, ko) => withInner(OResult.dec(ok, ko), { ok, ko })
export const Option: {
<T>(inner: Codec<T>): Codec<T | undefined> & { inner: Codec<T> }
enc: <T_1>(
inner: Encoder<T_1>,
) => Encoder<T_1 | undefined> & { inner: Encoder<T_1> }
dec: <T_2>(
inner: Decoder<T_2>,
) => Decoder<T_2 | undefined> & { inner: Decoder<T_2> }
} = (inner) => withInner(OOption(inner), inner)
Option.enc = (inner) => withInner(OOption.enc(inner), inner)
Option.dec = (inner) => withInner(OOption.dec(inner), inner)