230 lines
8.3 KiB
JavaScript
230 lines
8.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ProxyDeserializer = exports.ProxyVisitor = exports.GenericSeed = void 0;
|
|
const utils_1 = require("../utils");
|
|
class GenericSeed {
|
|
constructor(visitor = new ProxyVisitor()) {
|
|
Object.defineProperty(this, "visitor", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
this.visitor = visitor;
|
|
}
|
|
static deserialize(deserializer, visitor = new ProxyVisitor()) {
|
|
return deserializer.deserializeAny(visitor);
|
|
}
|
|
deserialize(deserializer) {
|
|
return GenericSeed.deserialize(deserializer, this.visitor);
|
|
}
|
|
}
|
|
exports.GenericSeed = GenericSeed;
|
|
class ProxyMapAccess {
|
|
constructor(access, options) {
|
|
Object.defineProperty(this, "access", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
Object.defineProperty(this, "options", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
if (access instanceof ProxyMapAccess) {
|
|
return this;
|
|
}
|
|
this.access = access;
|
|
this.options = options;
|
|
}
|
|
wrapResponse(result) {
|
|
var _a, _b, _c, _d;
|
|
if (result.done) {
|
|
return result;
|
|
}
|
|
else if ((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)) {
|
|
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([
|
|
key,
|
|
value
|
|
]);
|
|
}
|
|
else {
|
|
return result;
|
|
}
|
|
}
|
|
nextKeySeed(seed) {
|
|
return this.wrapResponse(this.access.nextKeySeed(seed));
|
|
}
|
|
nextValueSeed(seed) {
|
|
return this.access.nextValueSeed(seed);
|
|
}
|
|
nextEntrySeed(kseed, vseed) {
|
|
return this.wrapResponse(this.access.nextEntrySeed(kseed, vseed));
|
|
}
|
|
nextKey() {
|
|
return this.wrapResponse(this.access.nextKey());
|
|
}
|
|
nextValue() {
|
|
return this.access.nextValue();
|
|
}
|
|
nextEntry() {
|
|
return this.wrapResponse(this.access.nextEntry());
|
|
}
|
|
sizeHint() {
|
|
var _a, _b;
|
|
return (_b = (_a = this.access).sizeHint) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
}
|
|
*generate(next) {
|
|
let item;
|
|
while ((item = next()) && !item.done) {
|
|
yield item.value;
|
|
}
|
|
}
|
|
keys(seed) {
|
|
return this.generate(seed == null ?
|
|
this.nextKey.bind(this) :
|
|
this.nextKeySeed.bind(this, seed));
|
|
}
|
|
values(seed) {
|
|
return this.generate(seed == null ?
|
|
this.nextValue.bind(this) :
|
|
this.nextValueSeed.bind(this, seed));
|
|
}
|
|
entries(kseed, vseed) {
|
|
return this.generate(kseed == null || vseed == null ?
|
|
this.nextEntry.bind(this) :
|
|
this.nextEntrySeed.bind(this, kseed, vseed));
|
|
}
|
|
[Symbol.iterator]() {
|
|
return this.entries();
|
|
}
|
|
}
|
|
class ProxyVisitor {
|
|
constructor(overrides, options) {
|
|
Object.defineProperty(this, "overrides", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
Object.defineProperty(this, "options", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
if (overrides instanceof ProxyVisitor) {
|
|
return overrides;
|
|
}
|
|
this.overrides = overrides;
|
|
this.options = options;
|
|
}
|
|
visitBoolean(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitBoolean) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitNumber(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitNumber) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitBigInt(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitBigInt) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitString(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitString) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitSymbol(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitSymbol) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitNull() {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitNull) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : null;
|
|
}
|
|
visitObject(access) {
|
|
var _a, _b;
|
|
const proxy = new ProxyMapAccess(access, this.options);
|
|
if ((0, utils_1.isFunction)((_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitObject)) {
|
|
return (_b = this.overrides) === null || _b === void 0 ? void 0 : _b.visitObject(proxy);
|
|
}
|
|
const result = [];
|
|
let entry;
|
|
while ((entry = proxy.nextEntry()) && !entry.done) {
|
|
result.push(entry.value);
|
|
}
|
|
return Object.fromEntries(result);
|
|
}
|
|
visitIterable(access) {
|
|
var _a, _b;
|
|
if ((0, utils_1.isFunction)((_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitIterable)) {
|
|
return (_b = this.overrides) === null || _b === void 0 ? void 0 : _b.visitIterable(access);
|
|
}
|
|
const result = [];
|
|
let element;
|
|
while ((element = access.nextElement())) {
|
|
result.push(element);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
exports.ProxyVisitor = ProxyVisitor;
|
|
class ProxyDeserializer {
|
|
constructor(deserializer, options) {
|
|
Object.defineProperty(this, "deserializer", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
Object.defineProperty(this, "options", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
this.deserializer = deserializer;
|
|
this.options = options;
|
|
}
|
|
deserializeAny(visitor) {
|
|
return this.deserializer.deserializeAny(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeBoolean(visitor) {
|
|
return this.deserializer.deserializeBoolean(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeNumber(visitor) {
|
|
return this.deserializer.deserializeNumber(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeBigInt(visitor) {
|
|
return this.deserializer.deserializeBigInt(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeString(visitor) {
|
|
return this.deserializer.deserializeString(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeSymbol(visitor) {
|
|
return this.deserializer.deserializeSymbol(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeNull(visitor) {
|
|
return this.deserializer.deserializeNull(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeObject(visitor) {
|
|
return this.deserializer.deserializeObject(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeIterable(visitor) {
|
|
return this.deserializer.deserializeIterable(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
deserializeFunction(visitor) {
|
|
return this.deserializer.deserializeFunction(new ProxyVisitor(visitor, this.options));
|
|
}
|
|
}
|
|
exports.ProxyDeserializer = ProxyDeserializer;
|