@typeberry/lib 0.1.2-220a073 → 0.1.2-4ae774a
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/index.cjs +14 -3
- package/index.d.ts +15 -0
- package/index.js +14 -3
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1947,13 +1947,15 @@ function validateLength(range, length, context) {
|
|
|
1947
1947
|
|
|
1948
1948
|
/** A caching wrapper for either object or sequence item. */
|
|
1949
1949
|
class ViewField {
|
|
1950
|
+
name;
|
|
1950
1951
|
getView;
|
|
1951
1952
|
getValue;
|
|
1952
1953
|
getEncoded;
|
|
1953
1954
|
cachedValue;
|
|
1954
1955
|
cachedView;
|
|
1955
1956
|
cachedBlob;
|
|
1956
|
-
constructor(getView, getValue, getEncoded) {
|
|
1957
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
1958
|
+
this.name = name;
|
|
1957
1959
|
this.getView = getView;
|
|
1958
1960
|
this.getValue = getValue;
|
|
1959
1961
|
this.getEncoded = getEncoded;
|
|
@@ -1979,6 +1981,9 @@ class ViewField {
|
|
|
1979
1981
|
}
|
|
1980
1982
|
return this.cachedBlob;
|
|
1981
1983
|
}
|
|
1984
|
+
toString() {
|
|
1985
|
+
return `ViewField<${this.name}>`;
|
|
1986
|
+
}
|
|
1982
1987
|
}
|
|
1983
1988
|
/**
|
|
1984
1989
|
* A base class for all the lazy views.
|
|
@@ -2053,7 +2058,7 @@ class ObjectView {
|
|
|
2053
2058
|
const fieldDecoder = skipper.decoder.clone();
|
|
2054
2059
|
const field = this.descriptorsKeys[i];
|
|
2055
2060
|
const type = this.descriptors[field];
|
|
2056
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2061
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2057
2062
|
// skip the field
|
|
2058
2063
|
type.skip(skipper);
|
|
2059
2064
|
// cache data
|
|
@@ -2065,6 +2070,9 @@ class ObjectView {
|
|
|
2065
2070
|
}
|
|
2066
2071
|
return lastItem;
|
|
2067
2072
|
}
|
|
2073
|
+
toString() {
|
|
2074
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2075
|
+
}
|
|
2068
2076
|
}
|
|
2069
2077
|
/**
|
|
2070
2078
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2153,7 +2161,7 @@ class SequenceView {
|
|
|
2153
2161
|
// create new cached prop
|
|
2154
2162
|
const fieldDecoder = skipper.decoder.clone();
|
|
2155
2163
|
const type = this.descriptor;
|
|
2156
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2164
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2157
2165
|
// skip the field
|
|
2158
2166
|
type.skip(skipper);
|
|
2159
2167
|
// cache data
|
|
@@ -2165,6 +2173,9 @@ class SequenceView {
|
|
|
2165
2173
|
}
|
|
2166
2174
|
return lastItem;
|
|
2167
2175
|
}
|
|
2176
|
+
toString() {
|
|
2177
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2178
|
+
}
|
|
2168
2179
|
}
|
|
2169
2180
|
|
|
2170
2181
|
/**
|
package/index.d.ts
CHANGED
|
@@ -2527,6 +2527,7 @@ declare class ViewField<T, V> implements ViewField<T, V> {
|
|
|
2527
2527
|
private cachedBlob: BytesBlob | undefined;
|
|
2528
2528
|
|
|
2529
2529
|
constructor(
|
|
2530
|
+
private readonly name: string,
|
|
2530
2531
|
private readonly getView: () => V,
|
|
2531
2532
|
private readonly getValue: () => T,
|
|
2532
2533
|
private readonly getEncoded: () => BytesBlob,
|
|
@@ -2555,6 +2556,10 @@ declare class ViewField<T, V> implements ViewField<T, V> {
|
|
|
2555
2556
|
}
|
|
2556
2557
|
return this.cachedBlob;
|
|
2557
2558
|
}
|
|
2559
|
+
|
|
2560
|
+
toString() {
|
|
2561
|
+
return `ViewField<${this.name}>`;
|
|
2562
|
+
}
|
|
2558
2563
|
}
|
|
2559
2564
|
|
|
2560
2565
|
/**
|
|
@@ -2638,6 +2643,7 @@ declare abstract class ObjectView<T> {
|
|
|
2638
2643
|
const field = this.descriptorsKeys[i];
|
|
2639
2644
|
const type = this.descriptors[field as keyof DescriptorRecord<T>];
|
|
2640
2645
|
lastItem = new ViewField(
|
|
2646
|
+
`${this.toString()}.${String(field)}`,
|
|
2641
2647
|
() => type.View.decode(fieldDecoder.clone()),
|
|
2642
2648
|
() => type.decode(fieldDecoder.clone()),
|
|
2643
2649
|
() => type.skipEncoded(fieldDecoder.clone()),
|
|
@@ -2655,6 +2661,10 @@ declare abstract class ObjectView<T> {
|
|
|
2655
2661
|
|
|
2656
2662
|
return lastItem as ViewField<T[K], unknown>;
|
|
2657
2663
|
}
|
|
2664
|
+
|
|
2665
|
+
toString() {
|
|
2666
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2667
|
+
}
|
|
2658
2668
|
}
|
|
2659
2669
|
|
|
2660
2670
|
/**
|
|
@@ -2755,6 +2765,7 @@ declare class SequenceView<T, V = T> {
|
|
|
2755
2765
|
const fieldDecoder = skipper.decoder.clone();
|
|
2756
2766
|
const type = this.descriptor;
|
|
2757
2767
|
lastItem = new ViewField(
|
|
2768
|
+
`${this.toString()}[${index}]`,
|
|
2758
2769
|
() => type.View.decode(fieldDecoder.clone()),
|
|
2759
2770
|
() => type.decode(fieldDecoder.clone()),
|
|
2760
2771
|
() => type.skipEncoded(fieldDecoder.clone()),
|
|
@@ -2771,6 +2782,10 @@ declare class SequenceView<T, V = T> {
|
|
|
2771
2782
|
}
|
|
2772
2783
|
return lastItem;
|
|
2773
2784
|
}
|
|
2785
|
+
|
|
2786
|
+
toString() {
|
|
2787
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2788
|
+
}
|
|
2774
2789
|
}
|
|
2775
2790
|
|
|
2776
2791
|
/**
|
package/index.js
CHANGED
|
@@ -1944,13 +1944,15 @@ function validateLength(range, length, context) {
|
|
|
1944
1944
|
|
|
1945
1945
|
/** A caching wrapper for either object or sequence item. */
|
|
1946
1946
|
class ViewField {
|
|
1947
|
+
name;
|
|
1947
1948
|
getView;
|
|
1948
1949
|
getValue;
|
|
1949
1950
|
getEncoded;
|
|
1950
1951
|
cachedValue;
|
|
1951
1952
|
cachedView;
|
|
1952
1953
|
cachedBlob;
|
|
1953
|
-
constructor(getView, getValue, getEncoded) {
|
|
1954
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
1955
|
+
this.name = name;
|
|
1954
1956
|
this.getView = getView;
|
|
1955
1957
|
this.getValue = getValue;
|
|
1956
1958
|
this.getEncoded = getEncoded;
|
|
@@ -1976,6 +1978,9 @@ class ViewField {
|
|
|
1976
1978
|
}
|
|
1977
1979
|
return this.cachedBlob;
|
|
1978
1980
|
}
|
|
1981
|
+
toString() {
|
|
1982
|
+
return `ViewField<${this.name}>`;
|
|
1983
|
+
}
|
|
1979
1984
|
}
|
|
1980
1985
|
/**
|
|
1981
1986
|
* A base class for all the lazy views.
|
|
@@ -2050,7 +2055,7 @@ class ObjectView {
|
|
|
2050
2055
|
const fieldDecoder = skipper.decoder.clone();
|
|
2051
2056
|
const field = this.descriptorsKeys[i];
|
|
2052
2057
|
const type = this.descriptors[field];
|
|
2053
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2058
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2054
2059
|
// skip the field
|
|
2055
2060
|
type.skip(skipper);
|
|
2056
2061
|
// cache data
|
|
@@ -2062,6 +2067,9 @@ class ObjectView {
|
|
|
2062
2067
|
}
|
|
2063
2068
|
return lastItem;
|
|
2064
2069
|
}
|
|
2070
|
+
toString() {
|
|
2071
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2072
|
+
}
|
|
2065
2073
|
}
|
|
2066
2074
|
/**
|
|
2067
2075
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2150,7 +2158,7 @@ class SequenceView {
|
|
|
2150
2158
|
// create new cached prop
|
|
2151
2159
|
const fieldDecoder = skipper.decoder.clone();
|
|
2152
2160
|
const type = this.descriptor;
|
|
2153
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2161
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2154
2162
|
// skip the field
|
|
2155
2163
|
type.skip(skipper);
|
|
2156
2164
|
// cache data
|
|
@@ -2162,6 +2170,9 @@ class SequenceView {
|
|
|
2162
2170
|
}
|
|
2163
2171
|
return lastItem;
|
|
2164
2172
|
}
|
|
2173
|
+
toString() {
|
|
2174
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2175
|
+
}
|
|
2165
2176
|
}
|
|
2166
2177
|
|
|
2167
2178
|
/**
|