scoop:scoop.core:0.1.0
src/inspection.scoop
Selected production source · src/inspection.scoop
1
/**2
* Creates a typed observation of a value for structured inspection without defining a3
* serialization format.4
*/5
public interface ValueInspector<T> {6
/**7
* Builds an observation; member and element reads can remain lazy until requested.8
*/9
public fun inspect(value: T): ValueView10
}12
/**13
* Adapts a function returning ValueView to the inspection protocol.14
*/15
public class ValueInspectorFunction<T> public constructor(private val body: (T) -> ValueView)16
: ValueInspector<T> {17
/**18
* Invokes the wrapped inspection function.19
*/20
public override fun inspect(value: T): ValueView = body(value)21
}23
/**24
* A typed observation with an optional reference identity and lazily described shape. It need not25
* be a snapshot of mutable data.26
*/27
public interface ValueView {28
/**29
* The concrete type identity of the observed value.30
*/31
public val type: TypeRef32
/**33
* A managed identity used to recognize repeated references or cycles; value observations34
* normally have None.35
*/36
public val referenceIdentity: Option<Any>37
/**38
* Obtains the structural view of this value.39
*/40
public fun shape(): ValueShape41
}43
/**44
* A function-backed observation whose shape is evaluated on request.45
*/46
public class ValueObservation public constructor(47
/**48
* The concrete type associated with this observation.49
*/50
public override val type: TypeRef,51
/**52
* The reference identity supplied by the inspector, or None for identity-free observations.53
*/54
public override val referenceIdentity: Option<Any>,55
private val describeBody: () -> ValueShape56
) : ValueView {57
/**58
* Evaluates the supplied shape function.59
*/60
public override fun shape(): ValueShape = describeBody()61
}63
/**64
* The observable scalar, record, variant, tuple, sequence, or opaque representation of a value.65
*/66
public enum ValueShape {67
/**68
* One scalar value.69
*/70
Scalar(ScalarValue),71
/**72
* Named record members and an optional base view.73
*/74
Record(RecordView),75
/**76
* The active payload-enum variant.77
*/78
Variant(VariantView),79
/**80
* An integer-backed enum value.81
*/82
IntegerEnum(IntegerEnumView),83
/**84
* Ordered tuple elements.85
*/86
Tuple(TupleView),87
/**88
* An indexed sequence of values.89
*/90
Sequence(SequenceView),91
/**92
* A descriptive value with no exposed internal structure.93
*/94
Opaque(OpaqueValue)95
}97
/**98
* A scalar observation retaining its logical category and numeric representation.99
*/100
public enum ScalarValue {101
/**102
* A logical true or false value.103
*/104
Boolean(Boolean),105
/**106
* A signed integer observed as Long.107
*/108
Signed(Long),109
/**110
* An unsigned integer observed as ULong.111
*/112
Unsigned(ULong),113
/**114
* A binary32 floating-point value.115
*/116
Float(Float),117
/**118
* A binary64 floating-point value.119
*/120
Double(Double),121
/**122
* One Unicode scalar.123
*/124
Char(Char),125
/**126
* An immutable Unicode string.127
*/128
String(String),129
/**130
* The zero-sized Unit value.131
*/132
Unit133
}135
/**136
* Connects an observed member to its declared field or property metadata.137
*/138
public enum ObservedMember {139
/**140
* A stored field observation with field metadata.141
*/142
Field(FieldInfo),143
/**144
* A property observation with its accessor and declaration metadata.145
*/146
Property(PropertyInfo)147
}149
/**150
* Pairs member metadata with a deferred read. Reading may execute a property getter and may fail.151
*/152
public struct MemberView(val info: ObservedMember, val readBody: () -> ValueView) {153
/**154
* Evaluates the member's read function and returns its current observation.155
*/156
public fun read(): ValueView = readBody()157
}159
/**160
* The members of a record plus an optional view of its base subobject.161
*/162
public struct RecordView(val members: Array<MemberView>, val base: Option<ValueView> = None)164
/**165
* The active payload variant and its observable members.166
*/167
public struct VariantView(val info: VariantInfo, val members: Array<MemberView>)169
/**170
* The active integer-backed enum value with its declared variant metadata.171
*/172
public struct IntegerEnumView(val info: IntegerEnumVariantInfo)174
/**175
* An indexed lazy tuple observation with a fixed reported size.176
*/177
public struct TupleView(val size: Long, val elementBody: (Long) -> ValueView) {178
/**179
* Reads the requested zero-based tuple element through the supplied callback.180
*/181
public fun element(index: Long): ValueView = elementBody(index)182
}184
/**185
* An indexed lazy sequence observation. Its size and reads follow the underlying inspector's186
* mutation contract.187
*/188
public struct SequenceView(val size: Long, val elementBody: (Long) -> ValueView) {189
/**190
* Reads the requested zero-based sequence element through the supplied callback.191
*/192
public fun element(index: Long): ValueView = elementBody(index)193
}195
/**196
* A descriptive placeholder for a value whose internals are intentionally not exposed.197
*/198
public struct OpaqueValue(val description: String)200
/**201
* Observes any T as opaque text without exposing fields or reference identity.202
*/203
public class OpaqueInspector<T> public constructor(private val description: String)204
: ValueInspector<T> {205
/**206
* Creates an opaque observation using the configured description.207
*/208
public override fun inspect(value: T): ValueView =209
ValueObservation(typeInfo<T>().type, None, { ValueShape.Opaque(OpaqueValue(description)) })210
}212
/**213
* Observes Unit as a scalar without reference identity.214
*/215
public object UnitInspector : ValueInspector<Unit> {216
/**217
* Returns the Unit scalar observation.218
*/219
public override fun inspect(value: Unit): ValueView =220
ValueObservation(typeInfo<Unit>().type, None, { ValueShape.Scalar(ScalarValue.Unit) })221
}