mirror of
https://github.com/Effect-TS/effect.git
synced 2026-12-04 03:35:36 +08:00
Type Atom.Serializable encode/decode as Schema.Json (#8763)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Tim Smart <hello@timsmart.co>
This commit is contained in:
committed by
effect-bot
co-authored by
Claude Opus 5.5
Tim Smart
parent
2edc9c2915
commit
04a3e070c1
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"effect": minor
|
||||
---
|
||||
|
||||
Fix `Atom.Serializable` to encode to and decode from `Schema.Json`, matching the JSON codec used by `Atom.serializable`. Encoded results may now require narrowing; runtime behavior is unchanged.
|
||||
@@ -2622,7 +2622,8 @@ export type SerializableTypeId = "~effect-atom/atom/Atom/Serializable"
|
||||
* **Details**
|
||||
*
|
||||
* The key identifies the atom in dehydrated state, and the encode/decode
|
||||
* functions convert between the atom value and its JSON encoding.
|
||||
* functions convert between the atom value and its JSON representation, as
|
||||
* produced by the schema's JSON codec (`Schema.toCodecJson`).
|
||||
*
|
||||
* @stability unstable
|
||||
* @category models
|
||||
|
||||
@@ -474,7 +474,7 @@ class RegistryImpl implements AtomRegistry {
|
||||
this.removeNodeTimeout(node)
|
||||
}
|
||||
if (typeof key === "string" && this.preloadedSerializable.has(key)) {
|
||||
const encoded = this.preloadedSerializable.get(key)
|
||||
const encoded = this.preloadedSerializable.get(key) as Schema.Json
|
||||
this.preloadedSerializable.delete(key)
|
||||
const serializable = (atom as any as Atom.Serializable<any>)[SerializableTypeId]
|
||||
let decoded: A
|
||||
|
||||
@@ -67,4 +67,14 @@ describe("Atom", () => {
|
||||
expect(runtime.fn).type.toBeCallableWith(() => Effect.void, { reactivityKeys: keys })
|
||||
})
|
||||
})
|
||||
|
||||
describe("serializable", () => {
|
||||
it("encodes to and decodes from the JSON representation", () => {
|
||||
const atom = Atom.serializable(Atom.make(1n), { key: "bigint", schema: Schema.BigInt })
|
||||
const serializable = atom[Atom.SerializableTypeId]
|
||||
|
||||
expect(serializable.encode).type.toBe<(value: bigint) => Schema.Json>()
|
||||
expect(serializable.decode).type.toBe<(value: Schema.Json) => bigint>()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user