@typeberry/convert 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.js +17 -3
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6867,13 +6867,15 @@ function validateLength(range, length, context) {
|
|
|
6867
6867
|
|
|
6868
6868
|
/** A caching wrapper for either object or sequence item. */
|
|
6869
6869
|
class ViewField {
|
|
6870
|
+
name;
|
|
6870
6871
|
getView;
|
|
6871
6872
|
getValue;
|
|
6872
6873
|
getEncoded;
|
|
6873
6874
|
cachedValue;
|
|
6874
6875
|
cachedView;
|
|
6875
6876
|
cachedBlob;
|
|
6876
|
-
constructor(getView, getValue, getEncoded) {
|
|
6877
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
6878
|
+
this.name = name;
|
|
6877
6879
|
this.getView = getView;
|
|
6878
6880
|
this.getValue = getValue;
|
|
6879
6881
|
this.getEncoded = getEncoded;
|
|
@@ -6899,6 +6901,9 @@ class ViewField {
|
|
|
6899
6901
|
}
|
|
6900
6902
|
return this.cachedBlob;
|
|
6901
6903
|
}
|
|
6904
|
+
toString() {
|
|
6905
|
+
return `ViewField<${this.name}>`;
|
|
6906
|
+
}
|
|
6902
6907
|
}
|
|
6903
6908
|
/**
|
|
6904
6909
|
* A base class for all the lazy views.
|
|
@@ -6973,7 +6978,7 @@ class ObjectView {
|
|
|
6973
6978
|
const fieldDecoder = skipper.decoder.clone();
|
|
6974
6979
|
const field = this.descriptorsKeys[i];
|
|
6975
6980
|
const type = this.descriptors[field];
|
|
6976
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
6981
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
6977
6982
|
// skip the field
|
|
6978
6983
|
type.skip(skipper);
|
|
6979
6984
|
// cache data
|
|
@@ -6985,6 +6990,9 @@ class ObjectView {
|
|
|
6985
6990
|
}
|
|
6986
6991
|
return lastItem;
|
|
6987
6992
|
}
|
|
6993
|
+
toString() {
|
|
6994
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
6995
|
+
}
|
|
6988
6996
|
}
|
|
6989
6997
|
/**
|
|
6990
6998
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -7073,7 +7081,7 @@ class SequenceView {
|
|
|
7073
7081
|
// create new cached prop
|
|
7074
7082
|
const fieldDecoder = skipper.decoder.clone();
|
|
7075
7083
|
const type = this.descriptor;
|
|
7076
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
7084
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
7077
7085
|
// skip the field
|
|
7078
7086
|
type.skip(skipper);
|
|
7079
7087
|
// cache data
|
|
@@ -7085,6 +7093,9 @@ class SequenceView {
|
|
|
7085
7093
|
}
|
|
7086
7094
|
return lastItem;
|
|
7087
7095
|
}
|
|
7096
|
+
toString() {
|
|
7097
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
7098
|
+
}
|
|
7088
7099
|
}
|
|
7089
7100
|
|
|
7090
7101
|
;// CONCATENATED MODULE: ./packages/core/codec/descriptors.ts
|
|
@@ -27354,6 +27365,9 @@ function toJson(data) {
|
|
|
27354
27365
|
if (value instanceof Map) {
|
|
27355
27366
|
return Object.fromEntries(value.entries());
|
|
27356
27367
|
}
|
|
27368
|
+
if (value instanceof ObjectView) {
|
|
27369
|
+
return value.materialize();
|
|
27370
|
+
}
|
|
27357
27371
|
return value;
|
|
27358
27372
|
}, 2);
|
|
27359
27373
|
}
|