skip on deserialize
This commit is contained in:
parent
db57f24b54
commit
ac02e19606
7 changed files with 63 additions and 33 deletions
32
dist/de/generic.js
vendored
32
dist/de/generic.js
vendored
|
@ -42,14 +42,14 @@ class ProxyMapAccess {
|
|||
}
|
||||
wrapResponse(result) {
|
||||
var _a, _b, _c, _d;
|
||||
if (result.done) {
|
||||
return result;
|
||||
}
|
||||
else if ((0, utils_1.isString)(result.value)) {
|
||||
switch (true) {
|
||||
default:
|
||||
case result.done: return result;
|
||||
case (0, utils_1.isString)(result.value): {
|
||||
const key = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.getDeserializationPropertyName(result.value)) !== null && _b !== void 0 ? _b : result.value;
|
||||
return utils_1.IterResult.Next(key);
|
||||
}
|
||||
else if (Array.isArray(result.value)) {
|
||||
case Array.isArray(result.value): {
|
||||
const [alias, value] = result.value;
|
||||
const key = (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.getDeserializationPropertyName(alias)) !== null && _d !== void 0 ? _d : alias;
|
||||
return utils_1.IterResult.Next([
|
||||
|
@ -57,10 +57,12 @@ class ProxyMapAccess {
|
|||
value
|
||||
]);
|
||||
}
|
||||
else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
shouldSkipEntry(entry) {
|
||||
var _a;
|
||||
return (_a = this.options) === null || _a === void 0 ? void 0 : _a.shouldSkipDeserialization(entry.value[0], entry.value[1]);
|
||||
}
|
||||
nextKeySeed(seed) {
|
||||
return this.wrapResponse(this.access.nextKeySeed(seed));
|
||||
}
|
||||
|
@ -68,7 +70,13 @@ class ProxyMapAccess {
|
|||
return this.access.nextValueSeed(seed);
|
||||
}
|
||||
nextEntrySeed(kseed, vseed) {
|
||||
return this.wrapResponse(this.access.nextEntrySeed(kseed, vseed));
|
||||
const response = this.wrapResponse(this.access.nextEntrySeed(kseed, vseed));
|
||||
if (!response.done && this.shouldSkipEntry(response)) {
|
||||
return this.nextEntrySeed(kseed, vseed);
|
||||
}
|
||||
else {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
nextKey() {
|
||||
return this.wrapResponse(this.access.nextKey());
|
||||
|
@ -77,7 +85,13 @@ class ProxyMapAccess {
|
|||
return this.access.nextValue();
|
||||
}
|
||||
nextEntry() {
|
||||
return this.wrapResponse(this.access.nextEntry());
|
||||
const response = this.wrapResponse(this.access.nextEntry());
|
||||
if (!response.done && this.shouldSkipEntry(response)) {
|
||||
return this.nextEntry();
|
||||
}
|
||||
else {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
sizeHint() {
|
||||
var _a, _b;
|
||||
|
|
4
dist/option.d.ts
vendored
4
dist/option.d.ts
vendored
|
@ -64,8 +64,8 @@ export declare class SerdeOptions {
|
|||
getNameFromAlias(alias: string): string | undefined;
|
||||
getDeserializationPropertyName(property: string): string;
|
||||
shouldSkip(stage: Stage, property: string, value: any): boolean;
|
||||
shouldSerialize(property: string, value: any): boolean;
|
||||
shouldDeserialize(property: string, value: any): boolean;
|
||||
shouldSkipSerialization(property: string, value: any): boolean;
|
||||
shouldSkipDeserialization(property: string, value: any): boolean;
|
||||
defaultFor(property: string): any;
|
||||
}
|
||||
export {};
|
||||
|
|
8
dist/option.js
vendored
8
dist/option.js
vendored
|
@ -190,11 +190,11 @@ class SerdeOptions {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
shouldSerialize(property, value) {
|
||||
return !this.shouldSkip(exports.Stage.Serialize, property, value);
|
||||
shouldSkipSerialization(property, value) {
|
||||
return this.shouldSkip(exports.Stage.Serialize, property, value);
|
||||
}
|
||||
shouldDeserialize(property, value) {
|
||||
return !this.shouldSkip(exports.Stage.Deserialize, property, value);
|
||||
shouldSkipDeserialization(property, value) {
|
||||
return this.shouldSkip(exports.Stage.Deserialize, property, value);
|
||||
}
|
||||
defaultFor(property) {
|
||||
const options = this.properties.get(property);
|
||||
|
|
2
dist/ser/impl.js
vendored
2
dist/ser/impl.js
vendored
|
@ -10,7 +10,7 @@ class UnhandledTypeError extends TypeError {
|
|||
function serializeObject(serializer, obj, options) {
|
||||
for (const key in obj) {
|
||||
const value = obj[key];
|
||||
if (options === null || options === void 0 ? void 0 : options.shouldSerialize(key, value)) {
|
||||
if (!(options === null || options === void 0 ? void 0 : options.shouldSkipSerialization(key, value))) {
|
||||
const name = (options === null || options === void 0 ? void 0 : options.getSerializationPropertyName(key)) || key;
|
||||
serializer.serializeEntry(name, value);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,10 @@ class ProxyMapAccess implements IMapAccess {
|
|||
}
|
||||
}
|
||||
|
||||
shouldSkipEntry<K, V>(entry: IteratorResult<[K, V]>) {
|
||||
return this.options?.shouldSkipDeserialization(entry.value[0] as string, entry.value[1])
|
||||
}
|
||||
|
||||
nextKeySeed<T, K extends Deserialize<T>>(seed: K): IteratorResult<T> {
|
||||
return this.wrapResponse<T>(this.access.nextKeySeed(seed))
|
||||
}
|
||||
|
@ -60,7 +64,13 @@ class ProxyMapAccess implements IMapAccess {
|
|||
}
|
||||
|
||||
nextEntrySeed<TK, TV, K extends Deserialize<TK>, V extends Deserialize<TV>>(kseed: K, vseed: V): IteratorResult<[TK, TV]> {
|
||||
return this.wrapResponse<[TK, TV]>(this.access.nextEntrySeed(kseed, vseed))
|
||||
const response = this.wrapResponse<[TK, TV]>(this.access.nextEntrySeed(kseed, vseed))
|
||||
|
||||
if (!response.done && this.shouldSkipEntry(response)) {
|
||||
return this.nextEntrySeed(kseed, vseed)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
nextKey<T>(): IteratorResult<T> {
|
||||
|
@ -72,7 +82,13 @@ class ProxyMapAccess implements IMapAccess {
|
|||
}
|
||||
|
||||
nextEntry<K, V>(): IteratorResult<[K, V]> {
|
||||
return this.wrapResponse<[K, V]>(this.access.nextEntry())
|
||||
const response = this.wrapResponse<[K, V]>(this.access.nextEntry())
|
||||
|
||||
if (!response.done && this.shouldSkipEntry(response)) {
|
||||
return this.nextEntry()
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
sizeHint?(): Nullable<number> {
|
||||
|
|
|
@ -199,12 +199,12 @@ export class SerdeOptions {
|
|||
}
|
||||
}
|
||||
|
||||
shouldSerialize(property: string, value: any) {
|
||||
return !this.shouldSkip(Stage.Serialize, property, value)
|
||||
shouldSkipSerialization(property: string, value: any) {
|
||||
return this.shouldSkip(Stage.Serialize, property, value)
|
||||
}
|
||||
|
||||
shouldDeserialize(property: string, value: any) {
|
||||
return !this.shouldSkip(Stage.Deserialize, property, value)
|
||||
shouldSkipDeserialization(property: string, value: any) {
|
||||
return this.shouldSkip(Stage.Deserialize, property, value)
|
||||
}
|
||||
|
||||
defaultFor(property: string) {
|
||||
|
|
|
@ -11,7 +11,7 @@ class UnhandledTypeError extends TypeError {
|
|||
function serializeObject<T, V extends object, S extends ISerializeObject<T>>(serializer: S, obj: V, options?: SerdeOptions): T {
|
||||
for (const key in obj) {
|
||||
const value = obj[key]
|
||||
if (options?.shouldSerialize(key, value)) {
|
||||
if (!options?.shouldSkipSerialization(key, value)) {
|
||||
const name = options?.getSerializationPropertyName(key) || key
|
||||
serializer.serializeEntry(name, value)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue