@microsoft/kiota-abstractions
Version:
Core abstractions for kiota generated libraries in TypeScript and JavaScript
39 lines • 1.6 kB
JavaScript
/** Proxy factory that allows the composition of before and after callbacks on existing factories. */
export class ParseNodeProxyFactory {
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 deserialization of any model object.
* @param _onAfter the callback to invoke after the deserialization of any model object.
*/
constructor(_concrete, _onBefore, _onAfter) {
this._concrete = _concrete;
this._onBefore = _onBefore;
this._onAfter = _onAfter;
if (!_concrete) {
throw new Error("_concrete cannot be undefined");
}
}
getRootParseNode(contentType, content) {
const node = this._concrete.getRootParseNode(contentType, content);
const originalBefore = node.onBeforeAssignFieldValues;
const originalAfter = node.onAfterAssignFieldValues;
node.onBeforeAssignFieldValues = (value) => {
if (this._onBefore)
this._onBefore(value);
if (originalBefore)
originalBefore(value);
};
node.onAfterAssignFieldValues = (value) => {
if (this._onAfter)
this._onAfter(value);
if (originalAfter)
originalAfter(value);
};
return node;
}
}
//# sourceMappingURL=parseNodeProxyFactory.js.map