(value: unknown)
| 45 | } |
| 46 | |
| 47 | function toPlain(value: unknown): JsonValue | undefined { |
| 48 | if (value instanceof Y.Map) { |
| 49 | const result: JsonRecord = {} |
| 50 | value.forEach((nested: unknown, key: string) => { |
| 51 | const converted = toPlain(nested) |
| 52 | if (converted !== undefined) result[key] = converted |
| 53 | }) |
| 54 | return result |
| 55 | } |
| 56 | |
| 57 | if (value instanceof Y.Array) { |
| 58 | return value.toArray().map(toPlain).filter((nested): nested is JsonValue => nested !== undefined) |
| 59 | } |
| 60 | |
| 61 | if (value === null || typeof value === "string" || typeof value === "boolean") return value |
| 62 | if (typeof value === "number") return Number.isFinite(value) ? value : undefined |
| 63 | |
| 64 | if (Array.isArray(value)) { |
| 65 | return value.map(toPlain).filter((nested): nested is JsonValue => nested !== undefined) |
| 66 | } |
| 67 | |
| 68 | if (isRecord(value)) { |
| 69 | const result: JsonRecord = {} |
| 70 | for (const [key, nested] of Object.entries(value)) { |
| 71 | const converted = toPlain(nested) |
| 72 | if (converted !== undefined) result[key] = converted |
| 73 | } |
| 74 | return result |
| 75 | } |
| 76 | |
| 77 | return undefined |
| 78 | } |
| 79 | |
| 80 | function applyYjsUpdate(data: Uint8Array): Y.Doc { |
| 81 | const doc = new Y.Doc() |
no test coverage detected