-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into issues/1-missing-data-types
- Loading branch information
Showing
6 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// A hook that can be added before or after the parsing of a [Parsable] object. | ||
/// | ||
/// See [ParseNode] or [ParseNodeProxyFactory] for abilities to add hooks to the | ||
/// parsing of a [Parsable] object. | ||
typedef ParsableHook = void Function(Parsable); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
/// A factory that creates a proxy for a [ParseNodeFactory] that allows for | ||
/// hooks to be added before and after the parsing of a [Parsable] object. | ||
abstract class ParseNodeProxyFactory implements ParseNodeFactory { | ||
/// Creates a new instance of the [ParseNodeProxyFactory] class. | ||
ParseNodeProxyFactory({ | ||
required ParseNodeFactory concrete, | ||
ParsableHook? onBefore, | ||
ParsableHook? onAfter, | ||
}) : _concrete = concrete, | ||
_onBefore = onBefore, | ||
_onAfter = onAfter; | ||
|
||
final ParseNodeFactory _concrete; | ||
final ParsableHook? _onBefore; | ||
final ParsableHook? _onAfter; | ||
|
||
@override | ||
String get validContentType => _concrete.validContentType; | ||
|
||
@override | ||
ParseNode getRootParseNode(String contentType, Uint8List content) { | ||
final node = _concrete.getRootParseNode(contentType, content); | ||
|
||
final originalBefore = node.onBeforeAssignFieldValues; | ||
node.onBeforeAssignFieldValues = (parsable) { | ||
originalBefore?.call(parsable); | ||
_onBefore?.call(parsable); | ||
}; | ||
|
||
final originalAfter = node.onAfterAssignFieldValues; | ||
node.onAfterAssignFieldValues = (parsable) { | ||
originalAfter?.call(parsable); | ||
_onAfter?.call(parsable); | ||
}; | ||
|
||
return node; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
lib/src/serialization/serialization_writer_proxy_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
part of '../../kiota_abstractions.dart'; | ||
|
||
abstract class SerializationWriterProxyFactory | ||
implements SerializationWriterFactory { | ||
SerializationWriterProxyFactory({ | ||
required SerializationWriterFactory concrete, | ||
ParsableHook? onBefore, | ||
ParsableHook? onAfter, | ||
void Function(Parsable, SerializationWriter)? onStart, | ||
}) : _concrete = concrete, | ||
_onBefore = onBefore, | ||
_onAfter = onAfter, | ||
_onStart = onStart; | ||
|
||
final SerializationWriterFactory _concrete; | ||
final ParsableHook? _onBefore; | ||
final ParsableHook? _onAfter; | ||
final void Function(Parsable, SerializationWriter)? _onStart; | ||
|
||
@override | ||
String get validContentType => _concrete.validContentType; | ||
|
||
@override | ||
SerializationWriter getSerializationWriter(String contentType) { | ||
final writer = _concrete.getSerializationWriter(contentType); | ||
|
||
final originalBefore = writer.onBeforeObjectSerialization; | ||
writer.onBeforeObjectSerialization = (p) { | ||
_onBefore?.call(p); | ||
originalBefore?.call(p); | ||
}; | ||
|
||
final originalAfter = writer.onAfterObjectSerialization; | ||
writer.onAfterObjectSerialization = (p) { | ||
_onAfter?.call(p); | ||
originalAfter?.call(p); | ||
}; | ||
|
||
final originalStart = writer.onStartObjectSerialization; | ||
writer.onStartObjectSerialization = (p, w) { | ||
_onStart?.call(p, w); | ||
originalStart?.call(p, w); | ||
}; | ||
|
||
return writer; | ||
} | ||
} |