Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scale-ts

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scale-ts - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0-alpha.0

7

dist/codecs/Enum.d.ts
import { Codec, Decoder, Encoder, StringRecord } from "../types";
import { VOID } from "../";
export declare const Enum: {
<O extends StringRecord<Codec<any>>, OT extends { [K in keyof O]: O[K] extends Codec<infer D> ? D extends typeof VOID ? {
<O extends StringRecord<Codec<any>>, OT extends { [K in keyof O]: O[K] extends Codec<infer D> ? D extends undefined ? {
tag: K;

@@ -11,3 +10,3 @@ value?: undefined;

} : unknown; }>(inner: O): Codec<OT[keyof O]>;
enc: <O_1 extends StringRecord<Encoder<any>>, OT_1 extends { [K_1 in keyof O_1]: O_1[K_1] extends Encoder<infer D_1> ? D_1 extends typeof VOID ? {
enc: <O_1 extends StringRecord<Encoder<any>>, OT_1 extends { [K_1 in keyof O_1]: O_1[K_1] extends Encoder<infer D_1> ? D_1 extends undefined ? {
tag: K_1;

@@ -19,3 +18,3 @@ value?: undefined;

} : unknown; }>(inner: O_1) => Encoder<OT_1[keyof O_1]>;
dec: <O_2 extends StringRecord<Decoder<any>>, OT_2 extends { [K_2 in keyof O_2]: O_2[K_2] extends Decoder<infer D_2> ? D_2 extends typeof VOID ? {
dec: <O_2 extends StringRecord<Decoder<any>>, OT_2 extends { [K_2 in keyof O_2]: O_2[K_2] extends Decoder<infer D_2> ? D_2 extends undefined ? {
tag: K_2;

@@ -22,0 +21,0 @@ value?: undefined;

@@ -15,3 +15,3 @@ export { bool } from "./bool";

export { i128 } from "./i128";
export { _void, VOID } from "./void";
export { _void } from "./void";
export { Bytes } from "./Bytes";

@@ -18,0 +18,0 @@ export { Enum } from "./Enum";

import { Codec } from "../types";
export declare const VOID: unique symbol;
export declare type VOID = typeof VOID;
export declare const _void: Codec<VOID>;
export declare const _void: Codec<undefined>;

@@ -50,3 +50,2 @@ var __defProp = Object.defineProperty;

U8Enum: () => U8Enum,
VOID: () => VOID,
Vector: () => Vector,

@@ -236,6 +235,8 @@ _void: () => _void,

var import_utils3 = require("@unstoppablejs/utils");
var textEncoder = new TextEncoder();
var strEnc = (str2) => {
const val = (0, import_utils3.utf16StrToUtf8Bytes)(str2);
const val = textEncoder.encode(str2);
return (0, import_utils3.mergeUint8)(compact.enc(val.length), val);
};
var textDecoder = new TextDecoder();
var strDec = toInternalBytes((bytes) => {

@@ -245,3 +246,3 @@ let nElements = compact.dec(bytes);

bytes.useBytes(nElements);
return (0, import_utils3.utf8BytesToUtf16Str)(arr);
return textDecoder.decode(arr);
});

@@ -314,5 +315,4 @@ var str = createCodec(strEnc, strDec);

// src/codecs/void.ts
var VOID = Symbol("empty");
var emptyArr = new Uint8Array(0);
var _void = createCodec(() => emptyArr, () => VOID);
var _void = createCodec(() => emptyArr, Function.prototype);

@@ -347,3 +347,3 @@ // src/codecs/Bytes.ts

const innerResult = innerDecoder(bytes);
return innerResult === VOID ? { tag } : {
return {
tag,

@@ -350,0 +350,0 @@ value: innerResult

@@ -1,2 +0,2 @@

var R=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var ke=(e,t)=>{for(var o in t)R(e,o,{get:t[o],enumerable:!0})},ve=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of Ue(t))!Ve.call(e,c)&&c!==o&&R(e,c,{get:()=>t[c],enumerable:!(n=we(t,c))||n.enumerable});return e};var he=e=>ve(R({},"__esModule",{value:!0}),e);var P=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var j=(e,t,o)=>(P(e,t,"read from private field"),o?o.call(e):t.get(e)),_=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},L=(e,t,o,n)=>(P(e,t,"write to private field"),n?n.call(e,o):t.set(e,o),o);var nt={};ke(nt,{Bytes:()=>T,Enum:()=>B,Hex:()=>w,MapCodec:()=>U,Option:()=>V,Result:()=>k,SetCodec:()=>v,Struct:()=>h,Tuple:()=>D,U8Enum:()=>S,VOID:()=>g,Vector:()=>x,_void:()=>re,bool:()=>I,compact:()=>C,createCodec:()=>r,date32:()=>F,date64:()=>G,enhanceCodec:()=>M,enhanceDecoder:()=>y,enhanceEncoder:()=>f,i128:()=>ne,i16:()=>ee,i32:()=>te,i64:()=>oe,i8:()=>z,str:()=>J,u128:()=>Z,u16:()=>Q,u32:()=>X,u64:()=>Y,u8:()=>u});module.exports=he(nt);var r=(e,t)=>{let o=[e,t];return o.enc=e,o.dec=t,o},f=(e,t)=>o=>e(t(o)),y=(e,t)=>o=>t(e(o)),M=([e,t],o,n)=>r(f(e,o),y(t,n));var W=require("@unstoppablejs/utils"),E,A=class extends Uint8Array{constructor(){super(...arguments);_(this,E,0)}useBytes(o){L(this,E,j(this,E)+o)}get usedBytes(){return j(this,E)}};E=new WeakMap;var s=e=>t=>e(t instanceof A?t:new A(typeof t=="string"?(0,W.fromHex)(t).buffer:t instanceof Uint8Array?t.buffer:t));var d={u8:"u8",u16:"u16",u32:"u32",u64:"u64",i8:"i8",i16:"i16",i32:"i32",i64:"i64"},$={[d.u8]:[1,"getUint8","setUint8"],[d.u16]:[2,"getUint16","setUint16"],[d.u32]:[4,"getUint32","setUint32"],[d.u64]:[8,"getBigUint64","setBigUint64"],[d.i8]:[1,"getInt8","setInt8"],[d.i16]:[2,"getInt16","setInt16"],[d.i32]:[4,"getInt32","setInt32"],[d.i64]:[8,"getBigInt64","setBigInt64"]};function m(e){let[t,o]=$[e];return s(n=>{let c=new DataView(n.buffer)[o](n.usedBytes,!0);return n.useBytes(t),c})}function i(e){let[t,,o]=$[e];return n=>{let c=new Uint8Array(t);return new DataView(c.buffer)[o](0,n,!0),c}}var Se=i(d.u8),Re=m(d.u8),u=r(Se,Re);var je=e=>e?1:0,I=M(u,je,Boolean);var Me={[1]:d.u8,[2]:d.u16,[4]:d.u32},He=s(e=>{let t=e.usedBytes,o=e[t],n=o&3;if(n!==3){let l=n===2?4:n+1;return m(Me[l])(e)>>>2}let c=(o>>>2)+4,a=t+1;e.useBytes(c+1);let p=0n;for(let l=c-1;l>=0;l--)p=p<<8n|BigInt(e[a+l]);return p}),Ne=e=>{if(e<0)throw new Error(`Wrong Compat input (${e})`);if(e<1<<6){let n=new Uint8Array(1);return n[0]=Number(e)<<2,n}if(e<1<<14){let n=new Uint8Array(2),c=(Number(e)<<2)+1;return new DataView(n.buffer).setUint16(0,c,!0),n}if(e<1<<30){let n=new Uint8Array(4),c=(Number(e)<<2)+2;return new DataView(n.buffer).setUint32(0,c,!0),n}let t=[],o=BigInt(e);for(;o>0;)t.push(Number(o)),o>>=8n;return t.unshift((t.length-4<<2)+3),new Uint8Array(t)},C=r(Ne,He);var Pe=e=>{let t=e===32?"setUint32":"setBigUint64",o=e/8,n=e===32?c=>c:BigInt;return c=>{let a=new Uint8Array(o);return new DataView(a.buffer)[t](0,n(c.getTime()),!0),a}},_e=e=>{let t=e===32?"getUint32":"getBigUint64",o=e/8;return s(n=>{let c=new Date(Number(new DataView(n.buffer)[t](n.usedBytes,!0)));return n.useBytes(o),c})},q=e=>r(Pe(e),_e(e)),F=q(32),G=q(64);var O=require("@unstoppablejs/utils");var Le=e=>{let t=(0,O.utf16StrToUtf8Bytes)(e);return(0,O.mergeUint8)(C.enc(t.length),t)},We=s(e=>{let t=C.dec(e),o=new Uint8Array(e.buffer,e.usedBytes,t);return e.useBytes(t),(0,O.utf8BytesToUtf16Str)(o)}),J=r(Le,We);var $e=i(d.u16),qe=m(d.u16),Q=r($e,qe);var Fe=i(d.u32),Ge=m(d.u32),X=r(Fe,Ge);var Je=i(d.u64),Qe=m(d.u64),Y=r(Je,Qe);var Xe=e=>{let t=new Uint8Array(16),o=new DataView(t.buffer);return o.setBigUint64(0,e,!0),o.setBigUint64(8,e>>64n,!0),t},Ye=s(e=>{let t=new DataView(e.buffer),o=t.getBigUint64(e.usedBytes,!0),n=t.getBigUint64(e.usedBytes+8,!0);return e.useBytes(16),(n<<64n)+o}),Z=r(Xe,Ye);var Ze=i(d.i8),ze=m(d.i8),z=r(Ze,ze);var ee=r(i(d.i16),m(d.i16));var te=r(i(d.i32),m(d.i32));var oe=r(i(d.i64),m(d.i64));var et=e=>{let t=new Uint8Array(16),o=new DataView(t.buffer);return o.setBigUint64(0,e,!0),o.setBigInt64(8,e>>64n,!0),t},tt=s(e=>{let t=new DataView(e.buffer),o=t.getBigUint64(e.usedBytes,!0),n=t.getBigInt64(e.usedBytes+8,!0);return e.useBytes(16),(n<<64n)+o}),ne=r(et,tt);var g=Symbol("empty"),ot=new Uint8Array(0),re=r(()=>ot,()=>g);var ce=e=>t=>t.length===e?t:t.slice(0,e),de=e=>s(t=>{let o=t.usedBytes,n=e!==1/0?e:t.byteLength-o,c=new Uint8Array(t.buffer,o,n);return t.useBytes(n),c}),T=e=>r(ce(e),de(e));T.enc=ce;T.dec=de;var b=require("@unstoppablejs/utils");var se=e=>{let t=Object.keys(e);return({tag:o,value:n})=>{let c=t.indexOf(o);return(0,b.mergeUint8)(u.enc(c),e[o](n))}},me=e=>{let t=Object.entries(e);return s(o=>{let n=u.dec(o),[c,a]=t[n],p=a(o);return p===g?{tag:c}:{tag:c,value:p}})},B=e=>r(se((0,b.mapObject)(e,([t])=>t)),me((0,b.mapObject)(e,([,t])=>t)));B.enc=se;B.dec=me;var K=require("@unstoppablejs/utils");var ie=e=>f(T.enc(e),K.fromHex),ue=e=>y(T.dec(e),K.toHex),w=e=>r(ie(e),ue(e));w.enc=ie;w.dec=ue;var ae=require("@unstoppablejs/utils");var pe=(...e)=>s(t=>e.map(o=>o(t))),fe=(...e)=>t=>(0,ae.mergeUint8)(...t.map((o,n)=>e[n](o))),D=(...e)=>r(fe(...e.map(([t])=>t)),pe(...e.map(([,t])=>t)));D.enc=fe;D.dec=pe;var H=require("@unstoppablejs/utils");var ye=(e,t)=>t>0?o=>(0,H.mergeUint8)(...o.map(e)):o=>(0,H.mergeUint8)(C.enc(o.length),...o.map(e));function De(e,t){return s(o=>{let n=t>0?t:C.dec(o),c=new Array(n);for(let a=0;a<n;a++){let p=e(o);c[a]=p}return c})}function x(e,t){return r(ye(e[0],t),De(e[1],t))}x.enc=ye;x.dec=De;var xe=(e,t)=>f(x.enc(D.enc(e,t)),o=>Array.from(o.entries())),Ce=(e,t)=>y(x.dec(D.dec(e,t)),o=>new Map(o)),U=(e,t)=>r(xe(e[0],t[0]),Ce(e[1],t[1]));U.enc=xe;U.dec=Ce;var Te=require("@unstoppablejs/utils"),Oe=e=>s(t=>{let o=u.dec(t);if(o!==0)return e===I[1]?o===1:e(t)}),le=e=>t=>{let o=new Uint8Array(1);return t===void 0?(o[0]=0,o):(o[0]=1,e===I[0]?(o[0]=t?1:2,o):(0,Te.mergeUint8)(o,e(t)))},V=e=>r(le(e[0]),Oe(e[1]));V.enc=le;V.dec=Oe;var Ee=require("@unstoppablejs/utils"),Ie=(e,t)=>s(o=>{let c=u[1](o)===0,p=(c?e:t)(o);return{success:c,value:p}}),ge=(e,t)=>({success:o,value:n})=>(0,Ee.mergeUint8)(u[0](o?0:1),(o?e:t)(n)),k=(e,t)=>r(ge(e[0],t[0]),Ie(e[1],t[1]));k.dec=Ie;k.enc=ge;var be=e=>f(x.enc(e),t=>Array.from(t)),Ae=e=>y(x.dec(e),t=>new Set(t)),v=e=>r(be(e[0]),Ae(e[1]));v.enc=be;v.dec=Ae;var N=require("@unstoppablejs/utils");var Be=e=>{let t=Object.keys(e);return f(D.enc(...Object.values(e)),o=>t.map(n=>o[n]))},Ke=e=>{let t=Object.keys(e);return y(D.dec(...Object.values(e)),o=>Object.fromEntries(o.map((n,c)=>[t[c],n])))},h=e=>r(Be((0,N.mapObject)(e,t=>t[0])),Ke((0,N.mapObject)(e,t=>t[1])));h.enc=Be;h.dec=Ke;var S=e=>u;S.enc=e=>u[0];S.dec=e=>u[1];
var h=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Ue=Object.prototype.hasOwnProperty;var Ve=(e,t)=>{for(var o in t)h(e,o,{get:t[o],enumerable:!0})},ke=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of Be(t))!Ue.call(e,c)&&c!==o&&h(e,c,{get:()=>t[c],enumerable:!(n=we(t,c))||n.enumerable});return e};var ve=e=>ke(h({},"__esModule",{value:!0}),e);var H=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var S=(e,t,o)=>(H(e,t,"read from private field"),o?o.call(e):t.get(e)),N=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},P=(e,t,o,n)=>(H(e,t,"write to private field"),n?n.call(e,o):t.set(e,o),o);var rt={};Ve(rt,{Bytes:()=>T,Enum:()=>b,Hex:()=>K,MapCodec:()=>w,Option:()=>B,Result:()=>U,SetCodec:()=>V,Struct:()=>k,Tuple:()=>x,U8Enum:()=>v,Vector:()=>D,_void:()=>ne,bool:()=>g,compact:()=>C,createCodec:()=>r,date32:()=>W,date64:()=>$,enhanceCodec:()=>R,enhanceDecoder:()=>y,enhanceEncoder:()=>f,i128:()=>oe,i16:()=>z,i32:()=>ee,i64:()=>te,i8:()=>Z,str:()=>G,u128:()=>Y,u16:()=>J,u32:()=>Q,u64:()=>X,u8:()=>u});module.exports=ve(rt);var r=(e,t)=>{let o=[e,t];return o.enc=e,o.dec=t,o},f=(e,t)=>o=>e(t(o)),y=(e,t)=>o=>t(e(o)),R=([e,t],o,n)=>r(f(e,o),y(t,n));var _=require("@unstoppablejs/utils"),l,I=class extends Uint8Array{constructor(){super(...arguments);N(this,l,0)}useBytes(o){P(this,l,S(this,l)+o)}get usedBytes(){return S(this,l)}};l=new WeakMap;var s=e=>t=>e(t instanceof I?t:new I(typeof t=="string"?(0,_.fromHex)(t).buffer:t instanceof Uint8Array?t.buffer:t));var d={u8:"u8",u16:"u16",u32:"u32",u64:"u64",i8:"i8",i16:"i16",i32:"i32",i64:"i64"},F={[d.u8]:[1,"getUint8","setUint8"],[d.u16]:[2,"getUint16","setUint16"],[d.u32]:[4,"getUint32","setUint32"],[d.u64]:[8,"getBigUint64","setBigUint64"],[d.i8]:[1,"getInt8","setInt8"],[d.i16]:[2,"getInt16","setInt16"],[d.i32]:[4,"getInt32","setInt32"],[d.i64]:[8,"getBigInt64","setBigInt64"]};function m(e){let[t,o]=F[e];return s(n=>{let c=new DataView(n.buffer)[o](n.usedBytes,!0);return n.useBytes(t),c})}function i(e){let[t,,o]=F[e];return n=>{let c=new Uint8Array(t);return new DataView(c.buffer)[o](0,n,!0),c}}var he=i(d.u8),Se=m(d.u8),u=r(he,Se);var Re=e=>e?1:0,g=R(u,Re,Boolean);var je={[1]:d.u8,[2]:d.u16,[4]:d.u32},Me=s(e=>{let t=e.usedBytes,o=e[t],n=o&3;if(n!==3){let E=n===2?4:n+1;return m(je[E])(e)>>>2}let c=(o>>>2)+4,a=t+1;e.useBytes(c+1);let p=0n;for(let E=c-1;E>=0;E--)p=p<<8n|BigInt(e[a+E]);return p}),He=e=>{if(e<0)throw new Error(`Wrong Compat input (${e})`);if(e<1<<6){let n=new Uint8Array(1);return n[0]=Number(e)<<2,n}if(e<1<<14){let n=new Uint8Array(2),c=(Number(e)<<2)+1;return new DataView(n.buffer).setUint16(0,c,!0),n}if(e<1<<30){let n=new Uint8Array(4),c=(Number(e)<<2)+2;return new DataView(n.buffer).setUint32(0,c,!0),n}let t=[],o=BigInt(e);for(;o>0;)t.push(Number(o)),o>>=8n;return t.unshift((t.length-4<<2)+3),new Uint8Array(t)},C=r(He,Me);var Ne=e=>{let t=e===32?"setUint32":"setBigUint64",o=e/8,n=e===32?c=>c:BigInt;return c=>{let a=new Uint8Array(o);return new DataView(a.buffer)[t](0,n(c.getTime()),!0),a}},Pe=e=>{let t=e===32?"getUint32":"getBigUint64",o=e/8;return s(n=>{let c=new Date(Number(new DataView(n.buffer)[t](n.usedBytes,!0)));return n.useBytes(o),c})},L=e=>r(Ne(e),Pe(e)),W=L(32),$=L(64);var q=require("@unstoppablejs/utils");var _e=new TextEncoder,Fe=e=>{let t=_e.encode(e);return(0,q.mergeUint8)(C.enc(t.length),t)},Le=new TextDecoder,We=s(e=>{let t=C.dec(e),o=new Uint8Array(e.buffer,e.usedBytes,t);return e.useBytes(t),Le.decode(o)}),G=r(Fe,We);var $e=i(d.u16),qe=m(d.u16),J=r($e,qe);var Ge=i(d.u32),Je=m(d.u32),Q=r(Ge,Je);var Qe=i(d.u64),Xe=m(d.u64),X=r(Qe,Xe);var Ye=e=>{let t=new Uint8Array(16),o=new DataView(t.buffer);return o.setBigUint64(0,e,!0),o.setBigUint64(8,e>>64n,!0),t},Ze=s(e=>{let t=new DataView(e.buffer),o=t.getBigUint64(e.usedBytes,!0),n=t.getBigUint64(e.usedBytes+8,!0);return e.useBytes(16),(n<<64n)+o}),Y=r(Ye,Ze);var ze=i(d.i8),et=m(d.i8),Z=r(ze,et);var z=r(i(d.i16),m(d.i16));var ee=r(i(d.i32),m(d.i32));var te=r(i(d.i64),m(d.i64));var tt=e=>{let t=new Uint8Array(16),o=new DataView(t.buffer);return o.setBigUint64(0,e,!0),o.setBigInt64(8,e>>64n,!0),t},ot=s(e=>{let t=new DataView(e.buffer),o=t.getBigUint64(e.usedBytes,!0),n=t.getBigInt64(e.usedBytes+8,!0);return e.useBytes(16),(n<<64n)+o}),oe=r(tt,ot);var nt=new Uint8Array(0),ne=r(()=>nt,Function.prototype);var re=e=>t=>t.length===e?t:t.slice(0,e),ce=e=>s(t=>{let o=t.usedBytes,n=e!==1/0?e:t.byteLength-o,c=new Uint8Array(t.buffer,o,n);return t.useBytes(n),c}),T=e=>r(re(e),ce(e));T.enc=re;T.dec=ce;var O=require("@unstoppablejs/utils");var de=e=>{let t=Object.keys(e);return({tag:o,value:n})=>{let c=t.indexOf(o);return(0,O.mergeUint8)(u.enc(c),e[o](n))}},se=e=>{let t=Object.entries(e);return s(o=>{let n=u.dec(o),[c,a]=t[n],p=a(o);return{tag:c,value:p}})},b=e=>r(de((0,O.mapObject)(e,([t])=>t)),se((0,O.mapObject)(e,([,t])=>t)));b.enc=de;b.dec=se;var A=require("@unstoppablejs/utils");var me=e=>f(T.enc(e),A.fromHex),ie=e=>y(T.dec(e),A.toHex),K=e=>r(me(e),ie(e));K.enc=me;K.dec=ie;var ue=require("@unstoppablejs/utils");var ae=(...e)=>s(t=>e.map(o=>o(t))),pe=(...e)=>t=>(0,ue.mergeUint8)(...t.map((o,n)=>e[n](o))),x=(...e)=>r(pe(...e.map(([t])=>t)),ae(...e.map(([,t])=>t)));x.enc=pe;x.dec=ae;var j=require("@unstoppablejs/utils");var fe=(e,t)=>t>0?o=>(0,j.mergeUint8)(...o.map(e)):o=>(0,j.mergeUint8)(C.enc(o.length),...o.map(e));function ye(e,t){return s(o=>{let n=t>0?t:C.dec(o),c=new Array(n);for(let a=0;a<n;a++){let p=e(o);c[a]=p}return c})}function D(e,t){return r(fe(e[0],t),ye(e[1],t))}D.enc=fe;D.dec=ye;var xe=(e,t)=>f(D.enc(x.enc(e,t)),o=>Array.from(o.entries())),De=(e,t)=>y(D.dec(x.dec(e,t)),o=>new Map(o)),w=(e,t)=>r(xe(e[0],t[0]),De(e[1],t[1]));w.enc=xe;w.dec=De;var Ce=require("@unstoppablejs/utils"),Te=e=>s(t=>{let o=u.dec(t);if(o!==0)return e===g[1]?o===1:e(t)}),Ee=e=>t=>{let o=new Uint8Array(1);return t===void 0?(o[0]=0,o):(o[0]=1,e===g[0]?(o[0]=t?1:2,o):(0,Ce.mergeUint8)(o,e(t)))},B=e=>r(Ee(e[0]),Te(e[1]));B.enc=Ee;B.dec=Te;var le=require("@unstoppablejs/utils"),ge=(e,t)=>s(o=>{let c=u[1](o)===0,p=(c?e:t)(o);return{success:c,value:p}}),Oe=(e,t)=>({success:o,value:n})=>(0,le.mergeUint8)(u[0](o?0:1),(o?e:t)(n)),U=(e,t)=>r(Oe(e[0],t[0]),ge(e[1],t[1]));U.dec=ge;U.enc=Oe;var Ie=e=>f(D.enc(e),t=>Array.from(t)),be=e=>y(D.dec(e),t=>new Set(t)),V=e=>r(Ie(e[0]),be(e[1]));V.enc=Ie;V.dec=be;var M=require("@unstoppablejs/utils");var Ae=e=>{let t=Object.keys(e);return f(x.enc(...Object.values(e)),o=>t.map(n=>o[n]))},Ke=e=>{let t=Object.keys(e);return y(x.dec(...Object.values(e)),o=>Object.fromEntries(o.map((n,c)=>[t[c],n])))},k=e=>r(Ae((0,M.mapObject)(e,t=>t[0])),Ke((0,M.mapObject)(e,t=>t[1])));k.enc=Ae;k.dec=Ke;var v=e=>u;v.enc=e=>u[0];v.dec=e=>u[1];
//# sourceMappingURL=scale-ts.cjs.production.min.js.map

@@ -179,11 +179,9 @@ var __accessCheck = (obj, member, msg) => {

// src/codecs/str.ts
import {
mergeUint8,
utf16StrToUtf8Bytes,
utf8BytesToUtf16Str
} from "@unstoppablejs/utils";
import { mergeUint8 } from "@unstoppablejs/utils";
var textEncoder = new TextEncoder();
var strEnc = (str2) => {
const val = utf16StrToUtf8Bytes(str2);
const val = textEncoder.encode(str2);
return mergeUint8(compact.enc(val.length), val);
};
var textDecoder = new TextDecoder();
var strDec = toInternalBytes((bytes) => {

@@ -193,3 +191,3 @@ let nElements = compact.dec(bytes);

bytes.useBytes(nElements);
return utf8BytesToUtf16Str(arr);
return textDecoder.decode(arr);
});

@@ -262,5 +260,4 @@ var str = createCodec(strEnc, strDec);

// src/codecs/void.ts
var VOID = Symbol("empty");
var emptyArr = new Uint8Array(0);
var _void = createCodec(() => emptyArr, () => VOID);
var _void = createCodec(() => emptyArr, Function.prototype);

@@ -295,3 +292,3 @@ // src/codecs/Bytes.ts

const innerResult = innerDecoder(bytes);
return innerResult === VOID ? { tag } : {
return {
tag,

@@ -424,3 +421,2 @@ value: innerResult

U8Enum,
VOID,
Vector,

@@ -427,0 +423,0 @@ _void,

{
"version": "0.1.0",
"version": "0.2.0-alpha.0",
"repository": {

@@ -4,0 +4,0 @@ "type": "git",

@@ -27,7 +27,9 @@ # scale-ts

/*
Something very important is the types that are being inferred from this definition,
which both the encoder and the decoder will use. For instance, the input of the
encoder must be compatible with the following interface:
Something really cool about this library is that by having composable codecs
which have very good typings, then the inferred types of the resulting codecs
also have really good typings. For instance, the inferred types of codec
defined above are:
*/
interface SomeData {
type MyCodec = Codec<{
id: number;

@@ -41,10 +43,10 @@ name: string;

| { tag: allOrNothing; value: boolean; };
}
Which, as you might expect, it's the same interface that's returned by the
decoder.
}>
*/
Therefore, we won't get typing errors as long as we pass a valide interface
to the encoder:
const encodedData: ArrayBuffer = myCodec.enc({
event: { tag: Events.AllOrNothing, value: true },
event: { tag: 'allOrNothing', value: true },
name: "Some name",

@@ -104,1 +106,65 @@ id: 100,

```
## API
### bool
```ts
bool.enc(false)
// => 0x00
bool.dec("0x01")
// => true
```
### Bytes
Sometimes, mainly when creating your custom codecs, it's usefull to have a
codec that simply reads/writes a certain amount of bytes. For example, see the
example above for creating a custom `AccountId` codec.
```ts
const threeBytes = Bytes(3)
threeBytes.enc(new Uint8Array([0, 15, 255]))
// => 0x000fff
bool.dec("0x000fff00")
// => 0x000fff
```
### [Compact/general integers](https://docs.substrate.io/v3/advanced/scale-codec/#compactgeneral-integers)
Supported codecs are: `compact`, `u8`, `u16`, `u32`, `u64`, `u128`, `i8`, `i16`,
`i32`, `i64`, `i128`
```ts
compact.enc(65535)
// => 0xfeff0300
compact.dec('0xfeff0300')
// => 65535
i128.enc(-18676936063680574795862633153229949450n)
// => 0xf6f5f4f3f2f1f0f9f8f7f6f5f4f3f2f1
i128.dec('0xf6f5f4f3f2f1f0f9f8f7f6f5f4f3f2f1')
// => -18676936063680574795862633153229949450n
```
### date32/date64
```ts
```
### Enum
```ts
```
### hex
```ts
```
###

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc