@microsoft/kiota-abstractions
Version:
Core abstractions for kiota generated libraries in TypeScript and JavaScript
48 lines • 2.07 kB
JavaScript
/** Proxy factory that allows the composition of before and after callbacks on existing factories. */
export class SerializationWriterProxyFactory {
getValidContentType() {
return this._concrete.getValidContentType();
}
/**
* Creates a new proxy factory that wraps the specified concrete factory while composing the before and after callbacks.
* @param _concrete the concrete factory to wrap
* @param _onBefore the callback to invoke before the serialization of any model object.
* @param _onAfter the callback to invoke after the serialization of any model object.
* @param _onStart the callback to invoke when the serialization of a model object starts
*/
constructor(_concrete, _onBefore, _onAfter, _onStart) {
this._concrete = _concrete;
this._onBefore = _onBefore;
this._onAfter = _onAfter;
this._onStart = _onStart;
if (!_concrete) {
throw new Error("_concrete cannot be undefined");
}
}
getSerializationWriter(contentType) {
const writer = this._concrete.getSerializationWriter(contentType);
const originalBefore = writer.onBeforeObjectSerialization;
const originalAfter = writer.onAfterObjectSerialization;
const originalStart = writer.onStartObjectSerialization;
writer.onBeforeObjectSerialization = (value) => {
if (this._onBefore)
this._onBefore(value);
if (originalBefore)
originalBefore(value);
};
writer.onAfterObjectSerialization = (value) => {
if (this._onAfter)
this._onAfter(value);
if (originalAfter)
originalAfter(value);
};
writer.onStartObjectSerialization = (value, writer_) => {
if (this._onStart)
this._onStart(value, writer_);
if (originalStart)
originalStart(value, writer_);
};
return writer;
}
}
//# sourceMappingURL=serializationWriterProxyFactory.js.map