mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-30 15:04:48 +00:00
♻️ sync owner migration and facade thinning
This commit is contained in:
+8
-42
@@ -1,47 +1,29 @@
|
||||
///|
|
||||
pub type RecordPatch = (@core.Record) -> @core.Record
|
||||
pub type RecordPatch = @record_ops.RecordPatch
|
||||
|
||||
///|
|
||||
pub fn identity_patch() -> RecordPatch {
|
||||
fn(rec) { rec }
|
||||
@record_ops.identity_patch()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn set_target(target : String) -> RecordPatch {
|
||||
fn(rec) { rec.with_target(target) }
|
||||
@record_ops.set_target(target)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn prefix_message(prefix : String) -> RecordPatch {
|
||||
fn(rec) { rec.with_message("\{prefix}\{rec.message}") }
|
||||
@record_ops.prefix_message(prefix)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn append_fields(extra_fields : Array[@core.Field]) -> RecordPatch {
|
||||
fn(rec) {
|
||||
if extra_fields.length() == 0 {
|
||||
rec
|
||||
} else if rec.fields.length() == 0 {
|
||||
rec.with_fields(extra_fields)
|
||||
} else {
|
||||
rec.with_fields(rec.fields + extra_fields)
|
||||
}
|
||||
}
|
||||
@record_ops.append_fields(extra_fields)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn redact_field(key : String, placeholder? : String = "***") -> RecordPatch {
|
||||
fn(rec) {
|
||||
rec.with_fields(
|
||||
rec.fields.map(fn(field) {
|
||||
if field.key == key {
|
||||
field.with_value(placeholder)
|
||||
} else {
|
||||
field
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
@record_ops.redact_field(key, placeholder~)
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -49,26 +31,10 @@ pub fn redact_fields(
|
||||
keys : Array[String],
|
||||
placeholder? : String = "***",
|
||||
) -> RecordPatch {
|
||||
fn(rec) {
|
||||
rec.with_fields(
|
||||
rec.fields.map(fn(field) {
|
||||
if keys.contains(field.key) {
|
||||
field.with_value(placeholder)
|
||||
} else {
|
||||
field
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
@record_ops.redact_fields(keys, placeholder~)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn compose_patches(patches : Array[RecordPatch]) -> RecordPatch {
|
||||
fn(rec) {
|
||||
let mut current = rec
|
||||
for patch in patches {
|
||||
current = patch(current)
|
||||
}
|
||||
current
|
||||
}
|
||||
@record_ops.compose_patches(patches)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user