Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Add Scribe to your `commonMain` dependencies:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.rafambn:scribe:0.1.0")
implementation("com.rafambn:scribe:0.2.3")
}
}
}
Expand Down
1 change: 0 additions & 1 deletion docs/api-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ Note(
```kotlin
SealedScroll(
success = true,
errorMessage = null,
data = mapOf(
"scroll_id" to JsonPrimitive("checkout-42"),
"gateway" to JsonPrimitive("stripe"),
Expand Down
3 changes: 1 addition & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Use the library from shared code in your Kotlin Multiplatform module:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.rafambn:scribe:0.1.0")
implementation("com.rafambn:scribe:0.2.3")
}
}
}
Expand Down Expand Up @@ -78,7 +78,6 @@ The emitted `SealedScroll` shape:
```json
{
"success": true,
"errorMessage": null,
"data": {
"scroll_id": "checkout-42",
"gateway": "stripe",
Expand Down
6 changes: 3 additions & 3 deletions docs/openobserve-showcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The app covers the current public runtime features of Scribe:
- `newScroll(...)` with generated and custom IDs
- direct `Scroll` map writes (`scroll["field"] = ...`)
- map read/remove operations
- `seal(...)` with success and error outcomes
- `seal(...)` with success and failure outcomes
- `Margin`
- `EntrySaver`
- channel overflow behavior via `Channel(..., onBufferOverflow = DROP_OLDEST)`
Expand All @@ -31,7 +31,7 @@ That stream intentionally allows sparse fields. Every uploaded record includes:
- `saver_type`

Notes then contribute fields such as `tag`, `message`, `level`, and `note_timestamp`.
Scrolls contribute `scroll_id`, `success`, `error_message`, and fields from `SealedScroll.data`.
Scrolls contribute `scroll_id`, `success`, and fields from `SealedScroll.data`.

The single-stream design makes it easy to search everything in one place while still filtering by `event_kind`.

Expand Down Expand Up @@ -76,7 +76,7 @@ or:

1. Run `Checkout flow` and inspect the wide-event payload in `scribe_demo`.
2. Run `Map read/remove` to inspect map mutation behavior before sealing.
3. Run `Margins + seal(error)` and verify timing fields plus `success = false`.
3. Run `Margins + seal(failure)` and verify timing fields plus `success = false`.
4. Run `JSON object serialization` to validate nested payload fields in OpenObserve.
5. Run `String template message` to inspect message rendering in the `message` field.
6. Run `EntrySaver mixed flow` to send a note and a scroll through one saver path.
Expand Down
2 changes: 1 addition & 1 deletion scribe/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "com.rafambn"
version = "0.2.2"
version = "0.2.3"

kotlin {
jvm {
Expand Down
1 change: 0 additions & 1 deletion scribe/src/commonMain/kotlin/com/rafambn/scribe/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ sealed interface Entry
@Serializable
data class SealedScroll(
val success: Boolean,
val errorMessage: String?,
val data: Map<String, JsonElement>,
): Entry

Expand Down
8 changes: 2 additions & 6 deletions scribe/src/commonMain/kotlin/com/rafambn/scribe/Scroll.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ val Scroll.id: String
/**
* Seals this scroll and suspends until its [SealedScroll] is enqueued.
*/
suspend fun Scroll.seal(success: Boolean = true, error: Throwable? = null): SealedScroll {
suspend fun Scroll.seal(success: Boolean = true): SealedScroll {
Scribe.config?.margins?.footer(this)
val result = SealedScroll(
success = success,
errorMessage = error?.message,
data = this,
)
val result = SealedScroll(success = success, data = this)
Scribe.enqueue(result)
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@ class ScribeConcurrencyAndScrollTest {
val scroll = scribe.newScroll(id = "scroll-id")

scroll["state"] = JsonPrimitive("initial")
val first = scroll.seal(success = false, error = IllegalStateException("first"))
val second = scroll.seal(success = true, error = null)
val first = scroll.seal(success = false)
val second = scroll.seal(success = true)
shelf.awaitEvents(2)
scribe.retire()

assertEquals(false, first.success)
assertEquals("first", first.errorMessage)
assertEquals(JsonPrimitive("initial"), first.data["state"])

// Current behavior emits one SealedScroll per seal call.
assertEquals(true, second.success)
assertEquals(null, second.errorMessage)
assertEquals(JsonPrimitive("initial"), second.data["state"])
assertEquals(2, shelf.events.size)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ class ScribeScrollLifecycleTest {

scroll["gateway"] = JsonPrimitive("stripe")

scroll.seal(success = false, error = IllegalStateException("fail"))
scroll.seal(success = false)
scroll.seal(success = true)
shelf.awaitEvents(2)
scribe.retire()
val firstEvent = shelf.events.first()
val secondEvent = shelf.events.last()
assertFalse(firstEvent.success)
assertEquals("fail", firstEvent.errorMessage)
assertTrue(secondEvent.success)
assertEquals(JsonPrimitive("stripe"), firstEvent.data["gateway"])
}
Expand Down Expand Up @@ -75,7 +74,6 @@ class ScribeScrollLifecycleTest {
assertNotNull(failureEvent)
assertTrue(successEvent.success)
assertFalse(failureEvent.success)
assertEquals("order2 failed", failureEvent.errorMessage)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal class PaymentService {
scroll["gateway"] = JsonPrimitive("stripe")
} catch (t: Throwable) {
scroll["error_stage"] = JsonPrimitive("gateway_call")
scroll.seal(success = false, error = t)
scroll.seal(success = false)
throw t
}
}
Expand Down
2 changes: 1 addition & 1 deletion testApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The UI contains grouped demo actions:
- `Run second note(...)`
- `Checkout flow`
- `Map read/remove`
- `Margins + seal(error)`
- `Margins + seal(failure)`
- `JSON object serialization`
- `String template message`
- `EntrySaver mixed flow`
Expand Down
2 changes: 1 addition & 1 deletion testApp/shared/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply:
dependencies:
- $compose.foundation: exported
- $compose.material3: exported
- com.rafambn:scribe:0.1.0
- com.rafambn:scribe:0.2.3
- org.jetbrains.kotlinx:kotlinx-datetime:0.7.1

settings:
Expand Down
2 changes: 1 addition & 1 deletion testApp/shared/src/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fun Screen() {
buttons = listOf(
"Checkout flow" to controller::runCheckoutScenario,
"Map read/remove" to controller::runInspectionScenario,
"Margins + seal(error)" to controller::runMarginScenario,
"Margins + seal(failure)" to controller::runMarginScenario,
),
enabled = !state.isBusy,
)
Expand Down
10 changes: 5 additions & 5 deletions testApp/shared/src/ShowcaseController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ class ShowcaseController {
updateStatus("Ran custom-id scroll demo with map reads/removals and local active-scroll tracking.")
}

fun runMarginScenario() = launchScenario("Margin + seal(error) demo") {
fun runMarginScenario() = launchScenario("Margin + seal(failure) demo") {
val scribe = activeMainScribe("margin_scroll") ?: return@launchScenario
val scroll = openScroll(scribe, id = "inventory-sync-1")
scroll["demo_name"] = JsonPrimitive("margin_scroll")
scroll["flow"] = JsonPrimitive("inventory-sync")
scroll["warehouse"] = JsonPrimitive("gru-1")
scroll["cache_hit"] = JsonPrimitive(false)
scroll["failure_reason"] = JsonPrimitive("downstream retry scheduled")
sealScroll(
scroll,
success = false,
error = IllegalStateException("downstream retry scheduled"),
)
delay(250)
updateStatus("Ran Margin header/footer hooks with seal(success = false, error = ...).")
updateStatus("Ran Margin header/footer hooks with seal(success = false).")
}

fun runJsonSerializationScenario() = launchScenario("JSON serialization scroll demo") {
Expand Down Expand Up @@ -535,8 +535,8 @@ class ShowcaseController {
return scroll
}

private suspend fun sealScroll(scroll: Scroll, success: Boolean, error: Throwable? = null) {
scroll.seal(success = success, error = error)
private suspend fun sealScroll(scroll: Scroll, success: Boolean) {
scroll.seal(success = success)
activeScrolls.remove(scroll.id)
refreshActiveScrolls()
}
Expand Down
1 change: 0 additions & 1 deletion testApp/shared/src/ShowcaseModels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ fun payloadFromEntry(
payload["saver_type"] = JsonPrimitive(saverType)
payload["scroll_id"] = JsonPrimitive(stringField(entry.data, "scroll_id") ?: "missing-scroll-id")
payload["success"] = JsonPrimitive(entry.success)
entry.errorMessage?.let { payload["error_message"] = JsonPrimitive(it) }
stringField(entry.data, "message")?.let { payload["message"] = JsonPrimitive(it) }
entry.data["order_id"]?.let { payload["order_id"] = it }
?: entry.data["ordemId"]?.let { payload["order_id"] = it }
Expand Down
Loading